@firecms/collection_editor 3.0.0-canary.136 → 3.0.0-canary.138

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.umd.js CHANGED
@@ -2804,40 +2804,6 @@
2804
2804
  }
2805
2805
  return updatedProperty;
2806
2806
  }
2807
- function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }) {
2808
- return /* @__PURE__ */ jsxRuntime.jsx(
2809
- ui.SelectItem,
2810
- {
2811
- value,
2812
- disabled: optionDisabled,
2813
- className: "flex flex-row items-center",
2814
- children: /* @__PURE__ */ jsxRuntime.jsxs(
2815
- "div",
2816
- {
2817
- className: ui.cls(
2818
- "flex flex-row items-center text-base min-h-[48px]",
2819
- optionDisabled ? "w-full" : ""
2820
- ),
2821
- children: [
2822
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsxRuntime.jsx(core.PropertyConfigBadge, { propertyConfig }) }),
2823
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2824
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: propertyConfig.name }),
2825
- /* @__PURE__ */ jsxRuntime.jsx(
2826
- ui.Typography,
2827
- {
2828
- variant: "caption",
2829
- color: "disabled",
2830
- className: "max-w-sm",
2831
- children: existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description
2832
- }
2833
- )
2834
- ] })
2835
- ]
2836
- }
2837
- )
2838
- }
2839
- );
2840
- }
2841
2807
  function UrlPropertyField({
2842
2808
  disabled,
2843
2809
  showErrors
@@ -3054,6 +3020,7 @@
3054
3020
  property,
3055
3021
  onPropertyChanged,
3056
3022
  onPropertyChangedImmediate = true,
3023
+ onDismiss,
3057
3024
  onDelete,
3058
3025
  onError,
3059
3026
  initialErrors,
@@ -3160,6 +3127,7 @@
3160
3127
  includeIdAndTitle: includeIdAndName,
3161
3128
  propertyNamespace,
3162
3129
  onError,
3130
+ onDismiss,
3163
3131
  showErrors: forceShowErrors || formexController.submitCount > 0,
3164
3132
  existing: existingProperty,
3165
3133
  autoUpdateId,
@@ -3210,6 +3178,7 @@
3210
3178
  PropertyForm,
3211
3179
  {
3212
3180
  ...formProps,
3181
+ onDismiss: onCancel,
3213
3182
  onPropertyChanged: (params) => {
3214
3183
  onPropertyChanged?.(params);
3215
3184
  onOkClicked?.();
@@ -3259,6 +3228,7 @@
3259
3228
  onPropertyChanged,
3260
3229
  onDelete,
3261
3230
  propertyNamespace,
3231
+ onDismiss,
3262
3232
  onError,
3263
3233
  showErrors,
3264
3234
  disabled,
@@ -3271,8 +3241,6 @@
3271
3241
  const [selectOpen, setSelectOpen] = React.useState(autoOpenTypeSelect);
3272
3242
  const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
3273
3243
  const [selectedFieldConfigId, setSelectedFieldConfigId] = React.useState(values?.dataType ? core.getFieldId(values) : void 0);
3274
- const allSupportedFields = Object.entries(supportedFields).concat(Object.entries(propertyConfigs));
3275
- const displayedWidgets = inArray ? allSupportedFields.filter(([_, propertyConfig]) => !core.isPropertyBuilder(propertyConfig.property) && propertyConfig.property?.dataType !== "array") : allSupportedFields;
3276
3244
  const deferredValues = React.useDeferredValue(values);
3277
3245
  const nameFieldRef = React.useRef(null);
3278
3246
  const lastSubmittedProperty = React.useRef(values);
@@ -3453,72 +3421,23 @@
3453
3421
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex mt-2 justify-between", children: [
3454
3422
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex flex-col gap-2", children: [
3455
3423
  /* @__PURE__ */ jsxRuntime.jsx(
3456
- ui.Select,
3424
+ WidgetSelectView,
3457
3425
  {
3458
- error: Boolean(selectedWidgetError),
3459
- value: selectedFieldConfigId ?? "",
3460
- placeholder: "Select a property widget",
3426
+ initialProperty: values,
3427
+ value: selectedFieldConfigId,
3428
+ onValueChange: (value) => onWidgetSelectChanged(value),
3461
3429
  open: selectOpen,
3462
- onOpenChange: setSelectOpen,
3463
- position: "item-aligned",
3464
- disabled,
3465
- renderValue: (value) => {
3466
- if (!value) {
3467
- return /* @__PURE__ */ jsxRuntime.jsx("em", { children: "Select a property widget" });
3430
+ onOpenChange: (open, hasValue) => {
3431
+ if (!hasValue) {
3432
+ onDismiss?.();
3468
3433
  }
3469
- const key = value;
3470
- const propertyConfig = core.DEFAULT_FIELD_CONFIGS[key] ?? propertyConfigs[key];
3471
- const baseProperty = propertyConfig.property;
3472
- const baseFieldConfig = baseProperty && !core.isPropertyBuilder(baseProperty) ? core.getFieldConfig(baseProperty, propertyConfigs) : void 0;
3473
- const optionDisabled = core.isPropertyBuilder(baseProperty) || existing && baseProperty.dataType !== values?.dataType;
3474
- const computedFieldConfig = baseFieldConfig ? core.mergeDeep(baseFieldConfig, propertyConfig) : propertyConfig;
3475
- return /* @__PURE__ */ jsxRuntime.jsxs(
3476
- "div",
3477
- {
3478
- onClick: (e) => {
3479
- if (optionDisabled) {
3480
- e.stopPropagation();
3481
- e.preventDefault();
3482
- }
3483
- },
3484
- className: ui.cls(
3485
- "flex items-center",
3486
- optionDisabled ? "w-full pointer-events-none opacity-50" : ""
3487
- ),
3488
- children: [
3489
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsxRuntime.jsx(core.PropertyConfigBadge, { propertyConfig: computedFieldConfig }) }),
3490
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start text-base text-left", children: [
3491
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: computedFieldConfig.name }),
3492
- /* @__PURE__ */ jsxRuntime.jsx(
3493
- ui.Typography,
3494
- {
3495
- variant: "caption",
3496
- color: "disabled",
3497
- children: optionDisabled ? "You can only switch to widgets that use the same data type" : computedFieldConfig.description
3498
- }
3499
- )
3500
- ] })
3501
- ]
3502
- }
3503
- );
3504
- },
3505
- onValueChange: (value) => {
3506
- onWidgetSelectChanged(value);
3434
+ setSelectOpen(open);
3507
3435
  },
3508
- children: displayedWidgets.map(([key, propertyConfig]) => {
3509
- const baseProperty = propertyConfig.property;
3510
- const optionDisabled = existing && !core.isPropertyBuilder(baseProperty) && baseProperty.dataType !== values?.dataType;
3511
- return /* @__PURE__ */ jsxRuntime.jsx(
3512
- PropertySelectItem,
3513
- {
3514
- value: key,
3515
- optionDisabled,
3516
- propertyConfig,
3517
- existing
3518
- },
3519
- key
3520
- );
3521
- })
3436
+ disabled,
3437
+ showError: Boolean(selectedWidgetError),
3438
+ existing,
3439
+ propertyConfigs,
3440
+ inArray
3522
3441
  }
