@farmzone/fz-react-ui 1.0.10 → 1.0.12

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.cjs CHANGED
@@ -7238,9 +7238,13 @@ function SelectWithInputField(props) {
7238
7238
  }, [defaultPrefix, formValue, options]);
7239
7239
  const [selectedPrefix, setSelectedPrefix] = React6.useState(prefix);
7240
7240
  const [prevFormValue, setPrevFormValue] = React6.useState(formValue);
7241
+ const isUserInputChangeRef = React6.useRef(false);
7241
7242
  if (prevFormValue !== formValue) {
7242
7243
  setPrevFormValue(formValue);
7243
- setSelectedPrefix(formValue ? prefix : defaultPrefix);
7244
+ if (!isUserInputChangeRef.current) {
7245
+ setSelectedPrefix(formValue ? prefix : defaultPrefix);
7246
+ }
7247
+ isUserInputChangeRef.current = false;
7244
7248
  }
7245
7249
  React6.useLayoutEffect(() => {
7246
7250
  if (readOnly) return;
@@ -7249,9 +7253,7 @@ function SelectWithInputField(props) {
7249
7253
  }
7250
7254
  }, [formValue, normalizedFormValue, onChange, readOnly]);
7251
7255
  if (readOnly) {
7252
- const prefixLabel = options.find((o) => String(o.value) === prefix)?.label ?? prefix;
7253
- const displayText = inputPart ? `${prefixLabel} ${inputPart}` : prefix ? prefixLabel : "\u2014";
7254
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: fieldControlWrapClass(className), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: FIELD_READONLY_TEXT_CLASS, children: displayText || "\u2014" }) });
7256
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: fieldControlWrapClass(className), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: FIELD_READONLY_TEXT_CLASS, children: formValue }) });
7255
7257
  }
