@plasmicpkgs/antd5 0.0.83 → 0.0.85
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 +383 -95
- package/dist/antd.esm.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +387 -94
- package/dist/index.js.map +1 -1
- package/dist/registerForm.d.ts +30 -3
- package/dist/utils.d.ts +2 -0
- package/package.json +3 -3
- package/skinny/registerButton.cjs.js +1 -1
- package/skinny/registerButton.esm.js +1 -1
- package/skinny/registerCheckbox.cjs.js +1 -1
- package/skinny/registerCheckbox.esm.js +1 -1
- package/skinny/registerConfigProvider.cjs.js +1 -1
- package/skinny/registerConfigProvider.esm.js +1 -1
- package/skinny/registerDatePicker.cjs.js +1 -1
- package/skinny/registerDatePicker.esm.js +1 -1
- package/skinny/registerDropdown.cjs.js +1 -1
- package/skinny/registerDropdown.esm.js +1 -1
- package/skinny/registerForm.cjs.js +377 -96
- package/skinny/registerForm.cjs.js.map +1 -1
- package/skinny/registerForm.d.ts +30 -3
- package/skinny/registerForm.esm.js +375 -97
- package/skinny/registerForm.esm.js.map +1 -1
- package/skinny/registerInput.cjs.js +1 -1
- package/skinny/registerInput.esm.js +1 -1
- package/skinny/registerMenu.cjs.js +1 -1
- package/skinny/registerMenu.esm.js +1 -1
- package/skinny/registerModal.cjs.js +1 -1
- package/skinny/registerModal.esm.js +1 -1
- package/skinny/registerRadio.cjs.js +1 -1
- package/skinny/registerRadio.esm.js +1 -1
- package/skinny/{registerSelect-9c951faf.cjs.js → registerSelect-2c9dfc05.cjs.js} +2 -2
- package/skinny/{registerSelect-9c951faf.cjs.js.map → registerSelect-2c9dfc05.cjs.js.map} +1 -1
- package/skinny/{registerSelect-97163424.esm.js → registerSelect-3ef48596.esm.js} +2 -2
- package/skinny/{registerSelect-97163424.esm.js.map → registerSelect-3ef48596.esm.js.map} +1 -1
- package/skinny/registerSelect.cjs.js +2 -2
- package/skinny/registerSelect.esm.js +2 -2
- package/skinny/registerSwitch.cjs.js +1 -1
- package/skinny/registerSwitch.esm.js +1 -1
- package/skinny/registerTable.cjs.js +1 -1
- package/skinny/registerTable.esm.js +1 -1
- package/skinny/registerUpload.cjs.js +1 -1
- package/skinny/registerUpload.esm.js +1 -1
- package/skinny/{utils-6bd7e3c6.esm.js → utils-02582d7f.esm.js} +12 -2
- package/skinny/utils-02582d7f.esm.js.map +1 -0
- package/skinny/{utils-dbc32c4f.cjs.js → utils-838eeae8.cjs.js} +12 -1
- package/skinny/utils-838eeae8.cjs.js.map +1 -0
- package/skinny/utils.d.ts +2 -0
- package/skinny/utils-6bd7e3c6.esm.js.map +0 -1
- package/skinny/utils-dbc32c4f.cjs.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { InputType } from "./registerForm";
|
|
|
2
2
|
import { Registerable } from "./utils";
|
|
3
3
|
export declare function registerAll(loader?: Registerable): void;
|
|
4
4
|
export { buttonComponentName } from "./registerButton";
|
|
5
|
-
export { formComponentName, formGroupComponentName, formItemComponentName, formListComponentName, InputType, } from "./registerForm";
|
|
5
|
+
export { FormType, formTypeDescription, formComponentName, formGroupComponentName, formItemComponentName, formListComponentName, InputType, } from "./registerForm";
|
|
6
|
+
export { registerForm, registerFormGroup, registerFormItem, } from "./registerForm";
|
|
6
7
|
export type { SimplifiedFormItemsProp } from "./registerForm";
|
|
7
8
|
export declare const componentNameToInputType: {
|
|
8
9
|
"plasmic-antd5-input": InputType;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var query = require('@plasmicapp/query');
|
|
|
10
10
|
var enUS = require('antd/lib/locale/en_US.js');
|
|
11
11
|
var equal = require('fast-deep-equal');
|
|
12
12
|
var classNames = require('classnames');
|
|
13
|
+
var dataSources = require('@plasmicapp/data-sources');
|
|
13
14
|
var dayjs = require('dayjs');
|
|
14
15
|
|
|
15
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -81,6 +82,16 @@ function capitalize(value) {
|
|
|
81
82
|
function ensureArray(x) {
|
|
82
83
|
return Array.isArray(x) ? x : [x];
|
|
83
84
|
}
|
|
85
|
+
function setFieldsToUndefined(obj) {
|
|
86
|
+
if (typeof obj === "object" && obj !== null) {
|
|
87
|
+
for (const key in obj) {
|
|
88
|
+
if (typeof obj[key] === "object") {
|
|
89
|
+
setFieldsToUndefined(obj[key]);
|
|
90
|
+
}
|
|
91
|
+
obj[key] = void 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
84
95
|
|
|
85
96
|
var __defProp$e = Object.defineProperty;
|
|
86
97
|
var __defProps$b = Object.defineProperties;
|
|
@@ -2412,96 +2423,196 @@ var InputType = /* @__PURE__ */ ((InputType2) => {
|
|
|
2412
2423
|
InputType2["DatePicker"] = "DatePicker";
|
|
2413
2424
|
return InputType2;
|
|
2414
2425
|
})(InputType || {});
|
|
2426
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
2427
|
+
FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
|
|
2428
|
+
FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
|
|
2429
|
+
return FormType2;
|
|
2430
|
+
})(FormType || {});
|
|
2415
2431
|
const PathContext = React__default.default.createContext({ relativePath: [], fullPath: [] });
|
|
2416
2432
|
const InternalFormInstanceContext = React__default.default.createContext(void 0);
|
|
2417
2433
|
const FormLayoutContext = React__default.default.createContext(void 0);
|
|
2418
|
-
const Internal = (
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
antd.Radio.
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
const fireOnValuesChange = React__default.default.useCallback(() => {
|
|
2445
|
-
const values2 = form.getFieldsValue(true);
|
|
2446
|
-
if (!equal__default.default(values2, lastValue.current)) {
|
|
2447
|
-
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
|
|
2448
|
-
lastValue.current = values2;
|
|
2434
|
+
const Internal = React__default.default.forwardRef(
|
|
2435
|
+
(props, ref) => {
|
|
2436
|
+
var _b, _c, _d, _e;
|
|
2437
|
+
const [form] = antd.Form.useForm();
|
|
2438
|
+
const values = form.getFieldsValue(true);
|
|
2439
|
+
const lastValue = React__default.default.useRef(values);
|
|
2440
|
+
const _a = props, { extendedOnValuesChange, setRemountKey } = _a, rest = __objRest$3(_a, ["extendedOnValuesChange", "setRemountKey"]);
|
|
2441
|
+
let childrenNode;
|
|
2442
|
+
if (props.mode === "advanced") {
|
|
2443
|
+
childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
|
|
2444
|
+
} else {
|
|
2445
|
+
childrenNode = /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, ((_b = props.formItems) != null ? _b : []).map((formItem) => /* @__PURE__ */ React__default.default.createElement(
|
|
2446
|
+
FormItemWrapper,
|
|
2447
|
+
__spreadProps$3(__spreadValues$4({}, formItem), {
|
|
2448
|
+
noLabel: formItem.inputType === "Checkbox" /* Checkbox */ || formItem.noLabel,
|
|
2449
|
+
style: { width: "100%" }
|
|
2450
|
+
}),
|
|
2451
|
+
formItem.inputType === "Text" /* Text */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input, null) : formItem.inputType === "Password" /* Password */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input.Password, null) : formItem.inputType === "Text Area" /* TextArea */ ? /* @__PURE__ */ React__default.default.createElement(antd.Input.TextArea, null) : formItem.inputType === "Number" /* Number */ ? /* @__PURE__ */ React__default.default.createElement(antd.InputNumber, null) : formItem.inputType === "Checkbox" /* Checkbox */ ? /* @__PURE__ */ React__default.default.createElement(antd.Checkbox, null, formItem.label) : formItem.inputType === "Select" /* Select */ ? /* @__PURE__ */ React__default.default.createElement(antd.Select, { options: formItem.options }) : formItem.inputType === "DatePicker" /* DatePicker */ ? /* @__PURE__ */ React__default.default.createElement(antd.DatePicker, null) : formItem.inputType === "Radio Group" /* RadioGroup */ ? /* @__PURE__ */ React__default.default.createElement(
|
|
2452
|
+
antd.Radio.Group,
|
|
2453
|
+
{
|
|
2454
|
+
options: formItem.options,
|
|
2455
|
+
optionType: formItem.optionType,
|
|
2456
|
+
style: { padding: "8px" }
|
|
2457
|
+
}
|
|
2458
|
+
) : null
|
|
2459
|
+
)), props.submitSlot);
|
|
2449
2460
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
() => {
|
|
2456
|
-
var _a2;
|
|
2457
|
-
return {
|
|
2458
|
-
layout: props.layout,
|
|
2459
|
-
labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
|
|
2460
|
-
};
|
|
2461
|
-
},
|
|
2462
|
-
[props.layout, (_c = props.labelCol) == null ? void 0 : _c.span]
|
|
2463
|
-
);
|
|
2464
|
-
return /* @__PURE__ */ React__default.default.createElement(
|
|
2465
|
-
InternalFormInstanceContext.Provider,
|
|
2466
|
-
{
|
|
2467
|
-
value: {
|
|
2468
|
-
layout: formLayout,
|
|
2469
|
-
fireOnValuesChange,
|
|
2470
|
-
forceRemount: () => setRemountKey((k) => k + 1)
|
|
2461
|
+
const fireOnValuesChange = React__default.default.useCallback(() => {
|
|
2462
|
+
const values2 = form.getFieldsValue(true);
|
|
2463
|
+
if (!equal__default.default(values2, lastValue.current)) {
|
|
2464
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
|
|
2465
|
+
lastValue.current = values2;
|
|
2471
2466
|
}
|
|
2472
|
-
},
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2467
|
+
}, [form, lastValue]);
|
|
2468
|
+
React__default.default.useEffect(() => {
|
|
2469
|
+
fireOnValuesChange();
|
|
2470
|
+
}, []);
|
|
2471
|
+
const formLayout = React__default.default.useMemo(
|
|
2472
|
+
() => {
|
|
2473
|
+
var _a2;
|
|
2474
|
+
return {
|
|
2475
|
+
layout: props.layout,
|
|
2476
|
+
labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
|
|
2477
|
+
};
|
|
2478
|
+
},
|
|
2479
|
+
[props.layout, (_c = props.labelCol) == null ? void 0 : _c.span]
|
|
2480
|
+
);
|
|
2481
|
+
React__default.default.useImperativeHandle(ref, () => ({
|
|
2482
|
+
formInstance: form,
|
|
2483
|
+
setFieldsValue: (newValues) => {
|
|
2484
|
+
form.setFieldsValue(newValues);
|
|
2485
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
2486
|
+
},
|
|
2487
|
+
setFieldValue: (namePath, value) => {
|
|
2488
|
+
form.setFieldValue(namePath, value);
|
|
2489
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
2490
|
+
},
|
|
2491
|
+
resetFields: () => {
|
|
2492
|
+
form.resetFields();
|
|
2493
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
2494
|
+
},
|
|
2495
|
+
clearFields: () => {
|
|
2496
|
+
const values2 = form.getFieldsValue(true);
|
|
2497
|
+
setFieldsToUndefined(values2);
|
|
2498
|
+
form.setFieldsValue(values2);
|
|
2499
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
2500
|
+
}
|
|
2501
|
+
}));
|
|
2502
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
2503
|
+
InternalFormInstanceContext.Provider,
|
|
2504
|
+
{
|
|
2505
|
+
value: {
|
|
2506
|
+
layout: formLayout,
|
|
2507
|
+
fireOnValuesChange,
|
|
2508
|
+
forceRemount: () => setRemountKey((k) => k + 1)
|
|
2509
|
+
}
|
|
2510
|
+
},
|
|
2511
|
+
/* @__PURE__ */ React__default.default.createElement(FormLayoutContext.Provider, { value: formLayout }, /* @__PURE__ */ React__default.default.createElement(
|
|
2512
|
+
antd.Form,
|
|
2513
|
+
__spreadProps$3(__spreadValues$4({}, rest), {
|
|
2514
|
+
key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
|
|
2515
|
+
onValuesChange: (...args) => {
|
|
2516
|
+
var _a2;
|
|
2517
|
+
(_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
|
|
2518
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(args[1]);
|
|
2519
|
+
},
|
|
2520
|
+
form,
|
|
2521
|
+
labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
|
|
2522
|
+
wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
|
|
2523
|
+
}),
|
|
2524
|
+
/* @__PURE__ */ React__default.default.createElement("style", null, `
|
|
2487
2525
|
.ant-form-item-explain + div, .ant-form-item-margin-offset {
|
|
2488
2526
|
display: none;
|
|
2489
2527
|
}
|
|
2490
2528
|
`),
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
const
|
|
2498
|
-
React__default.default.
|
|
2499
|
-
if (
|
|
2500
|
-
|
|
2529
|
+
childrenNode
|
|
2530
|
+
))
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
);
|
|
2534
|
+
function useFormItemDefinitions(rawData, props, formRef) {
|
|
2535
|
+
const { mode, formItems, setControlContextData } = props;
|
|
2536
|
+
return React__default.default.useMemo(() => {
|
|
2537
|
+
if (mode !== "simplified" || !formRef || !rawData || rawData.error) {
|
|
2538
|
+
return void 0;
|
|
2539
|
+
}
|
|
2540
|
+
const data = dataSources.normalizeData(rawData);
|
|
2541
|
+
const schema = data == null ? void 0 : data.schema;
|
|
2542
|
+
if (!data || !schema || !data.data) {
|
|
2543
|
+
return void 0;
|
|
2501
2544
|
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2545
|
+
const row = data.data.length > 0 ? data.data[0] : void 0;
|
|
2546
|
+
const { mergedFields, minimalFullLengthFields } = dataSources.deriveFieldConfigs(
|
|
2547
|
+
formItems != null ? formItems : [],
|
|
2548
|
+
schema,
|
|
2549
|
+
(field) => __spreadValues$4({
|
|
2550
|
+
inputType: "Text" /* Text */
|
|
2551
|
+
}, field && {
|
|
2552
|
+
key: field.id,
|
|
2553
|
+
fieldId: field.id,
|
|
2554
|
+
label: field.label,
|
|
2555
|
+
name: field.id,
|
|
2556
|
+
inputType: field.type === "string" ? "Text" /* Text */ : field.type === "number" ? "Number" /* Number */ : field.type === "boolean" ? "Checkbox" /* Checkbox */ : "Text" /* Text */,
|
|
2557
|
+
//missing date and date-time
|
|
2558
|
+
initialValue: row ? row[field.id] : void 0,
|
|
2559
|
+
hidden: field.primaryKey
|
|
2560
|
+
})
|
|
2561
|
+
);
|
|
2562
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
2563
|
+
schema: data.schema,
|
|
2564
|
+
minimalFullLengthFields,
|
|
2565
|
+
mergedFields,
|
|
2566
|
+
formInstance: formRef.formInstance
|
|
2567
|
+
});
|
|
2568
|
+
return mergedFields;
|
|
2569
|
+
}, [mode, setControlContextData, formItems, rawData, formRef]);
|
|
2504
2570
|
}
|
|
2571
|
+
const useRawData = (connection) => {
|
|
2572
|
+
const rawDataSchema = dataSources.usePlasmicDataOp(connection == null ? void 0 : connection.dataSchema);
|
|
2573
|
+
const rawDataEntry = dataSources.usePlasmicDataOp(connection == null ? void 0 : connection.dataEntry);
|
|
2574
|
+
if (!connection) {
|
|
2575
|
+
return void 0;
|
|
2576
|
+
}
|
|
2577
|
+
return 0 /* NewEntry */ === connection.formType ? rawDataSchema : rawDataEntry;
|
|
2578
|
+
};
|
|
2579
|
+
const FormWrapper = React__default.default.forwardRef(
|
|
2580
|
+
(props, ref) => {
|
|
2581
|
+
const [remountKey, setRemountKey] = React__default.default.useState(0);
|
|
2582
|
+
const previousInitialValues = usePrevious(props.initialValues);
|
|
2583
|
+
const wrapperRef = React__default.default.useRef(null);
|
|
2584
|
+
React__default.default.useEffect(() => {
|
|
2585
|
+
if (previousInitialValues !== props.initialValues && JSON.stringify(previousInitialValues) !== JSON.stringify(props.initialValues)) {
|
|
2586
|
+
setRemountKey((k) => k + 1);
|
|
2587
|
+
}
|
|
2588
|
+
}, [previousInitialValues, props.initialValues]);
|
|
2589
|
+
React__default.default.useImperativeHandle(
|
|
2590
|
+
ref,
|
|
2591
|
+
() => wrapperRef.current ? __spreadValues$4({}, wrapperRef.current) : {}
|
|
2592
|
+
);
|
|
2593
|
+
const rawData = useRawData(props.data);
|
|
2594
|
+
const formItemDefinitions = useFormItemDefinitions(
|
|
2595
|
+
rawData,
|
|
2596
|
+
props,
|
|
2597
|
+
wrapperRef.current
|
|
2598
|
+
);
|
|
2599
|
+
const _a = props, { formItems } = _a, rest = __objRest$3(_a, ["formItems"]);
|
|
2600
|
+
const actualFormItems = props.mode === "simplified" && formItemDefinitions ? formItemDefinitions : formItems;
|
|
2601
|
+
if (props.mode === "simplified" && rawData && "error" in rawData) {
|
|
2602
|
+
return /* @__PURE__ */ React__default.default.createElement("div", null, "Error when fetching data: ", rawData.error.message);
|
|
2603
|
+
}
|
|
2604
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
2605
|
+
Internal,
|
|
2606
|
+
__spreadProps$3(__spreadValues$4({
|
|
2607
|
+
key: remountKey
|
|
2608
|
+
}, rest), {
|
|
2609
|
+
setRemountKey,
|
|
2610
|
+
formItems: actualFormItems,
|
|
2611
|
+
ref: wrapperRef
|
|
2612
|
+
})
|
|
2613
|
+
);
|
|
2614
|
+
}
|
|
2615
|
+
);
|
|
2505
2616
|
const COMMON_ACTIONS = [
|
|
2506
2617
|
{
|
|
2507
2618
|
type: "button-action",
|
|
@@ -2515,7 +2626,7 @@ const COMMON_ACTIONS = [
|
|
|
2515
2626
|
"children"
|
|
2516
2627
|
);
|
|
2517
2628
|
},
|
|
2518
|
-
hidden: (props) => props.mode
|
|
2629
|
+
hidden: (props) => props.mode !== "advanced"
|
|
2519
2630
|
}
|
|
2520
2631
|
// {
|
|
2521
2632
|
// type: "button-action" as const,
|
|
@@ -2572,7 +2683,71 @@ const colProp = (displayName, defaultValue, description) => ({
|
|
|
2572
2683
|
description,
|
|
2573
2684
|
defaultValue
|
|
2574
2685
|
});
|
|
2686
|
+
const formHelpers = {
|
|
2687
|
+
states: {
|
|
2688
|
+
value: {
|
|
2689
|
+
onMutate: (value, $ref) => {
|
|
2690
|
+
var _a;
|
|
2691
|
+
(_a = $ref == null ? void 0 : $ref.formInstance) == null ? void 0 : _a.setFieldsValue(value);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2575
2696
|
const formComponentName = "plasmic-antd5-form";
|
|
2697
|
+
const formTypeDescription = `
|
|
2698
|
+
You can create form with two different behaviors:
|
|
2699
|
+
|
|
2700
|
+
|
|
2701
|
+
|
|
2702
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
2703
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
2704
|
+
|
|
2705
|
+
|
|
2706
|
+
|
|
2707
|
+
For both options, you can customize later.
|
|
2708
|
+
`;
|
|
2709
|
+
const getConnectionDBPropRegistration = () => ({
|
|
2710
|
+
formType: {
|
|
2711
|
+
type: "choice",
|
|
2712
|
+
options: [
|
|
2713
|
+
{ label: "New entry", value: 0 /* NewEntry */ },
|
|
2714
|
+
{ label: "Update entry", value: 1 /* UpdateEntry */ }
|
|
2715
|
+
],
|
|
2716
|
+
displayName: "Form Type",
|
|
2717
|
+
disableDynamicValue: true,
|
|
2718
|
+
defaultValueHint: "Select the form type...",
|
|
2719
|
+
description: `
|
|
2720
|
+
You can create form with two different behaviors:
|
|
2721
|
+
|
|
2722
|
+
|
|
2723
|
+
|
|
2724
|
+
1. Create a new entry: The form will be created empty and it will create a new row when submitted.
|
|
2725
|
+
2. Update an entry: The form will be pre-filled with the row values and it will update the table entry when submitted.
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
|
|
2729
|
+
For both options, you can customize later.
|
|
2730
|
+
`
|
|
2731
|
+
},
|
|
2732
|
+
dataSchema: {
|
|
2733
|
+
type: "dataSourceOp",
|
|
2734
|
+
description: "The data to generate the form",
|
|
2735
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 0 /* NewEntry */,
|
|
2736
|
+
displayName: "",
|
|
2737
|
+
disableDynamicValue: true,
|
|
2738
|
+
allowedOps: () => ["getTableSchema"],
|
|
2739
|
+
hideCacheKey: true
|
|
2740
|
+
},
|
|
2741
|
+
dataEntry: {
|
|
2742
|
+
type: "dataSourceOp",
|
|
2743
|
+
description: "The data to generate the form",
|
|
2744
|
+
hidden: (_ps, _ctx, { item }) => item.formType !== 1 /* UpdateEntry */,
|
|
2745
|
+
displayName: "",
|
|
2746
|
+
disableDynamicValue: true,
|
|
2747
|
+
allowedOps: () => ["getOne"],
|
|
2748
|
+
hideCacheKey: true
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2576
2751
|
function registerForm(loader) {
|
|
2577
2752
|
registerComponentHelper(loader, FormWrapper, {
|
|
2578
2753
|
name: formComponentName,
|
|
@@ -2586,13 +2761,22 @@ function registerForm(loader) {
|
|
|
2586
2761
|
type: "controlMode",
|
|
2587
2762
|
defaultValue: "simplified"
|
|
2588
2763
|
},
|
|
2764
|
+
data: {
|
|
2765
|
+
type: "object",
|
|
2766
|
+
fields: getConnectionDBPropRegistration(),
|
|
2767
|
+
hidden: (ps) => ps.mode !== "simplified" || !ps.data,
|
|
2768
|
+
nameFunc: () => "DB Connection"
|
|
2769
|
+
},
|
|
2589
2770
|
formItems: {
|
|
2590
2771
|
displayName: "Fields",
|
|
2591
2772
|
type: "array",
|
|
2592
2773
|
itemType: {
|
|
2593
2774
|
type: "object",
|
|
2594
2775
|
fields: __spreadValues$4({
|
|
2595
|
-
label:
|
|
2776
|
+
label: {
|
|
2777
|
+
type: "string",
|
|
2778
|
+
defaultValueHint: getDefaultValueHint("label")
|
|
2779
|
+
},
|
|
2596
2780
|
inputType: {
|
|
2597
2781
|
type: "choice",
|
|
2598
2782
|
options: Object.values(InputType).filter(
|
|
@@ -2602,7 +2786,8 @@ function registerForm(loader) {
|
|
|
2602
2786
|
"Radio" /* Radio */
|
|
2603
2787
|
].includes(inputType)
|
|
2604
2788
|
),
|
|
2605
|
-
defaultValue: "Text" /* Text
|
|
2789
|
+
defaultValue: "Text" /* Text */,
|
|
2790
|
+
defaultValueHint: getDefaultValueHint("inputType")
|
|
2606
2791
|
},
|
|
2607
2792
|
options: {
|
|
2608
2793
|
type: "array",
|
|
@@ -2671,7 +2856,10 @@ function registerForm(loader) {
|
|
|
2671
2856
|
displayName: "Option Type"
|
|
2672
2857
|
}
|
|
2673
2858
|
}, commonFormItemProps),
|
|
2674
|
-
nameFunc: (item) =>
|
|
2859
|
+
nameFunc: (item) => {
|
|
2860
|
+
var _a, _b;
|
|
2861
|
+
return (_b = (_a = item.fieldId) != null ? _a : item.label) != null ? _b : item.name;
|
|
2862
|
+
}
|
|
2675
2863
|
},
|
|
2676
2864
|
defaultValue: [
|
|
2677
2865
|
{
|
|
@@ -2685,7 +2873,31 @@ function registerForm(loader) {
|
|
|
2685
2873
|
inputType: "Text Area" /* TextArea */
|
|
2686
2874
|
}
|
|
2687
2875
|
],
|
|
2688
|
-
hidden: (
|
|
2876
|
+
hidden: (ps) => {
|
|
2877
|
+
if (ps.mode === "advanced") {
|
|
2878
|
+
return true;
|
|
2879
|
+
}
|
|
2880
|
+
if (ps.mode === "simplified") {
|
|
2881
|
+
return false;
|
|
2882
|
+
}
|
|
2883
|
+
return !ps.data || !ps.formType;
|
|
2884
|
+
},
|
|
2885
|
+
unstable__keyFunc: (x) => x.key,
|
|
2886
|
+
unstable__minimalValue: (ps, contextData) => {
|
|
2887
|
+
return ps.mode === "simplified" ? ps.formItems : contextData == null ? void 0 : contextData.minimalFullLengthFields;
|
|
2888
|
+
},
|
|
2889
|
+
unstable__canDelete: (item, ps, ctx) => {
|
|
2890
|
+
if (ps.mode !== "database-schema-driven") {
|
|
2891
|
+
return true;
|
|
2892
|
+
}
|
|
2893
|
+
if (!(ctx == null ? void 0 : ctx.schema)) {
|
|
2894
|
+
return false;
|
|
2895
|
+
}
|
|
2896
|
+
if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
|
|
2897
|
+
return false;
|
|
2898
|
+
}
|
|
2899
|
+
return true;
|
|
2900
|
+
}
|
|
2689
2901
|
},
|
|
2690
2902
|
submitSlot: __spreadValues$4({
|
|
2691
2903
|
type: "slot",
|
|
@@ -2708,7 +2920,7 @@ function registerForm(loader) {
|
|
|
2708
2920
|
}),
|
|
2709
2921
|
children: {
|
|
2710
2922
|
type: "slot",
|
|
2711
|
-
hidden: (props) => props.mode
|
|
2923
|
+
hidden: (props) => props.mode !== "advanced"
|
|
2712
2924
|
},
|
|
2713
2925
|
initialValues: {
|
|
2714
2926
|
displayName: "Initial field values",
|
|
@@ -2821,7 +3033,13 @@ function registerForm(loader) {
|
|
|
2821
3033
|
advanced: true
|
|
2822
3034
|
}
|
|
2823
3035
|
},
|
|
2824
|
-
actions:
|
|
3036
|
+
actions: [
|
|
3037
|
+
...COMMON_ACTIONS,
|
|
3038
|
+
{
|
|
3039
|
+
type: "form-schema",
|
|
3040
|
+
hidden: (ps) => ps.mode !== "simplified" || !!ps.data
|
|
3041
|
+
}
|
|
3042
|
+
],
|
|
2825
3043
|
states: {
|
|
2826
3044
|
value: {
|
|
2827
3045
|
type: "readonly",
|
|
@@ -2829,6 +3047,54 @@ function registerForm(loader) {
|
|
|
2829
3047
|
onChangeProp: "extendedOnValuesChange"
|
|
2830
3048
|
}
|
|
2831
3049
|
},
|
|
3050
|
+
componentHelpers: {
|
|
3051
|
+
helpers: formHelpers,
|
|
3052
|
+
importName: "formHelpers",
|
|
3053
|
+
importPath: "@plasmicpkgs/antd5/skinny/registerForm"
|
|
3054
|
+
},
|
|
3055
|
+
refActions: {
|
|
3056
|
+
setFieldsValue: {
|
|
3057
|
+
displayName: "Set multiple fields",
|
|
3058
|
+
argTypes: [
|
|
3059
|
+
{
|
|
3060
|
+
name: "newValues",
|
|
3061
|
+
displayName: "New Values",
|
|
3062
|
+
type: "exprEditor"
|
|
3063
|
+
}
|
|
3064
|
+
]
|
|
3065
|
+
},
|
|
3066
|
+
setFieldValue: {
|
|
3067
|
+
displayName: "Set field",
|
|
3068
|
+
argTypes: [
|
|
3069
|
+
{
|
|
3070
|
+
name: "namePath",
|
|
3071
|
+
displayName: "Name Path",
|
|
3072
|
+
type: {
|
|
3073
|
+
type: "dataSelector",
|
|
3074
|
+
data: (_, ctx) => {
|
|
3075
|
+
if (!(ctx == null ? void 0 : ctx.formInstance)) {
|
|
3076
|
+
return {};
|
|
3077
|
+
}
|
|
3078
|
+
return ctx.formInstance.getFieldsValue(true);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
},
|
|
3082
|
+
{
|
|
3083
|
+
name: "value",
|
|
3084
|
+
displayName: "New Value",
|
|
3085
|
+
type: "exprEditor"
|
|
3086
|
+
}
|
|
3087
|
+
]
|
|
3088
|
+
},
|
|
3089
|
+
resetFields: {
|
|
3090
|
+
displayName: "Reset fields to initial value",
|
|
3091
|
+
argTypes: []
|
|
3092
|
+
},
|
|
3093
|
+
clearFields: {
|
|
3094
|
+
displayName: "Clear fields",
|
|
3095
|
+
argTypes: []
|
|
3096
|
+
}
|
|
3097
|
+
},
|
|
2832
3098
|
importPath: "@plasmicpkgs/antd5/skinny/registerForm",
|
|
2833
3099
|
importName: "FormWrapper"
|
|
2834
3100
|
});
|
|
@@ -2935,10 +3201,13 @@ function FormItemWrapper(props) {
|
|
|
2935
3201
|
initialValue: props.initialValue,
|
|
2936
3202
|
name: props.name
|
|
2937
3203
|
});
|
|
3204
|
+
const fullPath = React__default.default.useContext(PathContext).fullPath;
|
|
2938
3205
|
const internalFormCtx = React__default.default.useContext(InternalFormInstanceContext);
|
|
2939
3206
|
const { fireOnValuesChange, forceRemount } = internalFormCtx != null ? internalFormCtx : {};
|
|
2940
3207
|
(_b = props.setControlContextData) == null ? void 0 : _b.call(props, {
|
|
2941
|
-
internalFormCtx
|
|
3208
|
+
internalFormCtx,
|
|
3209
|
+
formInstance: form,
|
|
3210
|
+
parentFormItemPath: fullPath
|
|
2942
3211
|
});
|
|
2943
3212
|
React__default.default.useEffect(() => {
|
|
2944
3213
|
if (prevPropValues.current.name !== props.name) {
|
|
@@ -2968,15 +3237,16 @@ function FormItemWrapper(props) {
|
|
|
2968
3237
|
);
|
|
2969
3238
|
}
|
|
2970
3239
|
function deriveValuePropName(props) {
|
|
3240
|
+
var _a;
|
|
2971
3241
|
if (props.valuePropName) {
|
|
2972
3242
|
return props.valuePropName;
|
|
2973
3243
|
}
|
|
2974
|
-
const valueProps = React__default.default.Children.map(props.children, (child) => {
|
|
2975
|
-
var
|
|
3244
|
+
const valueProps = ((_a = React__default.default.Children.map(props.children, (child) => {
|
|
3245
|
+
var _a2;
|
|
2976
3246
|
if (React__default.default.isValidElement(child)) {
|
|
2977
3247
|
const childType = child.type;
|
|
2978
3248
|
if (childType) {
|
|
2979
|
-
const x = (
|
|
3249
|
+
const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.valueProp;
|
|
2980
3250
|
if (x) {
|
|
2981
3251
|
return x;
|
|
2982
3252
|
}
|
|
@@ -2987,7 +3257,7 @@ function deriveValuePropName(props) {
|
|
|
2987
3257
|
}
|
|
2988
3258
|
}
|
|
2989
3259
|
return void 0;
|
|
2990
|
-
}).filter((x) => !!x);
|
|
3260
|
+
})) != null ? _a : []).filter((x) => !!x);
|
|
2991
3261
|
if (valueProps.length > 0) {
|
|
2992
3262
|
return valueProps[0];
|
|
2993
3263
|
}
|
|
@@ -3019,12 +3289,29 @@ function FormItemForwarder(_a) {
|
|
|
3019
3289
|
return i === 0 && React.isValidElement(child) ? React.cloneElement(child, newProps) : child;
|
|
3020
3290
|
});
|
|
3021
3291
|
}
|
|
3292
|
+
function getDefaultValueHint(field) {
|
|
3293
|
+
return (_props, contextData, { item }) => {
|
|
3294
|
+
if (!contextData || !("mergedFields" in contextData)) {
|
|
3295
|
+
return void 0;
|
|
3296
|
+
}
|
|
3297
|
+
if (item == null ? void 0 : item.fieldId) {
|
|
3298
|
+
const fieldSetting = contextData.mergedFields.find(
|
|
3299
|
+
(f) => f.fieldId === item.fieldId
|
|
3300
|
+
);
|
|
3301
|
+
return fieldSetting == null ? void 0 : fieldSetting[field];
|
|
3302
|
+
}
|
|
3303
|
+
return void 0;
|
|
3304
|
+
};
|
|
3305
|
+
}
|
|
3022
3306
|
const commonFormItemProps = {
|
|
3023
3307
|
name: {
|
|
3024
|
-
type: "string"
|
|
3308
|
+
type: "string",
|
|
3309
|
+
required: true,
|
|
3310
|
+
defaultValueHint: getDefaultValueHint("name")
|
|
3025
3311
|
},
|
|
3026
3312
|
initialValue: {
|
|
3027
|
-
type: "string"
|
|
3313
|
+
type: "string",
|
|
3314
|
+
defaultValueHint: getDefaultValueHint("initialValue")
|
|
3028
3315
|
},
|
|
3029
3316
|
rules: {
|
|
3030
3317
|
displayName: "Validation rules",
|
|
@@ -3067,7 +3354,8 @@ const commonFormItemProps = {
|
|
|
3067
3354
|
},
|
|
3068
3355
|
hidden: {
|
|
3069
3356
|
type: "boolean",
|
|
3070
|
-
advanced: true
|
|
3357
|
+
advanced: true,
|
|
3358
|
+
defaultValueHint: getDefaultValueHint("hidden")
|
|
3071
3359
|
},
|
|
3072
3360
|
validateTrigger: {
|
|
3073
3361
|
type: "choice",
|
|
@@ -4225,6 +4513,7 @@ const inputTypeToComponentName = Object.fromEntries(
|
|
|
4225
4513
|
Object.entries(componentNameToInputType).map((kv) => kv.reverse())
|
|
4226
4514
|
);
|
|
4227
4515
|
|
|
4516
|
+
exports.FormType = FormType;
|
|
4228
4517
|
exports.InputType = InputType;
|
|
4229
4518
|
exports.buttonComponentName = buttonComponentName;
|
|
4230
4519
|
exports.componentNameToInputType = componentNameToInputType;
|
|
@@ -4232,7 +4521,11 @@ exports.formComponentName = formComponentName;
|
|
|
4232
4521
|
exports.formGroupComponentName = formGroupComponentName;
|
|
4233
4522
|
exports.formItemComponentName = formItemComponentName;
|
|
4234
4523
|
exports.formListComponentName = formListComponentName;
|
|
4524
|
+
exports.formTypeDescription = formTypeDescription;
|
|
4235
4525
|
exports.inputTypeToComponentName = inputTypeToComponentName;
|
|
4236
4526
|
exports.registerAll = registerAll;
|
|
4527
|
+
exports.registerForm = registerForm;
|
|
4528
|
+
exports.registerFormGroup = registerFormGroup;
|
|
4529
|
+
exports.registerFormItem = registerFormItem;
|
|
4237
4530
|
exports.useFormInstanceMaybe = useFormInstanceMaybe;
|
|
4238
4531
|
//# sourceMappingURL=index.js.map
|