3523
3442
  ),
3524
3443
  selectedWidgetError && /* @__PURE__ */ jsxRuntime.jsx(
@@ -3594,6 +3513,196 @@
3594
3513
  }
3595
3514
  return error;
3596
3515
  }
3516
+ const WIDGET_TYPE_MAP = {
3517
+ text_field: "Text",
3518
+ multiline: "Text",
3519
+ markdown: "Text",
3520
+ url: "Text",
3521
+ email: "Text",
3522
+ switch: "Boolean",
3523
+ select: "Select",
3524
+ multi_select: "Select",
3525
+ number_input: "Number",
3526
+ number_select: "Select",
3527
+ multi_number_select: "Select",
3528
+ file_upload: "File",
3529
+ multi_file_upload: "File",
3530
+ reference: "Reference",
3531
+ multi_references: "Reference",
3532
+ date_time: "Date",
3533
+ group: "Group",
3534
+ key_value: "Group",
3535
+ repeat: "Array",
3536
+ custom_array: "Array",
3537
+ block: "Group"
3538
+ };
3539
+ function WidgetSelectView({
3540
+ initialProperty,
3541
+ value,
3542
+ onValueChange,
3543
+ open,
3544
+ onOpenChange,
3545
+ disabled,
3546
+ showError,
3547
+ existing,
3548
+ propertyConfigs,
3549
+ inArray
3550
+ }) {
3551
+ const allSupportedFields = Object.entries(supportedFields).concat(Object.entries(propertyConfigs));
3552
+ const displayedWidgets = (inArray ? allSupportedFields.filter(([_, propertyConfig2]) => !core.isPropertyBuilder(propertyConfig2.property) && propertyConfig2.property?.dataType !== "array") : allSupportedFields).map(([key2, propertyConfig2]) => ({
3553
+ [key2]: propertyConfig2
3554
+ })).reduce((a, b) => {
3555
+ return {
3556
+ ...a,
3557
+ ...b
3558
+ };
3559
+ }, {});
3560
+ const key = value;
3561
+ const propertyConfig = key ? core.DEFAULT_FIELD_CONFIGS[key] ?? propertyConfigs[key] : void 0;
3562
+ const baseProperty = propertyConfig?.property;
3563
+ const baseFieldConfig = baseProperty && !core.isPropertyBuilder(baseProperty) ? core.getFieldConfig(baseProperty, propertyConfigs) : void 0;
3564
+ const computedFieldConfig = baseFieldConfig && propertyConfig ? core.mergeDeep(baseFieldConfig, propertyConfig) : propertyConfig;
3565
+ const groups = [...new Set(Object.keys(displayedWidgets).map((key2) => {
3566
+ const group = WIDGET_TYPE_MAP[key2];
3567
+ if (group) {
3568
+ return group;
3569
+ }
3570
+ return "Custom/Other";
3571
+ }))];
3572
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3573
+ /* @__PURE__ */ jsxRuntime.jsxs(
3574
+ "div",
3575
+ {
3576
+ onClick: () => {
3577
+ if (!disabled) {
3578
+ onOpenChange(!open, Boolean(value));
3579
+ }
3580
+ },
3581
+ className: ui.cls(
3582
+ "select-none rounded-md text-sm p-4",
3583
+ ui.fieldBackgroundMixin,
3584
+ disabled ? ui.fieldBackgroundDisabledMixin : ui.fieldBackgroundHoverMixin,
3585
+ "relative flex items-center"
3586
+ ),
3587
+ children: [
3588
+ !value && /* @__PURE__ */ jsxRuntime.jsx("em", { children: "Select a property widget" }),
3589
+ value && computedFieldConfig && /* @__PURE__ */ jsxRuntime.jsxs(
3590
+ "div",
3591
+ {
3592
+ className: ui.cls(
3593
+ "flex items-center"
3594
+ ),
3595
+ children: [
3596
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsxRuntime.jsx(core.PropertyConfigBadge, { propertyConfig: computedFieldConfig }) }),
3597
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start text-base text-left", children: [
3598
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: computedFieldConfig.name }),
3599
+ /* @__PURE__ */ jsxRuntime.jsx(
3600
+ ui.Typography,
3601
+ {
3602
+ variant: "caption",
3603
+ color: "secondary",
3604
+ children: computedFieldConfig.description
3605
+ }
3606
+ )
3607
+ ] })
3608
+ ]
3609
+ }
3610
+ )
3611
+ ]
3612
+ }
3613
+ ),
3614
+ /* @__PURE__ */ jsxRuntime.jsxs(
3615
+ ui.Dialog,
3616
+ {
3617
+ open,
3618
+ onOpenChange: (open2) => onOpenChange(open2, Boolean(value)),
3619
+ maxWidth: "4xl",
3620
+ children: [
3621
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DialogTitle, { children: "Select a property widget" }),
3622
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DialogContent, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: groups.map((group) => {
3623
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4", children: [
3624
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: group }),
3625
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 mt-4", children: Object.entries(displayedWidgets).map(([key2, propertyConfig2]) => {
3626
+ const groupKey = WIDGET_TYPE_MAP[key2];
3627
+ if (groupKey === group) {
3628
+ return /* @__PURE__ */ jsxRuntime.jsx(
3629
+ WidgetSelectViewItem,
3630
+ {
3631
+ initialProperty,
3632
+ onClick: () => {
3633
+ onValueChange(key2);
3634
+ onOpenChange(false, true);
3635
+ },
3636
+ propertyConfig: propertyConfig2,
3637
+ existing
3638
+ },
3639
+ key2
3640
+ );
3641
+ }
3642
+ return null;
3643
+ }) })
3644
+ ] }, group);
3645
+ }) }) })
3646
+ ]
3647
+ }
3648
+ )
3649
+ ] });
3650
+ }
3651
+ function WidgetSelectViewItem({
3652
+ onClick,
3653
+ initialProperty,
3654
+ // optionDisabled,
3655
+ propertyConfig,
3656
+ existing
3657
+ }) {
3658
+ const baseProperty = propertyConfig.property;
3659
+ const shouldWarnChangingDataType = existing && !core.isPropertyBuilder(baseProperty) && baseProperty.dataType !== initialProperty?.dataType;
3660
+ return /* @__PURE__ */ jsxRuntime.jsx(
3661
+ ui.Card,
3662
+ {
3663
+ onClick,
3664
+ className: "flex flex-row items-center px-4 py-2",
3665
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
3666
+ "div",
3667
+ {
3668
+ className: ui.cls(
3669
+ "flex flex-row items-center text-base min-h-[48px]"
3670
+ ),
3671
+ children: [
3672
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsxRuntime.jsx(core.PropertyConfigBadge, { propertyConfig, disabled: shouldWarnChangingDataType }) }),
3673
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3674
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row gap-2 items-center", children: [
3675
+ shouldWarnChangingDataType && /* @__PURE__ */ jsxRuntime.jsx(
3676
+ ui.Tooltip,
3677
+ {
3678
+ title: "This widget uses a different data type than the initially selected widget. This can cause errors with existing data.",
3679
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.WarningOffIcon, { size: "smallest", className: "w-4" })
3680
+ }
3681
+ ),
3682
+ /* @__PURE__ */ jsxRuntime.jsx(
3683
+ ui.Typography,
3684
+ {
3685
+ color: shouldWarnChangingDataType ? "secondary" : void 0,
3686
+ children: propertyConfig.name
3687
+ }
3688
+ )
3689
+ ] }),
3690
+ /* @__PURE__ */ jsxRuntime.jsx(
3691
+ ui.Typography,
3692
+ {
3693
+ variant: "caption",
3694
+ color: "secondary",
3695
+ className: "max-w-sm",
3696
+ children: propertyConfig.description
3697
+ }
3698
+ )
3699
+ ] })
3700
+ ]
3701
+ }
3702
+ )
3703
+ }
3704
+ );
3705
+ }
3597
3706
  function camelCase(str) {
3598
3707
  if (!str) return "";
3599
3708
  return (str.slice(0, 1).toLowerCase() + str.slice(1)).replace(/([-_ ]){1,}/g, " ").split(/[-_ ]/).reduce((cur, acc) => {
@@ -4086,6 +4195,7 @@
4086
4195
  getData,
4087
4196
  propertyConfigs,
4088
4197
  collectionEditable,
4198
+ onCancel: closePropertyDialog,
4089
4199
  onOkClicked: asDialog ? closePropertyDialog : void 0
4090
4200
  },
4091
4201
  `edit_view_${selectedPropertyIndex}`
@@ -5226,6 +5336,40 @@
5226
5336
  }
5227
5337
  );
5228
5338
  }
5339
+ function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }) {
5340
+ return /* @__PURE__ */ jsxRuntime.jsx(
5341
+ ui.SelectItem,
5342
+ {
5343
+ value,
5344
+ disabled: optionDisabled,
5345
+ className: "flex flex-row items-center",
5346
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
5347
+ "div",
5348
+ {
5349
+ className: ui.cls(
5350
+ "flex flex-row items-center text-base min-h-[48px]",
5351
+ optionDisabled ? "w-full" : ""
5352
+ ),
5353
+ children: [
5354
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsxRuntime.jsx(core.PropertyConfigBadge, { propertyConfig }) }),
5355
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5356
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: propertyConfig.name }),
5357
+ /* @__PURE__ */ jsxRuntime.jsx(
5358
+ ui.Typography,
5359
+ {
5360
+ variant: "caption",
5361
+ color: "disabled",
5362
+ className: "max-w-sm",
5363
+ children: existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description
5364
+ }
5365
+ )
5366
+ ] })
5367
+ ]
5368
+ }
5369
+ )
5370
+ }
5371
+ );
5372
+ }
5229
5373
  function CollectionEditorImportDataPreview({
5230
5374
  importConfig,
5231
5375
  properties,