@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
package/dist/antd.esm.js
CHANGED
|
@@ -8,6 +8,7 @@ import { addLoadingStateListener } from '@plasmicapp/query';
|
|
|
8
8
|
import enUS from 'antd/lib/locale/en_US.js';
|
|
9
9
|
import equal from 'fast-deep-equal';
|
|
10
10
|
import classNames from 'classnames';
|
|
11
|
+
import { normalizeData, deriveFieldConfigs, usePlasmicDataOp } from '@plasmicapp/data-sources';
|
|
11
12
|
import dayjs from 'dayjs';
|
|
12
13
|
|
|
13
14
|
function makeRegisterGlobalContext(component, meta) {
|
|
@@ -2409,12 +2410,17 @@ var InputType = /* @__PURE__ */ ((InputType2) => {
|
|
|
2409
2410
|
InputType2["DatePicker"] = "DatePicker";
|
|
2410
2411
|
return InputType2;
|
|
2411
2412
|
})(InputType || {});
|
|
2413
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
2414
|
+
FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
|
|
2415
|
+
FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
|
|
2416
|
+
return FormType2;
|
|
2417
|
+
})(FormType || {});
|
|
2412
2418
|
const PathContext = React.createContext({ relativePath: [], fullPath: [] });
|
|
2413
2419
|
const InternalFormInstanceContext = React.createContext(void 0);
|
|
2414
2420
|
const FormLayoutContext = React.createContext(void 0);
|
|
2415
2421
|
const Internal = React.forwardRef(
|
|
2416
2422
|
(props, ref) => {
|
|
2417
|
-
var _b, _c, _d, _e
|
|
2423
|
+
var _b, _c, _d, _e;
|
|
2418
2424
|
const [form] = Form.useForm();
|
|
2419
2425
|
const values = form.getFieldsValue(true);
|
|
2420
2426
|
const lastValue = React.useRef(values);
|
|
@@ -2459,7 +2465,6 @@ const Internal = React.forwardRef(
|
|
|
2459
2465
|
},
|
|
2460
2466
|
[props.layout, (_c = props.labelCol) == null ? void 0 : _c.span]
|
|
2461
2467
|
);
|
|
2462
|
-
(_d = props.setControlContextData) == null ? void 0 : _d.call(props, { formInstance: form });
|
|
2463
2468
|
React.useImperativeHandle(ref, () => ({
|
|
2464
2469
|
formInstance: form,
|
|
2465
2470
|
setFieldsValue: (newValues) => {
|
|
@@ -2500,8 +2505,8 @@ const Internal = React.forwardRef(
|
|
|
2500
2505
|
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(args[1]);
|
|
2501
2506
|
},
|
|
2502
2507
|
form,
|
|
2503
|
-
labelCol: ((
|
|
2504
|
-
wrapperCol: ((
|
|
2508
|
+
labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
|
|
2509
|
+
wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
|
|
2505
2510
|
}),
|
|
2506
2511
|
/* @__PURE__ */ React.createElement("style", null, `
|
|
2507
2512
|
.ant-form-item-explain + div, .ant-form-item-margin-offset {
|
|
@@ -2513,6 +2518,51 @@ const Internal = React.forwardRef(
|
|
|
2513
2518
|
);
|
|
2514
2519
|
}
|
|
2515
2520
|
);
|
|
2521
|
+
function useFormItemDefinitions(rawData, props, formRef) {
|
|
2522
|
+
const { mode, formItems, setControlContextData } = props;
|
|
2523
|
+
return React.useMemo(() => {
|
|
2524
|
+
if (mode !== "simplified" || !formRef || !rawData || rawData.error) {
|
|
2525
|
+
return void 0;
|
|
2526
|
+
}
|
|
2527
|
+
const data = normalizeData(rawData);
|
|
2528
|
+
const schema = data == null ? void 0 : data.schema;
|
|
2529
|
+
if (!data || !schema || !data.data) {
|
|
2530
|
+
return void 0;
|
|
2531
|
+
}
|
|
2532
|
+
const row = data.data.length > 0 ? data.data[0] : void 0;
|
|
2533
|
+
const { mergedFields, minimalFullLengthFields } = deriveFieldConfigs(
|
|
2534
|
+
formItems != null ? formItems : [],
|
|
2535
|
+
schema,
|
|
2536
|
+
(field) => __spreadValues$4({
|
|
2537
|
+
inputType: "Text" /* Text */
|
|
2538
|
+
}, field && {
|
|
2539
|
+
key: field.id,
|
|
2540
|
+
fieldId: field.id,
|
|
2541
|
+
label: field.label,
|
|
2542
|
+
name: field.id,
|
|
2543
|
+
inputType: field.type === "string" ? "Text" /* Text */ : field.type === "number" ? "Number" /* Number */ : field.type === "boolean" ? "Checkbox" /* Checkbox */ : "Text" /* Text */,
|
|
2544
|
+
//missing date and date-time
|
|
2545
|
+
initialValue: row ? row[field.id] : void 0,
|
|
2546
|
+
hidden: field.primaryKey
|
|
2547
|
+
})
|
|
2548
|
+
);
|
|
2549
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2550
|
+
schema: data.schema,
|
|
2551
|
+
minimalFullLengthFields,
|
|
2552
|
+
mergedFields,
|
|
2553
|
+
formInstance: formRef.formInstance
|
|
2554
|
+
});
|
|
2555
|
+
return mergedFields;
|
|
2556
|
+
}, [mode, setControlContextData, formItems, rawData, formRef]);
|
|
2557
|
+
}
|
|
2558
|
+
const useRawData = (connection) => {
|
|
2559
|
+
const rawDataSchema = usePlasmicDataOp(connection == null ? void 0 : connection.dataSchema);
|
|
2560
|
+
const rawDataEntry = usePlasmicDataOp(connection == null ? void 0 : connection.dataEntry);
|
|
2561
|
+
if (!connection) {
|
|
2562
|
+
return void 0;
|
|
2563
|
+
}
|
|
2564
|
+
return 0 /* NewEntry */ === connection.formType ? rawDataSchema : rawDataEntry;
|
|
2565
|
+
};
|
|
2516
2566
|
const FormWrapper = React.forwardRef(
|
|
2517
2567
|
(props, ref) => {
|
|
2518
2568
|
const [remountKey, setRemountKey] = React.useState(0);
|
|
@@ -2527,12 +2577,24 @@ const FormWrapper = React.forwardRef(
|
|
|
2527
2577
|
ref,
|
|
2528
2578
|
() => wrapperRef.current ? __spreadValues$4({}, wrapperRef.current) : {}
|
|
2529
2579
|
);
|
|
2580
|
+
const rawData = useRawData(props.data);
|
|
2581
|
+
const formItemDefinitions = useFormItemDefinitions(
|
|
2582
|
+
rawData,
|
|
2583
|
+
props,
|
|
2584
|
+
wrapperRef.current
|
|
2585
|
+
);
|
|
2586
|
+
const _a = props, { formItems } = _a, rest = __objRest$3(_a, ["formItems"]);
|
|
2587
|
+
const actualFormItems = props.mode === "simplified" && formItemDefinitions ? formItemDefinitions : formItems;
|
|
2588
|
+
if (props.mode === "simplified" && rawData && "error" in rawData) {
|
|
2589
|
+
return /* @__PURE__ */ React.createElement("div", null, "Error when fetching data: ", rawData.error.message);
|
|
2590
|
+
}
|
|
2530
2591
|
return /* @__PURE__ */ React.createElement(
|
|
2531
2592
|
Internal,
|
|
2532
2593
|
__spreadProps$3(__spreadValues$4({
|
|
2533
2594
|
key: remountKey
|
|
2534
|
-
},
|
|
2595
|
+
}, rest), {
|
|
2535
2596
|
setRemountKey,
|
|
2597
|
+
formItems: actualFormItems,
|
|
2536
2598
|
ref: wrapperRef
|
|
2537
2599
|
})
|
|
2538
2600
|
);
|
|
@@ -2551,7 +2613,7 @@ const COMMON_ACTIONS = [
|
|
|
2551
2613
|
"children"
|
|
2552
2614
|
);
|
|
2553
2615
|
},
|
|
2554
|
-
hidden: (props) => props.mode
|
|
2616
|
+
hidden: (props) => props.mode !== "advanced"
|
|
2555
2617
|
}
|
|
2556
2618
|
// {
|
|
2557
2619
|
// type: "button-action" as const,
|
|
@@ -2619,6 +2681,60 @@ const formHelpers = {
|
|
|
2619
2681
|
}
|
|
2620
2682
|
};
|
|
2621
2683
|
const formComponentName = "plasmic-antd5-form";
|
|
2684
|
+
const formTypeDescription = `
|
|
2685
|
+
You can create form with two different behaviors:
|
|
2686
|
+
|
|
2687
|
+
|
|
2688
|
+
|
|
2689
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
2690
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
2691
|
+
|
|
2692
|
+
|
|
2693
|
+
|
|
2694
|
+
For both options, you can customize later.
|
|
2695
|
+
`;
|
|
2696
|
+
const getConnectionDBPropRegistration = () => ({
|
|
2697
|
+
formType: {
|
|
2698
|
+
type: "choice",
|
|
2699
|
+
options: [
|
|
2700
|
+
{ label: "New entry", value: 0 /* NewEntry */ },
|
|
2701
|
+
{ label: "Update entry", value: 1 /* UpdateEntry */ }
|
|
2702
|
+
],
|
|
2703
|
+
displayName: "Form Type",
|
|
2704
|
+
disableDynamicValue: true,
|
|
2705
|
+
defaultValueHint: "Select the form type...",
|
|
2706
|
+
description: `
|
|
2707
|
+
You can create form with two different behaviors:
|
|
2708
|
+
|
|
2709
|
+
|
|
2710
|
+
|
|
2711
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
2712
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
2713
|
+
|
|
2714
|
+
|
|
2715
|
+
|
|
2716
|
+
For both options, you can customize later.
|
|
2717
|
+
`
|
|
2718
|
+
},
|
|
2719
|
+
dataSchema: {
|
|
2720
|
+
type: "dataSourceOp",
|
|
2721
|
+
description: "The data to generate the form",
|
|
2722
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 0 /* NewEntry */,
|
|
2723
|
+
displayName: "",
|
|
2724
|
+
disableDynamicValue: true,
|
|
2725
|
+
allowedOps: () => ["getTableSchema"],
|
|
2726
|
+
hideCacheKey: true
|
|
2727
|
+
},
|
|
2728
|
+
dataEntry: {
|
|
2729
|
+
type: "dataSourceOp",
|
|
2730
|
+
description: "The data to generate the form",
|
|
2731
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 1 /* UpdateEntry */,
|
|
2732
|
+
displayName: "",
|
|
2733
|
+
disableDynamicValue: true,
|
|
2734
|
+
allowedOps: () => ["getOne"],
|
|
2735
|
+
hideCacheKey: true
|
|
2736
|
+
}
|
|
2737
|
+
});
|
|
2622
2738
|
function registerForm(loader) {
|
|
2623
2739
|
registerComponentHelper(loader, FormWrapper, {
|
|
2624
2740
|
name: formComponentName,
|
|
@@ -2632,13 +2748,22 @@ function registerForm(loader) {
|
|
|
2632
2748
|
type: "controlMode",
|
|
2633
2749
|
defaultValue: "simplified"
|
|
2634
2750
|
},
|
|
2751
|
+
data: {
|
|
2752
|
+
type: "object",
|
|
2753
|
+
fields: getConnectionDBPropRegistration(),
|
|
2754
|
+
hidden: (ps) => ps.mode !== "simplified" || !ps.data,
|
|
2755
|
+
nameFunc: () => "DB Connection"
|
|
2756
|
+
},
|
|
2635
2757
|
formItems: {
|
|
2636
2758
|
displayName: "Fields",
|
|
2637
2759
|
type: "array",
|
|
2638
2760
|
itemType: {
|
|
2639
2761
|
type: "object",
|
|
2640
2762
|
fields: __spreadValues$4({
|
|
2641
|
-
label:
|
|
2763
|
+
label: {
|
|
2764
|
+
type: "string",
|
|
2765
|
+
defaultValueHint: getDefaultValueHint("label")
|
|
2766
|
+
},
|
|
2642
2767
|
inputType: {
|
|
2643
2768
|
type: "choice",
|
|
2644
2769
|
options: Object.values(InputType).filter(
|
|
@@ -2648,7 +2773,8 @@ function registerForm(loader) {
|
|
|
2648
2773
|
"Radio" /* Radio */
|
|
2649
2774
|
].includes(inputType)
|
|
2650
2775
|
),
|
|
2651
|
-
defaultValue: "Text" /* Text
|
|
2776
|
+
defaultValue: "Text" /* Text */,
|
|
2777
|
+
defaultValueHint: getDefaultValueHint("inputType")
|
|
2652
2778
|
},
|
|
2653
2779
|
options: {
|
|
2654
2780
|
type: "array",
|
|
@@ -2717,7 +2843,10 @@ function registerForm(loader) {
|
|
|
2717
2843
|
displayName: "Option Type"
|
|
2718
2844
|
}
|
|
2719
2845
|
}, commonFormItemProps),
|
|
2720
|
-
nameFunc: (item) =>
|
|
2846
|
+
nameFunc: (item) => {
|
|
2847
|
+
var _a, _b;
|
|
2848
|
+
return (_b = (_a = item.fieldId) != null ? _a : item.label) != null ? _b : item.name;
|
|
2849
|
+
}
|
|
2721
2850
|
},
|
|
2722
2851
|
defaultValue: [
|
|
2723
2852
|
{
|
|
@@ -2731,7 +2860,31 @@ function registerForm(loader) {
|
|
|
2731
2860
|
inputType: "Text Area" /* TextArea */
|
|
2732
2861
|
}
|
|
2733
2862
|
],
|
|
2734
|
-
hidden: (
|
|
2863
|
+
hidden: (ps) => {
|
|
2864
|
+
if (ps.mode === "advanced") {
|
|
2865
|
+
return true;
|
|
2866
|
+
}
|
|
2867
|
+
if (ps.mode === "simplified") {
|
|
2868
|
+
return false;
|
|
2869
|
+
}
|
|
2870
|
+
return !ps.data || !ps.formType;
|
|
2871
|
+
},
|
|
2872
|
+
unstable__keyFunc: (x) => x.key,
|
|
2873
|
+
unstable__minimalValue: (ps, contextData) => {
|
|
2874
|
+
return ps.mode === "simplified" ? ps.formItems : contextData == null ? void 0 : contextData.minimalFullLengthFields;
|
|
2875
|
+
},
|
|
2876
|
+
unstable__canDelete: (item, ps, ctx) => {
|
|
2877
|
+
if (ps.mode !== "database-schema-driven") {
|
|
2878
|
+
return true;
|
|
2879
|
+
}
|
|
2880
|
+
if (!(ctx == null ? void 0 : ctx.schema)) {
|
|
2881
|
+
return false;
|
|
2882
|
+
}
|
|
2883
|
+
if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
return true;
|
|
2887
|
+
}
|
|
2735
2888
|
},
|
|
2736
2889
|
submitSlot: __spreadValues$4({
|
|
2737
2890
|
type: "slot",
|
|
@@ -2754,7 +2907,7 @@ function registerForm(loader) {
|
|
|
2754
2907
|
}),
|
|
2755
2908
|
children: {
|
|
2756
2909
|
type: "slot",
|
|
2757
|
-
hidden: (props) => props.mode
|
|
2910
|
+
hidden: (props) => props.mode !== "advanced"
|
|
2758
2911
|
},
|
|
2759
2912
|
initialValues: {
|
|
2760
2913
|
displayName: "Initial field values",
|
|
@@ -2867,7 +3020,13 @@ function registerForm(loader) {
|
|
|
2867
3020
|
advanced: true
|
|
2868
3021
|
}
|
|
2869
3022
|
},
|
|
2870
|
-
actions:
|
|
3023
|
+
actions: [
|
|
3024
|
+
...COMMON_ACTIONS,
|
|
3025
|
+
{
|
|
3026
|
+
type: "form-schema",
|
|
3027
|
+
hidden: (ps) => ps.mode !== "simplified" || !!ps.data
|
|
3028
|
+
}
|
|
3029
|
+
],
|
|
2871
3030
|
states: {
|
|
2872
3031
|
value: {
|
|
2873
3032
|
type: "readonly",
|
|
@@ -3029,10 +3188,13 @@ function FormItemWrapper(props) {
|
|
|
3029
3188
|
initialValue: props.initialValue,
|
|
3030
3189
|
name: props.name
|
|
3031
3190
|
});
|
|
3191
|
+
const fullPath = React.useContext(PathContext).fullPath;
|
|
3032
3192
|
const internalFormCtx = React.useContext(InternalFormInstanceContext);
|
|
3033
3193
|
const { fireOnValuesChange, forceRemount } = internalFormCtx != null ? internalFormCtx : {};
|
|
3034
3194
|
(_b = props.setControlContextData) == null ? void 0 : _b.call(props, {
|
|
3035
|
-
internalFormCtx
|
|
3195
|
+
internalFormCtx,
|
|
3196
|
+
formInstance: form,
|
|
3197
|
+
parentFormItemPath: fullPath
|
|
3036
3198
|
});
|
|
3037
3199
|
React.useEffect(() => {
|
|
3038
3200
|
if (prevPropValues.current.name !== props.name) {
|
|
@@ -3062,15 +3224,16 @@ function FormItemWrapper(props) {
|
|
|
3062
3224
|
);
|
|
3063
3225
|
}
|
|
3064
3226
|
function deriveValuePropName(props) {
|
|
3227
|
+
var _a;
|
|
3065
3228
|
if (props.valuePropName) {
|
|
3066
3229
|
return props.valuePropName;
|
|
3067
3230
|
}
|
|
3068
|
-
const valueProps = React.Children.map(props.children, (child) => {
|
|
3069
|
-
var
|
|
3231
|
+
const valueProps = ((_a = React.Children.map(props.children, (child) => {
|
|
3232
|
+
var _a2;
|
|
3070
3233
|
if (React.isValidElement(child)) {
|
|
3071
3234
|
const childType = child.type;
|
|
3072
3235
|
if (childType) {
|
|
3073
|
-
const x = (
|
|
3236
|
+
const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.valueProp;
|
|
3074
3237
|
if (x) {
|
|
3075
3238
|
return x;
|
|
3076
3239
|
}
|
|
@@ -3081,7 +3244,7 @@ function deriveValuePropName(props) {
|
|
|
3081
3244
|
}
|
|
3082
3245
|
}
|
|
3083
3246
|
return void 0;
|
|
3084
|
-
}).filter((x) => !!x);
|
|
3247
|
+
})) != null ? _a : []).filter((x) => !!x);
|
|
3085
3248
|
if (valueProps.length > 0) {
|
|
3086
3249
|
return valueProps[0];
|
|
3087
3250
|
}
|
|
@@ -3113,12 +3276,29 @@ function FormItemForwarder(_a) {
|
|
|
3113
3276
|
return i === 0 && isValidElement(child) ? cloneElement(child, newProps) : child;
|
|
3114
3277
|
});
|
|
3115
3278
|
}
|
|
3279
|
+
function getDefaultValueHint(field) {
|
|
3280
|
+
return (_props, contextData, { item }) => {
|
|
3281
|
+
if (!contextData || !("mergedFields" in contextData)) {
|
|
3282
|
+
return void 0;
|
|
3283
|
+
}
|
|
3284
|
+
if (item == null ? void 0 : item.fieldId) {
|
|
3285
|
+
const fieldSetting = contextData.mergedFields.find(
|
|
3286
|
+
(f) => f.fieldId === item.fieldId
|
|
3287
|
+
);
|
|
3288
|
+
return fieldSetting == null ? void 0 : fieldSetting[field];
|
|
3289
|
+
}
|
|
3290
|
+
return void 0;
|
|
3291
|
+
};
|
|
3292
|
+
}
|
|
3116
3293
|
const commonFormItemProps = {
|
|
3117
3294
|
name: {
|
|
3118
|
-
type: "string"
|
|
3295
|
+
type: "string",
|
|
3296
|
+
required: true,
|
|
3297
|
+
defaultValueHint: getDefaultValueHint("name")
|
|
3119
3298
|
},
|
|
3120
3299
|
initialValue: {
|
|
3121
|
-
type: "string"
|
|
3300
|
+
type: "string",
|
|
3301
|
+
defaultValueHint: getDefaultValueHint("initialValue")
|
|
3122
3302
|
},
|
|
3123
3303
|
rules: {
|
|
3124
3304
|
displayName: "Validation rules",
|
|
@@ -3161,7 +3341,8 @@ const commonFormItemProps = {
|
|
|
3161
3341
|
},
|
|
3162
3342
|
hidden: {
|
|
3163
3343
|
type: "boolean",
|
|
3164
|
-
advanced: true
|
|
3344
|
+
advanced: true,
|
|
3345
|
+
defaultValueHint: getDefaultValueHint("hidden")
|
|
3165
3346
|
},
|
|
3166
3347
|
validateTrigger: {
|
|
3167
3348
|
type: "choice",
|
|
@@ -4319,5 +4500,5 @@ const inputTypeToComponentName = Object.fromEntries(
|
|
|
4319
4500
|
Object.entries(componentNameToInputType).map((kv) => kv.reverse())
|
|
4320
4501
|
);
|
|
4321
4502
|
|
|
4322
|
-
export { InputType, buttonComponentName, componentNameToInputType, formComponentName, formGroupComponentName, formItemComponentName, formListComponentName, inputTypeToComponentName, registerAll, useFormInstanceMaybe };
|
|
4503
|
+
export { FormType, InputType, buttonComponentName, componentNameToInputType, formComponentName, formGroupComponentName, formItemComponentName, formListComponentName, formTypeDescription, inputTypeToComponentName, registerAll, registerForm, registerFormGroup, registerFormItem, useFormInstanceMaybe };
|
|
4323
4504
|
//# sourceMappingURL=antd.esm.js.map
|