Skip to content

Commit

Permalink
internal: sets documentElement to user select none during drag
Browse files Browse the repository at this point in the history
  • Loading branch information
sashamilenkovic committed Dec 14, 2024
1 parent 9c8e9b7 commit 16e3d5e
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 6 deletions.
8 changes: 7 additions & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ var baseDragState = {
originalZIndex: void 0,
pointerSelection: false,
preventEnter: false,
rootUserSelect: void 0,
nodePointerdown: void 0,
longPress: false,
scrolling: false,
Expand Down Expand Up @@ -1181,6 +1182,7 @@ function resetState() {
remapJustFinished: false,
selectedNodes: [],
nodePointerdown: void 0,
rootUserSelect: void 0,
preventSynthDrag: false,
scrolling: false,
selectedParent: void 0,
Expand Down Expand Up @@ -1248,6 +1250,10 @@ function handleRootPointermove(e) {
state,
nodes2
);
state.rootUserSelect = window.getComputedStyle(
document.documentElement
).userSelect;
document.body.style.userSelect = "none";
synthMove(e, synthDragState);
} else if (isSynthDragState(state)) {
synthMove(e, state);
Expand Down Expand Up @@ -2259,7 +2265,7 @@ function handlePointercancel(data, state2) {
}
function handleEnd3(state2) {
if (state2.draggedNode) state2.draggedNode.el.draggable = false;
document.body.style.userSelect = "";
document.body.style.userSelect = state2.rootUserSelect || "";
if (isSynthDragState(state2)) cancelSynthScroll(state2);
if ("longPressTimeout" in state2 && state2.longPressTimeout)
clearTimeout(state2.longPressTimeout);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
8 changes: 7 additions & 1 deletion dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ var baseDragState = {
originalZIndex: void 0,
pointerSelection: false,
preventEnter: false,
rootUserSelect: void 0,
nodePointerdown: void 0,
longPress: false,
scrolling: false,
Expand Down Expand Up @@ -1091,6 +1092,7 @@ function resetState() {
remapJustFinished: false,
selectedNodes: [],
nodePointerdown: void 0,
rootUserSelect: void 0,
preventSynthDrag: false,
scrolling: false,
selectedParent: void 0,
Expand Down Expand Up @@ -1158,6 +1160,10 @@ function handleRootPointermove(e) {
state,
nodes2
);
state.rootUserSelect = window.getComputedStyle(
document.documentElement
).userSelect;
document.body.style.userSelect = "none";
synthMove(e, synthDragState);
} else if (isSynthDragState(state)) {
synthMove(e, state);
Expand Down Expand Up @@ -2169,7 +2175,7 @@ function handlePointercancel(data, state2) {
}
function handleEnd3(state2) {
if (state2.draggedNode) state2.draggedNode.el.draggable = false;
document.body.style.userSelect = "";
document.body.style.userSelect = state2.rootUserSelect || "";
if (isSynthDragState(state2)) cancelSynthScroll(state2);
if ("longPressTimeout" in state2 && state2.longPressTimeout)
clearTimeout(state2.longPressTimeout);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/react/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
1 change: 1 addition & 0 deletions dist/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
1 change: 1 addition & 0 deletions dist/vue/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
1 change: 1 addition & 0 deletions dist/vue/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};
interface DragStateProps<T> {
/**
Expand Down
2 changes: 1 addition & 1 deletion docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineNuxtConfig({
css: ["@/assets/css/main.css"],

experimental: {
componentIslands: true,
componentIslands: false,
},

runtimeConfig: {
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const baseDragState = {
originalZIndex: undefined,
pointerSelection: false,
preventEnter: false,
rootUserSelect: undefined,
nodePointerdown: undefined,
longPress: false,
scrolling: false,
Expand Down Expand Up @@ -160,6 +161,7 @@ export function resetState() {
remapJustFinished: false,
selectedNodes: [],
nodePointerdown: undefined,
rootUserSelect: undefined,
preventSynthDrag: false,
scrolling: false,
selectedParent: undefined,
Expand Down Expand Up @@ -280,6 +282,12 @@ function handleRootPointermove(e: PointerEvent) {
nodes
);

state.rootUserSelect = window.getComputedStyle(
document.documentElement
).userSelect;

document.body.style.userSelect = "none";

synthMove(e, synthDragState);
} else if (isSynthDragState(state)) {
synthMove(e, state);
Expand Down Expand Up @@ -1992,7 +2000,7 @@ export function handlePointercancel<T>(
export function handleEnd<T>(state: DragState<T> | SynthDragState<T>) {
if (state.draggedNode) state.draggedNode.el.draggable = false;

document.body.style.userSelect = "";
document.body.style.userSelect = state.rootUserSelect || "";

if (isSynthDragState(state)) cancelSynthScroll(state);

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ export type BaseDragState<T> = {
parent: ParentRecord<T>;
};
scrolling: boolean;
rootUserSelect: string | undefined;
};

export interface DragStateProps<T> {
Expand Down

0 comments on commit 16e3d5e

Please sign in to comment.