@plasmicpkgs/antd5 0.0.26 → 0.0.27

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/antd.esm.js CHANGED
@@ -4,7 +4,7 @@ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
4
4
  import Checkbox from 'antd/es/checkbox';
5
5
  import CheckboxGroup from 'antd/es/checkbox/Group';
6
6
  import React from 'react';
7
- import { GlobalActionsProvider } from '@plasmicapp/host';
7
+ import { GlobalActionsProvider, usePlasmicCanvasContext, DataProvider, repeatedElement } from '@plasmicapp/host';
8
8
  import registerToken from '@plasmicapp/host/registerToken';
9
9
  import { addLoadingStateListener } from '@plasmicapp/query';
10
10
  import ConfigProvider from 'antd/es/config-provider';
@@ -14,6 +14,10 @@ import useNotification from 'antd/es/notification/useNotification';
14
14
  import theme from 'antd/es/theme';
15
15
  import Dropdown from 'antd/es/dropdown';
16
16
  import Menu from 'antd/es/menu';
17
+ import Form from 'antd/lib/form';
18
+ import FormItem from 'antd/lib/form/FormItem';
19
+ import FormList from 'antd/lib/form/FormList';
20
+ import equal from 'fast-deep-equal';
17
21
  import Modal from 'antd/es/modal';
18
22
  import Radio from 'antd/es/radio';
19
23
  import RadioGroup from 'antd/es/radio/group';
@@ -63,6 +67,18 @@ function asArray(x) {
63
67
  return [x];
64
68
  }
65
69
  }
70
+ function omit(obj, ...keys) {
71
+ if (Object.keys(obj).length === 0) {
72
+ return obj;
73
+ }
74
+ const res = {};
75
+ for (const key of Object.keys(obj)) {
76
+ if (!keys.includes(key)) {
77
+ res[key] = obj[key];
78
+ }
79
+ }
80
+ return res;
81
+ }
66
82
 
67
83
  const AntdButton = Button;
68
84
  function registerButton(loader) {
@@ -138,33 +154,33 @@ function registerButton(loader) {
138
154
  });
139
155
  }
140
156
 
