@firecms/ui 3.0.0-rc.2 → 3.0.0-rc.3

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
@@ -27728,251 +27728,122 @@
27728
27728
  }
27729
27729
  return t15;
27730
27730
  }
27731
- const DateTimeField = (t0) => {
27732
- const $ = reactCompilerRuntime.c(57);
27733
- const {
27734
- value,
27735
- label,
27736
- onChange,
27737
- disabled,
27738
- clearable,
27739
- mode: t1,
27740
- error,
27741
- size: t2,
27742
- className,
27743
- style,
27744
- inputClassName,
27745
- invisible
27746
- } = t0;
27747
- const mode = t1 === void 0 ? "date" : t1;
27748
- const size = t2 === void 0 ? "large" : t2;
27731
+ const DateTimeField = ({
27732
+ value,
27733
+ label,
27734
+ onChange,
27735
+ disabled,
27736
+ clearable,
27737
+ mode = "date",
27738
+ error,
27739
+ size = "large",
27740
+ className,
27741
+ style,
27742
+ inputClassName,
27743
+ invisible
27744
+ }) => {
27749
27745
  const inputRef = React.useRef(null);
27750
27746
  const [focused, setFocused] = React.useState(false);
27747
+ const [internalValue, setInternalValue] = React.useState("");
27748
+ const [isTyping, setIsTyping] = React.useState(false);
27751
27749
  const invalidValue = value !== void 0 && value !== null && !(value instanceof Date);
27752
27750
  useInjectStyles("DateTimeField", inputStyles);
27753
- let t3;
27754
- if ($[0] !== onChange) {
27755
- t3 = (e) => {
27756
- e.preventDefault();
27751
+ const handleClear = (e) => {
27752
+ e.preventDefault();
27753
+ setInternalValue("");
27754
+ setIsTyping(false);
27755
+ onChange?.(null);
27756
+ };
27757
+ const valueAsInputValue = (dateValue, mode_0) => {
27758
+ if (!dateValue) {
27759
+ return "";
27760
+ }
27761
+ const pad = (n) => n.toString().padStart(2, "0");
27762
+ const year = dateValue.getFullYear();
27763
+ const month = pad(dateValue.getMonth() + 1);
27764
+ const day = pad(dateValue.getDate());
27765
+ if (mode_0 === "date") {
27766
+ return `${year}-${month}-${day}`;
27767
+ } else {
27768
+ const hours = pad(dateValue.getHours());
27769
+ const minutes = pad(dateValue.getMinutes());
27770
+ return `${year}-${month}-${day}T${hours}:${minutes}`;
27771
+ }
27772
+ };
27773
+ const handleInputChange = (e_0) => {
27774
+ const inputValue = e_0.target.value;
27775
+ setInternalValue(inputValue);
27776
+ setIsTyping(true);
27777
+ if (!inputValue) {
27757
27778
  onChange?.(null);
27758
- };
27759
- $[0] = onChange;
27760
- $[1] = t3;
27761
- } else {
27762
- t3 = $[1];
27763
- }
27764
- const handleClear = t3;
27765
- const valueAsInputValue = _temp2$1;
27766
- let t4;
27767
- if ($[2] !== mode || $[3] !== onChange) {
27768
- t4 = (e_0) => {
27769
- const inputValue = e_0.target.value;
27770
- if (!inputValue) {
27771
- onChange?.(null);
27772
- return;
27779
+ return;
27780
+ }
27781
+ try {
27782
+ const parsed = new Date(inputValue);
27783
+ if (isNaN(parsed.getTime())) {
27784
+ throw new Error("Invalid date");
27773
27785
  }
27774
27786
  let newDate;
27775
- try {
27776
- if (mode === "date_time") {
27777
- const [datePart, timePart] = inputValue.split("T");
27778
- const [year_0, month_0, day_0] = datePart.split("-").map(Number);
27779
- const [hours_0, minutes_0] = timePart.split(":").map(Number);
27780
- newDate = new Date(year_0, month_0 - 1, day_0, hours_0, minutes_0);
27781
- } else {
27782
- const [year_1, month_1, day_1] = inputValue.split("-").map(Number);
27783
- newDate = new Date(year_1, month_1 - 1, day_1);
27784
- }
27785
- } catch (t52) {
27786
- newDate = null;
27787
+ if (mode === "date") {
27788
+ const userTimezoneOffset = parsed.getTimezoneOffset() * 6e4;
27789
+ newDate = new Date(parsed.getTime() + userTimezoneOffset);
27790
+ } else {
27791
+ newDate = parsed;
27787
27792
  }
27788
27793
  onChange?.(newDate);
27789
- };
27790
- $[2] = mode;
27791
- $[3] = onChange;
27792
- $[4] = t4;
27793
- } else {
27794
- t4 = $[4];
27795
- }
27796
- const handleInputChange = t4;
27797
- let t5;
27798
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
27799
- t5 = /* @__PURE__ */ jsxRuntime.jsx("style", { children: inputStyles });
27800
- $[5] = t5;
27801
- } else {
27802
- t5 = $[5];
27803
- }
27804
- const t6 = !invisible && fieldBackgroundMixin;
27805
- const t7 = disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin;
27806
- const t8 = size === "smallest";
27807
- const t9 = size === "small";
27808
- const t10 = size === "medium";
27809
- const t11 = size === "large";
27810
- let t12;
27811
- if ($[6] !== className || $[7] !== t10 || $[8] !== t11 || $[9] !== t6 || $[10] !== t7 || $[11] !== t8 || $[12] !== t9) {
27812
- t12 = cls("rounded-md relative max-w-full", t6, t7, {
27813
- "min-h-[28px]": t8,
27814
- "min-h-[32px]": t9,
27815
- "min-h-[42px]": t10,
27816
- "min-h-[64px]": t11
27817
- }, className);
27818
- $[6] = className;
27819
- $[7] = t10;
27820
- $[8] = t11;
27821
- $[9] = t6;
27822
- $[10] = t7;
27823
- $[11] = t8;
27824
- $[12] = t9;
27825
- $[13] = t12;
27826
- } else {
27827
- t12 = $[13];
27828
- }
27829
- let t13;
27830
- if ($[14] !== disabled) {
27831
- t13 = () => {
27794
+ } catch (e_1) {
27795
+ return;
27796
+ }
27797
+ };
27798
+ const handleFocus = () => {
27799
+ setFocused(true);
27800
+ setIsTyping(true);
27801
+ setInternalValue(valueAsInputValue(value ?? null, mode));
27802
+ };
27803
+ const handleBlur = () => {
27804
+ setFocused(false);
27805
+ setIsTyping(false);
27806
+ };
27807
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
27808
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: inputStyles }),
27809
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cls("rounded-md relative max-w-full", !invisible && fieldBackgroundMixin, disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin, {
27810
+ "min-h-[28px]": size === "smallest",
27811
+ "min-h-[32px]": size === "small",
27812
+ "min-h-[42px]": size === "medium",
27813
+ "min-h-[64px]": size === "large"
27814
+ }, className), style, onClick: () => {
27832
27815
  if (!disabled) {
27833
27816
  inputRef.current?.focus();
27834
27817
  }
27835
- };
27836
- $[14] = disabled;
27837
- $[15] = t13;
27838
- } else {
27839
- t13 = $[15];
27840
- }
27841
- let t14;
27842
- if ($[16] !== disabled || $[17] !== error || $[18] !== focused || $[19] !== label) {
27843
- t14 = label && /* @__PURE__ */ jsxRuntime.jsx(InputLabel, { className: cls("absolute top-1 pointer-events-none", !error ? focused ? "text-primary" : "text-text-secondary dark:text-text-secondary-dark" : "text-red-500 dark:text-red-500", disabled ? "opacity-50" : ""), shrink: true, children: label });
27844
- $[16] = disabled;
27845
- $[17] = error;
27846
- $[18] = focused;
27847
- $[19] = label;
27848
- $[20] = t14;
27849
- } else {
27850
- t14 = $[20];
27851
- }
27852
- const t15 = mode === "date_time" ? "datetime-local" : "date";
27853
- const t16 = valueAsInputValue(value ?? null, mode);
27854
- let t17;
27855
- let t18;
27856
- if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
27857
- t17 = () => setFocused(true);
27858
- t18 = () => setFocused(false);
27859
- $[21] = t17;
27860
- $[22] = t18;
27861
- } else {
27862
- t17 = $[21];
27863
- t18 = $[22];
27864
- }
27865
- const t19 = clearable ? "pr-14" : "pr-12";
27866
- const t20 = size === "smallest";
27867
- const t21 = size === "small";
27868
- const t22 = size === "medium";
27869
- const t23 = size === "large";
27870
- let t24;
27871
- if ($[23] !== disabled || $[24] !== inputClassName || $[25] !== label || $[26] !== t19 || $[27] !== t20 || $[28] !== t21 || $[29] !== t22 || $[30] !== t23) {
27872
- t24 = cls("w-full outline-none bg-transparent leading-normal text-base px-3", t19, "rounded-md", {
27873
- "min-h-[28px]": t20,
27874
- "min-h-[32px]": t21,
27875
- "min-h-[42px]": t22,
27876
- "min-h-[64px]": t23
27877
- }, label ? "pt-8 pb-2" : "py-2", inputClassName, disabled && "border border-transparent outline-none opacity-50 dark:opacity-50 text-surface-accent-600 dark:text-surface-accent-500");
27878
- $[23] = disabled;
27879
- $[24] = inputClassName;
27880
- $[25] = label;
27881
- $[26] = t19;
27882
- $[27] = t20;
27883
- $[28] = t21;
27884
- $[29] = t22;
27885
- $[30] = t23;
27886
- $[31] = t24;
27887
- } else {
27888
- t24 = $[31];
27889
- }
27890
- let t25;
27891
- if ($[32] !== disabled || $[33] !== handleInputChange || $[34] !== t15 || $[35] !== t16 || $[36] !== t24) {
27892
- t25 = /* @__PURE__ */ jsxRuntime.jsx("input", { ref: inputRef, type: t15, value: t16, onChange: handleInputChange, onFocus: t17, onBlur: t18, disabled, className: t24 });
27893
- $[32] = disabled;
27894
- $[33] = handleInputChange;
27895
- $[34] = t15;
27896
- $[35] = t16;
27897
- $[36] = t24;
27898
- $[37] = t25;
27899
- } else {
27900
- t25 = $[37];
27901
- }
27902
- let t26;
27903
- if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
27904
- t26 = (e_2) => {
27905
- e_2.stopPropagation();
27906
- inputRef.current?.showPicker();
27907
- };
27908
- $[38] = t26;
27909
- } else {
27910
- t26 = $[38];
27911
- }
27912
- let t27;
27913
- if ($[39] === Symbol.for("react.memo_cache_sentinel")) {
27914
- t27 = /* @__PURE__ */ jsxRuntime.jsx(IconButton, { onClick: t26, className: "absolute right-3 top-1/2 transform -translate-y-1/2 !text-surface-accent-500", children: /* @__PURE__ */ jsxRuntime.jsx(CalendarMonthIcon, { color: "disabled" }) });
27915
- $[39] = t27;
27916
- } else {
27917
- t27 = $[39];
27918
- }
27919
- let t28;
27920
- if ($[40] !== clearable || $[41] !== handleClear || $[42] !== value) {
27921
- t28 = clearable && value && /* @__PURE__ */ jsxRuntime.jsx(IconButton, { onClick: handleClear, className: "absolute right-14 top-1/2 transform -translate-y-1/2 text-surface-accent-400 ", children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) });
27922
- $[40] = clearable;
27923
- $[41] = handleClear;
27924
- $[42] = value;
27925
- $[43] = t28;
27926
- } else {
27927
- t28 = $[43];
27928
- }
27929
- let t29;
27930
- if ($[44] !== style || $[45] !== t12 || $[46] !== t13 || $[47] !== t14 || $[48] !== t25 || $[49] !== t28) {
27931
- t29 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: t12, style, onClick: t13, children: [
27932
- t14,
27933
- t25,
27934
- t27,
27935
- t28
27936
- ] });
27937
- $[44] = style;
27938
- $[45] = t12;
27939
- $[46] = t13;
27940
- $[47] = t14;
27941
- $[48] = t25;
27942
- $[49] = t28;
27943
- $[50] = t29;
27944
- } else {
27945
- t29 = $[50];
27946
- }
27947
- let t30;
27948
- if ($[51] !== invalidValue || $[52] !== value) {
27949
- t30 = invalidValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center m-2", children: [
27818
+ }, children: [
27819
+ label && /* @__PURE__ */ jsxRuntime.jsx(
27820
+ InputLabel,
27821
+ {
27822
+ className: cls("absolute top-1 pointer-events-none", !error ? focused ? "text-primary" : "text-text-secondary dark:text-text-secondary-dark" : "text-red-500 dark:text-red-500", disabled ? "opacity-50" : ""),
27823
+ shrink: true,
27824
+ children: label
27825
+ }
27826
+ ),
27827
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ref: inputRef, type: mode === "date_time" ? "datetime-local" : "date", value: isTyping ? internalValue : valueAsInputValue(value ?? null, mode), onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, disabled, className: cls("w-full outline-none bg-transparent leading-normal text-base px-3", clearable ? "pr-14" : "pr-12", "rounded-md", {
27828
+ "min-h-[28px]": size === "smallest",
27829
+ "min-h-[32px]": size === "small",
27830
+ "min-h-[42px]": size === "medium",
27831
+ "min-h-[64px]": size === "large"
27832
+ }, label ? "pt-8 pb-2" : "py-2", inputClassName, disabled && "border border-transparent outline-none opacity-50 dark:opacity-50 text-surface-accent-600 dark:text-surface-accent-500") }),
27833
+ /* @__PURE__ */ jsxRuntime.jsx(IconButton, { onClick: (e_2) => {
27834
+ e_2.stopPropagation();
27835
+ inputRef.current?.showPicker();
27836
+ }, className: "absolute right-3 top-1/2 transform -translate-y-1/2 !text-surface-accent-500", children: /* @__PURE__ */ jsxRuntime.jsx(CalendarMonthIcon, { color: "disabled" }) }),
27837
+ clearable && value && /* @__PURE__ */ jsxRuntime.jsx(IconButton, { onClick: handleClear, className: "absolute right-14 top-1/2 transform -translate-y-1/2 text-surface-accent-400 ", children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
27838
+ ] }),
27839
+ invalidValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center m-2", children: [
27950
27840
  /* @__PURE__ */ jsxRuntime.jsx(ErrorIcon, { size: "small", color: "error" }),
