Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/@visual-json/react/src/json-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function EditorLayout({
sidebarOpen: boolean;
}) {
const [sidebarWidth, setSidebarWidth] = useState(280);
const [isDragging, setIsDragging] = useState(false);
const [isNarrow, setIsNarrow] = useState(false);
const [activePanel, setActivePanel] = useState<"tree" | "form">("tree");
const containerRef = useRef<HTMLDivElement>(null);
Expand All @@ -140,6 +141,7 @@ function EditorLayout({
const handleMouseDown = useCallback(
(e: React.MouseEvent) => {
dragging.current = true;
setIsDragging(true);
startX.current = e.clientX;
startWidth.current = sidebarWidth;
document.body.style.cursor = "col-resize";
Expand All @@ -157,6 +159,7 @@ function EditorLayout({

const handleMouseUp = () => {
dragging.current = false;
setIsDragging(false);
document.body.style.cursor = "";
document.body.style.userSelect = "";
document.removeEventListener("mousemove", handleMouseMove);
Expand Down Expand Up @@ -299,7 +302,7 @@ function EditorLayout({
display: "flex",
flexDirection: "column",
width: sidebarOpen ? sidebarWidth : 0,
transition: "width 0.2s ease",
transition: isDragging ? "none" : "width 0.2s ease",
}}
>
<SearchBar />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
display: flex;
flex-direction: column;
width: {sidebarOpen ? sidebarWidth + 'px' : '0'};
transition: width 0.2s ease;
transition: {isDragging ? 'none' : 'width 0.2s ease'};
"
>
<SearchBar />
Expand Down
12 changes: 6 additions & 6 deletions packages/@visual-json/vue/src/components/JsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const sidebarWidth = shallowRef(280);
const isNarrow = shallowRef(false);
const activePanel = shallowRef<"tree" | "form">("tree");
const containerRef = shallowRef<HTMLDivElement | null>(null);
let dragging = false;
const isDragging = shallowRef(false);
let startX = 0;
let startWidth = 0;
let observer: ResizeObserver | null = null;
Expand All @@ -95,20 +95,20 @@ onUnmounted(() => {
});

function handleMouseDown(e: MouseEvent) {
dragging = true;
isDragging.value = true;
startX = e.clientX;
startWidth = sidebarWidth.value;
document.body.style.cursor = "col-resize";
document.body.style.userSelect = "none";

function handleMouseMove(ev: MouseEvent) {
if (!dragging) return;
if (!isDragging.value) return;
const delta = ev.clientX - startX;
sidebarWidth.value = Math.max(180, Math.min(600, startWidth + delta));
}

function handleMouseUp() {
dragging = false;
isDragging.value = false;
document.body.style.cursor = "";
document.body.style.userSelect = "";
document.removeEventListener("mousemove", handleMouseMove);
Expand Down Expand Up @@ -267,7 +267,7 @@ const containerStyle = computed<CSSProperties>(() => ({
display: 'flex',
flexDirection: 'column',
width: props.sidebarOpen ? sidebarWidth + 'px' : '0',
transition: 'width 0.2s ease',
transition: isDragging ? 'none' : 'width 0.2s ease',
}"
>
<SearchBar />
Expand Down Expand Up @@ -309,7 +309,7 @@ const containerStyle = computed<CSSProperties>(() => ({
"
@mouseleave="
(e) => {
if (!dragging) {
if (!isDragging) {
const parent = (e.currentTarget as HTMLElement).parentElement;
if (parent)
parent.style.backgroundColor =
Expand Down
Loading