141
- var __defProp$6 = Object.defineProperty;
142
- var __defProps$5 = Object.defineProperties;
143
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
144
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
145
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
146
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
147
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
148
- var __spreadValues$6 = (a, b) => {
157
+ var __defProp$7 = Object.defineProperty;
158
+ var __defProps$6 = Object.defineProperties;
159
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
160
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
161
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
162
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
163
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
164
+ var __spreadValues$7 = (a, b) => {
149
165
  for (var prop in b || (b = {}))
150
- if (__hasOwnProp$6.call(b, prop))
151
- __defNormalProp$6(a, prop, b[prop]);
152
- if (__getOwnPropSymbols$6)
153
- for (var prop of __getOwnPropSymbols$6(b)) {
154
- if (__propIsEnum$6.call(b, prop))
155
- __defNormalProp$6(a, prop, b[prop]);
166
+ if (__hasOwnProp$7.call(b, prop))
167
+ __defNormalProp$7(a, prop, b[prop]);
168
+ if (__getOwnPropSymbols$7)
169
+ for (var prop of __getOwnPropSymbols$7(b)) {
170
+ if (__propIsEnum$7.call(b, prop))
171
+ __defNormalProp$7(a, prop, b[prop]);
156
172
  }
157
173
  return a;
158
174
  };
159
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
175
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
160
176
  var __objRest$6 = (source, exclude) => {
161
177
  var target = {};
162
178
  for (var prop in source)
163
- if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
179
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
164
180
  target[prop] = source[prop];
165
- if (source != null && __getOwnPropSymbols$6)
166
- for (var prop of __getOwnPropSymbols$6(source)) {
167
- if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
181
+ if (source != null && __getOwnPropSymbols$7)
182
+ for (var prop of __getOwnPropSymbols$7(source)) {
183
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
168
184
  target[prop] = source[prop];
169
185
  }
170
186
  return target;
@@ -178,7 +194,7 @@ function AntdCheckbox(props) {
178
194
  return void 0;
179
195
  }
180
196
  }, [onChange]);
181
- return /* @__PURE__ */ React.createElement(Checkbox, __spreadProps$5(__spreadValues$6({}, rest), {
197
+ return /* @__PURE__ */ React.createElement(Checkbox, __spreadProps$6(__spreadValues$7({}, rest), {
182
198
  onChange: wrappedOnChange
183
199
  }));
184
200
  }
@@ -289,33 +305,33 @@ function registerCheckbox(loader) {
289
305
  });
290
306
  }
291
307
 
292
- var __defProp$5 = Object.defineProperty;
293
- var __defProps$4 = Object.defineProperties;
294
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
295
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
296
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
297
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
298
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
299
- var __spreadValues$5 = (a, b) => {
308
+ var __defProp$6 = Object.defineProperty;
309
+ var __defProps$5 = Object.defineProperties;
310
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
311
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
312
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
313
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
314
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
315
+ var __spreadValues$6 = (a, b) => {
300
316
  for (var prop in b || (b = {}))
301
- if (__hasOwnProp$5.call(b, prop))
302
- __defNormalProp$5(a, prop, b[prop]);
303
- if (__getOwnPropSymbols$5)
304
- for (var prop of __getOwnPropSymbols$5(b)) {
305
- if (__propIsEnum$5.call(b, prop))
306
- __defNormalProp$5(a, prop, b[prop]);
317
+ if (__hasOwnProp$6.call(b, prop))
318
+ __defNormalProp$6(a, prop, b[prop]);
319
+ if (__getOwnPropSymbols$6)
320
+ for (var prop of __getOwnPropSymbols$6(b)) {
321
+ if (__propIsEnum$6.call(b, prop))
322
+ __defNormalProp$6(a, prop, b[prop]);
307
323
  }
308
324
  return a;
309
325
  };
310
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
326
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
311
327
  var __objRest$5 = (source, exclude) => {
312
328
  var target = {};
313
329
  for (var prop in source)
314
- if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
330
+ if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
315
331
  target[prop] = source[prop];
316
- if (source != null && __getOwnPropSymbols$5)
317
- for (var prop of __getOwnPropSymbols$5(source)) {
318
- if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
332
+ if (source != null && __getOwnPropSymbols$6)
333
+ for (var prop of __getOwnPropSymbols$6(source)) {
334
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
319
335
  target[prop] = source[prop];
320
336
  }
321
337
  return target;
@@ -337,7 +353,7 @@ function themeToAntdConfig(opts) {
337
353
  wireframe,
338
354
  spacing
339
355
  } = opts;
340
- return __spreadProps$4(__spreadValues$5({}, spacing && { size: spacing }), {
356
+ return __spreadProps$5(__spreadValues$6({}, spacing && { size: spacing }), {
341
357
  theme: {
342
358
  token: Object.fromEntries(Object.entries({
343
359
  colorTextBase,
@@ -359,9 +375,9 @@ function themeToAntdConfig(opts) {
359
375
  }
360
376
  function AntdConfigProvider(props) {
361
377
  const _a = props, { children, themeStyles } = _a, rest = __objRest$5(_a, ["children", "themeStyles"]);
362
- return /* @__PURE__ */ React.createElement(ConfigProvider, __spreadValues$5({
378
+ return /* @__PURE__ */ React.createElement(ConfigProvider, __spreadValues$6({
363
379
  locale: enUS
364
- }, themeToAntdConfig(__spreadProps$4(__spreadValues$5({}, rest), {
380
+ }, themeToAntdConfig(__spreadProps$5(__spreadValues$6({}, rest), {
365
381
  fontFamily: themeStyles.fontFamily,
366
382
  fontSize: themeStyles.fontSize ? parseInt(themeStyles.fontSize) : void 0,
367
383
  lineHeight: themeStyles.lineHeight ? parseInt(themeStyles.lineHeight) : void 0,
@@ -382,7 +398,7 @@ function InnerConfigProvider(props) {
382
398
  showNotification: (opts) => {
383
399
  var _b;
384
400
  const _a = opts, rest = __objRest$5(_a, ["type"]);
385
- app.notification[(_b = opts.type) != null ? _b : "info"](__spreadValues$5({}, rest));
401
+ app.notification[(_b = opts.type) != null ? _b : "info"](__spreadValues$6({}, rest));
386
402
  },
387
403
  hideNotifications: () => {
388
404
  app.notification.destroy();
@@ -638,7 +654,7 @@ function registerTokens(loader) {
638
654
  regs.forEach((t) => registerToken(t));
639
655
  }
640
656
  }
641
- const registerConfigProvider = makeRegisterGlobalContext(AntdConfigProvider, __spreadProps$4(__spreadValues$5({
657
+ const registerConfigProvider = makeRegisterGlobalContext(AntdConfigProvider, __spreadProps$5(__spreadValues$6({
642
658
  name: "plasmic-antd5-config-provider",
643
659
  displayName: "Ant Design System Settings",
644
660
  props: {
@@ -743,40 +759,40 @@ const registerConfigProvider = makeRegisterGlobalContext(AntdConfigProvider, __s
743
759
  importName: "AntdConfigProvider"
744
760
  }));
745
761
 
746
- var __defProp$4 = Object.defineProperty;
747
- var __defProps$3 = Object.defineProperties;
748
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
749
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
750
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
751
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
752
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
753
- var __spreadValues$4 = (a, b) => {
762
+ var __defProp$5 = Object.defineProperty;
763
+ var __defProps$4 = Object.defineProperties;
764
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
765
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
766
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
767
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
768
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
769
+ var __spreadValues$5 = (a, b) => {
754
770
  for (var prop in b || (b = {}))
755
- if (__hasOwnProp$4.call(b, prop))
756
- __defNormalProp$4(a, prop, b[prop]);
757
- if (__getOwnPropSymbols$4)
758
- for (var prop of __getOwnPropSymbols$4(b)) {
759
- if (__propIsEnum$4.call(b, prop))
760
- __defNormalProp$4(a, prop, b[prop]);
771
+ if (__hasOwnProp$5.call(b, prop))
772
+ __defNormalProp$5(a, prop, b[prop]);
773
+ if (__getOwnPropSymbols$5)
774
+ for (var prop of __getOwnPropSymbols$5(b)) {
775
+ if (__propIsEnum$5.call(b, prop))
776
+ __defNormalProp$5(a, prop, b[prop]);
761
777
  }
762
778
  return a;
763
779
  };
764
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
780
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
765
781
  var __objRest$4 = (source, exclude) => {
766
782
  var target = {};
767
783
  for (var prop in source)
768
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
784
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
769
785
  target[prop] = source[prop];
770
- if (source != null && __getOwnPropSymbols$4)
771
- for (var prop of __getOwnPropSymbols$4(source)) {
772
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
786
+ if (source != null && __getOwnPropSymbols$5)
787
+ for (var prop of __getOwnPropSymbols$5(source)) {
788
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
773
789
  target[prop] = source[prop];
774
790
  }
775
791
  return target;
776
792
  };
777
793
  function AntdDropdown(props) {
778
794
  const _a = props, { children, onAction, menuItems } = _a, rest = __objRest$4(_a, ["children", "onAction", "menuItems"]);
779
- return /* @__PURE__ */ React.createElement(Dropdown, __spreadProps$3(__spreadValues$4({}, rest), {
795
+ return /* @__PURE__ */ React.createElement(Dropdown, __spreadProps$4(__spreadValues$5({}, rest), {
780
796
  overlay: () => {
781
797
  var _a2;
782
798
  const items = (_a2 = menuItems == null ? void 0 : menuItems()) != null ? _a2 : [];
@@ -880,6 +896,502 @@ function registerDropdown(loader) {
880
896
  });
881
897
  }
882
898
 
899
+ var __defProp$4 = Object.defineProperty;
900
+ var __defProps$3 = Object.defineProperties;
901
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
902
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
903
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
904
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
905
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
906
+ var __spreadValues$4 = (a, b) => {
907
+ for (var prop in b || (b = {}))
908
+ if (__hasOwnProp$4.call(b, prop))
909
+ __defNormalProp$4(a, prop, b[prop]);
910
+ if (__getOwnPropSymbols$4)
911
+ for (var prop of __getOwnPropSymbols$4(b)) {
912
+ if (__propIsEnum$4.call(b, prop))
913
+ __defNormalProp$4(a, prop, b[prop]);
914
+ }
915
+ return a;
916
+ };
917
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
918
+ const PathContext = React.createContext({ relativePath: [], fullPath: [] });
919
+ const InternalFormInstanceContext = React.createContext(void 0);
920
+ const Internal = (props) => {
921
+ const [form] = Form.useForm();
922
+ const values = form.getFieldsValue(true);
923
+ const lastValue = React.useRef(values);
924
+ const childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
925
+ const fireOnValuesChange = () => {
926
+ var _a;
927
+ const values2 = form.getFieldsValue(true);
928
+ if (!equal(values2, lastValue.current)) {
929
+ (_a = props.extendedOnValuesChange) == null ? void 0 : _a.call(props, values2);
930
+ lastValue.current = values2;
931
+ }
932
+ };
933
+ React.useEffect(() => {
934
+ fireOnValuesChange();
935
+ }, []);
936
+ return /* @__PURE__ */ React.createElement(InternalFormInstanceContext.Provider, {
937
+ value: {
938
+ fireOnValuesChange,
939
+ forceRemount: () => props.setRemountKey((k) => k + 1)
940
+ }
941
+ }, /* @__PURE__ */ React.createElement(Form, __spreadProps$3(__spreadValues$4({}, props), {
942
+ onValuesChange: (...args) => {
943
+ var _a, _b;
944
+ (_a = props.onValuesChange) == null ? void 0 : _a.call(props, ...args);
945
+ (_b = props.extendedOnValuesChange) == null ? void 0 : _b.call(props, args[1]);
946
+ },
947
+ form
948
+ }), childrenNode));
949
+ };
950
+ function FormWrapper(props) {
951
+ const [remountKey, setRemountKey] = React.useState(0);
952
+ return /* @__PURE__ */ React.createElement(Internal, __spreadProps$3(__spreadValues$4({
953
+ key: remountKey
954
+ }, props), {
955
+ setRemountKey
956
+ }));
957
+ }
958
+ const COMMON_ACTIONS = [
959
+ {
960
+ type: "button-action",
961
+ label: "Append new Form.Item",
962
+ onClick: ({ studioOps }) => {
963
+ studioOps.appendToSlot({
964
+ type: "component",
965
+ name: "plasmic-antd5-form-item"
966
+ }, "children");
967
+ }
968
+ },
969
+ {
970
+ type: "button-action",
971
+ label: "Append new Form.Group",
972
+ onClick: ({ studioOps }) => {
973
+ studioOps.appendToSlot({
974
+ type: "component",
975
+ name: "plasmic-antd5-form-group"
976
+ }, "children");
977
+ }
978
+ },
979
+ {
980
+ type: "button-action",
981
+ label: "Append new Form.List",
982
+ onClick: ({ studioOps }) => {
983
+ studioOps.appendToSlot({
984
+ type: "component",
985
+ name: "plasmic-antd5-form-list"
986
+ }, "children");
987
+ }
988
+ }
989
+ ];
990
+ function registerForm(loader) {
991
+ registerComponentHelper(loader, FormWrapper, {
992
+ name: "plasmic-antd5-form",
993
+ displayName: "Form",
994
+ props: {
995
+ children: {
996
+ type: "slot",
997
+ defaultValue: [
998
+ {
999
+ type: "component",
1000
+ name: "plasmic-antd5-form-item"
1001
+ },
1002
+ {
1003
+ type: "component",
1004
+ name: "plasmic-antd5-form-item"
1005
+ },
1006
+ {
1007
+ type: "default-component",
1008
+ kind: "button",
1009
+ props: {
1010
+ children: {
1011
+ type: "text",
1012
+ value: "Submit"
1013
+ }
1014
+ }
1015
+ }
1016
+ ]
1017
+ },
1018
+ initialValues: {
1019
+ type: "code",
1020
+ lang: "json",
1021
+ forceRemount: true
1022
+ },
1023
+ layout: {
1024
+ type: "choice",
1025
+ options: ["horizontal", "vertical", "inline"],
1026
+ defaultValue: "horizontal"
1027
+ },
1028
+ colon: {
1029
+ type: "boolean",
1030
+ description: `Configure the default value of colon for Form.Item. Indicates whether the colon after the label is displayed (only effective when prop layout is horizontal)`,
1031
+ defaultValue: true,
1032
+ advanced: true
1033
+ },
1034
+ requiredMark: {
1035
+ displayName: "Show required fields?",
1036
+ type: "boolean",
1037
+ advanced: true
1038
+ },
1039
+ extendedOnValuesChange: {
1040
+ type: "eventHandler",
1041
+ argTypes: [
1042
+ {
1043
+ name: "changedValues",
1044
+ type: "object"
1045
+ },
1046
+ {
1047
+ name: "allValues",
1048
+ type: "object"
1049
+ }
1050
+ ]
1051
+ },
1052
+ onFinish: {
1053
+ type: "eventHandler",
1054
+ argTypes: [
1055
+ {
1056
+ name: "values",
1057
+ type: "object"
1058
+ }
1059
+ ]
1060
+ },
1061
+ onFinishFailed: {
1062
+ type: "eventHandler",
1063
+ argTypes: [
1064
+ {
1065
+ name: "data",
1066
+ type: "object"
1067
+ }
1068
+ ]
1069
+ },
1070
+ validateTrigger: {
1071
+ type: "choice",
1072
+ options: ["onSubmit", "onChange"],
1073
+ multiSelect: true,
1074
+ defaultValue: ["onChange"],
1075
+ advanced: true
1076
+ }
1077
+ },
1078
+ actions: COMMON_ACTIONS,
1079
+ states: {
1080
+ value: {
1081
+ type: "readonly",
1082
+ variableType: "object",
1083
+ onChangeProp: "extendedOnValuesChange"
1084
+ }
1085
+ },
1086
+ importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1087
+ importName: "Form"
1088
+ });
1089
+ }
1090
+ function plasmicRulesToAntdRules(plasmicRules) {
1091
+ var _a, _b;
1092
+ const rules = [];
1093
+ for (const plasmicRule of plasmicRules) {
1094
+ switch (plasmicRule.ruleType) {
1095
+ case "enum":
1096
+ rules.push({
1097
+ type: "enum",
1098
+ enum: (_b = (_a = plasmicRule.options) == null ? void 0 : _a.map((opt) => opt.value)) != null ? _b : [],
1099
+ message: plasmicRule.message
1100
+ });
1101
+ break;
1102
+ case "required":
1103
+ rules.push({
1104
+ required: true,
1105
+ message: plasmicRule.message
1106
+ });
1107
+ break;
1108
+ case "whitespace":
1109
+ rules.push({
1110
+ whitespace: true,
1111
+ message: plasmicRule.message
1112
+ });
1113
+ break;
1114
+ case "len":
1115
+ case "min":
1116
+ case "max":
1117
+ rules.push({
1118
+ [plasmicRule.ruleType]: plasmicRule.length,
1119
+ message: plasmicRule.message
1120
+ });
1121
+ break;
1122
+ case "advanced":
1123
+ rules.push({
1124
+ validator: (...args) => {
1125
+ var _a2;
1126
+ return ((_a2 = plasmicRule.custom) == null ? void 0 : _a2.apply(null, args)) ? Promise.resolve() : Promise.reject();
1127
+ },
1128
+ message: plasmicRule.message
1129
+ });
1130
+ }
1131
+ }
1132
+ return rules;
1133
+ }
1134
+ const useFormItemRelativeName = (name) => {
1135
+ const pathCtx = React.useContext(PathContext);
1136
+ return typeof name === "object" ? [...pathCtx.relativePath, ...name] : typeof name === "string" ? [...pathCtx.relativePath, name] : void 0;
1137
+ };
1138
+ const useFormItemFullName = (name) => {
1139
+ const pathCtx = React.useContext(PathContext);
1140
+ return typeof name === "object" ? [...pathCtx.fullPath, ...name] : typeof name === "string" ? [...pathCtx.fullPath, name] : void 0;
1141
+ };
1142
+ function FormItemWrapper(props) {
1143
+ var _a;
1144
+ const relativeFormItemName = useFormItemRelativeName(props.name);
1145
+ const fullFormItemName = useFormItemFullName(props.name);
1146
+ const rules = props.rules ? plasmicRulesToAntdRules(props.rules) : void 0;
1147
+ const inCanvas = !!usePlasmicCanvasContext();
1148
+ if (inCanvas) {
1149
+ const form = Form.useFormInstance();
1150
+ const prevPropValues = React.useRef({
1151
+ initialValue: props.initialValue,
1152
+ name: props.name
1153
+ });
1154
+ const { fireOnValuesChange, forceRemount } = (_a = React.useContext(InternalFormInstanceContext)) != null ? _a : {};
1155
+ React.useEffect(() => {
1156
+ if (prevPropValues.current.name !== props.name) {
1157
+ forceRemount == null ? void 0 : forceRemount();
1158
+ }
1159
+ if (!fullFormItemName || form.getFieldValue(fullFormItemName) !== prevPropValues.current.initialValue) {
1160
+ return;
1161
+ }
1162
+ form.setFieldValue(fullFormItemName, props.initialValue);
1163
+ prevPropValues.current.initialValue = props.initialValue;
1164
+ fireOnValuesChange == null ? void 0 : fireOnValuesChange();
1165
+ }, [props.initialValue, fullFormItemName]);
1166
+ }
1167
+ return /* @__PURE__ */ React.createElement(FormItem, __spreadProps$3(__spreadValues$4({}, omit(props, "rules")), {
1168
+ name: relativeFormItemName,
1169
+ rules
1170
+ }));
1171
+ }
1172
+ function registerFormItem(loader) {
1173
+ registerComponentHelper(loader, FormItemWrapper, {
1174
+ name: "plasmic-antd5-form-item",
1175
+ displayName: "Form.Item",
1176
+ parentComponentName: "plasmic-antd5-form",
1177
+ props: {
1178
+ label: {
1179
+ type: "slot",
1180
+ defaultValue: {
1181
+ type: "text",
1182
+ value: "Label"
1183
+ }
1184
+ },
1185
+ children: {
1186
+ type: "slot",
1187
+ defaultValue: {
1188
+ type: "default-component",
1189
+ kind: "text-input"
1190
+ }
1191
+ },
1192
+ name: {
1193
+ type: "string"
1194
+ },
1195
+ initialValue: {
1196
+ type: "string"
1197
+ },
1198
+ required: {
1199
+ type: "boolean"
1200
+ },
1201
+ rules: {
1202
+ type: "formValidationRules",
1203
+ displayName: "rules"
1204
+ },
1205
+ colon: {
1206
+ type: "boolean",
1207
+ defaultValue: false,
1208
+ advanced: true
1209
+ },
1210
+ labelAlign: {
1211
+ type: "choice",
1212
+ options: ["left", "right"],
1213
+ advanced: true
1214
+ },
1215
+ hidden: {
1216
+ type: "boolean",
1217
+ advanced: true
1218
+ }
1219
+ },
1220
+ importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1221
+ importName: "FormItemWrapper"
1222
+ });
1223
+ }
1224
+ function FormGroup(props) {
1225
+ const pathCtx = React.useContext(PathContext);
1226
+ return /* @__PURE__ */ React.createElement(PathContext.Provider, {
1227
+ value: {
1228
+ relativePath: [...pathCtx.relativePath, props.name],
1229
+ fullPath: [...pathCtx.fullPath, props.name]
1230
+ }
1231
+ }, props.children);
1232
+ }
1233
+ function registerFormGroup(loader) {
1234
+ registerComponentHelper(loader, FormGroup, {
1235
+ name: "plasmic-antd5-form-group",
1236
+ displayName: "Form.Group",
1237
+ parentComponentName: "plasmic-antd5-form",
1238
+ actions: COMMON_ACTIONS,
1239
+ props: {
1240
+ name: {
1241
+ type: "string"
1242
+ },
1243
+ children: {
1244
+ type: "slot"
1245
+ }
1246
+ },
1247
+ importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1248
+ importName: "FormGroup"
1249
+ });
1250
+ }
1251
+ const FormListWrapper = React.forwardRef(function FormListWrapper2(props, ref) {
1252
+ var _a;
1253
+ const relativeFormItemName = useFormItemRelativeName(props.name);
1254
+ const fullFormItemName = useFormItemFullName(props.name);
1255
+ const operationsRef = React.useRef(void 0);
1256
+ React.useImperativeHandle(ref, () => ({
1257
+ add(defaultValue, insertIndex) {
1258
+ if (operationsRef.current) {
1259
+ const { add } = operationsRef.current[1];
1260
+ add(defaultValue, insertIndex);
1261
+ }
1262
+ },
1263
+ remove(index) {
1264
+ if (operationsRef.current) {
1265
+ const { remove } = operationsRef.current[1];
1266
+ remove(index);
1267
+ }
1268
+ },
1269
+ move(from, to) {
1270
+ if (operationsRef.current) {
1271
+ const { move } = operationsRef.current[1];
1272
+ move(from, to);
1273
+ }
1274
+ }
1275
+ }), [operationsRef]);
1276
+ const inCanvas = !!usePlasmicCanvasContext();
1277
+ if (inCanvas) {
1278
+ const form = Form.useFormInstance();
1279
+ const prevPropValues = React.useRef({
1280
+ initialValue: props.initialValue,
1281
+ name: props.name
1282
+ });
1283
+ const { fireOnValuesChange, forceRemount } = (_a = React.useContext(InternalFormInstanceContext)) != null ? _a : {};
1284
+ React.useEffect(() => {
1285
+ if (prevPropValues.current.name !== props.name) {
1286
+ forceRemount == null ? void 0 : forceRemount();
1287
+ }
1288
+ if (fullFormItemName) {
1289
+ form.setFieldValue(fullFormItemName, props.initialValue);
1290
+ prevPropValues.current.initialValue = props.initialValue;
1291
+ fireOnValuesChange == null ? void 0 : fireOnValuesChange();
1292
+ }
1293
+ }, [props.initialValue, fullFormItemName]);
1294
+ }
1295
+ return /* @__PURE__ */ React.createElement(FormList, __spreadProps$3(__spreadValues$4({}, props), {
1296
+ name: relativeFormItemName != null ? relativeFormItemName : []
1297
+ }), (...args) => {
1298
+ operationsRef.current = args;
1299
+ return args[0].map((field, index) => /* @__PURE__ */ React.createElement(PathContext.Provider, {
1300
+ value: {
1301
+ relativePath: [field.name],
1302
+ fullPath: [...fullFormItemName != null ? fullFormItemName : [], field.name]
1303
+ }
1304
+ }, /* @__PURE__ */ React.createElement(DataProvider, {
1305
+ name: "currentField",
1306
+ data: field
1307
+ }, /* @__PURE__ */ React.createElement(DataProvider, {
1308
+ name: "currentFieldIndex",
1309
+ data: index
1310
+ }, repeatedElement(index, props.children)))));
1311
+ });
1312
+ });
1313
+ function registerFormList(loader) {
1314
+ registerComponentHelper(loader, FormListWrapper, {
1315
+ name: "plasmic-antd5-form-list",
1316
+ parentComponentName: "plasmic-antd5-form",
1317
+ displayName: "Form.List",
1318
+ actions: COMMON_ACTIONS,
1319
+ props: {
1320
+ children: {
1321
+ type: "slot",
1322
+ defaultValue: [
1323
+ {
1324
+ type: "component",
1325
+ name: "plasmic-antd5-form-item",
1326
+ props: {
1327
+ name: "item"
1328
+ }
1329
+ }
1330
+ ]
1331
+ },
1332
+ name: {
1333
+ type: "string",
1334
+ defaultValue: "list"
1335
+ },
1336
+ initialValue: {
1337
+ type: "object",
1338
+ defaultValue: [
1339
+ {
1340
+ item: "Item 1"
1341
+ },
1342
+ {
1343
+ item: "Item 2"
1344
+ }
1345
+ ]
1346
+ }
1347
+ },
1348
+ unstable__refActions: {
1349
+ add: {
1350
+ displayName: "Add an item",
1351
+ parameters: [
1352
+ {
1353
+ name: "defaultValue",
1354
+ displayName: "Default value",
1355
+ type: "object"
1356
+ },
1357
+ {
1358
+ name: "insertIndex",
1359
+ displayName: "Insert index",
1360
+ type: "number"
1361
+ }
1362
+ ]
1363
+ },
1364
+ remove: {
1365
+ displayName: "Remove an item",
1366
+ parameters: [
1367
+ {
1368
+ name: "index",
1369
+ displayName: "Index",
1370
+ type: "number"
1371
+ }
1372
+ ]
1373
+ },
1374
+ move: {
1375
+ displayName: "Move field",
1376
+ parameters: [
1377
+ {
1378
+ name: "from",
1379
+ displayName: "From",
1380
+ type: "number"
1381
+ },
1382
+ {
1383
+ name: "to",
1384
+ displayName: "To",
1385
+ type: "number"
1386
+ }
1387
+ ]
1388
+ }
1389
+ },
1390
+ importPath: "@plasmicpkgs/antd5/skinny/registerForm",
1391
+ importName: "FormListWrapper"
1392
+ });
1393
+ }
1394
+
883
1395
  const AntdMenu = Menu;
884
1396
  const AntdMenuDivider = Menu.Divider;
885
1397
  const AntdMenuItem = Menu.Item;
@@ -1893,6 +2405,10 @@ function registerAll(loader) {
1893
2405
  registerButton(loader);
1894
2406
  registerMenu(loader);
1895
2407
  registerDropdown(loader);
2408
+ registerForm(loader);
2409
+ registerFormItem(loader);
2410
+ registerFormGroup(loader);
2411
+ registerFormList(loader);
1896
2412
  }
1897
2413
 
1898
2414
  export { registerAll };