playbook_ui 16.9.0.pre.alpha.touchdragmulticontainers17268 → 16.9.0.pre.alpha.touchdragmulticontainers17271

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89c52f53eea784d92355431d75ff12e5b12309cc1daa70b45c9811369a9d51d9
4
- data.tar.gz: 8424c9aeabd6007e2ba9151207c40f798bad2c5243ceb597aa43b176859b5326
3
+ metadata.gz: 68c5efbb867c4afb1698ad5d63b0280a6a93aa798f60f2e974ac82beab57232e
4
+ data.tar.gz: 63e67402a6e5a31443575dbf19f2710f4c4ff397013d82cbc9515cb8193dcec8
5
5
  SHA512:
6
- metadata.gz: 2bd62a01ea9037bd4b5b86e6d70d947b08ddcc445f534db3edffabde5ab29c3d527dc779ba6b41552cd875078bbfb1d7287a1f1badbc9e0aa27d537cc8079aa4
7
- data.tar.gz: bd30042e81eaa8205affab38ab44be73865af3adaec7d060be15a7aabb3058fe55d5a63a04fd3258a6be63d804da9c2eacdb02a540b62f0607e965f89ea0c529
6
+ metadata.gz: eeed97fa95a5195c7c9c15a500508e67fd5010f1d8a753df55cc6b0bee173a83cd7b202eb7d110cba69b2d7500d7c3df8ab552fa0482e3da779e969f09ae6289
7
+ data.tar.gz: 85126a6b3965ec648c12b6557b7ea1b562fc797d52b7191d6305d3f4eb1a4faba78da313da747719d9328115d7d560ef1aec736db2441b8084b1c1eb6cf61838
@@ -606,14 +606,6 @@ export const DraggableProvider = ({
606
606
  }), [state, dropZoneType, dropZoneColor, dropZoneDirection]);
607
607
 
608
608
  return (
609
- <DragContext.Provider value={contextValue}>
610
- <div
611
- data-pb-draggable-root
612
- style={{ display: "contents" }}
613
- >
614
- {children}
615
- </div>
616
- </DragContext.Provider>
609
+ <DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
617
610
  );
618
611
  };
619
-
@@ -1,3 +1 @@
1
- The Draggable kit can also be used to achieve more complex, multiple container functionality as shown here. This complex usage requires the full subcomponent structure — **one** `DraggableProvider` with multiple `Draggable.Container` components so items can move between columns.
2
-
3
- For lists that should stay separate, see [Independent Draggable Containers](#draggable_independent_containers).
1
+ The Draggable kit can also be used to achieve more complex, multiple container functionality as shown here. This complex usage requires the full subcomponent structure.
@@ -4,7 +4,6 @@ examples:
4
4
  - draggable_with_list: Draggable with List Kit
5
5
  - draggable_with_selectable_list: Draggable with SelectableList Kit
6
6
  - draggable_with_cards: Draggable with Cards
7
- - draggable_independent_containers: Independent Draggable Containers
8
7
  - draggable_with_table: Draggable with Table
9
8
  - draggable_drop_zones: Draggable Drop Zones
10
9
  - draggable_drop_zones_colors: Draggable Drop Zones Colors
@@ -1,6 +1,5 @@
1
1
  export { default as DraggableDefault } from './_draggable_default.jsx'
2
2
  export { default as DraggableWithCards } from './_draggable_with_cards.jsx'
3
- export { default as DraggableIndependentContainers } from './_draggable_independent_containers.jsx'
4
3
  export { default as DraggableWithList } from './_draggable_with_list.jsx'
5
4
  export { default as DraggableWithSelectableList } from './_draggable_with_selectable_list.jsx'
6
5
  export { default as DraggableMultipleContainers } from './_draggable_multiple_containers.jsx'
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  DRAG_HANDLE_SELECTOR,
3
- DRAGGABLE_ROOT_SELECTOR,
4
3
  getContainerFromElement,
5
4
  getDragIdFromElement,
6
- getDraggableRootFromElement,
7
5
  } from "./utilities/touchDrag";
8
6
 
9
7
  describe("touchDrag utilities", () => {
@@ -37,29 +35,4 @@ describe("touchDrag utilities", () => {
37
35
  const item = document.querySelector(".pb_draggable_item");
38
36
  expect(getContainerFromElement(item)).toBe("To Do");
39
37
  });
40
-
41
- test("getDraggableRootFromElement finds nearest draggable root", () => {
42
- document.body.innerHTML = `
43
- <div data-pb-draggable-root>
44
- <div class="pb_draggable_container" data-pb-drag-container="To Do">
45
- <div class="pb_draggable_item" data-pb-drag-id="1"></div>
46
- </div>
47
- </div>
48
- `;
49
-
50
- const item = document.querySelector(".pb_draggable_item");
51
- expect(getDraggableRootFromElement(item)).toHaveAttribute("data-pb-draggable-root");
52
- });
53
-
54
- test("DRAGGABLE_ROOT_SELECTOR matches rails and react draggable roots", () => {
55
- document.body.innerHTML = `
56
- <div data-pb-draggable>
57
- <div class="pb_draggable">
58
- <div data-pb-draggable-root></div>
59
- </div>
60
- </div>
61
- `;
62
-
63
- expect(document.querySelector(DRAGGABLE_ROOT_SELECTOR)).toHaveAttribute("data-pb-draggable");
64
- });
65
38
  });
