@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.
Files changed (94) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/antd.esm.js +5118 -4965
  3. package/dist/antd.esm.js.map +1 -1
  4. package/dist/form/Form.d.ts +72 -0
  5. package/dist/form/FormGroup.d.ts +6 -0
  6. package/dist/form/FormItem.d.ts +33 -0
  7. package/dist/form/FormList.d.ts +5 -0
  8. package/dist/form/SchemaForm.d.ts +9 -0
  9. package/dist/form/contexts.d.ts +40 -0
  10. package/dist/form/registerForm.d.ts +9 -0
  11. package/dist/form/registerFormGroup.d.ts +2 -0
  12. package/dist/form/registerFormItem.d.ts +2 -0
  13. package/dist/form/registerFormList.d.ts +2 -0
  14. package/dist/form/sharedRegistration.d.ts +14 -0
  15. package/dist/index.d.ts +6 -4
  16. package/dist/index.js +5136 -4972
  17. package/dist/index.js.map +1 -1
  18. package/dist/names.d.ts +18 -0
  19. package/dist/registerButton.d.ts +1 -2
  20. package/dist/registerCheckbox.d.ts +0 -2
  21. package/dist/registerInput.d.ts +0 -4
  22. package/dist/registerRadio.d.ts +0 -3
  23. package/dist/registerSelect.d.ts +0 -3
  24. package/dist/registerSwitch.d.ts +0 -1
  25. package/package.json +5 -5
  26. package/skinny/Form.cjs.js +268 -0
  27. package/skinny/Form.cjs.js.map +1 -0
  28. package/skinny/Form.esm.js +256 -0
  29. package/skinny/Form.esm.js.map +1 -0
  30. package/skinny/FormGroup.cjs.js +26 -0
  31. package/skinny/FormGroup.cjs.js.map +1 -0
  32. package/skinny/FormGroup.esm.js +20 -0
  33. package/skinny/FormGroup.esm.js.map +1 -0
  34. package/skinny/FormItem.cjs.js +290 -0
  35. package/skinny/FormItem.cjs.js.map +1 -0
  36. package/skinny/FormItem.esm.js +284 -0
  37. package/skinny/FormItem.esm.js.map +1 -0
  38. package/skinny/FormList.cjs.js +98 -0
  39. package/skinny/FormList.cjs.js.map +1 -0
  40. package/skinny/FormList.esm.js +92 -0
  41. package/skinny/FormList.esm.js.map +1 -0
  42. package/skinny/SchemaForm.cjs.js +199 -0
  43. package/skinny/SchemaForm.cjs.js.map +1 -0
  44. package/skinny/SchemaForm.esm.js +191 -0
  45. package/skinny/SchemaForm.esm.js.map +1 -0
  46. package/skinny/contexts-4c7952c1.esm.js +20 -0
  47. package/skinny/contexts-4c7952c1.esm.js.map +1 -0
  48. package/skinny/contexts-a2387bed.cjs.js +31 -0
  49. package/skinny/contexts-a2387bed.cjs.js.map +1 -0
  50. package/skinny/names-3aea627b.cjs.js +34 -0
  51. package/skinny/names-3aea627b.cjs.js.map +1 -0
  52. package/skinny/names-73583568.esm.js +18 -0
  53. package/skinny/names-73583568.esm.js.map +1 -0
  54. package/skinny/names.d.ts +18 -0
  55. package/skinny/registerButton.cjs.js +3 -4
  56. package/skinny/registerButton.cjs.js.map +1 -1
  57. package/skinny/registerButton.d.ts +1 -2
  58. package/skinny/registerButton.esm.js +3 -3
  59. package/skinny/registerButton.esm.js.map +1 -1
  60. package/skinny/registerCheckbox.cjs.js +5 -8
  61. package/skinny/registerCheckbox.cjs.js.map +1 -1
  62. package/skinny/registerCheckbox.d.ts +0 -2
  63. package/skinny/registerCheckbox.esm.js +2 -3
  64. package/skinny/registerCheckbox.esm.js.map +1 -1
  65. package/skinny/registerForm.cjs.js +460 -1387
  66. package/skinny/registerForm.cjs.js.map +1 -1
  67. package/skinny/registerForm.esm.js +460 -1375
  68. package/skinny/registerForm.esm.js.map +1 -1
  69. package/skinny/registerInput.cjs.js +8 -15
  70. package/skinny/registerInput.cjs.js.map +1 -1
  71. package/skinny/registerInput.d.ts +0 -4
  72. package/skinny/registerInput.esm.js +2 -5
  73. package/skinny/registerInput.esm.js.map +1 -1
  74. package/skinny/registerRadio.cjs.js +6 -11
  75. package/skinny/registerRadio.cjs.js.map +1 -1
  76. package/skinny/registerRadio.d.ts +0 -3
  77. package/skinny/registerRadio.esm.js +2 -4
  78. package/skinny/registerRadio.esm.js.map +1 -1
  79. package/skinny/registerSelect.cjs.js +7 -12
  80. package/skinny/registerSelect.cjs.js.map +1 -1
  81. package/skinny/registerSelect.d.ts +0 -3
  82. package/skinny/registerSelect.esm.js +2 -4
  83. package/skinny/registerSelect.esm.js.map +1 -1
  84. package/skinny/registerSwitch.cjs.js +2 -3
  85. package/skinny/registerSwitch.cjs.js.map +1 -1
  86. package/skinny/registerSwitch.d.ts +0 -1
  87. package/skinny/registerSwitch.esm.js +2 -2
  88. package/skinny/registerSwitch.esm.js.map +1 -1
  89. package/skinny/registerUpload.cjs.js +10 -6
  90. package/skinny/registerUpload.cjs.js.map +1 -1
  91. package/skinny/registerUpload.esm.js +10 -6
  92. package/skinny/registerUpload.esm.js.map +1 -1
  93. package/dist/registerForm.d.ts +0 -143
  94. package/skinny/registerForm.d.ts +0 -143
@@ -1,400 +1,65 @@
1
1
  'use strict';
2
2
 
3
- var dataSources = require('@plasmicapp/data-sources');
4
- var host = require('@plasmicapp/host');
3
+ var names = require('./names-3aea627b.cjs.js');
4
+ var utils = require('./utils-174b9d45.cjs.js');
5
+ var Form = require('./Form.cjs.js');
6
+ var SchemaForm = require('./SchemaForm.cjs.js');
5
7
  var antd = require('antd');
6
- var equal = require('fast-deep-equal');
7
8
  var React = require('react');
8
- var reactUtils = require('./react-utils-11b0221a.cjs.js');
9
- var registerButton = require('./registerButton.cjs.js');
10
9
  var registerCheckbox = require('./registerCheckbox.cjs.js');
11
10
  var registerDatePicker = require('./registerDatePicker.cjs.js');
12
- var registerInput = require('./registerInput.cjs.js');
13
11
  var registerRadio = require('./registerRadio.cjs.js');
14
12
  var registerSelect = require('./registerSelect.cjs.js');
15
- var registerSwitch = require('./registerSwitch.cjs.js');
16
- var utils = require('./utils-174b9d45.cjs.js');
17
- require('classnames');
18
- require('dayjs');
13
+ var FormGroup = require('./FormGroup.cjs.js');
14
+ var FormItem = require('./FormItem.cjs.js');
15
+ var FormList = require('./FormList.cjs.js');
19
16
  require('@plasmicapp/host/registerComponent');
20
17
  require('@plasmicapp/host/registerGlobalContext');
18
+ require('fast-deep-equal');
19
+ require('./contexts-a2387bed.cjs.js');
20
+ require('@plasmicapp/data-sources');
21
+ require('dayjs');
22
+ require('./react-utils-11b0221a.cjs.js');
23
+ require('classnames');
24
+ require('@plasmicapp/host');
21
25
 
22
26
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
27
 
24
- var equal__default = /*#__PURE__*/_interopDefault(equal);
25
28
  var React__default = /*#__PURE__*/_interopDefault(React);
26
29
 
