@plasmicpkgs/antd5 0.0.53 → 0.0.55

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.
Files changed (40) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/antd.esm.js +257 -121
  3. package/dist/antd.esm.js.map +1 -1
  4. package/dist/index.js +257 -121
  5. package/dist/index.js.map +1 -1
  6. package/dist/registerForm.d.ts +9 -1
  7. package/package.json +2 -2
  8. package/skinny/registerButton.cjs.js +1 -1
  9. package/skinny/registerButton.esm.js +1 -1
  10. package/skinny/registerCheckbox.cjs.js +1 -1
  11. package/skinny/registerCheckbox.esm.js +1 -1
  12. package/skinny/registerConfigProvider.cjs.js +1 -1
  13. package/skinny/registerConfigProvider.esm.js +1 -1
  14. package/skinny/registerDropdown.cjs.js +1 -1
  15. package/skinny/registerDropdown.esm.js +1 -1
  16. package/skinny/registerForm.cjs.js +234 -103
  17. package/skinny/registerForm.cjs.js.map +1 -1
  18. package/skinny/registerForm.d.ts +9 -1
  19. package/skinny/registerForm.esm.js +234 -103
  20. package/skinny/registerForm.esm.js.map +1 -1
  21. package/skinny/registerInput.cjs.js +1 -1
  22. package/skinny/registerInput.esm.js +1 -1
  23. package/skinny/registerMenu.cjs.js +1 -1
  24. package/skinny/registerMenu.esm.js +1 -1
  25. package/skinny/registerModal.cjs.js +1 -1
  26. package/skinny/registerModal.esm.js +1 -1
  27. package/skinny/registerRadio.cjs.js +25 -8
  28. package/skinny/registerRadio.cjs.js.map +1 -1
  29. package/skinny/registerRadio.esm.js +25 -8
  30. package/skinny/registerRadio.esm.js.map +1 -1
  31. package/skinny/registerSelect.cjs.js +1 -1
  32. package/skinny/registerSelect.esm.js +1 -1
  33. package/skinny/registerTable.cjs.js +1 -1
  34. package/skinny/registerTable.esm.js +1 -1
  35. package/skinny/registerUpload.cjs.js +1 -1
  36. package/skinny/registerUpload.esm.js +1 -1
  37. package/skinny/{utils-dff55ae0.cjs.js → utils-2d964db8.cjs.js} +1 -14
  38. package/skinny/{utils-dff55ae0.cjs.js.map → utils-2d964db8.cjs.js.map} +1 -1
  39. package/skinny/{utils-94b1c934.esm.js → utils-d0e80a56.esm.js} +2 -14
  40. package/skinny/{utils-94b1c934.esm.js.map → utils-d0e80a56.esm.js.map} +1 -1
@@ -3,7 +3,7 @@ import { Form } from 'antd';
3
3
  import equal from 'fast-deep-equal';
4
4
  import React, { isValidElement, cloneElement } from 'react';
5
5
  import classNames from 'classnames';
6
- import { u as usePrevious, r as registerComponentHelper, o as omit } from './utils-94b1c934.esm.js';
6
+ import { u as usePrevious, r as registerComponentHelper } from './utils-d0e80a56.esm.js';
7
7
  import '@plasmicapp/host/registerComponent';
8
8
  import '@plasmicapp/host/registerGlobalContext';
9
9
 
@@ -141,8 +141,9 @@ const FormItem = Form.Item;
141
141
  const FormList = Form.List;
142
142
  const PathContext = React.createContext({ relativePath: [], fullPath: [] });
143
143
  const InternalFormInstanceContext = React.createContext(void 0);