27951
27841
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pl-2", children: [
27952
27842
  /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body2", children: "Invalid date value for this field" }),
27953
27843
  /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body2", children: `The provided value is: ${JSON.stringify(value)}` })
27954
27844
  ] })
27955
- ] });
27956
- $[51] = invalidValue;
27957
- $[52] = value;
27958
- $[53] = t30;
27959
- } else {
27960
- t30 = $[53];
27961
- }
27962
- let t31;
27963
- if ($[54] !== t29 || $[55] !== t30) {
27964
- t31 = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
27965
- t5,
27966
- t29,
27967
- t30
27968
- ] });
27969
- $[54] = t29;
27970
- $[55] = t30;
27971
- $[56] = t31;
27972
- } else {
27973
- t31 = $[56];
27974
- }
27975
- return t31;
27845
+ ] })
27846
+ ] });
27976
27847
  };
27977
27848
  const inputStyles = `
27978
27849
  /* Hide the default calendar icon in Chrome, Safari, Edge, Opera */
@@ -27987,25 +27858,6 @@
27987
27858
  -moz-appearance:textfield;
27988
27859
  }
27989
27860
  `;
27990
- function _temp$3(n) {
27991
- return n.toString().padStart(2, "0");
27992
- }
27993
- function _temp2$1(dateValue, mode_0) {
27994
- if (!dateValue) {
27995
- return "";
27996
- }
27997
- const pad = _temp$3;
27998
- const year = dateValue.getFullYear();
27999
- const month = pad(dateValue.getMonth() + 1);
28000
- const day = pad(dateValue.getDate());
28001
- if (mode_0 === "date") {
28002
- return `${year}-${month}-${day}`;
28003
- } else {
28004
- const hours = pad(dateValue.getHours());
28005
- const minutes = pad(dateValue.getMinutes());
28006
- return `${year}-${month}-${day}T${hours}:${minutes}`;
28007
- }
28008
- }
28009
27861
  const widthClasses = {
28010
27862
  xs: "max-w-xs min-w-xs w-xs",
28011
27863
  sm: "max-w-sm min-w-sm w-sm",
@@ -28136,7 +27988,7 @@
28136
27988
  const t22 = maxWidth && !fullScreen ? widthClasses[maxWidth] : void 0;
28137
27989
  let t23;
28138
27990
  if ($[16] !== className || $[17] !== t17 || $[18] !== t18 || $[19] !== t19 || $[20] !== t20 || $[21] !== t21 || $[22] !== t22) {
28139
- t23 = cls(paperMixin, "z-30", "relative", "outline-none focus:outline-none", t17, t18, "text-surface-accent-900 dark:text-white", "justify-center items-center", t19, "ease-in-out duration-200", t20, t21, t22, className);
27991
+ t23 = cls(paperMixin, "rounded-2xl", "z-30", "relative", "overflow-hidden", "outline-none focus:outline-none", t17, t18, "text-surface-accent-900 dark:text-white", "justify-center items-center", t19, "ease-in-out duration-200", t20, t21, t22, className);
28140
27992
  $[16] = className;
28141
27993
  $[17] = t17;
28142
27994
  $[18] = t18;
@@ -28210,7 +28062,7 @@
28210
28062
  const t3 = translucent ? "backdrop-blur-sm" : "";
28211
28063
  let t4;
28212
28064
  if ($[0] !== className || $[1] !== position || $[2] !== t3) {
28213
- t4 = cls(defaultBorderMixin, "py-3 px-4 border-t flex flex-row items-center justify-end bottom-0 right-0 left-0 text-right z-2 gap-2", position, "bg-white bg-opacity-60 dark:bg-surface-900 dark:bg-opacity-60", t3, className);
28065
+ t4 = cls(defaultBorderMixin, "pt-2 pb-4 px-4 border-t flex flex-row items-center justify-end bottom-0 right-0 left-0 text-right z-2 gap-2", position, "bg-white bg-opacity-60 dark:bg-surface-900 dark:bg-opacity-60", t3, className);
28214
28066
  $[0] = className;
28215
28067
  $[1] = position;
28216
28068
  $[2] = t3;
@@ -28252,7 +28104,7 @@
28252
28104
  let t2;
28253
28105
  if ($[2] !== className || $[3] !== includeMargin) {
28254
28106
  t2 = cls("flex-grow", {
28255
- "my-6 mx-6": includeMargin
28107
+ "my-8 mx-8": includeMargin
28256
28108
  }, className);
28257
28109
  $[2] = className;
28258
28110
  $[3] = includeMargin;
@@ -28313,7 +28165,7 @@
28313
28165
  let t4;
28314
28166
  if ($[8] !== className || $[9] !== includeMargin) {
28315
28167
  t4 = cls({
28316
- "mt-6 mx-6": includeMargin
28168
+ "mt-8 mx-8": includeMargin
28317
28169
  }, className);
28318
28170
  $[8] = className;
28319
28171
  $[9] = includeMargin;
@@ -28911,7 +28763,7 @@
28911
28763
  }
28912
28764
  let t3;
28913
28765
  if ($[3] !== className) {
28914
- t3 = cls(paperMixin, focusedDisabled, "shadow py-2 z-30", className);
28766
+ t3 = cls(paperMixin, focusedDisabled, "py-2 z-30", className);
28915
28767
  $[3] = className;
28916
28768
  $[4] = t3;
28917
28769
  } else {
@@ -28966,7 +28818,7 @@
28966
28818
  } = t0;
28967
28819
  const dense = t1 === void 0 ? false : t1;
28968
28820
  const t2 = onClick && "cursor-pointer";
28969
- const t3 = dense ? "px-3 py-1.5" : "px-4 py-2";
28821
+ const t3 = dense ? "px-4 py-1.5" : "px-4 py-2";
28970
28822
  let t4;
28971
28823
  if ($[0] !== className || $[1] !== t2 || $[2] !== t3) {
28972
28824
  t4 = cls(t2, "rounded-md text-sm font-medium text-surface-accent-700 dark:text-surface-accent-300 hover:bg-surface-accent-100 dark:hover:bg-surface-accent-900 flex items-center gap-4", t3, className);
@@ -32100,6 +31952,8 @@
32100
31952
  return "bg-primary";
32101
31953
  case "secondary":
32102
31954
  return "bg-secondary";
31955
+ case "warning":
31956
+ return "bg-orange-500";
32103
31957
  case "error":
32104
31958
  return "bg-red-500";
32105
31959
  default: