@natoora-libs/core 0.2.23 → 0.2.24

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.
@@ -8785,6 +8785,9 @@ var HashtagInput = ({
8785
8785
  helperText,
8786
8786
  onCreateTag,
8787
8787
  onDeleteTag,
8788
+ autoFocus = false,
8789
+ disableOnBlurCreation = false,
8790
+ onBlur,
8788
8791
  ...props
8789
8792
  }) => {
8790
8793
  const { palette: palette2 } = (0, import_material75.useTheme)();
@@ -8792,14 +8795,17 @@ var HashtagInput = ({
8792
8795
  const sanitizeTag = (value) => {
8793
8796
  return value.toLowerCase().replace(/[^a-z0-9#]/g, "").trim();
8794
8797
  };
8798
+ const handleAddTag = () => {
8799
+ const cleanedTag = sanitizeTag(inputValue);
8800
+ if (!cleanedTag) return;
8801
+ onCreateTag?.(cleanedTag);
8802
+ setInputValue("");
8803
+ };
8795
8804
  const handleKeyDown = (event) => {
8796
8805
  if ((event.key === " " || event.key === "Enter") && inputValue) {
8797
8806
  event.preventDefault();
8798
8807
  event.stopPropagation();
8799
- const cleaned = sanitizeTag(inputValue);
8800
- if (!cleaned) return;
8801
- onCreateTag?.(cleaned);
8802
- setInputValue("");
8808
+ handleAddTag();
8803
8809
  }
8804
8810
  };
8805
8811
  return /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(
@@ -8821,16 +8827,23 @@ var HashtagInput = ({
8821
8827
  onDeleteTag?.(details.option);
8822
8828
  }
8823
8829
  },
8824
- renderInput: (params) => /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(
8830
+ renderInput: (textFieldProps) => /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(
8825
8831
  import_material75.TextField,
8826
8832
  {
8827
- ...params,
8833
+ ...textFieldProps,
8834
+ autoFocus,
8828
8835
  label,
8829
8836
  placeholder,
8830
8837
  helperText,
8831
8838
  variant,
8832
8839
  error,
8833
- onKeyDown: handleKeyDown
8840
+ onKeyDown: handleKeyDown,
8841
+ onBlur: (e) => {
8842
+ if (!disableOnBlurCreation) {
8843
+ handleAddTag();
8844
+ }
8845
+ onBlur?.(e);
8846
+ }
8834
8847
  }
8835
8848
  ),
8836
8849
  renderValue: (value, getTagProps) => value.map((option, index) => {
@@ -8868,6 +8881,7 @@ var TableDesktopTagsField = ({
8868
8881
  }) => {
8869
8882
  const [error, setError] = (0, import_react46.useState)();
8870
8883
  const [values, setValues] = (0, import_react46.useState)([]);
8884
+ const valuesRef = (0, import_react46.useRef)([]);
8871
8885
  const validateTag = (tag) => {
8872
8886
  if (tag.length >= 30) {
8873
8887
  return false;
@@ -8884,13 +8898,19 @@ var TableDesktopTagsField = ({
8884
8898
  setError(null);
8885
8899
  const newTags = isRemoving ? values.filter((t) => t !== tag) : [...values, tag];
8886
8900
  setValues(newTags);
8901
+ valuesRef.current = newTags;
8887
8902
  };
8888
- (0, import_react46.useEffect)(() => {
8889
- setValues((initialValue ?? []).map((val) => val.tag));
8903
+ const initialValueTags = (0, import_react46.useMemo)(() => {
8904
+ return (initialValue ?? []).map((val) => val.tag);
8890
8905
  }, [initialValue]);
8906
+ (0, import_react46.useEffect)(() => {
8907
+ setValues(initialValueTags);
8908
+ valuesRef.current = initialValueTags;
8909
+ }, [initialValueTags]);
8891
8910
  return /* @__PURE__ */ (0, import_jsx_runtime133.jsx)(import_jsx_runtime133.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime133.jsx)(
8892
8911
  HashtagInput,
8893
8912
  {
8913
+ autoFocus: true,
8894
8914
  label: inputLabel,
8895
8915
  variant,
8896
8916
  size,
@@ -8907,11 +8927,14 @@ var TableDesktopTagsField = ({
8907
8927
  handleManageTags(tag, "REMOVE");
8908
8928
  },
8909
8929
  onBlur: () => {
8930
+ const currentTagsString = [...valuesRef.current].sort().join(", ");
8931
+ const initialTagsString = [...initialValueTags].sort().join(", ");
8932
+ if (currentTagsString === initialTagsString) return;
8910
8933
  onUpdateEditableCell?.({
8911
8934
  rowId,
8912
8935
  columnId,
8913
- value: values,
8914
- label: values.join(", ")
8936
+ value: valuesRef.current,
8937
+ label: valuesRef.current.join(", ")
8915
8938
  });
8916
8939
  }
8917
8940
  }