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