@plasmicpkgs/antd5 0.0.84 → 0.0.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/antd.esm.js +202 -21
- package/dist/antd.esm.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +206 -20
- package/dist/index.js.map +1 -1
- package/dist/registerForm.d.ts +19 -1
- package/dist/utils.d.ts +1 -0
- package/package.json +3 -3
- package/skinny/registerForm.cjs.js +203 -20
- package/skinny/registerForm.cjs.js.map +1 -1
- package/skinny/registerForm.d.ts +19 -1
- package/skinny/registerForm.esm.js +202 -21
- package/skinny/registerForm.esm.js.map +1 -1
- package/skinny/utils-02582d7f.esm.js.map +1 -1
- package/skinny/utils-838eeae8.cjs.js.map +1 -1
- package/skinny/utils.d.ts +1 -0
|
@@ -9,6 +9,7 @@ import { inputComponentName, textAreaComponentName, inputNumberComponentName, pa
|
|
|
9
9
|
import { radioGroupComponentName } from './registerRadio.esm.js';
|
|
10
10
|
import { switchComponentName } from './registerSwitch.esm.js';
|
|
11
11
|
import { s as setFieldsToUndefined, u as usePrevious, e as ensureArray, r as registerComponentHelper } from './utils-02582d7f.esm.js';
|
|
12
|
+
import { normalizeData, deriveFieldConfigs, usePlasmicDataOp } from '@plasmicapp/data-sources';
|
|
12
13
|
import 'classnames';
|
|
13
14
|
import '@plasmicapp/host/registerComponent';
|
|
14
15
|
import '@plasmicapp/host/registerGlobalContext';
|
|
@@ -60,12 +61,17 @@ var InputType = /* @__PURE__ */ ((InputType2) => {
|
|
|
60
61
|
InputType2["DatePicker"] = "DatePicker";
|
|
61
62
|
return InputType2;
|
|
62
63
|
})(InputType || {});
|
|
64
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
65
|
+
FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
|
|
66
|
+
FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
|
|
67
|
+
return FormType2;
|
|
68
|
+
})(FormType || {});
|
|
63
69
|
const PathContext = React.createContext({ relativePath: [], fullPath: [] });
|
|
64
70
|
const InternalFormInstanceContext = React.createContext(void 0);
|
|
65
71
|
const FormLayoutContext = React.createContext(void 0);
|
|
66
72
|
const Internal = React.forwardRef(
|
|
67
73
|
(props, ref) => {
|
|
68
|
-
var _b, _c, _d, _e
|
|
74
|
+
var _b, _c, _d, _e;
|
|
69
75
|
const [form] = Form.useForm();
|
|
70
76
|
const values = form.getFieldsValue(true);
|
|
71
77
|
const lastValue = React.useRef(values);
|
|
@@ -110,7 +116,6 @@ const Internal = React.forwardRef(
|
|
|
110
116
|
},
|
|
111
117
|
[props.layout, (_c = props.labelCol) == null ? void 0 : _c.span]
|
|
112
118
|
);
|
|
113
|
-
(_d = props.setControlContextData) == null ? void 0 : _d.call(props, { formInstance: form });
|
|
114
119
|
React.useImperativeHandle(ref, () => ({
|
|
115
120
|
formInstance: form,
|
|
116
121
|
setFieldsValue: (newValues) => {
|
|
@@ -151,8 +156,8 @@ const Internal = React.forwardRef(
|
|
|
151
156
|
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(args[1]);
|
|
152
157
|
},
|
|
153
158
|
form,
|
|
154
|
-
labelCol: ((
|
|
155
|
-
wrapperCol: ((
|
|
159
|
+
labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
|
|
160
|
+
wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
|
|
156
161
|
}),
|
|
157
162
|
/* @__PURE__ */ React.createElement("style", null, `
|
|
158
163
|
.ant-form-item-explain + div, .ant-form-item-margin-offset {
|
|
@@ -164,6 +169,51 @@ const Internal = React.forwardRef(
|
|
|
164
169
|
);
|
|
165
170
|
}
|
|
166
171
|
);
|
|
172
|
+
function useFormItemDefinitions(rawData, props, formRef) {
|
|
173
|
+
const { mode, formItems, setControlContextData } = props;
|
|
174
|
+
return React.useMemo(() => {
|
|
175
|
+
if (mode !== "simplified" || !formRef || !rawData || rawData.error) {
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
const data = normalizeData(rawData);
|
|
179
|
+
const schema = data == null ? void 0 : data.schema;
|
|
180
|
+
if (!data || !schema || !data.data) {
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
183
|
+
const row = data.data.length > 0 ? data.data[0] : void 0;
|
|
184
|
+
const { mergedFields, minimalFullLengthFields } = deriveFieldConfigs(
|
|
185
|
+
formItems != null ? formItems : [],
|
|
186
|
+
schema,
|
|
187
|
+
(field) => __spreadValues({
|
|
188
|
+
inputType: "Text" /* Text */
|
|
189
|
+
}, field && {
|
|
190
|
+
key: field.id,
|
|
191
|
+
fieldId: field.id,
|
|
192
|
+
label: field.label,
|
|
193
|
+
name: field.id,
|
|
194
|
+
inputType: field.type === "string" ? "Text" /* Text */ : field.type === "number" ? "Number" /* Number */ : field.type === "boolean" ? "Checkbox" /* Checkbox */ : "Text" /* Text */,
|
|
195
|
+
//missing date and date-time
|
|
196
|
+
initialValue: row ? row[field.id] : void 0,
|
|
197
|
+
hidden: field.primaryKey
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
201
|
+
schema: data.schema,
|
|
202
|
+
minimalFullLengthFields,
|
|
203
|
+
mergedFields,
|
|
204
|
+
formInstance: formRef.formInstance
|
|
205
|
+
});
|
|
206
|
+
return mergedFields;
|
|
207
|
+
}, [mode, setControlContextData, formItems, rawData, formRef]);
|
|
208
|
+
}
|
|
209
|
+
const useRawData = (connection) => {
|
|
210
|
+
const rawDataSchema = usePlasmicDataOp(connection == null ? void 0 : connection.dataSchema);
|
|
211
|
+
const rawDataEntry = usePlasmicDataOp(connection == null ? void 0 : connection.dataEntry);
|
|
212
|
+
if (!connection) {
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
return 0 /* NewEntry */ === connection.formType ? rawDataSchema : rawDataEntry;
|
|
216
|
+
};
|
|
167
217
|
const FormWrapper = React.forwardRef(
|
|
168
218
|
(props, ref) => {
|
|
169
219
|
const [remountKey, setRemountKey] = React.useState(0);
|
|
@@ -178,12 +228,24 @@ const FormWrapper = React.forwardRef(
|
|
|
178
228
|
ref,
|
|
179
229
|
() => wrapperRef.current ? __spreadValues({}, wrapperRef.current) : {}
|
|
180
230
|
);
|
|
231
|
+
const rawData = useRawData(props.data);
|
|
232
|
+
const formItemDefinitions = useFormItemDefinitions(
|
|
233
|
+
rawData,
|
|
234
|
+
props,
|
|
235
|
+
wrapperRef.current
|
|
236
|
+
);
|
|
237
|
+
const _a = props, { formItems } = _a, rest = __objRest(_a, ["formItems"]);
|
|
238
|
+
const actualFormItems = props.mode === "simplified" && formItemDefinitions ? formItemDefinitions : formItems;
|
|
239
|
+
if (props.mode === "simplified" && rawData && "error" in rawData) {
|
|
240
|
+
return /* @__PURE__ */ React.createElement("div", null, "Error when fetching data: ", rawData.error.message);
|
|
241
|
+
}
|
|
181
242
|
return /* @__PURE__ */ React.createElement(
|
|
182
243
|
Internal,
|
|
183
244
|
__spreadProps(__spreadValues({
|
|
184
245
|
key: remountKey
|
|
185
|
-
},
|
|
246
|
+
}, rest), {
|
|
186
247
|
setRemountKey,
|
|
248
|
+
formItems: actualFormItems,
|
|
187
249
|
ref: wrapperRef
|
|
188
250
|
})
|
|
189
251
|
);
|
|
@@ -202,7 +264,7 @@ const COMMON_ACTIONS = [
|
|
|
202
264
|
"children"
|
|
203
265
|
);
|
|
204
266
|
},
|
|
205
|
-
hidden: (props) => props.mode
|
|
267
|
+
hidden: (props) => props.mode !== "advanced"
|
|
206
268
|
}
|
|
207
269
|
// {
|
|
208
270
|
// type: "button-action" as const,
|
|
@@ -270,6 +332,60 @@ const formHelpers = {
|
|
|
270
332
|
}
|
|
271
333
|
};
|
|
272
334
|
const formComponentName = "plasmic-antd5-form";
|
|
335
|
+
const formTypeDescription = `
|
|
336
|
+
You can create form with two different behaviors:
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
341
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
For both options, you can customize later.
|
|
346
|
+
`;
|
|
347
|
+
const getConnectionDBPropRegistration = () => ({
|
|
348
|
+
formType: {
|
|
349
|
+
type: "choice",
|
|
350
|
+
options: [
|
|
351
|
+
{ label: "New entry", value: 0 /* NewEntry */ },
|
|
352
|
+
{ label: "Update entry", value: 1 /* UpdateEntry */ }
|
|
353
|
+
],
|
|
354
|
+
displayName: "Form Type",
|
|
355
|
+
disableDynamicValue: true,
|
|
356
|
+
defaultValueHint: "Select the form type...",
|
|
357
|
+
description: `
|
|
358
|
+
You can create form with two different behaviors:
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
363
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
For both options, you can customize later.
|
|
368
|
+
`
|
|
369
|
+
},
|
|
370
|
+
dataSchema: {
|
|
371
|
+
type: "dataSourceOp",
|
|
372
|
+
description: "The data to generate the form",
|
|
373
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 0 /* NewEntry */,
|
|
374
|
+
displayName: "",
|
|
375
|
+
disableDynamicValue: true,
|
|
376
|
+
allowedOps: () => ["getTableSchema"],
|
|
377
|
+
hideCacheKey: true
|
|
378
|
+
},
|
|
379
|
+
dataEntry: {
|
|
380
|
+
type: "dataSourceOp",
|
|
381
|
+
description: "The data to generate the form",
|
|
382
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 1 /* UpdateEntry */,
|
|
383
|
+
displayName: "",
|
|
384
|
+
disableDynamicValue: true,
|
|
385
|
+
allowedOps: () => ["getOne"],
|
|
386
|
+
hideCacheKey: true
|
|
387
|
+
}
|
|
388
|
+
});
|
|
273
389
|
function registerForm(loader) {
|
|
274
390
|
registerComponentHelper(loader, FormWrapper, {
|
|
275
391
|
name: formComponentName,
|
|
@@ -283,13 +399,22 @@ function registerForm(loader) {
|
|
|
283
399
|
type: "controlMode",
|
|
284
400
|
defaultValue: "simplified"
|
|
285
401
|
},
|
|
402
|
+
data: {
|
|
403
|
+
type: "object",
|
|
404
|
+
fields: getConnectionDBPropRegistration(),
|
|
405
|
+
hidden: (ps) => ps.mode !== "simplified" || !ps.data,
|
|
406
|
+
nameFunc: () => "DB Connection"
|
|
407
|
+
},
|
|
286
408
|
formItems: {
|
|
287
409
|
displayName: "Fields",
|
|
288
410
|
type: "array",
|
|
289
411
|
itemType: {
|
|
290
412
|
type: "object",
|
|
291
413
|
fields: __spreadValues({
|
|
292
|
-
label:
|
|
414
|
+
label: {
|
|
415
|
+
type: "string",
|
|
416
|
+
defaultValueHint: getDefaultValueHint("label")
|
|
417
|
+
},
|
|
293
418
|
inputType: {
|
|
294
419
|
type: "choice",
|
|
295
420
|
options: Object.values(InputType).filter(
|
|
@@ -299,7 +424,8 @@ function registerForm(loader) {
|
|
|
299
424
|
"Radio" /* Radio */
|
|
300
425
|
].includes(inputType)
|
|
301
426
|
),
|
|
302
|
-
defaultValue: "Text" /* Text
|
|
427
|
+
defaultValue: "Text" /* Text */,
|
|
428
|
+
defaultValueHint: getDefaultValueHint("inputType")
|
|
303
429
|
},
|
|
304
430
|
options: {
|
|
305
431
|
type: "array",
|
|
@@ -368,7 +494,10 @@ function registerForm(loader) {
|
|
|
368
494
|
displayName: "Option Type"
|
|
369
495
|
}
|
|
370
496
|
}, commonFormItemProps),
|
|
371
|
-
nameFunc: (item) =>
|
|
497
|
+
nameFunc: (item) => {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
return (_b = (_a = item.fieldId) != null ? _a : item.label) != null ? _b : item.name;
|
|
500
|
+
}
|
|
372
501
|
},
|
|
373
502
|
defaultValue: [
|
|
374
503
|
{
|
|
@@ -382,7 +511,31 @@ function registerForm(loader) {
|
|
|
382
511
|
inputType: "Text Area" /* TextArea */
|
|
383
512
|
}
|
|
384
513
|
],
|
|
385
|
-
hidden: (
|
|
514
|
+
hidden: (ps) => {
|
|
515
|
+
if (ps.mode === "advanced") {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
if (ps.mode === "simplified") {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
return !ps.data || !ps.formType;
|
|
522
|
+
},
|
|
523
|
+
unstable__keyFunc: (x) => x.key,
|
|
524
|
+
unstable__minimalValue: (ps, contextData) => {
|
|
525
|
+
return ps.mode === "simplified" ? ps.formItems : contextData == null ? void 0 : contextData.minimalFullLengthFields;
|
|
526
|
+
},
|
|
527
|
+
unstable__canDelete: (item, ps, ctx) => {
|
|
528
|
+
if (ps.mode !== "database-schema-driven") {
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
if (!(ctx == null ? void 0 : ctx.schema)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
386
539
|
},
|
|
387
540
|
submitSlot: __spreadValues({
|
|
388
541
|
type: "slot",
|
|
@@ -405,7 +558,7 @@ function registerForm(loader) {
|
|
|
405
558
|
}),
|
|
406
559
|
children: {
|
|
407
560
|
type: "slot",
|
|
408
|
-
hidden: (props) => props.mode
|
|
561
|
+
hidden: (props) => props.mode !== "advanced"
|
|
409
562
|
},
|
|
410
563
|
initialValues: {
|
|
411
564
|
displayName: "Initial field values",
|
|
@@ -518,7 +671,13 @@ function registerForm(loader) {
|
|
|
518
671
|
advanced: true
|
|
519
672
|
}
|
|
520
673
|
},
|
|
521
|
-
actions:
|
|
674
|
+
actions: [
|
|
675
|
+
...COMMON_ACTIONS,
|
|
676
|
+
{
|
|
677
|
+
type: "form-schema",
|
|
678
|
+
hidden: (ps) => ps.mode !== "simplified" || !!ps.data
|
|
679
|
+
}
|
|
680
|
+
],
|
|
522
681
|
states: {
|
|
523
682
|
value: {
|
|
524
683
|
type: "readonly",
|
|
@@ -680,10 +839,13 @@ function FormItemWrapper(props) {
|
|
|
680
839
|
initialValue: props.initialValue,
|
|
681
840
|
name: props.name
|
|
682
841
|
});
|
|
842
|
+
const fullPath = React.useContext(PathContext).fullPath;
|
|
683
843
|
const internalFormCtx = React.useContext(InternalFormInstanceContext);
|
|
684
844
|
const { fireOnValuesChange, forceRemount } = internalFormCtx != null ? internalFormCtx : {};
|
|
685
845
|
(_b = props.setControlContextData) == null ? void 0 : _b.call(props, {
|
|
686
|
-
internalFormCtx
|
|
846
|
+
internalFormCtx,
|
|
847
|
+
formInstance: form,
|
|
848
|
+
parentFormItemPath: fullPath
|
|
687
849
|
});
|
|
688
850
|
React.useEffect(() => {
|
|
689
851
|
if (prevPropValues.current.name !== props.name) {
|
|
@@ -713,15 +875,16 @@ function FormItemWrapper(props) {
|
|
|
713
875
|
);
|
|
714
876
|
}
|
|
715
877
|
function deriveValuePropName(props) {
|
|
878
|
+
var _a;
|
|
716
879
|
if (props.valuePropName) {
|
|
717
880
|
return props.valuePropName;
|
|
718
881
|
}
|
|
719
|
-
const valueProps = React.Children.map(props.children, (child) => {
|
|
720
|
-
var
|
|
882
|
+
const valueProps = ((_a = React.Children.map(props.children, (child) => {
|
|
883
|
+
var _a2;
|
|
721
884
|
if (React.isValidElement(child)) {
|
|
722
885
|
const childType = child.type;
|
|
723
886
|
if (childType) {
|
|
724
|
-
const x = (
|
|
887
|
+
const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.valueProp;
|
|
725
888
|
if (x) {
|
|
726
889
|
return x;
|
|
727
890
|
}
|
|
@@ -732,7 +895,7 @@ function deriveValuePropName(props) {
|
|
|
732
895
|
}
|
|
733
896
|
}
|
|
734
897
|
return void 0;
|
|
735
|
-
}).filter((x) => !!x);
|
|
898
|
+
})) != null ? _a : []).filter((x) => !!x);
|
|
736
899
|
if (valueProps.length > 0) {
|
|
737
900
|
return valueProps[0];
|
|
738
901
|
}
|
|
@@ -764,12 +927,29 @@ function FormItemForwarder(_a) {
|
|
|
764
927
|
return i === 0 && isValidElement(child) ? cloneElement(child, newProps) : child;
|
|
765
928
|
});
|
|
766
929
|
}
|
|
930
|
+
function getDefaultValueHint(field) {
|
|
931
|
+
return (_props, contextData, { item }) => {
|
|
932
|
+
if (!contextData || !("mergedFields" in contextData)) {
|
|
933
|
+
return void 0;
|
|
934
|
+
}
|
|
935
|
+
if (item == null ? void 0 : item.fieldId) {
|
|
936
|
+
const fieldSetting = contextData.mergedFields.find(
|
|
937
|
+
(f) => f.fieldId === item.fieldId
|
|
938
|
+
);
|
|
939
|
+
return fieldSetting == null ? void 0 : fieldSetting[field];
|
|
940
|
+
}
|
|
941
|
+
return void 0;
|
|
942
|
+
};
|
|
943
|
+
}
|
|
767
944
|
const commonFormItemProps = {
|
|
768
945
|
name: {
|
|
769
|
-
type: "string"
|
|
946
|
+
type: "string",
|
|
947
|
+
required: true,
|
|
948
|
+
defaultValueHint: getDefaultValueHint("name")
|
|
770
949
|
},
|
|
771
950
|
initialValue: {
|
|
772
|
-
type: "string"
|
|
951
|
+
type: "string",
|
|
952
|
+
defaultValueHint: getDefaultValueHint("initialValue")
|
|
773
953
|
},
|
|
774
954
|
rules: {
|
|
775
955
|
displayName: "Validation rules",
|
|
@@ -812,7 +992,8 @@ const commonFormItemProps = {
|
|
|
812
992
|
},
|
|
813
993
|
hidden: {
|
|
814
994
|
type: "boolean",
|
|
815
|
-
advanced: true
|
|
995
|
+
advanced: true,
|
|
996
|
+
defaultValueHint: getDefaultValueHint("hidden")
|
|
816
997
|
},
|
|
817
998
|
validateTrigger: {
|
|
818
999
|
type: "choice",
|
|
@@ -1180,5 +1361,5 @@ function registerFormList(loader) {
|
|
|
1180
1361
|
});
|
|
1181
1362
|
}
|
|
1182
1363
|
|
|
1183
|
-
export { FormGroup, FormItemWrapper, FormListWrapper, FormWrapper, InputType, formComponentName, formGroupComponentName, formHelpers, formItemComponentName, formListComponentName, registerForm, registerFormGroup, registerFormItem, registerFormList, useFormInstanceMaybe };
|
|
1364
|
+
export { FormGroup, FormItemWrapper, FormListWrapper, FormType, FormWrapper, InputType, formComponentName, formGroupComponentName, formHelpers, formItemComponentName, formListComponentName, formTypeDescription, registerForm, registerFormGroup, registerFormItem, registerFormList, useFormInstanceMaybe };
|
|
1184
1365
|
//# sourceMappingURL=registerForm.esm.js.map
|