@firecms/collection_editor 3.0.0-canary.102 → 3.0.0-canary.103

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
@@ -25,6 +25,7 @@
25
25
  name: Yup__namespace.string().required("Required"),
26
26
  path: Yup__namespace.string().required("Required")
27
27
  });
28
+ const useCollectionEditorController = () => React.useContext(CollectionEditorContext);
28
29
  function CollectionDetailsForm({
29
30
  isNewCollection,
30
31
  reservedGroups,
@@ -44,8 +45,12 @@
44
45
  isSubmitting,
45
46
  submitCount
46
47
  } = formex.useFormex();
48
+ const collectionEditor = useCollectionEditorController();
47
49
  const [iconDialogOpen, setIconDialogOpen] = React.useState(false);
48
50
  const [advancedPanelExpanded, setAdvancedPanelExpanded] = React.useState(false);
51
+ const updateDatabaseId = (databaseId) => {
52
+ setFieldValue("databaseId", databaseId ?? void 0);
53
+ };
49
54
  const updateName = (name) => {
50
55
  setFieldValue("name", name);
51
56
  const pathTouched = formex.getIn(touched, "path");
@@ -66,6 +71,7 @@
66
71
  setAdvancedPanelExpanded(true);
67
72
  }
68
73
  }, [errors.id]);
74
+ const DatabaseField = collectionEditor.components?.DatabaseField ?? DefaultDatabaseField;
69
75
  const collectionIcon = /* @__PURE__ */ jsxRuntime.jsx(core.IconForView, { collectionOrView: values });
70
76
  const groupOptions = groups?.filter((group) => !reservedGroups?.includes(group));
71
77
  const {
@@ -92,9 +98,16 @@
92
98
  /* @__PURE__ */ jsxRuntime.jsxs(
93
99
  "div",
94
100
  {
95
- className: "flex flex-row py-2 pt-3 items-center",
101
+ className: "flex flex-row gap-2 py-2 pt-3 items-center",
96
102
  children: [
97
103
  /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: !isNewCollection ? "h5" : "h4", className: "flex-grow", children: isNewCollection ? "New collection" : `${values?.name} collection` }),
104
+ /* @__PURE__ */ jsxRuntime.jsx(
105
+ DatabaseField,
106
+ {
107
+ databaseId: values.databaseId,
108
+ onDatabaseIdUpdate: updateDatabaseId
109
+ }
110
+ ),
98
111
  /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Change icon", children: /* @__PURE__ */ jsxRuntime.jsx(
99
112
  ui.IconButton,
100
113
  {
@@ -173,7 +186,7 @@
173
186
  })
174
187
  }
175
188
  ),
176
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: showErrors && Boolean(errors.group) ? errors.group : "Group of the collection" })
189
+ /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: showErrors && Boolean(errors.group) ? errors.group : "Group in the home page" })
177
190
  ] }),
178
191
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
179
192
  ui.ExpandablePanel,
@@ -377,6 +390,30 @@
377
390
  )
378
391
  ] }) });
379
392
  }
393
+ function DefaultDatabaseField({
394
+ databaseId,
395
+ onDatabaseIdUpdate
396
+ }) {
397
+ return /* @__PURE__ */ jsxRuntime.jsx(
398
+ ui.Tooltip,
399
+ {
400
+ title: "Database ID",
401
+ side: "top",
402
+ align: "start",
403
+ children: /* @__PURE__ */ jsxRuntime.jsx(
404
+ ui.TextField,
405
+ {
406
+ size: "smallest",
407
+ invisible: true,
408
+ inputClassName: "text-end",
409
+ value: databaseId ?? "",
410
+ onChange: (e) => onDatabaseIdUpdate(e.target.value),
411
+ placeholder: "(default)"
412
+ }
413
+ )
414
+ }
415
+ );
416
+ }
380
417
  function idToPropertiesPath(id) {
381
418
  return "properties." + id.replaceAll(".", ".properties.");
382
419
  }
@@ -1961,19 +1998,6 @@
1961
1998
  showErrors
1962
1999
  }
1963
2000
  ),