144
+ const FormLayoutContext = React.createContext(void 0);
144
145
  const Internal = (props) => {
145
- var _b, _c;
146
+ var _b, _c, _d;
146
147
  const [form] = Form.useForm();
147
148
  const values = form.getFieldsValue(true);
148
149
  const lastValue = React.useRef(values);
@@ -158,15 +159,26 @@ const Internal = (props) => {
158
159
  React.useEffect(() => {
159
160
  fireOnValuesChange();
160
161
  }, []);
162
+ const formLayout = React.useMemo(
163
+ () => {
164
+ var _a2;
165
+ return {
166
+ layout: props.layout,
167
+ labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
168
+ };
169
+ },
170
+ [props.layout, (_b = props.labelCol) == null ? void 0 : _b.span]
171
+ );
161
172
  return /* @__PURE__ */ React.createElement(
162
173
  InternalFormInstanceContext.Provider,
163
174
  {
164
175
  value: {
176
+ layout: formLayout,
165
177
  fireOnValuesChange,
166
178
  forceRemount: () => setRemountKey((k) => k + 1)
167
179
  }
168
180
  },
169
- /* @__PURE__ */ React.createElement(
181
+ /* @__PURE__ */ React.createElement(FormLayoutContext.Provider, { value: formLayout }, /* @__PURE__ */ React.createElement(
170
182
  Form,
171
183
  __spreadProps(__spreadValues({}, rest), {
172
184
  key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
@@ -176,16 +188,16 @@ const Internal = (props) => {
176
188
  extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(args[1]);
177
189
  },
178
190
  form,
179
- labelCol: ((_b = props.labelCol) == null ? void 0 : _b.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
180
- wrapperCol: ((_c = props.wrapperCol) == null ? void 0 : _c.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
191
+ labelCol: ((_c = props.labelCol) == null ? void 0 : _c.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
192
+ wrapperCol: ((_d = props.wrapperCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
181
193
  }),
182
194
  /* @__PURE__ */ React.createElement("style", null, `
183
- .ant-form-item-explain + div, .ant-form-item-margin-offset {
184
- display: none;
185
- }
186
- `),
195
+ .ant-form-item-explain + div, .ant-form-item-margin-offset {
196
+ display: none;
197
+ }
198
+ `),
187
199
  childrenNode
188
- )
200
+ ))
189
201
  );
190
202
  };
191
203
  function FormWrapper(props) {
@@ -239,40 +251,41 @@ const COMMON_ACTIONS = [
239
251
  // },
240
252
  // },
241
253
  ];
242
- function registerForm(loader) {
243
- const colProp = (displayName, defaultValue) => ({
244
- type: "object",
245
- displayName,
246
- advanced: true,
247
- fields: {
248
- span: {
249
- type: "number",
250
- displayName: "Grid columns",
251
- description: "The number of grid columns to span (24 columns available)",
252
- min: 1,
253
- max: 24
254
- },
255
- offset: {
256
- type: "number",
257
- displayName: "Offset columns",
258
- description: "Number of grid columns to skip from the left",
259
- min: 0,
260
- max: 23
261
- },
262
- horizontalOnly: {
263
- type: "boolean",
264
- displayName: "Horizontal only",
265
- description: "Only apply to horizontal layout"
266
- }
254
+ const colProp = (displayName, defaultValue, description) => ({
255
+ type: "object",
256
+ displayName,
257
+ advanced: true,
258
+ fields: {
259
+ span: {
260
+ type: "number",
261
+ displayName: "Width",
262
+ description: "The number of grid columns to span in width (out of 24 columns total)",
263
+ min: 1,
264
+ max: 24
267
265
  },
268
- defaultValue
269
- });
266
+ offset: {
267
+ type: "number",
268
+ displayName: "Offset",
269
+ description: "Number of grid columns to skip from the left (out of 24 columns total)",
270
+ min: 0,
271
+ max: 23
272
+ },
273
+ horizontalOnly: {
274
+ type: "boolean",
275
+ displayName: "Horizontal only",
276
+ description: "Only apply to horizontal layout"
277
+ }
278
+ },
279
+ description,
280
+ defaultValue
281
+ });
282
+ function registerForm(loader) {
270
283
  registerComponentHelper(loader, FormWrapper, {
271
284
  name: "plasmic-antd5-form",
272
285
  displayName: "Form",
273
286
  defaultStyles: {
274
- display: "plasmic-content-layout",
275
- gridRowGap: "10px"
287
+ layout: "vbox",
288
+ alignItems: "flex-start"
276
289
  },
277
290
  props: {
278
291
  children: {
@@ -310,13 +323,21 @@ function registerForm(loader) {
310
323
  },
311
324
  {
312
325
  type: "component",
313
- name: "plasmic-antd5-button",
326
+ name: "plasmic-antd5-form-item",
314
327
  props: {
328
+ noLabel: true,
315
329
  children: {
316
- type: "text",
317
- value: "Submit"
318
- },
319
- submitsForm: true
330
+ type: "component",
331
+ name: "plasmic-antd5-button",
332
+ props: {
333
+ children: {
334
+ type: "text",
335
+ value: "Submit"
336
+ },
337
+ type: "primary",
338
+ submitsForm: true
339
+ }
340
+ }
320
341
  }
321
342
  }
322
343
  ]
@@ -333,16 +354,25 @@ function registerForm(loader) {
333
354
  type: "choice",
334
355
  options: ["left", "right"],
335
356
  defaultValueHint: "right",
336
- advanced: true
357
+ advanced: true,
358
+ hidden: (ps) => ps.layout !== "horizontal"
337
359
  },
338
- labelCol: colProp("Label layout", {
339
- span: 8,
340
- horizontalOnly: true
341
- }),
342
- wrapperCol: colProp("Field layout", {
343
- span: 16,
344
- horizontalOnly: true
345
- }),
360
+ labelCol: colProp(
361
+ "Label layout",
362
+ {
363
+ span: 8,
364
+ horizontalOnly: true
365
+ },
366
+ "Set the width and offset of the labels"
367
+ ),
368
+ wrapperCol: colProp(
369
+ "Control layout",
370
+ {
371
+ span: 16,
372
+ horizontalOnly: true
373
+ },
374
+ "Set the width and offset of the form controls"
375
+ ),
346
376
  colon: {
347
377
  type: "boolean",
348
378
  description: `Show a colon after labels by default (only for horizontal layout)`,
@@ -430,6 +460,7 @@ function registerForm(loader) {
430
460
  }
431
461
  function plasmicRulesToAntdRules(plasmicRules, label) {
432
462
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
463
+ const effectiveLabel = label || "This field";
433
464
  const rules = [];
434
465
  for (const plasmicRule of plasmicRules) {
435
466
  switch (plasmicRule.ruleType) {
@@ -437,37 +468,37 @@ function plasmicRulesToAntdRules(plasmicRules, label) {
437
468
  rules.push({
438
469
  type: "enum",
439
470
  enum: (_b = (_a = plasmicRule.options) == null ? void 0 : _a.map((opt) => opt.value)) != null ? _b : [],
440
- message: (_c = plasmicRule.message) != null ? _c : `Please specify a valid value`
471
+ message: (_c = plasmicRule.message) != null ? _c : `${effectiveLabel} must be a valid value`
441
472
  });
442
473
  break;
443
474
  case "required":
444
475
  rules.push({
445
476
  required: true,
446
- message: (_d = plasmicRule.message) != null ? _d : `Please specify ${label || "this field"}`
477
+ message: (_d = plasmicRule.message) != null ? _d : `${effectiveLabel} is required`
447
478
  });
448
479
  break;
449
480
  case "regex":
450
481
  rules.push({
451
482
  pattern: new RegExp((_e = plasmicRule.pattern) != null ? _e : ""),
452
- message: (_f = plasmicRule.message) != null ? _f : `Please enter a valid value`
483
+ message: (_f = plasmicRule.message) != null ? _f : `${effectiveLabel} must be a valid value`
453
484
  });
454
485
  break;
455
486
  case "whitespace":
456
487
  rules.push({
457
488
  whitespace: true,
458
- message: (_g = plasmicRule.message) != null ? _g : `Please specify ${label || "this field"}`
489
+ message: (_g = plasmicRule.message) != null ? _g : `${effectiveLabel} is required`
459
490
  });
460
491
  break;
461
492
  case "min":
462
493
  rules.push({
463
494
  [plasmicRule.ruleType]: plasmicRule.length,
464
- message: (_h = plasmicRule.message) != null ? _h : `Must be at least ${plasmicRule.length} characters`
495
+ message: (_h = plasmicRule.message) != null ? _h : `${effectiveLabel} must be at least ${plasmicRule.length} characters`
465
496
  });
466
497
  break;
467
498
  case "max":
468
499
  rules.push({
469
500
  [plasmicRule.ruleType]: plasmicRule.length,
470
- message: (_i = plasmicRule.message) != null ? _i : `Must be at most ${plasmicRule.length} characters`
501
+ message: (_i = plasmicRule.message) != null ? _i : `${effectiveLabel} must be at most ${plasmicRule.length} characters`
471
502
  });
472
503
  break;
473
504
  case "advanced":
@@ -494,14 +525,34 @@ function useFormInstanceMaybe() {
494
525
  return Form.useFormInstance();
495
526
  }
496
527
  function FormItemWrapper(props) {
497
- var _a, _b;
498
- const relativeFormItemName = useFormItemRelativeName(props.name);
499
- const fullFormItemName = useFormItemFullName(props.name);
500
- const bestEffortLabel = !props.noLabel && reactNodeToString(props.label) || ensureArray(props.name).slice(-1)[0];
501
- const rules = props.rules ? plasmicRulesToAntdRules(
502
- props.rules,
528
+ var _b;
529
+ const _a = props, {
530
+ rules: plasmicRules,
531
+ description,
532
+ noLabel,
533
+ name,
534
+ hideValidationMessage,
535
+ customizeProps,
536
+ setControlContextData,
537
+ alignLabellessWithControls = true
538
+ } = _a, rest = __objRest(_a, [
539
+ "rules",
540
+ "description",
541
+ "noLabel",
542
+ "name",
543
+ "hideValidationMessage",
544
+ "customizeProps",
545
+ "setControlContextData",
546
+ "alignLabellessWithControls"
547
+ ]);
548
+ const relativeFormItemName = useFormItemRelativeName(name);
549
+ const fullFormItemName = useFormItemFullName(name);
550
+ const bestEffortLabel = !noLabel && reactNodeToString(props.label) || ensureArray(props.name).slice(-1)[0];
551
+ const rules = plasmicRules ? plasmicRulesToAntdRules(
552
+ plasmicRules,
503
553
  typeof bestEffortLabel === "number" ? "" + bestEffortLabel : bestEffortLabel
504
554
  ) : void 0;
555
+ const layoutContext = React.useContext(FormLayoutContext);
505
556
  const inCanvas = !!usePlasmicCanvasContext();
506
557
  if (inCanvas) {
507
558
  const form = useFormInstanceMaybe();
@@ -511,7 +562,7 @@ function FormItemWrapper(props) {
511
562
  });
512
563
  const internalFormCtx = React.useContext(InternalFormInstanceContext);
513
564
  const { fireOnValuesChange, forceRemount } = internalFormCtx != null ? internalFormCtx : {};
514
- (_a = props.setControlContextData) == null ? void 0 : _a.call(props, {
565
+ (_b = props.setControlContextData) == null ? void 0 : _b.call(props, {
515
566
  internalFormCtx
516
567
  });
517
568
  React.useEffect(() => {
@@ -528,14 +579,15 @@ function FormItemWrapper(props) {
528
579
  }
529
580
  return /* @__PURE__ */ React.createElement(
530
581
  FormItem,
531
- __spreadValues(__spreadProps(__spreadValues({}, omit(props, "rules")), {
532
- label: props.noLabel ? void 0 : props.label,
582
+ __spreadProps(__spreadValues({}, rest), {
583
+ label: noLabel ? void 0 : props.label,
533
584
  name: relativeFormItemName,
534
- rules
535
- }), props.helpTextMode === "extra" ? { extra: props.help } : props.helpTextMode === "help" ? (
536
- // Never show validation errors in this mode, even if user didn't specify help
537
- { help: (_b = props.help) != null ? _b : "" }
538
- ) : {}),
585
+ rules,
586
+ extra: description,
587
+ help: hideValidationMessage ? "" : props.help,
588
+ colon: noLabel ? false : void 0,
589
+ wrapperCol: (layoutContext == null ? void 0 : layoutContext.layout) === "horizontal" && noLabel && alignLabellessWithControls && layoutContext.labelSpan ? { offset: layoutContext.labelSpan } : void 0
590
+ }),
539
591
  props.customizeProps ? /* @__PURE__ */ React.createElement(FormItemForwarder, { formItemProps: props }) : props.children
540
592
  );
541
593
  }
@@ -565,13 +617,18 @@ function registerFormItem(loader) {
565
617
  name: "plasmic-antd5-form-item",
566
618
  displayName: "Form Item",
567
619
  parentComponentName: "plasmic-antd5-form",
620
+ defaultStyles: {
621
+ marginBottom: "24px",
622
+ width: "stretch"
623
+ },
568
624
  props: {
569
625
  label: {
570
626
  type: "slot",
571
627
  defaultValue: {
572
628
  type: "text",
573
629
  value: "Label"
574
- }
630
+ },
631
+ hidden: (ps) => !!ps.noLabel
575
632
  },
576
633
  children: {
577
634
  type: "slot",
@@ -589,10 +646,26 @@ function registerFormItem(loader) {
589
646
  rules: {
590
647
  type: "formValidationRules"
591
648
  },
649
+ valuePropName: {
650
+ type: "string",
651
+ advanced: true,
652
+ defaultValueHint: "value",
653
+ description: "The prop name for specifying the value of the form control component"
654
+ },
592
655
  noLabel: {
593
656
  type: "boolean",
594
657
  advanced: true
595
658
  },
659
+ alignLabellessWithControls: {
660
+ type: "boolean",
661
+ displayName: "Align with controls?",
662
+ description: "Aligns the content with form controls in the grid",
663
+ hidden: (ps, ctx) => {
664
+ var _a;
665
+ return !ps.noLabel || ((_a = ctx == null ? void 0 : ctx.internalFormCtx) == null ? void 0 : _a.layout.layout) !== "horizontal";
666
+ },
667
+ defaultValueHint: true
668
+ },
596
669
  colon: {
597
670
  type: "boolean",
598
671
  defaultValueHint: true,
@@ -602,7 +675,11 @@ function registerFormItem(loader) {
602
675
  labelAlign: {
603
676
  type: "choice",
604
677
  options: ["left", "right"],
605
- advanced: true
678
+ advanced: true,
679
+ hidden: (ps, ctx) => {
680
+ var _a;
681
+ return !!ps.noLabel || ((_a = ctx == null ? void 0 : ctx.internalFormCtx) == null ? void 0 : _a.layout.layout) !== "horizontal";
682
+ }
606
683
  },
607
684
  hidden: {
608
685
  type: "boolean",
@@ -626,34 +703,16 @@ function registerFormItem(loader) {
626
703
  displayName: "Dependencies",
627
704
  description: "Form items can depend on other form items. This forces it to reevaluate the validation rules when the other form item changes."
628
705
  },
629
- helpTextMode: {
630
- type: "choice",
631
- displayName: "Help text",
632
- options: [
633
- {
634
- value: "errors",
635
- label: "Validation errors"
636
- },
637
- {
638
- value: "extra",
639
- label: "Custom help text and validation errors"
640
- },
641
- {
642
- value: "help",
643
- label: "Custom help text, no validation errors"
644
- }
645
- ],
646
- defaultValueHint: "Show validation errors",
647
- description: "What to show in the help text. Edit help text by editing the 'help' slot in the outline."
706
+ hideValidationMessage: {
707
+ type: "boolean",
708
+ displayName: "Hide validation message?",
709
+ description: "If true, will hide the validation error message",
710
+ defaultValueHint: false,
711
+ advanced: true
648
712
  },
649
- help: {
713
+ description: {
650
714
  type: "slot",
651
- hidden: (ps) => {
652
- var _a;
653
- return !["extra", "help"].includes((_a = ps.helpTextMode) != null ? _a : "");
654
- },
655
715
  hidePlaceholder: true
656
- // advanced: true,
657
716
  },
658
717
  customizeProps: {
659
718
  type: "function",
@@ -671,13 +730,85 @@ function registerFormItem(loader) {
671
730
  },
672
731
  noStyle: {
673
732
  type: "boolean",
674
- displayName: "Field only",
675
- description: "Don't render anything but the wrapped field component - so no label, help text, validation error, etc.",
733
+ displayName: "Field control only",
734
+ description: "Don't render anything but the field control - so no label, help text, validation error, etc.",
676
735
  advanced: true
677
736
  }
678
737
  },
679
738
  importPath: "@plasmicpkgs/antd5/skinny/registerForm",
680
- importName: "FormItemWrapper"
739
+ importName: "FormItemWrapper",
740
+ templates: {
741
+ Text: {
742
+ props: {
743
+ children: {
744
+ type: "component",
745
+ name: "plasmic-antd5-input"
746
+ }
747
+ }
748
+ },
749
+ "Long Text": {
750
+ props: {
751
+ children: {
752
+ type: "component",
753
+ name: "plasmic-antd5-textarea"
754
+ }
755
+ }
756
+ },
757
+ "Select dropdown": {
758
+ props: {
759
+ children: {
760
+ type: "component",
761
+ name: "plasmic-antd5-select"
762
+ }
763
+ }
764
+ },
765
+ Number: {
766
+ props: {
767
+ children: {
768
+ type: "component",
769
+ name: "plasmic-antd5-input-number"
770
+ }
771
+ }
772
+ },
773
+ Checkbox: {
774
+ props: {
775
+ children: {
776
+ type: "component",
777
+ name: "plasmic-antd5-checkbox"
778
+ },
779
+ valuePropName: "checked",
780
+ noLabel: true
781
+ }
782
+ },
783
+ Radios: {
784
+ props: {
785
+ children: {
786
+ type: "component",
787
+ name: "plasmic-antd5-radio-group"
788
+ }
789
+ }
790
+ },
791
+ Password: {
792
+ props: {
793
+ children: {
794
+ type: "component",
795
+ name: "plasmic-antd5-input-password"
796
+ }
797
+ }
798
+ },
799
+ "Submit button": {
800
+ props: {
801
+ children: {
802
+ type: "component",
803
+ name: "plasmic-antd5-button",
804
+ props: {
805
+ type: "primary"
806
+ }
807
+ },
808
+ noLabel: true
809
+ }
810
+ }
811
+ }
681
812
  });
682
813
  }
683
814
  function FormGroup(props) {