@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 +94 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +94 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7204,9 +7204,13 @@ function SelectWithInputField(props) {
|
|
|
7204
7204
|
}, [defaultPrefix, formValue, options]);
|
|
7205
7205
|
const [selectedPrefix, setSelectedPrefix] = useState(prefix);
|
|
7206
7206
|
const [prevFormValue, setPrevFormValue] = useState(formValue);
|
|
7207
|
+
const isUserInputChangeRef = useRef(false);
|
|
7207
7208
|
if (prevFormValue !== formValue) {
|
|
7208
7209
|
setPrevFormValue(formValue);
|
|
7209
|
-
|
|
7210
|
+
if (!isUserInputChangeRef.current) {
|
|
7211
|
+
setSelectedPrefix(formValue ? prefix : defaultPrefix);
|
|
7212
|
+
}
|
|
7213
|
+
isUserInputChangeRef.current = false;
|
|
7210
7214
|
}
|
|
7211
7215
|
useLayoutEffect(() => {
|
|
7212
7216
|
if (readOnly) return;
|
|
@@ -7215,9 +7219,7 @@ function SelectWithInputField(props) {
|
|
|
7215
7219
|
}
|
|
7216
7220
|
}, [formValue, normalizedFormValue, onChange, readOnly]);
|
|
7217
7221
|
if (readOnly) {
|
|
7218
|
-
|
|
7219
|
-
const displayText = inputPart ? `${prefixLabel} ${inputPart}` : prefix ? prefixLabel : "\u2014";
|
|
7220
|
-
return /* @__PURE__ */ jsx("div", { className: fieldControlWrapClass(className), children: /* @__PURE__ */ jsx("span", { className: FIELD_READONLY_TEXT_CLASS, children: displayText || "\u2014" }) });
|
|
7222
|
+
return /* @__PURE__ */ jsx("div", { className: fieldControlWrapClass(className), children: /* @__PURE__ */ jsx("span", { className: FIELD_READONLY_TEXT_CLASS, children: formValue }) });
|
|
7221
7223
|
}
|
|
7222
7224
|
const updateCombined = (nextPrefix, nextInput) => {
|
|
7223
7225
|
onChange(combineSelectWithInputValue(nextPrefix, nextInput));
|
|
@@ -7231,6 +7233,7 @@ function SelectWithInputField(props) {
|
|
|
7231
7233
|
if (normalized) {
|
|
7232
7234
|
validationCtx?.markFieldHadValue(String(config.name));
|
|
7233
7235
|
}
|
|
7236
|
+
isUserInputChangeRef.current = true;
|
|
7234
7237
|
updateCombined(selectedPrefix, normalized);
|
|
7235
7238
|
};
|
|
7236
7239
|
const selectClass = resolveSelectClassNameProp(selectWithInputClassNames?.selectClassName, {
|
|
@@ -7269,6 +7272,7 @@ function SelectWithInputField(props) {
|
|
|
7269
7272
|
},
|
|
7270
7273
|
onBlur: (e) => {
|
|
7271
7274
|
const normalized = normalizeInput(e.target.value.normalize("NFKC"));
|
|
7275
|
+
isUserInputChangeRef.current = true;
|
|
7272
7276
|
updateCombined(selectedPrefix, normalized);
|
|
7273
7277
|
onBlur();
|
|
7274
7278
|
}
|
|
@@ -7926,6 +7930,15 @@ function MultiTabBar(props) {
|
|
|
7926
7930
|
const [draggingId, setDraggingId] = useState(null);
|
|
7927
7931
|
const [dropTargetId, setDropTargetId] = useState(null);
|
|
7928
7932
|
const [dropSide, setDropSide] = useState("before");
|
|
7933
|
+
const draggingIdRef = useRef(null);
|
|
7934
|
+
const dropTargetIdRef = useRef(null);
|
|
7935
|
+
const dropSideRef = useRef("before");
|
|
7936
|
+
const tabsRef = useRef(tabs);
|
|
7937
|
+
const dropHandledRef = useRef(false);
|
|
7938
|
+
draggingIdRef.current = draggingId;
|
|
7939
|
+
dropTargetIdRef.current = dropTargetId;
|
|
7940
|
+
dropSideRef.current = dropSide;
|
|
7941
|
+
tabsRef.current = tabs;
|
|
7929
7942
|
useEffect(() => {
|
|
7930
7943
|
if (!activeTabId || !scrollRef.current) return;
|
|
7931
7944
|
const el = tabRefs.current.get(activeTabId);
|
|
@@ -7963,60 +7976,100 @@ function MultiTabBar(props) {
|
|
|
7963
7976
|
el.addEventListener("wheel", onWheel, { passive: false });
|
|
7964
7977
|
return () => el.removeEventListener("wheel", onWheel);
|
|
7965
7978
|
}, []);
|
|
7979
|
+
const resolveDropPosition = (clientX) => {
|
|
7980
|
+
for (const [tabId, el] of tabRefs.current) {
|
|
7981
|
+
if (tabId === draggingIdRef.current) continue;
|
|
7982
|
+
const rect = el.getBoundingClientRect();
|
|
7983
|
+
if (clientX >= rect.left && clientX < rect.right) {
|
|
7984
|
+
setDropSide(clientX < rect.left + rect.width / 2 ? "before" : "after");
|
|
7985
|
+
setDropTargetId(tabId);
|
|
7986
|
+
return;
|
|
7987
|
+
}
|
|
7988
|
+
}
|
|
7989
|
+
let rightmostTabId = null;
|
|
7990
|
+
let maxRight = -Infinity;
|
|
7991
|
+
for (const [tabId, el] of tabRefs.current) {
|
|
7992
|
+
if (tabId === draggingIdRef.current) continue;
|
|
7993
|
+
const rect = el.getBoundingClientRect();
|
|
7994
|
+
if (rect.right > maxRight) {
|
|
7995
|
+
maxRight = rect.right;
|
|
7996
|
+
rightmostTabId = tabId;
|
|
7997
|
+
}
|
|
7998
|
+
}
|
|
7999
|
+
if (rightmostTabId && clientX >= maxRight) {
|
|
8000
|
+
setDropSide("after");
|
|
8001
|
+
setDropTargetId(rightmostTabId);
|
|
8002
|
+
}
|
|
8003
|
+
};
|
|
8004
|
+
const reorderTabs = (targetTabId, side, sourceTabs, sourceId) => {
|
|
8005
|
+
if (!onTabsReorder || sourceId === targetTabId) return;
|
|
8006
|
+
const fromIdx = sourceTabs.findIndex((t) => t.id === sourceId);
|
|
8007
|
+
if (fromIdx === -1) return;
|
|
8008
|
+
const newTabs = [...sourceTabs];
|
|
8009
|
+
const moved = newTabs.splice(fromIdx, 1)[0];
|
|
8010
|
+
let insertIdx = newTabs.findIndex((t) => t.id === targetTabId);
|
|
8011
|
+
if (insertIdx === -1) return;
|
|
8012
|
+
if (side === "after") insertIdx += 1;
|
|
8013
|
+
newTabs.splice(insertIdx, 0, moved);
|
|
8014
|
+
onTabsReorder(newTabs);
|
|
8015
|
+
};
|
|
8016
|
+
useEffect(() => {
|
|
8017
|
+
if (!onTabsReorder) return;
|
|
8018
|
+
const onDocDragOver = (e) => {
|
|
8019
|
+
if (!draggingIdRef.current) return;
|
|
8020
|
+
e.preventDefault();
|
|
8021
|
+
resolveDropPosition(e.clientX);
|
|
8022
|
+
};
|
|
8023
|
+
const onDocDrop = (e) => {
|
|
8024
|
+
if (dropHandledRef.current) {
|
|
8025
|
+
dropHandledRef.current = false;
|
|
8026
|
+
return;
|
|
8027
|
+
}
|
|
8028
|
+
e.preventDefault();
|
|
8029
|
+
const id = draggingIdRef.current;
|
|
8030
|
+
const target = dropTargetIdRef.current;
|
|
8031
|
+
if (id && target) reorderTabs(target, dropSideRef.current, tabsRef.current, id);
|
|
8032
|
+
setDraggingId(null);
|
|
8033
|
+
setDropTargetId(null);
|
|
8034
|
+
};
|
|
8035
|
+
document.addEventListener("dragover", onDocDragOver);
|
|
8036
|
+
document.addEventListener("drop", onDocDrop);
|
|
8037
|
+
return () => {
|
|
8038
|
+
document.removeEventListener("dragover", onDocDragOver);
|
|
8039
|
+
document.removeEventListener("drop", onDocDrop);
|
|
8040
|
+
};
|
|
8041
|
+
}, [onTabsReorder]);
|
|
7966
8042
|
const handleDragStart = (e, tabId) => {
|
|
7967
8043
|
setDraggingId(tabId);
|
|
7968
8044
|
e.dataTransfer.effectAllowed = "move";
|
|
7969
8045
|
};
|
|
7970
|
-
const handleDragOver = (e, tabId) => {
|
|
7971
|
-
e.preventDefault();
|
|
7972
|
-
if (tabId === draggingId) return;
|
|
7973
|
-
e.dataTransfer.dropEffect = "move";
|
|
7974
|
-
const rect = e.currentTarget.getBoundingClientRect();
|
|
7975
|
-
setDropSide(e.clientX < rect.left + rect.width / 2 ? "before" : "after");
|
|
7976
|
-
setDropTargetId(tabId);
|
|
7977
|
-
};
|
|
7978
8046
|
const handleDrop = (e, targetTabId) => {
|
|
7979
8047
|
e.preventDefault();
|
|
7980
8048
|
e.stopPropagation();
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
return;
|
|
7985
|
-
}
|
|
7986
|
-
if (onTabsReorder) {
|
|
7987
|
-
const fromIdx = tabs.findIndex((t) => t.id === draggingId);
|
|
7988
|
-
if (fromIdx !== -1) {
|
|
7989
|
-
const newTabs = [...tabs];
|
|
7990
|
-
const moved = newTabs.splice(fromIdx, 1)[0];
|
|
7991
|
-
let insertIdx = newTabs.findIndex((t) => t.id === targetTabId);
|
|
7992
|
-
if (insertIdx !== -1) {
|
|
7993
|
-
if (dropSide === "after") insertIdx += 1;
|
|
7994
|
-
newTabs.splice(insertIdx, 0, moved);
|
|
7995
|
-
onTabsReorder(newTabs);
|
|
7996
|
-
}
|
|
7997
|
-
}
|
|
7998
|
-
}
|
|
8049
|
+
dropHandledRef.current = true;
|
|
8050
|
+
const id = draggingIdRef.current;
|
|
8051
|
+
if (id && id !== targetTabId) reorderTabs(targetTabId, dropSideRef.current, tabsRef.current, id);
|
|
7999
8052
|
setDraggingId(null);
|
|
8000
8053
|
setDropTargetId(null);
|
|
8001
8054
|
};
|
|
8002
8055
|
const handleContainerDrop = (e) => {
|
|
8003
8056
|
e.preventDefault();
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
onTabsReorder(newTabs);
|
|
8057
|
+
dropHandledRef.current = true;
|
|
8058
|
+
const id = draggingIdRef.current;
|
|
8059
|
+
if (id && onTabsReorder) {
|
|
8060
|
+
const fromIdx = tabsRef.current.findIndex((t) => t.id === id);
|
|
8061
|
+
if (fromIdx !== -1 && fromIdx < tabsRef.current.length - 1) {
|
|
8062
|
+
const newTabs = [...tabsRef.current];
|
|
8063
|
+
const moved = newTabs.splice(fromIdx, 1)[0];
|
|
8064
|
+
newTabs.push(moved);
|
|
8065
|
+
onTabsReorder(newTabs);
|
|
8066
|
+
}
|
|
8015
8067
|
}
|
|
8016
8068
|
setDraggingId(null);
|
|
8017
8069
|
setDropTargetId(null);
|
|
8018
8070
|
};
|
|
8019
8071
|
const handleDragEnd = () => {
|
|
8072
|
+
dropHandledRef.current = false;
|
|
8020
8073
|
setDraggingId(null);
|
|
8021
8074
|
setDropTargetId(null);
|
|
8022
8075
|
};
|
|
@@ -8067,7 +8120,6 @@ function MultiTabBar(props) {
|
|
|
8067
8120
|
if (!isActive) onTabClick(tab.id);
|
|
8068
8121
|
},
|
|
8069
8122
|
onDragStart: (e) => handleDragStart(e, tab.id),
|
|
8070
|
-
onDragOver: (e) => handleDragOver(e, tab.id),
|
|
8071
8123
|
onDrop: (e) => handleDrop(e, tab.id),
|
|
8072
8124
|
onDragEnd: handleDragEnd,
|
|
8073
8125
|
className: `
|