@@ -1,6 +1,4 @@
1
1
  export const DRAG_HANDLE_SELECTOR = '.pb_draggable_handle, .card_draggable_handle';
2
- export const DRAGGABLE_ROOT_SELECTOR =
3
- '[data-pb-draggable], .pb_draggable, [data-pb-draggable-root]';
4
2
 
5
3
  const DRAG_THRESHOLD_PX = 5;
6
4
 
@@ -29,14 +27,6 @@ export const getContainerFromElement = (element: Element | null): string | undef
29
27
  return container.getAttribute('data-pb-drag-container') || undefined;
30
28
  };
31
29
 
32
- export const getDraggableRootFromElement = (
33
- element: Element | null
34
- ): HTMLElement | null => {
35
- if (!element) return null;
36
-
37
- return element.closest(DRAGGABLE_ROOT_SELECTOR) as HTMLElement | null;
38
- };
39
-
40
30
  type TouchDragHandlers = {
41
31
  onDragStart: (dragId: string, container?: string) => void;
42
32
  onDragEnter: (targetDragId: string, container?: string) => void;
@@ -49,7 +39,6 @@ type TouchDragOptions = {
49
39
  dragId: string;
50
40
  container?: string;
51
41
  itemElement: HTMLElement;
52
- draggableRoot?: HTMLElement | null;
53
42
  handlers: TouchDragHandlers;
54
43
  };
55
44
 
@@ -59,6 +48,7 @@ type TouchDragState = {
59
48
  startX: number;
60
49
  startY: number;
61
50
  lastTargetDragId: string | null;
51
+ lastContainer: string | undefined;
62
52
  };
63
53
 
64
54
  const createPreventableEvent = (): Event => ({
@@ -69,16 +59,10 @@ export const bindTouchDrag = ({
69
59
  dragId,
70
60
  container,
71
61
  itemElement,
72
- draggableRoot: draggableRootOption,
73
62
  handlers,
74
63
  }: TouchDragOptions): (() => void) => {
75
64
  if (!isTouchDragDevice()) return () => undefined;
76
65
 
77
- const draggableRoot =
78
- draggableRootOption ?? getDraggableRootFromElement(itemElement);
79
- const isWithinDraggableRoot = (element: Element | null) =>
80
- !draggableRoot || (!!element && draggableRoot.contains(element));
81
-
82
66
  const handle = itemElement.querySelector(DRAG_HANDLE_SELECTOR) as HTMLElement | null;
83
67
  const dragTarget = handle || itemElement;
84
68
 
@@ -88,12 +72,14 @@ export const bindTouchDrag = ({
88
72
  startX: 0,
89
73
  startY: 0,
90
74
  lastTargetDragId: null,
75
+ lastContainer: undefined,
91
76
  };
92
77
 
93
78
  const resetState = () => {
94
79
  state.active = false;
95
80
  state.dragging = false;
96
81
  state.lastTargetDragId = null;
82
+ state.lastContainer = undefined;
97
83
  itemElement.classList.remove('is_touch_active');
98
84
  };
99
85
 
@@ -128,27 +114,19 @@ export const bindTouchDrag = ({
128
114
  event.preventDefault();
129
115
 
130
116
  const elementBelow = document.elementFromPoint(touch.clientX, touch.clientY);
131
- if (!isWithinDraggableRoot(elementBelow)) return;
132
-
133
117
  const targetDragId = getDragIdFromElement(elementBelow);
134
118
  const targetContainer = getContainerFromElement(elementBelow);
135
- const targetItem = elementBelow?.closest('.pb_draggable_item');
136
-
137
- if (
138
- targetDragId &&
139
- targetDragId !== dragId &&
140
- targetDragId !== state.lastTargetDragId &&
141
- isWithinDraggableRoot(targetItem)
142
- ) {
119
+
120
+ if (targetDragId && targetDragId !== dragId && targetDragId !== state.lastTargetDragId) {
143
121
  state.lastTargetDragId = targetDragId;
144
122
  handlers.onDragEnter(targetDragId, targetContainer ?? container);
145
123
  }
146
124
 
147
- if (targetContainer) {
148
- const containerElement = elementBelow?.closest('.pb_draggable_container');
149
- if (isWithinDraggableRoot(containerElement)) {
150
- handlers.onDragOver(createPreventableEvent(), targetContainer);
151
- }
125
+ if (targetContainer && targetContainer !== state.lastContainer) {
126
+ state.lastContainer = targetContainer;
127
+ handlers.onDragOver(createPreventableEvent(), targetContainer);
128
+ } else if (targetContainer) {
129
+ handlers.onDragOver(createPreventableEvent(), targetContainer);
152
130
  }
153
131
  };
154
132
 
@@ -156,11 +134,8 @@ export const bindTouchDrag = ({
156
134
  if (!state.active) return;
157
135
 
158
136
  if (state.dragging && touch) {
159
- const sourceContainer = getContainerFromElement(itemElement) ?? container;
160
137
  const elementBelow = document.elementFromPoint(touch.clientX, touch.clientY);
161
- const dropContainer = isWithinDraggableRoot(elementBelow)
162
- ? (getContainerFromElement(elementBelow) ?? container)
163
- : sourceContainer;
138
+ const dropContainer = getContainerFromElement(elementBelow) ?? container;
164
139
 
165
140
  if (dropContainer) {
166
141
  handlers.onDrop(dropContainer);