@plasmicpkgs/antd5 0.0.28 → 0.0.30

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.
@@ -1,13 +1,95 @@
1
1
  import { usePlasmicCanvasContext, DataProvider, repeatedElement } from '@plasmicapp/host';
2
- import Form from 'antd/lib/form';
3
- import FormItem from 'antd/lib/form/FormItem';
4
- import FormList from 'antd/lib/form/FormList';
2
+ import Form from 'antd/es/form';
3
+ import FormItem from 'antd/es/form/FormItem';
4
+ import FormList from 'antd/es/form/FormList';
5
5
  import equal from 'fast-deep-equal';
6
- import React from 'react';
6
+ import React, { isValidElement, cloneElement } from 'react';
7
+ import classNames from 'classnames';
7
8
  import { r as registerComponentHelper, o as omit } from './utils-91b47110.js';
8
9
  import '@plasmicapp/host/registerComponent';
9
10
  import '@plasmicapp/host/registerGlobalContext';
10
11
 
12
+ var __defProp$1 = Object.defineProperty;
13
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
16
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues$1 = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp$1.call(b, prop))
20
+ __defNormalProp$1(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols$1)
22
+ for (var prop of __getOwnPropSymbols$1(b)) {
23
+ if (__propIsEnum$1.call(b, prop))
24
+ __defNormalProp$1(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ const isBrowser = typeof window !== "undefined";
29
+ const NONE = Symbol("NONE");
30
+ isBrowser ? React.useLayoutEffect : React.useEffect;
31
+ function mergeProps(props, ...restProps) {
32
+ if (restProps.every((rest) => Object.keys(rest).length === 0)) {
33
+ return props;
34
+ }
35
+ const result = __spreadValues$1({}, props);
36
+ for (const rest of restProps) {
37
+ for (const key of Object.keys(rest)) {
38
+ result[key] = mergePropVals(key, result[key], rest[key]);
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ function updateRef(ref, value) {
44
+ if (!ref) {
45
+ return;
46
+ }
47
+ if (typeof ref === "function") {
48
+ ref(value);
49
+ } else {
50
+ if (!Object.isFrozen(ref)) {
51
+ ref.current = value;
52
+ }
53
+ }
54
+ }
55
+ function mergeRefs(...refs) {
56
+ return (value) => {
57
+ for (const ref of refs) {
58
+ updateRef(ref, value);
59
+ }
60
+ };
61
+ }
62
+ function mergePropVals(name, val1, val2) {
63
+ if (val1 === NONE || val2 === NONE) {
64
+ return null;
65
+ } else if (val1 == null) {
66
+ return val2;
67
+ } else if (val2 == null) {
68
+ return val1;
69
+ } else if (name === "className") {
70
+ return classNames(val1, val2);
71
+ } else if (name === "style") {
72
+ return __spreadValues$1(__spreadValues$1({}, val1), val2);
73
+ } else if (name === "ref") {
74
+ return mergeRefs(val1, val2);
75
+ } else if (typeof val1 !== typeof val2) {
76
+ return val2;
77
+ } else if (name.startsWith("on") && typeof val1 === "function") {
78
+ return (...args) => {
79
+ let res;
80
+ if (typeof val1 === "function") {
81
+ res = val1(...args);
82
+ }
83
+ if (typeof val2 === "function") {
84
+ res = val2(...args);
85
+ }
86
+ return res;
87
+ };
88
+ } else {
89
+ return val2;
90
+ }
91
+ }
92
+
11
93
  var __defProp = Object.defineProperty;
12
94
  var __defProps = Object.defineProperties;
13
95
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -27,18 +109,31 @@ var __spreadValues = (a, b) => {
27
109
  return a;
28
110
  };
29
111
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
112
+ var __objRest = (source, exclude) => {
113
+ var target = {};
114
+ for (var prop in source)
115
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
116
+ target[prop] = source[prop];
117
+ if (source != null && __getOwnPropSymbols)
118
+ for (var prop of __getOwnPropSymbols(source)) {
119
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
120
+ target[prop] = source[prop];
121
+ }
122
+ return target;
123
+ };
30
124
  const PathContext = React.createContext({ relativePath: [], fullPath: [] });
31
125
  const InternalFormInstanceContext = React.createContext(void 0);
32
126
  const Internal = (props) => {
127
+ var _a, _b;
33
128
  const [form] = Form.useForm();
34
129
  const values = form.getFieldsValue(true);
35
130
  const lastValue = React.useRef(values);
36
131
  const childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
37
132
  const fireOnValuesChange = () => {
38
- var _a;
133
+ var _a2;
39
134
  const values2 = form.getFieldsValue(true);
40
135
  if (!equal(values2, lastValue.current)) {
41
- (_a = props.extendedOnValuesChange) == null ? void 0 : _a.call(props, values2);
136
+ (_a2 = props.extendedOnValuesChange) == null ? void 0 : _a2.call(props, values2);
42
137
  lastValue.current = values2;
43
138
  }
44
139
  };
@@ -48,15 +143,18 @@ const Internal = (props) => {
48
143
  return /* @__PURE__ */ React.createElement(InternalFormInstanceContext.Provider, {
49
144
  value: {
50
145
  fireOnValuesChange,
51
- forceRemount: () => props.setRemountKey((k) => k + 1)
146
+ forceRemount: () => props.setRemountKey((k) => k + 1),
147
+ formProps: props
52
148
  }
53
149
  }, /* @__PURE__ */ React.createElement(Form, __spreadProps(__spreadValues({}, props), {
54
150
  onValuesChange: (...args) => {
55
- var _a, _b;
56
- (_a = props.onValuesChange) == null ? void 0 : _a.call(props, ...args);
57
- (_b = props.extendedOnValuesChange) == null ? void 0 : _b.call(props, args[1]);
151
+ var _a2, _b2;
152
+ (_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
153
+ (_b2 = props.extendedOnValuesChange) == null ? void 0 : _b2.call(props, args[1]);
58
154
  },
59
- form
155
+ form,
156
+ labelCol: ((_a = props.labelCol) == null ? void 0 : _a.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
157
+ wrapperCol: ((_b = props.wrapperCol) == null ? void 0 : _b.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
60
158
  }), childrenNode));
61
159
  };
62
160
  function FormWrapper(props) {
@@ -70,7 +168,7 @@ function FormWrapper(props) {
70
168
  const COMMON_ACTIONS = [
71
169
  {
72
170
  type: "button-action",
73
- label: "Append new Form.Item",
171
+ label: "Append new Form Item",
74
172
  onClick: ({ studioOps }) => {
75
173
  studioOps.appendToSlot({
76
174
  type: "component",
@@ -80,7 +178,7 @@ const COMMON_ACTIONS = [
80
178
  },
81
179
  {
82
180
  type: "button-action",
83
- label: "Append new Form.Group",
181
+ label: "Append new Form Group",
84
182
  onClick: ({ studioOps }) => {
85
183
  studioOps.appendToSlot({
86
184
  type: "component",
@@ -90,7 +188,7 @@ const COMMON_ACTIONS = [
90
188
  },
91
189
  {
92
190
  type: "button-action",
93
- label: "Append new Form.List",
191
+ label: "Append new Form List",
94
192
  onClick: ({ studioOps }) => {
95
193
  studioOps.appendToSlot({
96
194
  type: "component",
@@ -100,6 +198,33 @@ const COMMON_ACTIONS = [
100
198
  }
101
199
  ];
102
200
  function registerForm(loader) {
201
+ const colProp = (displayName, defaultValue) => ({
202
+ type: "object",
203
+ displayName,
204
+ advanced: true,
205
+ fields: {
206
+ span: {
207
+ type: "number",
208
+ displayName: "Grid columns",
209
+ description: "The number of grid columns to span (24 columns available)",
210
+ min: 1,
211
+ max: 24
212
+ },
213
+ offset: {
214
+ type: "number",
215
+ displayName: "Offset columns",
216
+ description: "Number of grid columns to skip from the left",
217
+ min: 0,
218
+ max: 23
219
+ },
220
+ horizontalOnly: {
221
+ type: "boolean",
222
+ displayName: "Horizontal only",
223
+ description: "Only apply to horizontal layout"
224
+ }
225
+ },
226
+ defaultValue
227
+ });
103
228
  registerComponentHelper(loader, FormWrapper, {
104
229
  name: "plasmic-antd5-form",
105
230
  displayName: "Form",
@@ -109,11 +234,33 @@ function registerForm(loader) {
109
234
  defaultValue: [
110
235
  {
111
236
  type: "component",
112
- name: "plasmic-antd5-form-item"
237
+ name: "plasmic-antd5-form-item",
238
+ props: {
239
+ label: {
240
+ type: "text",
241
+ value: "Name"
242
+ },
243
+ name: "name",
244
+ children: {
245
+ type: "component",
246
+ name: "plasmic-antd5-input"
247
+ }
248
+ }
113
249
  },
114
250
  {
115
251
  type: "component",
116
- name: "plasmic-antd5-form-item"
252
+ name: "plasmic-antd5-form-item",
253
+ props: {
254
+ label: {
255
+ type: "text",
256
+ value: "Message"
257
+ },
258
+ name: "message",
259
+ children: {
260
+ type: "component",
261
+ name: "plasmic-antd5-textarea"
262
+ }
263
+ }
117
264
  },
118
265
  {
119
266
  type: "default-component",
@@ -135,21 +282,51 @@ function registerForm(loader) {
135
282
  layout: {
136
283
  type: "choice",
137
284
  options: ["horizontal", "vertical", "inline"],
138
- defaultValue: "horizontal"
285
+ defaultValue: "vertical"
286
+ },
287
+ labelAlign: {
288
+ type: "choice",
289
+ options: ["left", "right"],
290
+ defaultValueHint: "right",
291
+ advanced: true
139
292
  },
293
+ labelCol: colProp("Label layout", {
294
+ span: 8,
295
+ horizontalOnly: true
296
+ }),
297
+ wrapperCol: colProp("Field layout", {
298
+ span: 16,
299
+ horizontalOnly: true
300
+ }),
140
301
  colon: {
141
302
  type: "boolean",
142
- 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)`,
143
- defaultValue: true,
303
+ description: `Show a colon after the label by default (only for horizontal layout)`,
304
+ defaultValueHint: true,
144
305
  advanced: true
145
306
  },
146
307
  requiredMark: {
147
- displayName: "Show required fields?",
148
- type: "boolean",
149
- advanced: true
308
+ displayName: "Required/optional mark",
309
+ type: "choice",
310
+ options: [
311
+ {
312
+ value: "optional",
313
+ label: "Indicate optional fields"
314
+ },
315
+ {
316
+ value: true,
317
+ label: "Indicate required fields with asterisk"
318
+ },
319
+ {
320
+ value: false,
321
+ label: "Show no indicators"
322
+ }
323
+ ],
324
+ advanced: true,
325
+ defaultValueHint: true
150
326
  },
151
327
  extendedOnValuesChange: {
152
328
  type: "eventHandler",
329
+ displayName: "On values change",
153
330
  argTypes: [
154
331
  {
155
332
  name: "changedValues",
@@ -163,6 +340,7 @@ function registerForm(loader) {
163
340
  },
164
341
  onFinish: {
165
342
  type: "eventHandler",
343
+ displayName: "On submit",
166
344
  argTypes: [
167
345
  {
168
346
  name: "values",
@@ -172,6 +350,7 @@ function registerForm(loader) {
172
350
  },
173
351
  onFinishFailed: {
174
352
  type: "eventHandler",
353
+ displayName: "On invalid submit",
175
354
  argTypes: [
176
355
  {
177
356
  name: "data",
@@ -181,9 +360,9 @@ function registerForm(loader) {
181
360
  },
182
361
  validateTrigger: {
183
362
  type: "choice",
184
- options: ["onSubmit", "onChange"],
363
+ options: ["onSubmit", "onChange", "onBlur"],
185
364
  multiSelect: true,
186
- defaultValue: ["onChange"],
365
+ defaultValueHint: ["onChange"],
187
366
  advanced: true
188
367
  }
189
368
  },
@@ -251,40 +430,68 @@ const useFormItemFullName = (name) => {
251
430
  const pathCtx = React.useContext(PathContext);
252
431
  return typeof name === "object" ? [...pathCtx.fullPath, ...name] : typeof name === "string" ? [...pathCtx.fullPath, name] : void 0;
253
432
  };
433
+ function useFormInstanceMaybe() {
434
+ return Form.useFormInstance();
435
+ }
254
436
  function FormItemWrapper(props) {
255
- var _a;
437
+ var _a, _b;
256
438
  const relativeFormItemName = useFormItemRelativeName(props.name);
257
439
  const fullFormItemName = useFormItemFullName(props.name);
258
440
  const rules = props.rules ? plasmicRulesToAntdRules(props.rules) : void 0;
259
441
  const inCanvas = !!usePlasmicCanvasContext();
260
442
  if (inCanvas) {
261
- const form = Form.useFormInstance();
443
+ const form = useFormInstanceMaybe();
262
444
  const prevPropValues = React.useRef({
263
445
  initialValue: props.initialValue,
264
446
  name: props.name
265
447
  });
266
- const { fireOnValuesChange, forceRemount } = (_a = React.useContext(InternalFormInstanceContext)) != null ? _a : {};
448
+ const internalFormCtx = React.useContext(InternalFormInstanceContext);
449
+ const { fireOnValuesChange, forceRemount } = internalFormCtx != null ? internalFormCtx : {};
450
+ (_a = props.setControlContextData) == null ? void 0 : _a.call(props, {
451
+ internalFormCtx
452
+ });
267
453
  React.useEffect(() => {
268
454
  if (prevPropValues.current.name !== props.name) {
269
455
  forceRemount == null ? void 0 : forceRemount();
270
456
  }
271
- if (!fullFormItemName || form.getFieldValue(fullFormItemName) !== prevPropValues.current.initialValue) {
457
+ if (!fullFormItemName || (form == null ? void 0 : form.getFieldValue(fullFormItemName)) !== prevPropValues.current.initialValue) {
272
458
  return;
273
459
  }
274
- form.setFieldValue(fullFormItemName, props.initialValue);
460
+ form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
275
461
  prevPropValues.current.initialValue = props.initialValue;
276
462
  fireOnValuesChange == null ? void 0 : fireOnValuesChange();
277
- }, [props.initialValue, fullFormItemName]);
463
+ }, [form, props.initialValue, fullFormItemName]);
278
464
  }
279
- return /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({}, omit(props, "rules")), {
465
+ return /* @__PURE__ */ React.createElement(FormItem, __spreadValues(__spreadProps(__spreadValues({}, omit(props, "rules")), {
466
+ label: props.noLabel ? void 0 : props.label,
280
467
  name: relativeFormItemName,
281
468
  rules
282
- }));
469
+ }), props.helpTextMode === "extra" ? { extra: props.help } : props.helpTextMode === "help" ? { help: (_b = props.help) != null ? _b : "" } : {}), props.customizeProps ? /* @__PURE__ */ React.createElement(FormItemForwarder, {
470
+ formItemProps: props
471
+ }) : props.children);
472
+ }
473
+ function FormItemForwarder(_a) {
474
+ var _b = _a, { formItemProps } = _b, props = __objRest(_b, ["formItemProps"]);
475
+ var _a2;
476
+ const status = Form.Item.useStatus();
477
+ const internalFormCtx = React.useContext(InternalFormInstanceContext);
478
+ const data = {
479
+ status: status.status
480
+ };
481
+ (_a2 = props.setControlContextData) == null ? void 0 : _a2.call(props, {
482
+ internalFormCtx,
483
+ status
484
+ });
485
+ return React.Children.map(formItemProps.children, (child, i) => {
486
+ var _a3;
487
+ const baseProps = __spreadValues(__spreadValues({}, (_a3 = child.props) != null ? _a3 : {}), props);
488
+ return i === 0 && isValidElement(child) ? cloneElement(child, mergeProps(baseProps, formItemProps.customizeProps(data, baseProps))) : child;
489
+ });
283
490
  }
284
491
  function registerFormItem(loader) {
285
492
  registerComponentHelper(loader, FormItemWrapper, {
286
493
  name: "plasmic-antd5-form-item",
287
- displayName: "Form.Item",
494
+ displayName: "Form Item",
288
495
  parentComponentName: "plasmic-antd5-form",
289
496
  props: {
290
497
  label: {
@@ -311,12 +518,18 @@ function registerFormItem(loader) {
311
518
  type: "boolean"
312
519
  },
313
520
  rules: {
314
- type: "formValidationRules",
315
- displayName: "rules"
521
+ type: "formValidationRules"
522
+ },
523
+ noLabel: {
524
+ type: "boolean",
525
+ advanced: true
316
526
  },
317
527
  colon: {
318
528
  type: "boolean",
319
- defaultValue: false,
529
+ defaultValueHint: (_ps, ctx) => {
530
+ var _a, _b;
531
+ return (_b = (_a = ctx == null ? void 0 : ctx.internalFormCtx) == null ? void 0 : _a.formProps.colon) != null ? _b : true;
532
+ },
320
533
  advanced: true
321
534
  },
322
535
  labelAlign: {
@@ -327,6 +540,66 @@ function registerFormItem(loader) {
327
540
  hidden: {
328
541
  type: "boolean",
329
542
  advanced: true
543
+ },
544
+ validateTrigger: {
545
+ type: "choice",
546
+ options: ["onSubmit", "onChange", "onBlur"],
547
+ multiSelect: true,
548
+ advanced: true
549
+ },
550
+ shouldUpdate: {
551
+ type: "boolean",
552
+ advanced: true,
553
+ displayName: "Always re-render",
554
+ description: "Form items normally only re-render when the corresponding form value changes, for performance. This forces it to always re-render."
555
+ },
556
+ helpTextMode: {
557
+ type: "choice",
558
+ displayName: "Help text",
559
+ options: [
560
+ {
561
+ value: "errors",
562
+ label: "Validation errors"
563
+ },
564
+ {
565
+ value: "extra",
566
+ label: "Custom help text and validation errors"
567
+ },
568
+ {
569
+ value: "help",
570
+ label: "Custom help text, no validation errors"
571
+ }
572
+ ],
573
+ defaultValueHint: "Show validation errors",
574
+ description: "What to show in the help text. Edit help text by editing the 'help' slot in the outline."
575
+ },
576
+ help: {
577
+ type: "slot",
578
+ hidden: (ps) => {
579
+ var _a;
580
+ return !["extra", "help"].includes((_a = ps.helpTextMode) != null ? _a : "");
581
+ },
582
+ hidePlaceholder: true
583
+ },
584
+ customizeProps: {
585
+ type: "function",
586
+ description: "Customize the props passed into the wrapped field component. Takes the current status ('success', 'warning', 'error', or 'validating').)",
587
+ argNames: ["fieldData"],
588
+ argValues: (_ps, ctx) => {
589
+ var _a;
590
+ return [
591
+ {
592
+ status: (_a = ctx == null ? void 0 : ctx.status) == null ? void 0 : _a.status
593
+ }
594
+ ];
595
+ },
596
+ advanced: true
597
+ },
598
+ noStyle: {
599
+ type: "boolean",
600
+ displayName: "Field only",
601
+ description: "Don't render anything but the wrapped field component - so no label, help text, validation error, etc.",
602
+ advanced: true
330
603
  }
331
604
  },
332
605
  importPath: "@plasmicpkgs/antd5/skinny/registerForm",
@@ -345,7 +618,7 @@ function FormGroup(props) {
345
618
  function registerFormGroup(loader) {
346
619
  registerComponentHelper(loader, FormGroup, {
347
620
  name: "plasmic-antd5-form-group",
348
- displayName: "Form.Group",
621
+ displayName: "Form Group",
349
622
  parentComponentName: "plasmic-antd5-form",
350
623
  actions: COMMON_ACTIONS,
351
624
  props: {
@@ -387,7 +660,7 @@ const FormListWrapper = React.forwardRef(function FormListWrapper2(props, ref) {
387
660
  }), [operationsRef]);
388
661
  const inCanvas = !!usePlasmicCanvasContext();
389
662
  if (inCanvas) {
390
- const form = Form.useFormInstance();
663
+ const form = useFormInstanceMaybe();
391
664
  const prevPropValues = React.useRef({
392
665
  initialValue: props.initialValue,
393
666
  name: props.name
@@ -398,7 +671,7 @@ const FormListWrapper = React.forwardRef(function FormListWrapper2(props, ref) {
398
671
  forceRemount == null ? void 0 : forceRemount();
399
672
  }
400
673
  if (fullFormItemName) {
401
- form.setFieldValue(fullFormItemName, props.initialValue);
674
+ form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
402
675
  prevPropValues.current.initialValue = props.initialValue;
403
676
  fireOnValuesChange == null ? void 0 : fireOnValuesChange();
404
677
  }
@@ -426,33 +699,63 @@ function registerFormList(loader) {
426
699
  registerComponentHelper(loader, FormListWrapper, {
427
700
  name: "plasmic-antd5-form-list",
428
701
  parentComponentName: "plasmic-antd5-form",
429
- displayName: "Form.List",
702
+ displayName: "Form List",
430
703
  actions: COMMON_ACTIONS,
431
704
  props: {
432
705
  children: {
433
706
  type: "slot",
434
707
  defaultValue: [
435
708
  {
436
- type: "component",
437
- name: "plasmic-antd5-form-item",
438
- props: {
439
- name: "item"
440
- }
709
+ type: "hbox",
710
+ children: [
711
+ {
712
+ type: "component",
713
+ name: "plasmic-antd5-form-item",
714
+ props: {
715
+ name: "firstName",
716
+ label: {
717
+ type: "text",
718
+ value: "First name"
719
+ },
720
+ children: {
721
+ type: "component",
722
+ name: "plasmic-antd5-input"
723
+ }
724
+ }
725
+ },
726
+ {
727
+ type: "component",
728
+ name: "plasmic-antd5-form-item",
729
+ props: {
730
+ name: "lastName",
731
+ label: {
732
+ type: "text",
733
+ value: "Last name"
734
+ },
735
+ children: {
736
+ type: "component",
737
+ name: "plasmic-antd5-input"
738
+ }
739
+ }
740
+ }
741
+ ]
441
742
  }
442
743
  ]
443
744
  },
444
745
  name: {
445
746
  type: "string",
446
- defaultValue: "list"
747
+ defaultValue: "guests"
447
748
  },
448
749
  initialValue: {
449
- type: "object",
750
+ type: "array",
450
751
  defaultValue: [
451
752
  {
452
- item: "Item 1"
753
+ firstName: "Jane",
754
+ lastName: "Doe"
453
755
  },
454
756
  {
455
- item: "Item 2"
757
+ firstName: "John",
758
+ lastName: "Smith"
456
759
  }
457
760
  ]
458
761
  }