1964
- widgetId === "markdown" && /* @__PURE__ */ jsxRuntime.jsx(
1965
- StringPropertyValidation,
1966
- {
1967
- disabled,
1968
- length: true,
1969
- lowercase: true,
1970
- max: true,
1971
- min: true,
1972
- trim: true,
1973
- uppercase: true,
1974
- showErrors
1975
- }
1976
- ),
1977
2001
  widgetId === "email" && /* @__PURE__ */ jsxRuntime.jsx(
1978
2002
  StringPropertyValidation,
1979
2003
  {
@@ -2784,7 +2808,7 @@
2784
2808
  "div",
2785
2809
  {
2786
2810
  className: ui.cls(
2787
- "flex flex-row items-center text-base min-h-[52px]",
2811
+ "flex flex-row items-center text-base min-h-[48px]",
2788
2812
  optionDisabled ? "w-full" : ""
2789
2813
  ),
2790
2814
  children: [
@@ -2894,6 +2918,121 @@
2894
2918
  "block"
2895
2919
  ];
2896
2920
  const supportedFields = Object.entries(core.DEFAULT_FIELD_CONFIGS).filter(([id]) => supportedFieldsIds.includes(id)).map(([id, config]) => ({ [id]: config })).reduce((a, b) => ({ ...a, ...b }), {});
2921
+ function MarkdownPropertyField({
2922
+ disabled,
2923
+ showErrors
2924
+ }) {
2925
+ const {
2926
+ values,
2927
+ setFieldValue
2928
+ } = formex.useFormex();
2929
+ const baseStoragePath = "storage";
2930
+ const fileName = `${baseStoragePath}.fileName`;
2931
+ const maxSize = `${baseStoragePath}.maxSize`;
2932
+ const storagePath = `${baseStoragePath}.storagePath`;
2933
+ const fileNameValue = formex.getIn(values, fileName) ?? "{rand}_{file}";
2934
+ const storagePathValue = formex.getIn(values, storagePath) ?? "/";
2935
+ const maxSizeValue = formex.getIn(values, maxSize);
2936
+ const hasFilenameCallback = typeof fileNameValue === "function";
2937
+ const hasStoragePathCallback = typeof storagePathValue === "function";
2938
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2939
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(ValidationPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(
2940
+ StringPropertyValidation,
2941
+ {
2942
+ disabled,
2943
+ length: true,
2944
+ lowercase: true,
2945
+ max: true,
2946
+ min: true,
2947
+ trim: true,
2948
+ uppercase: true,
2949
+ showErrors
2950
+ }
2951
+ ) }) }),
2952
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
2953
+ ui.ExpandablePanel,
2954
+ {
2955
+ title: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row text-gray-500", children: [
2956
+ /* @__PURE__ */ jsxRuntime.jsx(ui.FileUploadIcon, {}),
2957
+ /* @__PURE__ */ jsxRuntime.jsx(
2958
+ ui.Typography,
2959
+ {
2960
+ variant: "subtitle2",
2961
+ className: "ml-2",
2962
+ children: "File upload config"
2963
+ }
2964
+ )
2965
+ ] }),
2966
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-2 p-4", children: [
2967
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
2968
+ formex.Field,
2969
+ {
2970
+ name: fileName,
2971
+ as: ui.DebouncedTextField,
2972
+ label: "File name",
2973
+ size: "small",
2974
+ disabled: hasFilenameCallback || disabled,
2975
+ value: hasFilenameCallback ? "-" : fileNameValue
2976
+ }
2977
+ ) }),
2978
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
2979
+ /* @__PURE__ */ jsxRuntime.jsx(
2980
+ formex.Field,
2981
+ {
2982
+ name: storagePath,
2983
+ as: ui.DebouncedTextField,
2984
+ label: "Storage path",
2985
+ disabled: hasStoragePathCallback || disabled,
2986
+ size: "small",
2987
+ value: hasStoragePathCallback ? "-" : storagePathValue
2988
+ }
2989
+ ),
2990
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Typography, { variant: "caption", className: "ml-3.5 mt-1 mb-2", children: [
2991
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: "You can use the following placeholders in the file name and storage path values:" }),
2992
+ /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
2993
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{file} - Full name of the uploaded file" }),
2994
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{file.name} - Name of the uploaded file without extension" }),
2995
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{file.ext} - Extension of the uploaded file" }),
2996
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{entityId} - ID of the entity" }),
2997
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{propertyKey} - ID of this field" }),
2998
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{path} - Path of this entity" }),
2999
+ /* @__PURE__ */ jsxRuntime.jsx("li", { children: "{rand} - Random value used to avoid name collisions" })
3000
+ ] })
3001
+ ] }),
3002
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "caption", className: "ml-3.5 mt-1 mb-2", children: "When using Markdown, the URL of the uploaded files are always saved in the text value (not the path)." })
3003
+ ] }),
3004
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
3005
+ ui.DebouncedTextField,
3006
+ {
3007
+ name: maxSize,
3008
+ type: "number",
3009
+ label: "Max size (in bytes)",
3010
+ size: "small",
3011
+ value: maxSizeValue !== void 0 && maxSizeValue !== null ? maxSizeValue.toString() : "",
3012
+ onChange: (e) => {
3013
+ const value = e.target.value;
3014
+ if (value === "") setFieldValue(maxSize, void 0);
3015
+ else setFieldValue(maxSize, parseInt(value));
3016
+ }
3017
+ }
3018
+ ) })
3019
+ ] })
3020
+ }
3021
+ ) }),
3022
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
3023
+ ui.TextField,
3024
+ {
3025
+ name: "defaultValue",
3026
+ disabled,
3027
+ onChange: (e) => {
3028
+ setFieldValue("defaultValue", e.target.value === "" ? void 0 : e.target.value);
3029
+ },
3030
+ label: "Default value",
3031
+ value: formex.getIn(values, "defaultValue") ?? ""
3032
+ }
3033
+ ) })
3034
+ ] });
3035
+ }
2897
3036
  const PropertyForm = React.memo(
2898
3037
  function PropertyForm2(props) {
2899
3038
  const {
@@ -2954,7 +3093,10 @@
2954
3093
  } = newPropertyWithId;
2955
3094
  doOnPropertyChanged({
2956
3095
  id,
2957
- property: { ...property2, editable: property2.editable ?? true }
3096
+ property: {
3097
+ ...property2,
3098
+ editable: property2.editable ?? true
3099
+ }
2958
3100
  });
2959
3101
  if (!existingProperty)
2960
3102
  controller.resetForm({ values: initialValue });
@@ -3159,7 +3301,7 @@
3159
3301
  }, 0);