27
- var __defProp = Object.defineProperty;
28
- var __defProps = Object.defineProperties;
29
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
30
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
31
- var __hasOwnProp = Object.prototype.hasOwnProperty;
32
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
33
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
34
- var __spreadValues = (a, b) => {
30
+ var __defProp$1 = Object.defineProperty;
31
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
32
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
33
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
34
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
35
+ var __spreadValues$1 = (a, b) => {
35
36
  for (var prop in b || (b = {}))
36
- if (__hasOwnProp.call(b, prop))
37
- __defNormalProp(a, prop, b[prop]);
38
- if (__getOwnPropSymbols)
39
- for (var prop of __getOwnPropSymbols(b)) {
40
- if (__propIsEnum.call(b, prop))
41
- __defNormalProp(a, prop, b[prop]);
37
+ if (__hasOwnProp$1.call(b, prop))
38
+ __defNormalProp$1(a, prop, b[prop]);
39
+ if (__getOwnPropSymbols$1)
40
+ for (var prop of __getOwnPropSymbols$1(b)) {
41
+ if (__propIsEnum$1.call(b, prop))
42
+ __defNormalProp$1(a, prop, b[prop]);
42
43
  }
43
44
  return a;
44
45
  };
45
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
46
- var __objRest = (source, exclude) => {
47
- var target = {};
48
- for (var prop in source)
49
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
50
- target[prop] = source[prop];
51
- if (source != null && __getOwnPropSymbols)
52
- for (var prop of __getOwnPropSymbols(source)) {
53
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
54
- target[prop] = source[prop];
55
- }
56
- return target;
57
- };
58
- const FormItem = antd.Form.Item;
59
- const FormList = antd.Form.List;
60
- var InputType = /* @__PURE__ */ ((InputType2) => {
61
- InputType2["Text"] = "Text";
62
- InputType2["TextArea"] = "Text Area";
63
- InputType2["Password"] = "Password";
64
- InputType2["Number"] = "Number";
65
- InputType2["Select"] = "Select";
66
- InputType2["Option"] = "Option";
67
- InputType2["OptionGroup"] = "Option Group";
68
- InputType2["Radio"] = "Radio";
69
- InputType2["RadioGroup"] = "Radio Group";
70
- InputType2["Checkbox"] = "Checkbox";
71
- InputType2["DatePicker"] = "DatePicker";
72
- InputType2["Unknown"] = "Unkown";
73
- return InputType2;
74
- })(InputType || {});
75
- var FormType = /* @__PURE__ */ ((FormType2) => {
76
- FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
77
- FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
78
- return FormType2;
79
- })(FormType || {});
80
- const PathContext = React__default.default.createContext({ relativePath: [], fullPath: [] });
81
- const InternalFormInstanceContext = React__default.default.createContext(void 0);
82
- const FormLayoutContext = React__default.default.createContext(void 0);
83
- const Internal = React__default.default.forwardRef(
84
- (props, ref) => {
85
- var _b, _c, _d, _e;
86
- const [form] = antd.Form.useForm();
87
- const values = form.getFieldsValue(true);
88
- const lastValue = React__default.default.useRef(values);
89
- const _a = props, {
90
- extendedOnValuesChange,
91
- forceRemount,
92
- formLayout,
93
- internalFieldCtx,
94
- setInternalFieldCtx
95
- } = _a, rest = __objRest(_a, [
96
- "extendedOnValuesChange",
97
- "forceRemount",
98
- "formLayout",
99
- "internalFieldCtx",
100
- "setInternalFieldCtx"
101
- ]);
102
- let childrenNode;
103
- if (props.mode !== "simplified") {
104
- childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
105
- } else {
106
- childrenNode = /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, ((_b = props.formItems) != null ? _b : []).map((formItem) => {
107
- var _a2, _b2, _c2;
108
- return /* @__PURE__ */ React__default.default.createElement(
109
- utils.ErrorBoundary,
110
- {
111
- canvasEnvId: props["data-plasmic-canvas-envs"],
112
- message: `Error rendering input for ${(_b2 = (_a2 = formItem.label) != null ? _a2 : formItem.name) != null ? _b2 : "undefined"}`
113
- },
114
- /* @__PURE__ */ React__default.default.createElement(
115
- FormItemWrapper,
116
- __spreadProps(__spreadValues({}, utils.omit(formItem, "key")), {
117
- noLabel: formItem.inputType === "Checkbox" /* Checkbox */ || formItem.noLabel,
118
- valuePropName: (_c2 = formItem.valuePropName) != null ? _c2 : formItem.inputType === "Checkbox" /* Checkbox */ ? "checked" : void 0,
119
- style: { width: "100%" }
120
- }),
121
- formItem.inputType === "Text" /* Text */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input, null) : formItem.inputType === "Password" /* Password */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input.Password, null) : formItem.inputType === "Text Area" /* TextArea */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input.TextArea, null) : formItem.inputType === "Number" /* Number */ ? /* @__PURE__ */ React__default.default.createElement(antd.InputNumber, null) : formItem.inputType === "Checkbox" /* Checkbox */ ? /* @__PURE__ */ React__default.default.createElement(registerCheckbox.AntdCheckbox, null, formItem.label) : formItem.inputType === "Select" /* Select */ ? /* @__PURE__ */ React__default.default.createElement(registerSelect.AntdSelect, { options: formItem.options }) : formItem.inputType === "DatePicker" /* DatePicker */ ? /* @__PURE__ */ React__default.default.createElement(registerDatePicker.AntdDatePicker, { showTime: formItem.showTime }) : formItem.inputType === "Radio Group" /* RadioGroup */ ? /* @__PURE__ */ React__default.default.createElement(
122
- registerRadio.AntdRadioGroup,
123
- {
124
- options: formItem.options,
125
- optionType: formItem.optionType,
126
- style: { padding: "8px" }
127
- }
128
- ) : null
129
- )
130
- );
131
- }), props.submitSlot);
132
- }
133
- const fireOnValuesChange = React__default.default.useCallback(() => {
134
- const values2 = form.getFieldsValue(true);
135
- if (!equal__default.default(values2, lastValue.current)) {
136
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
137
- lastValue.current = values2;
138
- }
139
- }, [form, lastValue]);
140
- React__default.default.useEffect(() => {
141
- fireOnValuesChange();
142
- }, []);
143
- React__default.default.useImperativeHandle(ref, () => ({
144
- formInstance: form,
145
- setFieldsValue: (newValues) => {
146
- form.setFieldsValue(newValues);
147
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
148
- },
149
- setFieldValue: (namePath, value) => {
150
- form.setFieldValue(namePath, value);
151
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
152
- },
153
- resetFields: () => {
154
- form.resetFields();
155
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
156
- },
157
- validateFields: async (...args) => {
158
- try {
159
- return await form.validateFields(...args);
160
- } catch (err) {
161
- return err;
162
- }
163
- },
164
- clearFields: () => {
165
- const values2 = form.getFieldsValue(true);
166
- utils.setFieldsToUndefined(values2);
167
- form.setFieldsValue(values2);
168
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
169
- }
170
- }));
171
- const registerField = React__default.default.useCallback(
172
- (fieldEntity) => {
173
- setInternalFieldCtx((ctx) => ({
174
- registeredFields: [...ctx.registeredFields, fieldEntity],
175
- preservedRegisteredFields: [
176
- ...ctx.preservedRegisteredFields,
177
- fieldEntity
178
- ]
179
- }));
180
- return () => {
181
- setInternalFieldCtx((ctx) => ({
182
- registeredFields: ctx.registeredFields.filter(
183
- (ent) => ent !== fieldEntity
184
- ),
185
- preservedRegisteredFields: ctx.preservedRegisteredFields.filter(
186
- (ent) => ent !== fieldEntity || fieldEntity.preserve
187
- )
188
- }));
189
- };
190
- },
191
- [setInternalFieldCtx]
192
- );
193
- return /* @__PURE__ */ React__default.default.createElement(
194
- InternalFormInstanceContext.Provider,
195
- {
196
- value: {
197
- layout: formLayout,
198
- fireOnValuesChange,
199
- forceRemount,
200
- registerField,
201
- internalFieldCtx,
202
- initialValues: (_c = props.initialValues) != null ? _c : {}
203
- }
204
- },
205
- /* @__PURE__ */ React__default.default.createElement(FormLayoutContext.Provider, { value: formLayout }, /* @__PURE__ */ React__default.default.createElement(
206
- antd.Form,
207
- __spreadProps(__spreadValues({}, rest), {
208
- key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
209
- onValuesChange: (...args) => {
210
- var _a2;
211
- (_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
212
- extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
213
- },
214
- onFinish: () => {
215
- var _a2;
216
- (_a2 = props.onFinish) == null ? void 0 : _a2.call(
217
- props,
218
- utils.pick(
219
- form.getFieldsValue(true),
220
- ...internalFieldCtx.preservedRegisteredFields.map(
221
- (field) => field.fullPath
222
- )
223
- )
224
- );
225
- },
226
- form,
227
- labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
228
- wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
229
- }),
230
- /* @__PURE__ */ React__default.default.createElement("style", null, `
231
- .ant-form-item-explain + div, .ant-form-item-margin-offset {
232
- display: none;
233
- }
234
- `),
235
- childrenNode
236
- ))
237
- );
238
- }
239
- );
240
- function deriveFormFieldConfigs(dataFormItems, schema, data) {
241
- return dataSources.deriveFieldConfigs(
242
- dataFormItems,
243
- schema,
244
- (field) => {
245
- var _a;
246
- return __spreadValues({
247
- inputType: "Text" /* Text */
248
- }, field && {
249
- key: field.id,
250
- fieldId: field.id,
251
- label: (_a = field.label) != null ? _a : field.id,
252
- name: field.id,
253
- inputType: field.type === "string" ? "Text" /* Text */ : field.type === "number" ? "Number" /* Number */ : field.type === "boolean" ? "Checkbox" /* Checkbox */ : "Text" /* Text */,
254
- //missing date and date-time
255
- initialValue: data ? data[field.id] : void 0
256
- });
257
- }
258
- );
259
- }
260
- function useFormItemDefinitions(rawData, props, formRef, commonFormCtxData) {
261
- const { mode, dataFormItems, setControlContextData } = props;
262
- const formInstance = formRef == null ? void 0 : formRef.formInstance;
263
- return React__default.default.useMemo(() => {
264
- const data = rawData && dataSources.normalizeData(rawData);
265
- const schema = data && (data == null ? void 0 : data.schema);
266
- if (mode !== "simplified" || !rawData || rawData.isLoading || rawData.error || !data || !schema || !data.data) {
267
- setControlContextData == null ? void 0 : setControlContextData(__spreadValues({
268
- formInstance
269
- }, commonFormCtxData));
270
- return void 0;
271
- }
272
- const row = data.data.length > 0 ? data.data[0] : void 0;
273
- const { mergedFields, minimalFullLengthFields } = deriveFormFieldConfigs(
274
- dataFormItems != null ? dataFormItems : [],
275
- schema,
276
- row
277
- );
278
- setControlContextData == null ? void 0 : setControlContextData(__spreadValues({
279
- schema: data.schema,
280
- minimalFullLengthFields,
281
- mergedFields,
282
- formInstance
283
- }, commonFormCtxData));
284
- return mergedFields;
285
- }, [
286
- mode,
287
- setControlContextData,
288
- dataFormItems,
289
- rawData,
290
- formInstance,
291
- commonFormCtxData
292
- ]);
293
- }
294
- const useRawData = (props) => {
295
- const rawData = dataSources.usePlasmicDataOp(props.data);
296
- return props.data ? rawData : void 0;
297
- };
298
- const FormWrapper = React__default.default.forwardRef(
299
- (props, ref) => {
300
- var _a;
301
- const [remountKey, setRemountKey] = React__default.default.useState(0);
302
- const forceRemount = React__default.default.useCallback(
303
- () => setRemountKey((k) => k + 1),
304
- [setRemountKey]
305
- );
306
- const previousInitialValues = utils.usePrevious(props.initialValues);
307
- const wrapperRef = React__default.default.useRef(null);
308
- React__default.default.useEffect(() => {
309
- if (previousInitialValues !== props.initialValues && JSON.stringify(previousInitialValues) !== JSON.stringify(props.initialValues)) {
310
- forceRemount();
311
- }
312
- }, [previousInitialValues, props.initialValues]);
313
- const [internalFieldCtx, setInternalFieldCtx] = React__default.default.useState({
314
- registeredFields: [],
315
- preservedRegisteredFields: []
316
- });
317
- React__default.default.useImperativeHandle(
318
- ref,
319
- () => wrapperRef.current ? __spreadValues({}, wrapperRef.current) : {}
320
- );
321
- const formLayout = React__default.default.useMemo(
322
- () => {
323
- var _a2;
324
- return {
325
- layout: props.layout,
326
- labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
327
- };
328
- },
329
- [props.layout, (_a = props.labelCol) == null ? void 0 : _a.span]
330
- );
331
- const commonFormCtxData = React__default.default.useMemo(
332
- () => ({
333
- layout: formLayout,
334
- internalFieldCtx
335
- }),
336
- [formLayout, internalFieldCtx]
337
- );
338
- const rawData = useRawData(props);
339
- const formItemDefinitions = useFormItemDefinitions(
340
- rawData,
341
- props,
342
- wrapperRef.current,
343
- commonFormCtxData
344
- );
345
- React__default.default.useEffect(() => {
346
- if (rawData && !rawData.isLoading) {
347
- forceRemount();
348
- }
349
- }, [rawData]);
350
- const previousDataOp = utils.usePrevious(props.data);
351
- React__default.default.useEffect(() => {
352
- if (previousDataOp == null && props.data != null || previousDataOp != null && props.data == null) {
353
- forceRemount();
354
- }
355
- }, [props.data]);
356
- const _b = props, { dataFormItems, formItems, data } = _b, rest = __objRest(_b, ["dataFormItems", "formItems", "data"]);
357
- const actualFormItems = props.mode === "simplified" && formItemDefinitions ? formItemDefinitions : data ? dataFormItems : formItems;
358
- const previousFormItems = React__default.default.useRef([]);
359
- React__default.default.useEffect(() => {
360
- if (!(rawData && rawData.isLoading)) {
361
- previousFormItems.current = actualFormItems != null ? actualFormItems : [];
362
- }
363
- }, [rawData, actualFormItems]);
364
- if (props.mode === "simplified" && rawData && "error" in rawData) {
365
- return /* @__PURE__ */ React__default.default.createElement("div", null, "Error when fetching data: ", rawData.error.message);
366
- }
367
- const isSchemaForm = props.mode === "simplified" && !!props.data;
368
- const isLoadingData = rawData == null ? void 0 : rawData.isLoading;
369
- return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement(
370
- Internal,
371
- __spreadProps(__spreadValues({
372
- key: remountKey
373
- }, rest), {
374
- forceRemount,
375
- formLayout,
376
- internalFieldCtx,
377
- setInternalFieldCtx,
378
- formItems: rawData && rawData.isLoading ? previousFormItems.current : actualFormItems,
379
- ref: wrapperRef,
380
- style: isSchemaForm && isLoadingData ? {
381
- opacity: 0.5,
382
- transitionDelay: "250ms",
383
- transition: "1s"
384
- } : {}
385
- })
386
- ), isSchemaForm && isLoadingData && /* @__PURE__ */ React__default.default.createElement(
387
- "div",
388
- {
389
- style: {
390
- position: "absolute",
391
- width: "100%",
392
- height: "100%"
393
- }
394
- }
395
- ));
396
- }
397
- );
46
+ const mapAntdComponentToInputType = /* @__PURE__ */ new Map([
47
+ [antd.Input, Form.InputType.Text],
48
+ [antd.Input.TextArea, Form.InputType.TextArea],
49
+ [antd.Input.Password, Form.InputType.Password],
50
+ [antd.InputNumber, Form.InputType.Number],
51
+ [registerSelect.AntdSelect, Form.InputType.Select],
52
+ [registerRadio.AntdRadioGroup, Form.InputType.RadioGroup],
53
+ [antd.Radio, Form.InputType.Radio],
54
+ [registerDatePicker.AntdDatePicker, Form.InputType.DatePicker],
55
+ [registerCheckbox.AntdCheckbox, Form.InputType.Checkbox]
56
+ ]);
57
+ const mapPlumeTypeToInputType = /* @__PURE__ */ new Map([
58
+ ["text-input", Form.InputType.Text],
59
+ ["select", Form.InputType.Select],
60
+ ["checkbox", Form.InputType.Checkbox],
61
+ ["switch", Form.InputType.Checkbox]
62
+ ]);
398
63
  const COMMON_ACTIONS = [
399
64
  {
400
65
  type: "button-action",
@@ -437,709 +102,99 @@ const COMMON_ACTIONS = [
437
102
  // },
438
103
  // },
439
104
  ];
440
- const colProp = (displayName, defaultValue, description) => ({
441
- type: "object",
442
- displayName,
443
- advanced: true,
444
- fields: {
445
- span: {
446
- type: "number",
447
- displayName: "Width",
448
- description: "The number of grid columns to span in width (out of 24 columns total)",
449
- min: 1,
450
- max: 24
451
- },
452
- offset: {
453
- type: "number",
454
- displayName: "Offset",
455
- description: "Number of grid columns to skip from the left (out of 24 columns total)",
456
- min: 0,
457
- max: 23
458
- },
459
- horizontalOnly: {
460
- type: "boolean",
461
- displayName: "Horizontal only",
462
- description: "Only apply when form layout is horizontal"
105
+ function getDefaultValueHint(field) {
106
+ return (_props, contextData, { item }) => {
107
+ var _a;
108
+ if (!contextData || !("mergedFields" in contextData)) {
109
+ return void 0;
463
110
  }
464
- },
465
- nameFunc: () => `Edit ${displayName}`,
466
- description,
467
- defaultValue
468
- });
469
- const formHelpers = {
470
- states: {
471
- value: {
472
- onMutate: (value, $ref) => {
473
- var _a;
474
- (_a = $ref == null ? void 0 : $ref.formInstance) == null ? void 0 : _a.setFieldsValue(value);
475
- }
111
+ if (item == null ? void 0 : item.fieldId) {
112
+ const fieldSetting = (_a = contextData.mergedFields) == null ? void 0 : _a.find(
113
+ (f) => f.fieldId === item.fieldId
114
+ );
115
+ return fieldSetting == null ? void 0 : fieldSetting[field];
476
116
  }
477
- }
478
- };
479
- const formComponentName = "plasmic-antd5-form";
480
- const formTypeDescription = `
481
- You can create form with two different behaviors:
482
-
483
-
484
-
485
- 1. Create a new entry: The form will be created empty and it will create a new row when submitted.
486
- 2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
487
-
488
-
489
-
490
- For both options, you can customize later.
491
- `;
492
- function registerForm(loader) {
493
- utils.registerComponentHelper(loader, FormWrapper, {
494
- name: formComponentName,
495
- displayName: "Form",
496
- description: "[Learn how to use forms](https://docs.plasmic.app/learn/forms/)",
497
- defaultStyles: {
498
- layout: "vbox",
499
- alignItems: "flex-start"
500
- },
501
- props: {
502
- mode: {
503
- type: "controlMode",
504
- defaultValue: "simplified"
505
- },
506
- data: {
507
- type: "formDataConnection",
508
- disableDynamicValue: true,
509
- disableLinkToProp: true,
510
- hidden: (ps) => ps.mode !== "simplified" || !ps.data
511
- },
512
- formItems: {
513
- displayName: "Fields",
514
- type: "array",
515
- itemType: commonSimplifiedFormArrayItemType("formItems"),
516
- defaultValue: [
517
- {
518
- label: "Name",
519
- name: "name",
520
- inputType: "Text" /* Text */
521
- },
522
- {
523
- label: "Message",
524
- name: "message",
525
- inputType: "Text Area" /* TextArea */
526
- }
527
- ],
528
- hidden: (ps) => {
529
- if (ps.mode === "advanced") {
530
- return true;
531
- }
532
- return !!ps.data;
117
+ return void 0;
118
+ };
119
+ }
120
+ function commonFormItemProps(usage) {
121
+ const getFormItemProps = (ps, _ctx, { item }) => {
122
+ if (usage === "simplified-form-item") {
123
+ return item;
124
+ } else {
125
+ return ps;
126
+ }
127
+ };
128
+ return {
129
+ name: {
130
+ type: "string",
131
+ required: true,
132
+ displayName: "Field key",
133
+ description: "Key name for this field value in the submitted form data.",
134
+ validator: (value, _ps, ctx) => {
135
+ var _a, _b, _c;
136
+ let currFullPath = [];
137
+ if (usage === "simplified-form-item") {
138
+ currFullPath = [value];
139
+ } else {
140
+ const formItemCtx = ctx;
141
+ currFullPath = [...(_a = formItemCtx == null ? void 0 : formItemCtx.parentFormItemPath) != null ? _a : [], value];
533
142
  }
143
+ const nameCounter = ((_c = (_b = ctx == null ? void 0 : ctx.internalFieldCtx) == null ? void 0 : _b.registeredFields) != null ? _c : []).filter((formItem) => utils.arrayEq(formItem.fullPath, currFullPath)).length;
144
+ return nameCounter === 1 ? true : `Repeated form field key: ${currFullPath.join(" \u2192 ")}`;
534
145
  },
535
- /**
536
- * dataFormItems are used to expand the form items from schema forms.
537
- * We can't use the formItems prop because it has a default value. Therefore, if we unset the formItems prop,
538
- * we would end up with the default value of formItems + schema form items.
539
- * Ideally, we would need to support dynamic default value.
540
- */
541
- dataFormItems: {
542
- displayName: "Data Fields",
543
- type: "array",
544
- itemType: commonSimplifiedFormArrayItemType("dataFormItems"),
545
- hidden: (ps) => {
546
- if (ps.mode === "advanced") {
547
- return true;
548
- }
549
- return !ps.data;
550
- },
551
- unstable__keyFunc: (x) => x.key,
552
- unstable__minimalValue: (ps, contextData) => {
553
- return ps.data ? contextData == null ? void 0 : contextData.minimalFullLengthFields : void 0;
554
- },
555
- unstable__canDelete: (item, ps, ctx) => {
556
- if (ps.mode !== "simplified") {
557
- return true;
558
- }
559
- if (!(ctx == null ? void 0 : ctx.schema)) {
560
- return false;
561
- }
562
- if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
563
- return false;
146
+ defaultValueHint: getDefaultValueHint("name")
147
+ },
148
+ initialValue: {
149
+ type: "dynamic",
150
+ control: (ps, ctx, {
151
+ item,
152
+ path
153
+ }) => {
154
+ var _a, _b, _c, _d;
155
+ let inputType = Form.InputType.Unknown;
156
+ if (usage === "simplified-form-item") {
157
+ inputType = item.inputType;
158
+ if (!ps.data) {
159
+ inputType = item.inputType;
160
+ } else if (path != null && typeof path[1] === "number") {
161
+ inputType = (_b = (_a = ctx == null ? void 0 : ctx.mergedFields) == null ? void 0 : _a[path[1]].inputType) != null ? _b : Form.InputType.Unknown;
564
162
  }
565
- return true;
566
- }
567
- },
568
- submitSlot: __spreadValues({
569
- type: "slot",
570
- hidden: () => true,
571
- defaultValue: {
572
- type: "component",
573
- name: registerButton.buttonComponentName,
574
- props: {
575
- type: "primary",
576
- submitsForm: true,
577
- children: {
578
- type: "text",
579
- value: "Submit"
580
- }
581
- }
582
- }
583
- }, {
584
- mergeWithParent: () => true,
585
- hiddenMergedProps: (ps) => !ps.mode
586
- }),
587
- children: {
588
- type: "slot",
589
- hidden: (props) => props.mode !== "advanced"
590
- },
591
- initialValues: {
592
- displayName: "Initial field values",
593
- type: "object"
594
- },
595
- layout: {
596
- displayName: "Form layout",
597
- type: "choice",
598
- options: ["horizontal", "vertical", "inline"],
599
- defaultValue: "vertical"
600
- },
601
- labelAlign: {
602
- type: "choice",
603
- options: ["left", "right"],
604
- defaultValueHint: "right",
605
- advanced: true,
606
- hidden: (ps) => ps.layout !== "horizontal"
607
- },
608
- labelCol: colProp(
609
- "Label layout",
610
- {
611
- span: 8,
612
- horizontalOnly: true
613
- },
614
- "Set the width and offset of the labels"
615
- ),
616
- wrapperCol: colProp(
617
- "Control layout",
618
- {
619
- span: 16,
620
- horizontalOnly: true
621
- },
622
- "Set the width and offset of the form controls"
623
- ),
624
- colon: {
625
- type: "boolean",
626
- description: `Show a colon after labels by default (only for horizontal layout)`,
627
- defaultValueHint: true,
628
- advanced: true,
629
- hidden: (props) => {
630
- var _a;
631
- return ((_a = props.layout) != null ? _a : "horizontal") !== "horizontal";
632
- }
633
- },
634
- requiredMark: {
635
- displayName: "Required/optional indicators",
636
- type: "choice",
637
- options: [
638
- {
639
- value: "optional",
640
- label: "Indicate optional fields"
641
- },
642
- {
643
- value: true,
644
- label: "Indicate required fields with asterisk"
645
- },
646
- {
647
- value: false,
648
- label: "Show no indicators"
649
- }
650
- ],
651
- advanced: true,
652
- defaultValueHint: true
653
- },
654
- extendedOnValuesChange: {
655
- type: "eventHandler",
656
- displayName: "On values change",
657
- argTypes: [
658
- {
659
- name: "changedValues",
660
- type: "object"
661
- },
662
- {
663
- name: "allValues",
664
- type: "object"
665
- }
666
- ]
667
- },
668
- onFinish: {
669
- type: "eventHandler",
670
- displayName: "On submit",
671
- argTypes: [
672
- {
673
- name: "values",
674
- type: "object"
675
- }
676
- ]
677
- },
678
- onFinishFailed: {
679
- // function({ values, errorFields, outOfDate })
680
- type: "eventHandler",
681
- displayName: "On invalid submit",
682
- argTypes: [
683
- {
684
- name: "data",
685
- type: "object"
686
- }
687
- ]
688
- },
689
- validateTrigger: {
690
- displayName: "Validate when",
691
- type: "choice",
692
- options: [
693
- { value: "onBlur", label: "a field loses focus" },
694
- { value: "onChange", label: "a field changes" },
695
- { value: "onSubmit", label: "the form is submitted" }
696
- ],
697
- multiSelect: true,
698
- defaultValueHint: ["onChange"],
699
- advanced: true
700
- }
701
- },
702
- actions: [
703
- ...COMMON_ACTIONS,
704
- {
705
- type: "form-schema",
706
- hidden: (ps) => ps.mode !== "simplified" || !!ps.data
707
- }
708
- ],
709
- states: {
710
- value: {
711
- type: "readonly",
712
- variableType: "object",
713
- onChangeProp: "extendedOnValuesChange"
714
- }
715
- },
716
- componentHelpers: {
717
- helpers: formHelpers,
718
- importName: "formHelpers",
719
- importPath: "@plasmicpkgs/antd5/skinny/registerForm"
720
- },
721
- refActions: {
722
- setFieldsValue: {
723
- displayName: "Set multiple fields",
724
- argTypes: [
725
- {
726
- name: "newValues",
727
- displayName: "New Values",
728
- type: "exprEditor"
729
- }
730
- ]
731
- },
732
- setFieldValue: {
733
- displayName: "Set field",
734
- argTypes: [
735
- {
736
- name: "namePath",
737
- displayName: "Name Path",
738
- type: {
739
- type: "dataSelector",
740
- data: (_, ctx) => {
741
- if (!(ctx == null ? void 0 : ctx.formInstance)) {
742
- return {};
743
- }
744
- return ctx.formInstance.getFieldsValue(true);
745
- }
746
- }
747
- },
748
- {
749
- name: "value",
750
- displayName: "New Value",
751
- type: "exprEditor"
752
- }
753
- ]
754
- },
755
- resetFields: {
756
- displayName: "Reset fields to initial value",
757
- argTypes: []
758
- },
759
- clearFields: {
760
- displayName: "Clear fields",
761
- argTypes: []
762
- },
763
- validateFields: {
764
- displayName: "Validate fields",
765
- argTypes: [
766
- {
767
- name: "nameList",
768
- displayName: "Name List",
769
- type: "object"
770
- },
771
- {
772
- name: "options",
773
- displayName: "Options",
774
- type: "object"
775
- }
776
- ]
777
- }
778
- },
779
- importPath: "@plasmicpkgs/antd5/skinny/registerForm",
780
- importName: "FormWrapper"
781
- });
782
- }
783
- function plasmicRulesToAntdRules(plasmicRules, label) {
784
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
785
- const effectiveLabel = label || "This field";
786
- const rules = [];
787
- for (const plasmicRule of plasmicRules) {
788
- switch (plasmicRule.ruleType) {
789
- case "enum":
790
- rules.push({
791
- type: "enum",
792
- enum: (_b = (_a = plasmicRule.options) == null ? void 0 : _a.map((opt) => opt.value)) != null ? _b : [],
793
- message: (_c = plasmicRule.message) != null ? _c : `${effectiveLabel} must be a valid value`
794
- });
795
- break;
796
- case "required":
797
- rules.push({
798
- required: true,
799
- message: (_d = plasmicRule.message) != null ? _d : `${effectiveLabel} is required`
800
- });
801
- break;
802
- case "regex":
803
- rules.push({
804
- pattern: new RegExp((_e = plasmicRule.pattern) != null ? _e : ""),
805
- message: (_f = plasmicRule.message) != null ? _f : `${effectiveLabel} must be a valid value`
806
- });
807
- break;
808
- case "whitespace":
809
- rules.push({
810
- whitespace: true,
811
- message: (_g = plasmicRule.message) != null ? _g : `${effectiveLabel} is required`
812
- });
813
- break;
814
- case "min":
815
- rules.push({
816
- [plasmicRule.ruleType]: plasmicRule.length,
817
- message: (_h = plasmicRule.message) != null ? _h : `${effectiveLabel} must be at least ${plasmicRule.length} characters`
818
- });
819
- break;
820
- case "max":
821
- rules.push({
822
- [plasmicRule.ruleType]: plasmicRule.length,
823
- message: (_i = plasmicRule.message) != null ? _i : `${effectiveLabel} must be at most ${plasmicRule.length} characters`
824
- });
825
- break;
826
- case "advanced":
827
- rules.push({
828
- validator: (...args) => {
829
- var _a2;
830
- return ((_a2 = plasmicRule.custom) == null ? void 0 : _a2.apply(null, args)) ? Promise.resolve() : Promise.reject();
831
- },
832
- message: plasmicRule.message
833
- });
834
- }
835
- }
836
- return rules;
837
- }
838
- const useFormItemRelativeName = (name) => {
839
- const pathCtx = React__default.default.useContext(PathContext);
840
- return typeof name === "object" ? [...pathCtx.relativePath, ...name] : typeof name === "string" ? [...pathCtx.relativePath, name] : void 0;
841
- };
842
- const useFormItemFullName = (name) => {
843
- const pathCtx = React__default.default.useContext(PathContext);
844
- return typeof name === "object" ? [...pathCtx.fullPath, ...name] : typeof name === "string" ? [...pathCtx.fullPath, name] : void 0;
845
- };
846
- function useFormInstanceMaybe() {
847
- return antd.Form.useFormInstance();
848
- }
849
- function FormItemWrapper(props) {
850
- var _b, _c, _d;
851
- const _a = props, {
852
- rules: plasmicRules,
853
- description,
854
- noLabel,
855
- name,
856
- hideValidationMessage,
857
- customizeProps,
858
- setControlContextData,
859
- alignLabellessWithControls = true
860
- } = _a, rest = __objRest(_a, [
861
- "rules",
862
- "description",
863
- "noLabel",
864
- "name",
865
- "hideValidationMessage",
866
- "customizeProps",
867
- "setControlContextData",
868
- "alignLabellessWithControls"
869
- ]);
870
- const relativeFormItemName = useFormItemRelativeName(name);
871
- const fullFormItemName = useFormItemFullName(name);
872
- const pathCtx = React__default.default.useContext(PathContext);
873
- const fieldEntity = React__default.default.useRef({
874
- preserve: (_b = props.preserve) != null ? _b : true,
875
- fullPath: pathCtx.fullPath,
876
- name
877
- }).current;
878
- const bestEffortLabel = !noLabel && reactUtils.reactNodeToString(props.label) || utils.ensureArray(props.name).slice(-1)[0];
879
- const rules = plasmicRules ? plasmicRulesToAntdRules(
880
- plasmicRules,
881
- typeof bestEffortLabel === "number" ? "" + bestEffortLabel : bestEffortLabel
882
- ) : void 0;
883
- const layoutContext = React__default.default.useContext(FormLayoutContext);
884
- const inCanvas = !!host.usePlasmicCanvasContext();
885
- const {
886
- fireOnValuesChange,
887
- forceRemount,
888
- registerField,
889
- initialValues,
890
- internalFieldCtx
891
- } = (_c = React__default.default.useContext(InternalFormInstanceContext)) != null ? _c : {};
892
- if (inCanvas) {
893
- const form = useFormInstanceMaybe();
894
- const prevPropValues = React__default.default.useRef({
895
- initialValue: props.initialValue,
896
- name: props.name
897
- });
898
- (_d = props.setControlContextData) == null ? void 0 : _d.call(props, {
899
- internalFieldCtx,
900
- formInstance: form,
901
- parentFormItemPath: pathCtx.fullPath,
902
- layout: layoutContext
903
- });
904
- React__default.default.useEffect(() => {
905
- if (prevPropValues.current.name !== props.name) {
906
- forceRemount == null ? void 0 : forceRemount();
907
- }
908
- if (!fullFormItemName || utils.get(initialValues, fullFormItemName) != null || props.initialValue == null) {
909
- return;
910
- }
911
- form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
912
- prevPropValues.current.initialValue = props.initialValue;
913
- fireOnValuesChange == null ? void 0 : fireOnValuesChange();
914
- }, [
915
- form,
916
- props.initialValue,
917
- JSON.stringify(pathCtx.fullPath),
918
- props.name,
919
- props.preserve
920
- ]);
921
- }
922
- React__default.default.useEffect(() => {
923
- var _a2;
924
- fieldEntity.fullPath = [
925
- ...pathCtx.fullPath,
926
- ...props.name != null ? [props.name] : []
927
- ];
928
- fieldEntity.name = props.name;
929
- fieldEntity.preserve = (_a2 = props.preserve) != null ? _a2 : true;
930
- }, [pathCtx.fullPath, props.name, props.preserve]);
931
- React__default.default.useEffect(() => {
932
- const unregister = registerField == null ? void 0 : registerField(fieldEntity);
933
- return () => unregister == null ? void 0 : unregister();
934
- }, []);
935
- return /* @__PURE__ */ React__default.default.createElement(
936
- FormItem,
937
- __spreadProps(__spreadValues({}, rest), {
938
- label: noLabel ? void 0 : props.label,
939
- name: relativeFormItemName,
940
- rules,
941
- extra: description,
942
- help: hideValidationMessage ? "" : props.help,
943
- colon: noLabel ? false : void 0,
944
- valuePropName: deriveValuePropName(props),
945
- trigger: deriveOnChangePropName(props),
946
- wrapperCol: (layoutContext == null ? void 0 : layoutContext.layout) === "horizontal" && noLabel && alignLabellessWithControls && layoutContext.labelSpan ? { offset: layoutContext.labelSpan } : void 0
947
- }),
948
- /* @__PURE__ */ React__default.default.createElement(FormItemForwarder, { formItemProps: props })
949
- );
950
- }
951
- function deriveValuePropName(props) {
952
- var _a;
953
- if (props.valuePropName) {
954
- return props.valuePropName;
955
- }
956
- const valueProps = ((_a = React__default.default.Children.map(props.children, (child) => {
957
- var _a2;
958
- if (React__default.default.isValidElement(child)) {
959
- const childType = child.type;
960
- if (childType) {
961
- const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.valueProp;
962
- if (x) {
963
- return x;
964
- }
965
- const plumeType = childType.__plumeType;
966
- if (plumeType && (plumeType === "checkbox" || plumeType === "switch")) {
967
- return "isChecked";
968
- }
969
- }
970
- }
971
- return void 0;
972
- })) != null ? _a : []).filter((x) => !!x);
973
- if (valueProps.length > 0) {
974
- return valueProps[0];
975
- }
976
- return void 0;
977
- }
978
- function deriveOnChangePropName(props) {
979
- var _a;
980
- if (props.trigger) {
981
- return props.trigger;
982
- }
983
- const triggerProps = ((_a = React__default.default.Children.map(props.children, (child) => {
984
- var _a2;
985
- if (React__default.default.isValidElement(child)) {
986
- const childType = child.type;
987
- if (childType) {
988
- const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.onChangeProp;
989
- if (x) {
990
- return x;
991
- }
992
- }
993
- }
994
- return void 0;
995
- })) != null ? _a : []).filter((x) => !!x);
996
- if (triggerProps.length > 0) {
997
- return triggerProps[0];
998
- }
999
- return void 0;
1000
- }
1001
- function FormItemForwarder(_a) {
1002
- var _b = _a, { formItemProps } = _b, props = __objRest(_b, ["formItemProps"]);
1003
- var _a2;
1004
- const status = antd.Form.Item.useStatus();
1005
- const internalFormCtx = React__default.default.useContext(InternalFormInstanceContext);
1006
- const data = {
1007
- status: status.status
1008
- };
1009
- (_a2 = props.setControlContextData) == null ? void 0 : _a2.call(props, {
1010
- internalFormCtx,
1011
- status
1012
- });
1013
- return React__default.default.Children.map(formItemProps.children, (child, i) => {
1014
- var _a3;
1015
- if (i === 0 && React.isValidElement(child)) {
1016
- let newProps = __spreadProps(__spreadValues(__spreadValues({
1017
- name: formItemProps.name
1018
- }, (_a3 = child.props) != null ? _a3 : {}), props), {
1019
- __plasmicFormField: true
1020
- });
1021
- if (formItemProps.customizeProps) {
1022
- newProps = reactUtils.mergeProps(
1023
- newProps,
1024
- formItemProps.customizeProps(data, newProps)
1025
- );
1026
- }
1027
- return React.cloneElement(child, newProps);
1028
- } else {
1029
- return child;
1030
- }
1031
- });
1032
- }
1033
- function getDefaultValueHint(field) {
1034
- return (_props, contextData, { item }) => {
1035
- var _a;
1036
- if (!contextData || !("mergedFields" in contextData)) {
1037
- return void 0;
1038
- }
1039
- if (item == null ? void 0 : item.fieldId) {
1040
- const fieldSetting = (_a = contextData.mergedFields) == null ? void 0 : _a.find(
1041
- (f) => f.fieldId === item.fieldId
1042
- );
1043
- return fieldSetting == null ? void 0 : fieldSetting[field];
1044
- }
1045
- return void 0;
1046
- };
1047
- }
1048
- const mapAntdComponentToInputType = /* @__PURE__ */ new Map([
1049
- [antd.Input, "Text" /* Text */],
1050
- [antd.Input.TextArea, "Text Area" /* TextArea */],
1051
- [antd.Input.Password, "Password" /* Password */],
1052
- [antd.InputNumber, "Number" /* Number */],
1053
- [registerSelect.AntdSelect, "Select" /* Select */],
1054
- [registerRadio.AntdRadioGroup, "Radio Group" /* RadioGroup */],
1055
- [antd.Radio, "Radio" /* Radio */],
1056
- [registerDatePicker.AntdDatePicker, "DatePicker" /* DatePicker */],
1057
- [registerCheckbox.AntdCheckbox, "Checkbox" /* Checkbox */]
1058
- ]);
1059
- const mapPlumeTypeToInputType = /* @__PURE__ */ new Map([
1060
- ["text-input", "Text" /* Text */],
1061
- ["select", "Select" /* Select */],
1062
- ["checkbox", "Checkbox" /* Checkbox */],
1063
- ["switch", "Checkbox" /* Checkbox */]
1064
- ]);
1065
- function commonFormItemProps(usage) {
1066
- const getFormItemProps = (ps, _ctx, { item }) => {
1067
- if (usage === "simplified-form-item") {
1068
- return item;
1069
- } else {
1070
- return ps;
1071
- }
1072
- };
1073
- return {
1074
- name: {
1075
- type: "string",
1076
- required: true,
1077
- displayName: "Field key",
1078
- description: "Key name for this field value in the submitted form data.",
1079
- validator: (value, _ps, ctx) => {
1080
- var _a, _b, _c;
1081
- let currFullPath = [];
1082
- if (usage === "simplified-form-item") {
1083
- currFullPath = [value];
1084
- } else {
1085
- const formItemCtx = ctx;
1086
- currFullPath = [...(_a = formItemCtx == null ? void 0 : formItemCtx.parentFormItemPath) != null ? _a : [], value];
1087
- }
1088
- const nameCounter = ((_c = (_b = ctx == null ? void 0 : ctx.internalFieldCtx) == null ? void 0 : _b.registeredFields) != null ? _c : []).filter((formItem) => utils.arrayEq(formItem.fullPath, currFullPath)).length;
1089
- return nameCounter === 1 ? true : `Repeated form field key: ${currFullPath.join(" \u2192 ")}`;
1090
- },
1091
- defaultValueHint: getDefaultValueHint("name")
1092
- },
1093
- initialValue: {
1094
- type: "dynamic",
1095
- control: (ps, ctx, {
1096
- item,
1097
- path
1098
- }) => {
1099
- var _a, _b, _c, _d;
1100
- let inputType = "Unkown" /* Unknown */;
1101
- if (usage === "simplified-form-item") {
1102
- inputType = item.inputType;
1103
- if (!ps.data) {
1104
- inputType = item.inputType;
1105
- } else if (path != null && typeof path[1] === "number") {
1106
- inputType = (_b = (_a = ctx == null ? void 0 : ctx.mergedFields) == null ? void 0 : _a[path[1]].inputType) != null ? _b : "Unkown" /* Unknown */;
1107
- }
1108
- } else {
1109
- if (!React__default.default.isValidElement(ps.children) || typeof ps.children.type === "string") {
1110
- inputType = "Unkown" /* Unknown */;
1111
- } else {
1112
- if (mapAntdComponentToInputType.has(ps.children.type)) {
1113
- inputType = (_c = mapAntdComponentToInputType.get(ps.children.type)) != null ? _c : "Unkown" /* Unknown */;
1114
- } else if ("__plumeType" in ps.children.type) {
1115
- inputType = (_d = mapPlumeTypeToInputType.get(
1116
- ps.children.type.__plumeType
1117
- )) != null ? _d : "Unkown" /* Unknown */;
163
+ } else {
164
+ if (!React__default.default.isValidElement(ps.children) || typeof ps.children.type === "string") {
165
+ inputType = Form.InputType.Unknown;
166
+ } else {
167
+ if (mapAntdComponentToInputType.has(ps.children.type)) {
168
+ inputType = (_c = mapAntdComponentToInputType.get(ps.children.type)) != null ? _c : Form.InputType.Unknown;
169
+ } else if ("__plumeType" in ps.children.type) {
170
+ inputType = (_d = mapPlumeTypeToInputType.get(
171
+ ps.children.type.__plumeType
172
+ )) != null ? _d : Form.InputType.Unknown;
1118
173
  }
1119
174
  }
1120
175
  }
1121
176
  if ([
1122
- "Text" /* Text */,
1123
- "Text Area" /* TextArea */,
1124
- "Password" /* Password */,
1125
- "Select" /* Select */,
1126
- "Radio Group" /* RadioGroup */
177
+ Form.InputType.Text,
178
+ Form.InputType.TextArea,
179
+ Form.InputType.Password,
180
+ Form.InputType.Select,
181
+ Form.InputType.RadioGroup
1127
182
  ].includes(inputType)) {
1128
183
  return {
1129
184
  type: "string",
1130
185
  defaultValueHint: getDefaultValueHint("initialValue")
1131
186
  };
1132
- } else if ("Number" /* Number */ === inputType) {
187
+ } else if (Form.InputType.Number === inputType) {
1133
188
  return {
1134
189
  type: "number",
1135
190
  defaultValueHint: getDefaultValueHint("initialValue")
1136
191
  };
1137
- } else if ("Checkbox" /* Checkbox */ === inputType) {
192
+ } else if (Form.InputType.Checkbox === inputType) {
1138
193
  return {
1139
194
  type: "boolean",
1140
195
  defaultValueHint: getDefaultValueHint("initialValue")
1141
196
  };
1142
- } else if ("DatePicker" /* DatePicker */ === inputType) {
197
+ } else if (Form.InputType.DatePicker === inputType) {
1143
198
  return {
1144
199
  type: "dateString",
1145
200
  defaultValueHint: getDefaultValueHint("initialValue")
@@ -1265,22 +320,22 @@ function commonFormItemProps(usage) {
1265
320
  }
1266
321
  const commonSimplifiedFormArrayItemType = (propName) => ({
1267
322
  type: "object",
1268
- fields: __spreadValues({
323
+ fields: __spreadValues$1({
1269
324
  label: {
1270
325
  type: "string",
1271
326
  defaultValueHint: getDefaultValueHint("label")
1272
327
  },
1273
328
  inputType: {
1274
329
  type: "choice",
1275
- options: Object.values(InputType).filter(
330
+ options: Object.values(Form.InputType).filter(
1276
331
  (inputType) => ![
1277
- "Option" /* Option */,
1278
- "Option Group" /* OptionGroup */,
1279
- "Radio" /* Radio */,
1280
- "Unkown" /* Unknown */
332
+ Form.InputType.Option,
333
+ Form.InputType.OptionGroup,
334
+ Form.InputType.Radio,
335
+ Form.InputType.Unknown
1281
336
  ].includes(inputType)
1282
337
  ),
1283
- defaultValue: "Text" /* Text */,
338
+ defaultValue: Form.InputType.Text,
1284
339
  defaultValueHint: getDefaultValueHint("inputType")
1285
340
  },
1286
341
  options: {
@@ -1297,7 +352,7 @@ const commonSimplifiedFormArrayItemType = (propName) => ({
1297
352
  defaultValue: "option",
1298
353
  hidden: (ps, _ctx, { path }) => {
1299
354
  var _a, _b;
1300
- if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== "Select" /* Select */) {
355
+ if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== Form.InputType.Select) {
1301
356
  return true;
1302
357
  }
1303
358
  return false;
@@ -1308,7 +363,7 @@ const commonSimplifiedFormArrayItemType = (propName) => ({
1308
363
  type: "string",
1309
364
  hidden: (ps, _ctx, { path, item }) => {
1310
365
  var _a, _b;
1311
- if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== "Select" /* Select */) {
366
+ if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== Form.InputType.Select) {
1312
367
  return false;
1313
368
  }
1314
369
  return item.type !== "option";
@@ -1326,379 +381,397 @@ const commonSimplifiedFormArrayItemType = (propName) => ({
1326
381
  },
1327
382
  hidden: (ps, _ctx, { path, item }) => {
1328
383
  var _a, _b;
1329
- if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== "Select" /* Select */) {
384
+ if (((_b = (_a = ps[propName]) == null ? void 0 : _a[path[1]]) == null ? void 0 : _b.inputType) !== Form.InputType.Select) {
1330
385
  return true;
1331
386
  }
1332
387
  return item.type !== "option-group";
1333
388
  }
1334
389
  }
1335
390
  },
1336
- nameFunc: (item) => item == null ? void 0 : item.label
391
+ nameFunc: (item) => item == null ? void 0 : item.label
392
+ },
393
+ hidden: (_ps, _ctx, { item }) => ![Form.InputType.Select, Form.InputType.RadioGroup].includes(item.inputType)
394
+ },
395
+ optionType: {
396
+ type: "choice",
397
+ options: [
398
+ { value: "default", label: "Radio" },
399
+ { value: "button", label: "Button" }
400
+ ],
401
+ hidden: (_ps, _ctx, { item }) => Form.InputType.RadioGroup !== item.inputType,
402
+ defaultValueHint: "Radio",
403
+ displayName: "Option Type"
404
+ },
405
+ showTime: {
406
+ type: "boolean",
407
+ displayName: "Show Time",
408
+ description: "To provide an additional time selection",
409
+ hidden: (_ps, _ctx, { item }) => ![Form.InputType.DatePicker].includes(item.inputType)
410
+ }
411
+ }, commonFormItemProps("simplified-form-item")),
412
+ nameFunc: (item) => {
413
+ var _a, _b;
414
+ return (_b = (_a = item.fieldId) != null ? _a : item.label) != null ? _b : item.name;
415
+ }
416
+ });
417
+
418
+ var __defProp = Object.defineProperty;
419
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
420
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
421
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
422
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
423
+ var __spreadValues = (a, b) => {
424
+ for (var prop in b || (b = {}))
425
+ if (__hasOwnProp.call(b, prop))
426
+ __defNormalProp(a, prop, b[prop]);
427
+ if (__getOwnPropSymbols)
428
+ for (var prop of __getOwnPropSymbols(b)) {
429
+ if (__propIsEnum.call(b, prop))
430
+ __defNormalProp(a, prop, b[prop]);
431
+ }
432
+ return a;
433
+ };
434
+ const colProp = (displayName, defaultValue, description) => ({
435
+ type: "object",
436
+ displayName,
437
+ advanced: true,
438
+ fields: {
439
+ span: {
440
+ type: "number",
441
+ displayName: "Width",
442
+ description: "The number of grid columns to span in width (out of 24 columns total)",
443
+ min: 1,
444
+ max: 24
445
+ },
446
+ offset: {
447
+ type: "number",
448
+ displayName: "Offset",
449
+ description: "Number of grid columns to skip from the left (out of 24 columns total)",
450
+ min: 0,
451
+ max: 23
452
+ },
453
+ horizontalOnly: {
454
+ type: "boolean",
455
+ displayName: "Horizontal only",
456
+ description: "Only apply when form layout is horizontal"
457
+ }
458
+ },
459
+ nameFunc: () => `Edit ${displayName}`,
460
+ description,
461
+ defaultValue
462
+ });
463
+ const formTypeDescription = `
464
+ You can create form with two different behaviors:
465
+
466
+
467
+
468
+ 1. Create a new entry: The form will be created empty and it will create a new row when submitted.
469
+ 2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
470
+
471
+
472
+
473
+ For both options, you can customize later.
474
+ `;
475
+ function registerForm(loader) {
476
+ utils.registerComponentHelper(loader, SchemaForm.SchemaForm, {
477
+ name: names.formComponentName,
478
+ displayName: "Form",
479
+ description: "[Learn how to use forms](https://docs.plasmic.app/learn/forms/)",
480
+ defaultStyles: {
481
+ layout: "vbox",
482
+ alignItems: "flex-start"
483
+ },
484
+ props: {
485
+ mode: {
486
+ type: "controlMode",
487
+ defaultValue: "simplified"
488
+ },
489
+ data: {
490
+ type: "formDataConnection",
491
+ disableDynamicValue: true,
492
+ disableLinkToProp: true,
493
+ hidden: (ps) => ps.mode !== "simplified" || !ps.data,
494
+ invariantable: true
495
+ },
496
+ formItems: {
497
+ displayName: "Fields",
498
+ type: "array",
499
+ itemType: commonSimplifiedFormArrayItemType("formItems"),
500
+ defaultValue: [
501
+ {
502
+ label: "Name",
503
+ name: "name",
504
+ inputType: Form.InputType.Text
505
+ },
506
+ {
507
+ label: "Message",
508
+ name: "message",
509
+ inputType: Form.InputType.TextArea
510
+ }
511
+ ],
512
+ hidden: (ps) => {
513
+ if (ps.mode === "advanced") {
514
+ return true;
515
+ }
516
+ return !!ps.data;
517
+ },
518
+ invariantable: true
519
+ },
520
+ /**
521
+ * dataFormItems are used to expand the form items from schema forms.
522
+ * We can't use the formItems prop because it has a default value. Therefore, if we unset the formItems prop,
523
+ * we would end up with the default value of formItems + schema form items.
524
+ * Ideally, we would need to support dynamic default value.
525
+ */
526
+ dataFormItems: {
527
+ displayName: "Data Fields",
528
+ type: "array",
529
+ itemType: commonSimplifiedFormArrayItemType("dataFormItems"),
530
+ hidden: (ps) => {
531
+ if (ps.mode === "advanced") {
532
+ return true;
533
+ }
534
+ return !ps.data;
535
+ },
536
+ unstable__keyFunc: (x) => x.key,
537
+ unstable__minimalValue: (ps, contextData) => {
538
+ return ps.data ? contextData == null ? void 0 : contextData.minimalFullLengthFields : void 0;
539
+ },
540
+ unstable__canDelete: (item, ps, ctx) => {
541
+ if (ps.mode !== "simplified") {
542
+ return true;
543
+ }
544
+ if (!(ctx == null ? void 0 : ctx.schema)) {
545
+ return false;
546
+ }
547
+ if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
548
+ return false;
549
+ }
550
+ return true;
551
+ },
552
+ invariantable: true
1337
553
  },
1338
- hidden: (_ps, _ctx, { item }) => !["Select" /* Select */, "Radio Group" /* RadioGroup */].includes(item.inputType)
1339
- },
1340
- optionType: {
1341
- type: "choice",
1342
- options: [
1343
- { value: "default", label: "Radio" },
1344
- { value: "button", label: "Button" }
1345
- ],
1346
- hidden: (_ps, _ctx, { item }) => "Radio Group" /* RadioGroup */ !== item.inputType,
1347
- defaultValueHint: "Radio",
1348
- displayName: "Option Type"
1349
- },
1350
- showTime: {
1351
- type: "boolean",
1352
- displayName: "Show Time",
1353
- description: "To provide an additional time selection",
1354
- hidden: (_ps, _ctx, { item }) => !["DatePicker" /* DatePicker */].includes(item.inputType)
1355
- }
1356
- }, commonFormItemProps("simplified-form-item")),
1357
- nameFunc: (item) => {
1358
- var _a, _b;
1359
- return (_b = (_a = item.fieldId) != null ? _a : item.label) != null ? _b : item.name;
1360
- }
1361
- });
1362
- const formItemComponentName = "plasmic-antd5-form-item";
1363
- function registerFormItem(loader) {
1364
- utils.registerComponentHelper(loader, FormItemWrapper, __spreadValues({
1365
- name: formItemComponentName,
1366
- displayName: "Form Field",
1367
- parentComponentName: formComponentName,
1368
- defaultStyles: {
1369
- marginBottom: "24px",
1370
- width: "stretch"
1371
- },
1372
- props: __spreadValues({
1373
- label: __spreadValues({
1374
- type: "slot",
1375
- defaultValue: {
1376
- type: "text",
1377
- value: "Label"
1378
- },
1379
- hidden: (ps) => !!ps.noLabel
1380
- }, { mergeWithParent: true }),
1381
- children: __spreadValues({
554
+ submitSlot: __spreadValues({
1382
555
  type: "slot",
556
+ hidden: () => true,
1383
557
  defaultValue: {
1384
558
  type: "component",
1385
- name: registerInput.inputComponentName
1386
- }
1387
- }, { mergeWithParent: true })
1388
- }, commonFormItemProps("advanced-form-item")),
1389
- importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1390
- importName: "FormItemWrapper",
1391
- treeLabel: (ps) => ps.name,
1392
- templates: {
1393
- Text: {
1394
- props: {
1395
- children: {
1396
- type: "component",
1397
- name: registerInput.inputComponentName
559
+ name: names.buttonComponentName,
560
+ props: {
561
+ type: "primary",
562
+ submitsForm: true,
563
+ children: {
564
+ type: "text",
565
+ value: "Submit"
566
+ }
1398
567
  }
1399
568
  }
569
+ }, {
570
+ mergeWithParent: () => true,
571
+ hiddenMergedProps: (ps) => !ps.mode
572
+ }),
573
+ children: {
574
+ type: "slot",
575
+ hidden: (props) => props.mode !== "advanced"
1400
576
  },
1401
- "Long Text": {
1402
- props: {
1403
- children: {
1404
- type: "component",
1405
- name: registerInput.textAreaComponentName
1406
- }
1407
- }
577
+ initialValues: {
578
+ displayName: "Initial field values",
579
+ type: "object"
1408
580
  },
1409
- "Select dropdown": {
1410
- props: {
1411
- children: {
1412
- type: "component",
1413
- name: registerSelect.selectComponentName
1414
- }
1415
- }
581
+ layout: {
582
+ displayName: "Form layout",
583
+ type: "choice",
584
+ options: ["horizontal", "vertical", "inline"],
585
+ defaultValue: "vertical"
1416
586
  },
1417
- Number: {
1418
- props: {
1419
- children: {
1420
- type: "component",
1421
- name: registerInput.inputNumberComponentName
1422
- }
1423
- }
587
+ labelAlign: {
588
+ type: "choice",
589
+ options: ["left", "right"],
590
+ defaultValueHint: "right",
591
+ advanced: true,
592
+ hidden: (ps) => ps.layout !== "horizontal"
1424
593
  },
1425
- Checkbox: {
1426
- props: {
1427
- children: {
1428
- type: "component",
1429
- name: registerCheckbox.checkboxComponentName
1430
- },
1431
- noLabel: true
594
+ labelCol: colProp(
595
+ "Label layout",
596
+ {
597
+ span: 8,
598
+ horizontalOnly: true
599
+ },
600
+ "Set the width and offset of the labels"
601
+ ),
602
+ wrapperCol: colProp(
603
+ "Control layout",
604
+ {
605
+ span: 16,
606
+ horizontalOnly: true
607
+ },
608
+ "Set the width and offset of the form controls"
609
+ ),
610
+ colon: {
611
+ type: "boolean",
612
+ description: `Show a colon after labels by default (only for horizontal layout)`,
613
+ defaultValueHint: true,
614
+ advanced: true,
615
+ hidden: (props) => {
616
+ var _a;
617
+ return ((_a = props.layout) != null ? _a : "horizontal") !== "horizontal";
1432
618
  }
1433
619
  },
1434
- Switch: {
1435
- props: {
1436
- children: {
1437
- type: "component",
1438
- name: registerSwitch.switchComponentName
620
+ requiredMark: {
621
+ displayName: "Required/optional indicators",
622
+ type: "choice",
623
+ options: [
624
+ {
625
+ value: "optional",
626
+ label: "Indicate optional fields"
1439
627
  },
1440
- noLabel: true
1441
- }
1442
- },
1443
- Radios: {
1444
- props: {
1445
- children: {
1446
- type: "component",
1447
- name: registerRadio.radioGroupComponentName
1448
- }
1449
- }
1450
- },
1451
- Password: {
1452
- props: {
1453
- children: {
1454
- type: "component",
1455
- name: registerInput.passwordComponentName
628
+ {
629
+ value: true,
630
+ label: "Indicate required fields with asterisk"
631
+ },
632
+ {
633
+ value: false,
634
+ label: "Show no indicators"
1456
635
  }
1457
- }
636
+ ],
637
+ advanced: true,
638
+ defaultValueHint: true
1458
639
  },
1459
- "Submit button": {
1460
- props: {
1461
- children: {
1462
- type: "component",
1463
- name: registerButton.buttonComponentName,
1464
- props: {
1465
- type: "primary"
1466
- }
640
+ extendedOnValuesChange: {
641
+ type: "eventHandler",
642
+ displayName: "On values change",
643
+ argTypes: [
644
+ {
645
+ name: "changedValues",
646
+ type: "object"
1467
647
  },
1468
- noLabel: true
1469
- }
1470
- }
1471
- }
1472
- }, { trapsSelection: true }));
1473
- }
1474
- function FormGroup(props) {
1475
- const pathCtx = React__default.default.useContext(PathContext);
1476
- return /* @__PURE__ */ React__default.default.createElement(
1477
- PathContext.Provider,
1478
- {
1479
- value: {
1480
- relativePath: [...pathCtx.relativePath, props.name],
1481
- fullPath: [...pathCtx.fullPath, props.name]
1482
- }
1483
- },
1484
- props.children
1485
- );
1486
- }
1487
- const formGroupComponentName = "plasmic-antd5-form-group";
1488
- function registerFormGroup(loader) {
1489
- utils.registerComponentHelper(loader, FormGroup, {
1490
- name: formGroupComponentName,
1491
- displayName: "Form Field Group",
1492
- parentComponentName: formComponentName,
1493
- actions: COMMON_ACTIONS,
1494
- props: {
1495
- name: {
1496
- type: "string",
1497
- displayName: "Form group key",
1498
- description: "Name of the field key for this group of form fields in the submitted form data."
1499
- },
1500
- children: {
1501
- type: "slot"
1502
- }
1503
- },
1504
- importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1505
- importName: "FormGroup"
1506
- });
1507
- }
1508
- const FormListWrapper = React__default.default.forwardRef(function FormListWrapper2(props, ref) {
1509
- var _a;
1510
- const relativeFormItemName = useFormItemRelativeName(props.name);
1511
- const fullFormItemName = useFormItemFullName(props.name);
1512
- const operationsRef = React__default.default.useRef(
1513
- void 0
1514
- );
1515
- React__default.default.useImperativeHandle(
1516
- ref,
1517
- () => ({
1518
- add(defaultValue, insertIndex) {
1519
- if (operationsRef.current) {
1520
- const { add } = operationsRef.current[1];
1521
- add(defaultValue, insertIndex);
1522
- }
1523
- },
1524
- remove(index) {
1525
- if (operationsRef.current) {
1526
- const { remove } = operationsRef.current[1];
1527
- remove(index);
1528
- }
1529
- },
1530
- move(from, to) {
1531
- if (operationsRef.current) {
1532
- const { move } = operationsRef.current[1];
1533
- move(from, to);
1534
- }
1535
- }
1536
- }),
1537
- [operationsRef]
1538
- );
1539
- const inCanvas = !!host.usePlasmicCanvasContext();
1540
- if (inCanvas) {
1541
- const form = useFormInstanceMaybe();
1542
- const prevPropValues = React__default.default.useRef({
1543
- initialValue: props.initialValue,
1544
- name: props.name
1545
- });
1546
- const { fireOnValuesChange, forceRemount } = (_a = React__default.default.useContext(InternalFormInstanceContext)) != null ? _a : {};
1547
- React__default.default.useEffect(() => {
1548
- if (prevPropValues.current.name !== props.name) {
1549
- forceRemount == null ? void 0 : forceRemount();
1550
- }
1551
- if (fullFormItemName) {
1552
- form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
1553
- prevPropValues.current.initialValue = props.initialValue;
1554
- fireOnValuesChange == null ? void 0 : fireOnValuesChange();
1555
- }
1556
- }, [JSON.stringify(props.initialValue), JSON.stringify(fullFormItemName)]);
1557
- }
1558
- return /* @__PURE__ */ React__default.default.createElement(FormList, __spreadProps(__spreadValues({}, props), { name: relativeFormItemName != null ? relativeFormItemName : [] }), (...args) => {
1559
- operationsRef.current = args;
1560
- return args[0].map((field, index) => /* @__PURE__ */ React__default.default.createElement(
1561
- PathContext.Provider,
1562
- {
1563
- value: {
1564
- relativePath: [field.name],
1565
- fullPath: [...fullFormItemName != null ? fullFormItemName : [], field.name]
1566
- }
1567
- },
1568
- /* @__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)))
1569
- ));
1570
- });
1571
- });
1572
- const formListComponentName = "plasmic-antd5-form-list";
1573
- function registerFormList(loader) {
1574
- utils.registerComponentHelper(loader, FormListWrapper, {
1575
- name: formListComponentName,
1576
- parentComponentName: formComponentName,
1577
- displayName: "Form List",
1578
- actions: COMMON_ACTIONS,
1579
- providesData: true,
1580
- props: {
1581
- children: {
1582
- type: "slot",
1583
- defaultValue: [
1584
648
  {
1585
- type: "hbox",
1586
- children: [
1587
- {
1588
- type: "component",
1589
- name: formItemComponentName,
1590
- props: {
1591
- name: "firstName",
1592
- label: {
1593
- type: "text",
1594
- value: "First name"
1595
- },
1596
- children: {
1597
- type: "component",
1598
- name: "plasmic-antd5-input"
1599
- }
1600
- }
1601
- },
1602
- {
1603
- type: "component",
1604
- name: formItemComponentName,
1605
- props: {
1606
- name: "lastName",
1607
- label: {
1608
- type: "text",
1609
- value: "Last name"
1610
- },
1611
- children: {
1612
- type: "component",
1613
- name: "plasmic-antd5-input"
1614
- }
1615
- }
1616
- }
1617
- ]
649
+ name: "allValues",
650
+ type: "object"
1618
651
  }
1619
652
  ]
1620
653
  },
1621
- name: {
1622
- type: "string",
1623
- defaultValue: "guests"
1624
- },
1625
- initialValue: {
1626
- type: "array",
1627
- defaultValue: [
654
+ onFinish: {
655
+ type: "eventHandler",
656
+ displayName: "On submit",
657
+ argTypes: [
1628
658
  {
1629
- firstName: "Jane",
1630
- lastName: "Doe"
1631
- },
659
+ name: "values",
660
+ type: "object"
661
+ }
662
+ ]
663
+ },
664
+ onFinishFailed: {
665
+ // function({ values, errorFields, outOfDate })
666
+ type: "eventHandler",
667
+ displayName: "On invalid submit",
668
+ argTypes: [
1632
669
  {
1633
- firstName: "John",
1634
- lastName: "Smith"
670
+ name: "data",
671
+ type: "object"
1635
672
  }
1636
673
  ]
674
+ },
675
+ validateTrigger: {
676
+ displayName: "Validate when",
677
+ type: "choice",
678
+ options: [
679
+ { value: "onBlur", label: "a field loses focus" },
680
+ { value: "onChange", label: "a field changes" },
681
+ { value: "onSubmit", label: "the form is submitted" }
682
+ ],
683
+ multiSelect: true,
684
+ defaultValueHint: ["onChange"],
685
+ advanced: true
686
+ }
687
+ },
688
+ actions: [
689
+ ...COMMON_ACTIONS,
690
+ {
691
+ type: "form-schema",
692
+ hidden: (ps) => ps.mode !== "simplified" || !!ps.data
693
+ }
694
+ ],
695
+ states: {
696
+ value: {
697
+ type: "readonly",
698
+ variableType: "object",
699
+ onChangeProp: "extendedOnValuesChange"
1637
700
  }
1638
701
  },
702
+ componentHelpers: {
703
+ helpers: Form.formHelpers,
704
+ importName: "formHelpers",
705
+ importPath: "@plasmicpkgs/antd5/skinny/Form"
706
+ },
1639
707
  refActions: {
1640
- add: {
1641
- displayName: "Add an item",
708
+ setFieldsValue: {
709
+ displayName: "Set multiple fields",
1642
710
  argTypes: [
1643
711
  {
1644
- name: "defaultValue",
1645
- displayName: "Default value",
1646
- type: "object"
1647
- },
1648
- {
1649
- name: "insertIndex",
1650
- displayName: "Insert index",
1651
- type: "number"
712
+ name: "newValues",
713
+ displayName: "New Values",
714
+ type: "exprEditor"
1652
715
  }
1653
716
  ]
1654
717
  },
1655
- remove: {
1656
- displayName: "Remove an item",
718
+ setFieldValue: {
719
+ displayName: "Set field",
1657
720
  argTypes: [
1658
721
  {
1659
- name: "index",
1660
- displayName: "Index",
1661
- type: "number"
722
+ name: "namePath",
723
+ displayName: "Name Path",
724
+ type: {
725
+ type: "dataSelector",
726
+ data: (_, ctx) => {
727
+ if (!(ctx == null ? void 0 : ctx.formInstance)) {
728
+ return {};
729
+ }
730
+ return ctx.formInstance.getFieldsValue(true);
731
+ }
732
+ }
733
+ },
734
+ {
735
+ name: "value",
736
+ displayName: "New Value",
737
+ type: "exprEditor"
1662
738
  }
1663
739
  ]
1664
740
  },
1665
- move: {
1666
- displayName: "Move field",
741
+ resetFields: {
742
+ displayName: "Reset fields to initial value",
743
+ argTypes: []
744
+ },
745
+ clearFields: {
746
+ displayName: "Clear fields",
747
+ argTypes: []
748
+ },
749
+ validateFields: {
750
+ displayName: "Validate fields",
1667
751
  argTypes: [
1668
752
  {
1669
- name: "from",
1670
- displayName: "From",
1671
- type: "number"
753
+ name: "nameList",
754
+ displayName: "Name List",
755
+ type: "object"
1672
756
  },
1673
757
  {
1674
- name: "to",
1675
- displayName: "To",
1676
- type: "number"
758
+ name: "options",
759
+ displayName: "Options",
760
+ type: "object"
1677
761
  }
1678
762
  ]
1679
763
  }
1680
764
  },
1681
- importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1682
- importName: "FormListWrapper"
765
+ importPath: "@plasmicpkgs/antd5/skinny/SchemaForm",
766
+ importName: "FormWrapper"
1683
767
  });
1684
768
  }
1685
769
 
1686
- exports.FormGroup = FormGroup;
1687
- exports.FormItemWrapper = FormItemWrapper;
1688
- exports.FormListWrapper = FormListWrapper;
1689
- exports.FormType = FormType;
1690
- exports.FormWrapper = FormWrapper;
1691
- exports.InputType = InputType;
1692
- exports.deriveFormFieldConfigs = deriveFormFieldConfigs;
1693
- exports.formComponentName = formComponentName;
1694
- exports.formGroupComponentName = formGroupComponentName;
1695
- exports.formHelpers = formHelpers;
1696
- exports.formItemComponentName = formItemComponentName;
1697
- exports.formListComponentName = formListComponentName;
770
+ exports.formHelpers = Form.formHelpers;
771
+ exports.FormWrapper = SchemaForm.SchemaForm;
772
+ exports.FormGroup = FormGroup.FormGroup;
773
+ exports.FormItemWrapper = FormItem.FormItemWrapper;
774
+ exports.FormListWrapper = FormList.FormListWrapper;
1698
775
  exports.formTypeDescription = formTypeDescription;
1699
776
  exports.registerForm = registerForm;
1700
- exports.registerFormGroup = registerFormGroup;
1701
- exports.registerFormItem = registerFormItem;
1702
- exports.registerFormList = registerFormList;
1703
- exports.useFormInstanceMaybe = useFormInstanceMaybe;
1704
777
  //# sourceMappingURL=registerForm.cjs.js.map