7256
7258
  const updateCombined = (nextPrefix, nextInput) => {
7257
7259
  onChange(combineSelectWithInputValue(nextPrefix, nextInput));
@@ -7265,6 +7267,7 @@ function SelectWithInputField(props) {
7265
7267
  if (normalized) {
7266
7268
  validationCtx?.markFieldHadValue(String(config.name));
7267
7269
  }
7270
+ isUserInputChangeRef.current = true;
7268
7271
  updateCombined(selectedPrefix, normalized);
7269
7272
  };
7270
7273
  const selectClass = resolveSelectClassNameProp(selectWithInputClassNames?.selectClassName, {
@@ -7303,6 +7306,7 @@ function SelectWithInputField(props) {
7303
7306
  },
7304
7307
  onBlur: (e) => {
7305
7308
  const normalized = normalizeInput(e.target.value.normalize("NFKC"));
7309
+ isUserInputChangeRef.current = true;
7306
7310
  updateCombined(selectedPrefix, normalized);
7307
7311
  onBlur();
7308
7312
  }
@@ -7960,6 +7964,15 @@ function MultiTabBar(props) {
7960
7964
  const [draggingId, setDraggingId] = React6.useState(null);
7961
7965
  const [dropTargetId, setDropTargetId] = React6.useState(null);
7962
7966
  const [dropSide, setDropSide] = React6.useState("before");
7967
+ const draggingIdRef = React6.useRef(null);
7968
+ const dropTargetIdRef = React6.useRef(null);
7969
+ const dropSideRef = React6.useRef("before");
7970
+ const tabsRef = React6.useRef(tabs);
7971
+ const dropHandledRef = React6.useRef(false);
7972
+ draggingIdRef.current = draggingId;
7973
+ dropTargetIdRef.current = dropTargetId;
7974
+ dropSideRef.current = dropSide;
7975
+ tabsRef.current = tabs;
7963
7976
  React6.useEffect(() => {
7964
7977
  if (!activeTabId || !scrollRef.current) return;
7965
7978
  const el = tabRefs.current.get(activeTabId);
@@ -7997,60 +8010,100 @@ function MultiTabBar(props) {
7997
8010
  el.addEventListener("wheel", onWheel, { passive: false });
7998
8011
  return () => el.removeEventListener("wheel", onWheel);
7999
8012
  }, []);
8013
+ const resolveDropPosition = (clientX) => {
8014
+ for (const [tabId, el] of tabRefs.current) {
8015
+ if (tabId === draggingIdRef.current) continue;
8016
+ const rect = el.getBoundingClientRect();
8017
+ if (clientX >= rect.left && clientX < rect.right) {
8018
+ setDropSide(clientX < rect.left + rect.width / 2 ? "before" : "after");
8019
+ setDropTargetId(tabId);
8020
+ return;
8021
+ }
8022
+ }
8023
+ let rightmostTabId = null;
8024
+ let maxRight = -Infinity;
8025
+ for (const [tabId, el] of tabRefs.current) {
8026
+ if (tabId === draggingIdRef.current) continue;
8027
+ const rect = el.getBoundingClientRect();
8028
+ if (rect.right > maxRight) {
8029
+ maxRight = rect.right;
8030
+ rightmostTabId = tabId;
8031
+ }
8032
+ }
8033
+ if (rightmostTabId && clientX >= maxRight) {
8034
+ setDropSide("after");
8035
+ setDropTargetId(rightmostTabId);
8036
+ }
8037
+ };
8038
+ const reorderTabs = (targetTabId, side, sourceTabs, sourceId) => {
8039
+ if (!onTabsReorder || sourceId === targetTabId) return;
8040
+ const fromIdx = sourceTabs.findIndex((t) => t.id === sourceId);
8041
+ if (fromIdx === -1) return;
8042
+ const newTabs = [...sourceTabs];
8043
+ const moved = newTabs.splice(fromIdx, 1)[0];
8044
+ let insertIdx = newTabs.findIndex((t) => t.id === targetTabId);
8045
+ if (insertIdx === -1) return;
8046
+ if (side === "after") insertIdx += 1;
8047
+ newTabs.splice(insertIdx, 0, moved);
8048
+ onTabsReorder(newTabs);
8049
+ };
8050
+ React6.useEffect(() => {
8051
+ if (!onTabsReorder) return;
8052
+ const onDocDragOver = (e) => {
8053
+ if (!draggingIdRef.current) return;
8054
+ e.preventDefault();
8055
+ resolveDropPosition(e.clientX);
8056
+ };
8057
+ const onDocDrop = (e) => {
8058
+ if (dropHandledRef.current) {
8059
+ dropHandledRef.current = false;
8060
+ return;
8061
+ }
8062
+ e.preventDefault();
8063
+ const id = draggingIdRef.current;
8064
+ const target = dropTargetIdRef.current;
8065
+ if (id && target) reorderTabs(target, dropSideRef.current, tabsRef.current, id);
8066
+ setDraggingId(null);
8067
+ setDropTargetId(null);
8068
+ };
8069
+ document.addEventListener("dragover", onDocDragOver);
8070
+ document.addEventListener("drop", onDocDrop);
8071
+ return () => {
8072
+ document.removeEventListener("dragover", onDocDragOver);
8073
+ document.removeEventListener("drop", onDocDrop);
8074
+ };
8075
+ }, [onTabsReorder]);
8000
8076
  const handleDragStart = (e, tabId) => {
8001
8077
  setDraggingId(tabId);
8002
8078
  e.dataTransfer.effectAllowed = "move";
8003
8079
  };
8004
- const handleDragOver = (e, tabId) => {
8005
- e.preventDefault();
8006
- if (tabId === draggingId) return;
8007
- e.dataTransfer.dropEffect = "move";
8008
- const rect = e.currentTarget.getBoundingClientRect();
8009
- setDropSide(e.clientX < rect.left + rect.width / 2 ? "before" : "after");
8010
- setDropTargetId(tabId);
8011
- };
8012
8080
  const handleDrop = (e, targetTabId) => {
8013
8081
  e.preventDefault();
8014
8082
  e.stopPropagation();
8015
- if (!draggingId || draggingId === targetTabId) {
8016
- setDraggingId(null);
8017
- setDropTargetId(null);
8018
- return;
8019
- }
8020
- if (onTabsReorder) {
8021
- const fromIdx = tabs.findIndex((t) => t.id === draggingId);
8022
- if (fromIdx !== -1) {
8023
- const newTabs = [...tabs];
8024
- const moved = newTabs.splice(fromIdx, 1)[0];
8025
- let insertIdx = newTabs.findIndex((t) => t.id === targetTabId);
8026
- if (insertIdx !== -1) {
8027
- if (dropSide === "after") insertIdx += 1;
8028
- newTabs.splice(insertIdx, 0, moved);
8029
- onTabsReorder(newTabs);
8030
- }
8031
- }
8032
- }
8083
+ dropHandledRef.current = true;
8084
+ const id = draggingIdRef.current;
8085
+ if (id && id !== targetTabId) reorderTabs(targetTabId, dropSideRef.current, tabsRef.current, id);
8033
8086
  setDraggingId(null);
8034
8087
  setDropTargetId(null);
8035
8088
  };
8036
8089
  const handleContainerDrop = (e) => {
8037
8090
  e.preventDefault();
8038
- if (!draggingId || !onTabsReorder) {
8039
- setDraggingId(null);
8040
- setDropTargetId(null);
8041
- return;
8042
- }
8043
- const fromIdx = tabs.findIndex((t) => t.id === draggingId);
8044
- if (fromIdx !== -1 && fromIdx < tabs.length - 1) {
8045
- const newTabs = [...tabs];
8046
- const moved = newTabs.splice(fromIdx, 1)[0];
8047
- newTabs.push(moved);
8048
- onTabsReorder(newTabs);
8091
+ dropHandledRef.current = true;
8092
+ const id = draggingIdRef.current;
8093
+ if (id && onTabsReorder) {
8094
+ const fromIdx = tabsRef.current.findIndex((t) => t.id === id);
8095
+ if (fromIdx !== -1 && fromIdx < tabsRef.current.length - 1) {
8096
+ const newTabs = [...tabsRef.current];
8097
+ const moved = newTabs.splice(fromIdx, 1)[0];
8098
+ newTabs.push(moved);
8099
+ onTabsReorder(newTabs);
8100
+ }
8049
8101
  }
8050
8102
  setDraggingId(null);
8051
8103
  setDropTargetId(null);
8052
8104
  };
8053
8105
  const handleDragEnd = () => {
8106
+ dropHandledRef.current = false;
8054
8107
  setDraggingId(null);
8055
8108
  setDropTargetId(null);
8056
8109
  };
@@ -8101,7 +8154,6 @@ function MultiTabBar(props) {
8101
8154
  if (!isActive) onTabClick(tab.id);
8102
8155
  },
8103
8156
  onDragStart: (e) => handleDragStart(e, tab.id),
8104
- onDragOver: (e) => handleDragOver(e, tab.id),
8105
8157
  onDrop: (e) => handleDrop(e, tab.id),
8106
8158
  onDragEnd: handleDragEnd,
8107
8159
  className: `