3160
3302
  };
3161
3303
  let childComponent;
3162
- if (selectedFieldConfigId === "text_field" || selectedFieldConfigId === "multiline" || selectedFieldConfigId === "markdown" || selectedFieldConfigId === "email") {
3304
+ if (selectedFieldConfigId === "text_field" || selectedFieldConfigId === "multiline" || selectedFieldConfigId === "email") {
3163
3305
  childComponent = /* @__PURE__ */ jsxRuntime.jsx(
3164
3306
  StringPropertyField,
3165
3307
  {
@@ -3176,6 +3318,14 @@
3176
3318
  showErrors
3177
3319
  }
3178
3320
  );
3321
+ } else if (selectedFieldConfigId === "markdown") {
3322
+ childComponent = /* @__PURE__ */ jsxRuntime.jsx(
3323
+ MarkdownPropertyField,
3324
+ {
3325
+ disabled,
3326
+ showErrors
3327
+ }
3328
+ );
3179
3329
  } else if (selectedFieldConfigId === "select" || selectedFieldConfigId === "number_select") {
3180
3330
  childComponent = /* @__PURE__ */ jsxRuntime.jsx(
3181
3331
  EnumPropertyField,
@@ -5803,7 +5953,8 @@
5803
5953
  getPathSuggestions,
5804
5954
  getUser,
5805
5955
  getData,
5806
- onAnalyticsEvent
5956
+ onAnalyticsEvent,
5957
+ components
5807
5958
  }) {
5808
5959
  const navigation = core.useNavigationController();
5809
5960
  const navigate = reactRouter.useNavigate();
@@ -5902,7 +6053,8 @@
5902
6053
  createCollection,
5903
6054
  editProperty,
5904
6055
  configPermissions: configPermissions ?? defaultConfigPermissions,
5905
- getPathSuggestions
6056
+ getPathSuggestions,
6057
+ components
5906
6058
  },
5907
6059
  children: [
5908
6060
  children,
@@ -6012,7 +6164,6 @@
6012
6164
  },
6013
6165
  equal
6014
6166
  );
6015
- const useCollectionEditorController = () => React.useContext(CollectionEditorContext);
6016
6167
  function EditorCollectionAction({
6017
6168
  path: fullPath,
6018
6169
  parentCollectionIds,
@@ -6336,7 +6487,8 @@
6336
6487
  getUser,
6337
6488
  collectionInference,
6338
6489
  getData,
6339
- onAnalyticsEvent
6490
+ onAnalyticsEvent,
6491
+ components
6340
6492
  }) {
6341
6493
  return {
6342
6494
  key: "collection_editor",
@@ -6352,7 +6504,8 @@
6352
6504
  getPathSuggestions,
6353
6505
  getUser,
6354
6506
  getData,
6355
- onAnalyticsEvent
6507
+ onAnalyticsEvent,
6508
+ components
6356
6509
  }
6357
6510
  },
6358
6511
  homePage: {