@plasmicpkgs/antd5 0.0.48 → 0.0.49

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/index.js CHANGED
@@ -75,6 +75,16 @@ function omit(obj, ...keys) {
75
75
  }
76
76
  return res;
77
77
  }
78
+ function usePrevious(value) {
79
+ const prevValue = React__default.default.useRef(void 0);
80
+ React__default.default.useEffect(() => {
81
+ prevValue.current = value;
82
+ return () => {
83
+ prevValue.current = void 0;
84
+ };
85
+ });
86
+ return prevValue.current;
87
+ }
78
88
 
79
89
  const AntdButton = antd.Button;
80
90
  function registerButton(loader) {
@@ -1081,19 +1091,19 @@ const FormList = antd.Form.List;
1081
1091
  const PathContext = React__default.default.createContext({ relativePath: [], fullPath: [] });
1082
1092
  const InternalFormInstanceContext = React__default.default.createContext(void 0);
1083
1093
  const Internal = (props) => {
1084
- var _a, _b;
1094
+ var _b, _c;
1085
1095
  const [form] = antd.Form.useForm();
1086
1096
  const values = form.getFieldsValue(true);
1087
1097
  const lastValue = React__default.default.useRef(values);
1098
+ const _a = props, { extendedOnValuesChange, setRemountKey } = _a, rest = __objRest$5(_a, ["extendedOnValuesChange", "setRemountKey"]);
1088
1099
  const childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
1089
- const fireOnValuesChange = () => {
1090
- var _a2;
1100
+ const fireOnValuesChange = React__default.default.useCallback(() => {
1091
1101
  const values2 = form.getFieldsValue(true);
1092
1102
  if (!equal__default.default(values2, lastValue.current)) {
1093
- (_a2 = props.extendedOnValuesChange) == null ? void 0 : _a2.call(props, values2);
1103
+ extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
1094
1104
  lastValue.current = values2;
1095
1105
  }
1096
- };
1106
+ }, [form, lastValue]);
1097
1107
  React__default.default.useEffect(() => {
1098
1108
  fireOnValuesChange();
1099
1109
  }, []);
@@ -1102,21 +1112,21 @@ const Internal = (props) => {
1102
1112
  {
1103
1113
  value: {
1104
1114
  fireOnValuesChange,
1105
- forceRemount: () => props.setRemountKey((k) => k + 1),
1106
- formProps: props
1115
+ forceRemount: () => setRemountKey((k) => k + 1)
1107
1116
  }
1108
1117
  },
1109
1118
  /* @__PURE__ */ React__default.default.createElement(
1110
1119
  antd.Form,
1111
- __spreadProps$5(__spreadValues$6({}, props), {
1120
+ __spreadProps$5(__spreadValues$6({}, rest), {
1121
+ key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
1112
1122
  onValuesChange: (...args) => {
1113
- var _a2, _b2;
1123
+ var _a2;
1114
1124
  (_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
1115
- (_b2 = props.extendedOnValuesChange) == null ? void 0 : _b2.call(props, args[1]);
1125
+ extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(args[1]);
1116
1126
  },
1117
1127
  form,
1118
- labelCol: ((_a = props.labelCol) == null ? void 0 : _a.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
1119
- wrapperCol: ((_b = props.wrapperCol) == null ? void 0 : _b.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
1128
+ labelCol: ((_b = props.labelCol) == null ? void 0 : _b.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
1129
+ wrapperCol: ((_c = props.wrapperCol) == null ? void 0 : _c.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
1120
1130
  }),
1121
1131
  /* @__PURE__ */ React__default.default.createElement("style", null, `
1122
1132
  .ant-form-item-explain + div, .ant-form-item-margin-offset {
@@ -1129,6 +1139,12 @@ const Internal = (props) => {
1129
1139
  };
1130
1140
  function FormWrapper(props) {
1131
1141
  const [remountKey, setRemountKey] = React__default.default.useState(0);
1142
+ const previousInitialValues = usePrevious(props.initialValues);
1143
+ React__default.default.useEffect(() => {
1144
+ if (previousInitialValues !== props.initialValues && JSON.stringify(previousInitialValues) !== JSON.stringify(props.initialValues)) {
1145
+ setRemountKey((k) => k + 1);
1146
+ }
1147
+ }, [previousInitialValues, props.initialValues]);
1132
1148
  return /* @__PURE__ */ React__default.default.createElement(Internal, __spreadProps$5(__spreadValues$6({ key: remountKey }, props), { setRemountKey }));
1133
1149
  }
1134
1150
  const COMMON_ACTIONS = [
@@ -1254,8 +1270,7 @@ function registerForm(loader) {
1254
1270
  ]
1255
1271
  },
1256
1272
  initialValues: {
1257
- type: "object",
1258
- forceRemount: true
1273
+ type: "object"
1259
1274
  },
1260
1275
  layout: {
1261
1276
  type: "choice",
@@ -1515,10 +1530,7 @@ function registerFormItem(loader) {
1515
1530
  },
1516
1531
  colon: {
1517
1532
  type: "boolean",
1518
- defaultValueHint: (_ps, ctx) => {
1519
- var _a, _b;
1520
- return (_b = (_a = ctx == null ? void 0 : ctx.internalFormCtx) == null ? void 0 : _a.formProps.colon) != null ? _b : true;
1521
- },
1533
+ defaultValueHint: true,
1522
1534
  advanced: true
1523
1535
  },
1524
1536
  labelAlign: {
@@ -1932,6 +1944,21 @@ function registerInput(loader) {
1932
1944
  },
1933
1945
  disabled: {
1934
1946
  type: "boolean"
1947
+ },
1948
+ type: {
1949
+ type: "choice",
1950
+ options: [
1951
+ "text",
1952
+ "password",
1953
+ "number",
1954
+ "date",
1955
+ "datetime-local",
1956
+ "time",
1957
+ "email",
1958
+ "tel",
1959
+ "hidden"
1960
+ ],
1961
+ defaultValueHint: "text"
1935
1962
  }
1936
1963
  }, COMMON_ADVANCED_PROPS), COMMON_DECORATOR_PROPS), COMMON_EVENT_HANDLERS),
1937
1964
  states: __spreadValues$5({}, COMMON_STATES),