playbook_ui 15.5.0.pre.alpha.draggablefix12577 → 15.5.0.pre.alpha.play250612607

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.
@@ -39,56 +39,59 @@ const reducer = (state: InitialStateType, action: ActionType) => {
39
39
 
40
40
  return { ...state, items: newItems };
41
41
  }
42
- case 'REORDER_ITEMS_CROSS_CONTAINER': {
42
+
43
+ // Used only when enableCrossContainerPreview is true
44
+ case "REORDER_ITEMS_CROSS_CONTAINER": {
43
45
  const { dragId, targetId, newContainer } = action.payload;
44
46
  const newItems = [...state.items];
45
- const draggedItem = newItems.find(item => item && item.id === dragId);
47
+ const draggedItem = newItems.find((item) => item && item.id === dragId);
48
+
49
+ if (!draggedItem) return state;
50
+
46
51
  const draggedIndex = newItems.indexOf(draggedItem);
47
- const targetIndex = newItems.findIndex(item => item && item.id === targetId);
52
+ const targetIndex = newItems.findIndex(
53
+ (item) => item && item.id === targetId
54
+ );
48
55
 
49
- // Update container temporarily so dropzone preview works correctly
50
- const updatedItem = { ...draggedItem, container: newContainer };
56
+ if (draggedIndex === -1 || targetIndex === -1) return state;
51
57
 
58
+ const updatedItem = { ...draggedItem, container: newContainer };
52
59
  newItems.splice(draggedIndex, 1);
53
60
  newItems.splice(targetIndex, 0, updatedItem);
54
61
 
55
62
  return { ...state, items: newItems };
56
63
  }
57
- case 'MOVE_TO_CONTAINER_END': {
64
+
65
+ // Used only when enableCrossContainerPreview is true
66
+ case "MOVE_TO_CONTAINER_END": {
58
67
  const { dragId, newContainer } = action.payload;
59
68
  const newItems = [...state.items];
60
- const draggedItem = newItems.find(item => item && item.id === dragId);
69
+ const draggedItem = newItems.find((item) => item && item.id === dragId);
70
+
71
+ if (!draggedItem) return state;
72
+
61
73
  const draggedIndex = newItems.indexOf(draggedItem);
74
+ if (draggedIndex === -1) return state;
62
75
 
63
- // Update container temporarily so dropzone preview works correctly
64
76
  const updatedItem = { ...draggedItem, container: newContainer };
65
77
 
66
78
  // Remove from current position
67
79
  newItems.splice(draggedIndex, 1);
68
80
 
69
- // Find the last item in the target container and insert after it
70
- const lastIndexInContainer = newItems.map(item => item.container).lastIndexOf(newContainer);
81
+ // Insert at end of target container
82
+ const lastIndexInContainer = newItems
83
+ .map((item) => item && item.container)
84
+ .lastIndexOf(newContainer);
85
+
71
86
  if (lastIndexInContainer === -1) {
72
- // Container is empty, add to end
73
87
  newItems.push(updatedItem);
74
88
  } else {
75
- // Insert after last item in container
76
89
  newItems.splice(lastIndexInContainer + 1, 0, updatedItem);
77
90
  }
78
91
 
79
92
  return { ...state, items: newItems };
80
93
  }
81
- case 'RESET_DRAG_CONTAINER': {
82
- const { itemId, originalContainer } = action.payload;
83
- return {
84
- ...state,
85
- items: state.items.map(item =>
86
- item.id === itemId
87
- ? { ...item, container: originalContainer }
88
- : item
89
- )
90
- };
91
- }
94
+
92
95
  default:
93
96
  return state;
94
97
  }
@@ -111,7 +114,9 @@ export const DraggableProvider = ({
111
114
  onDrop,
112
115
  onDragOver,
113
116
  dropZone = { type: 'ghost', color: 'neutral', direction: 'vertical' },
114
- providerId = 'default', // fallback provided for backward compatibility, so this does not become a required prop
117
+ providerId = 'default', // fallback provided for backward compatibility
118
+ // Opt-in flag for cross-container preview
119
+ enableCrossContainerPreview = false,
115
120
  }: DraggableProviderType) => {
116
121
  const [state, dispatch] = useReducer(reducer, initialState);
117
122
 
@@ -144,7 +149,6 @@ export const DraggableProvider = ({
144
149
  }, [state.items]);
145
150
 
146
151
  const handleDragStart = (id: string, container: string) => {
147
- console.log('[Draggable] handleDragStart:', { id, container, providerId });
148
152
  dispatch({ type: 'SET_DRAG_DATA', payload: { id: id, initialGroup: container, originId: providerId } });
149
153
  dispatch({ type: 'SET_IS_DRAGGING', payload: id });
150
154
  if (onDragStart) onDragStart(id, container);
@@ -154,18 +158,42 @@ export const DraggableProvider = ({
154
158
  if (state.dragData.originId !== providerId) return; // Ignore drag events from other providers
155
159
 
156
160
  if (state.dragData.id !== id) {
157
- // Check if this is a cross-container drag
158
- const isCrossContainer = state.dragData.initialGroup !== container;
159
- console.log('[Draggable] handleDragEnter:', { id, container, isCrossContainer, draggedId: state.dragData.id });
160
-
161
- if (isCrossContainer) {
162
- // Use cross-container reorder to update container temporarily for dropzone preview
163
- dispatch({ type: 'REORDER_ITEMS_CROSS_CONTAINER', payload: { dragId: state.dragData.id, targetId: id, newContainer: container } });
161
+ if (enableCrossContainerPreview) {
162
+ // Used only when enableCrossContainerPreview is true
163
+ const draggedItem = state.items.find(
164
+ (item) => item && item.id === state.dragData.id
165
+ );
166
+ const currentContainer =
167
+ draggedItem && draggedItem.container
168
+ ? draggedItem.container
169
+ : state.dragData.initialGroup;
170
+
171
+ const isCrossContainer =
172
+ currentContainer !== container &&
173
+ (currentContainer !== undefined || container !== undefined);
174
+
175
+ if (isCrossContainer) {
176
+ dispatch({
177
+ type: "REORDER_ITEMS_CROSS_CONTAINER",
178
+ payload: {
179
+ dragId: state.dragData.id,
180
+ targetId: id,
181
+ newContainer: container,
182
+ },
183
+ });
184
+ } else {
185
+ // Same container: keep original behavior
186
+ dispatch({
187
+ type: "REORDER_ITEMS",
188
+ payload: { dragId: state.dragData.id, targetId: id },
189
+ });
190
+ }
164
191
  } else {
165
- // Same container: use normal reorder no need to be fancy nancy
166
- dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
192
+ // Original behavior (no preview across containers)
193
+ dispatch({type: "REORDER_ITEMS", payload: { dragId: state.dragData.id, targetId: id }});
167
194
  }
168
- dispatch({ type: 'SET_DRAG_DATA', payload: { id: state.dragData.id, initialGroup: container, originId: providerId } });
195
+
196
+ dispatch({type: "SET_DRAG_DATA",payload: {id: state.dragData.id, initialGroup: container, originId: providerId}});
169
197
  }
170
198
  if (onDragEnter) onDragEnter(id, container);
171
199
  };
@@ -174,33 +202,30 @@ export const DraggableProvider = ({
174
202
  const draggedItemId = state.dragData.id;
175
203
  const originalContainer = state.dragData.initialGroup;
176
204
 
177
- console.log('[Draggable] handleDragEnd:', { draggedItemId, originalContainer });
178
-
179
- if (!draggedItemId) {
180
- console.warn('[Draggable] handleDragEnd: No draggedItemId found');
181
- dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
182
- dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
183
- dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
184
- return;
185
- }
186
-
187
- const draggedItem = state.items.find(item => item && item.id === draggedItemId);
188
- const finalContainer = draggedItem ? draggedItem.container : originalContainer;
189
-
190
- console.log('[Draggable] handleDragEnd item found:', { draggedItem: !!draggedItem, finalContainer });
191
-
192
- // Find items above and below in the same container
193
- const itemsInContainer = state.items.filter(item => item && item.container === finalContainer);
194
- const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
195
- const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
196
- const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
197
-
198
205
  dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
199
206
  dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
200
207
  dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
201
-
202
- // Pass enhanced info to onDragEnd callback to give dev more context
203
- if (onDragEnd) onDragEnd(draggedItemId, finalContainer, originalContainer, itemAbove, itemBelow);
208
+ if (onDragEnd) {
209
+ if (!enableCrossContainerPreview) {
210
+ onDragEnd();
211
+ } else {
212
+ const draggedItem = state.items.find(item => item && item.id === draggedItemId);
213
+ const finalContainer = draggedItem ? draggedItem.container : originalContainer;
214
+
215
+ const itemsInContainer = state.items.filter(item => item && item.container === finalContainer);
216
+ const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
217
+ const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
218
+ const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
219
+
220
+ onDragEnd(
221
+ draggedItemId,
222
+ finalContainer,
223
+ originalContainer,
224
+ itemAbove,
225
+ itemBelow
226
+ );
227
+ }
228
+ }
204
229
  };
205
230
 
206
231
  const changeCategory = (itemId: string, container: string) => {
@@ -212,46 +237,31 @@ export const DraggableProvider = ({
212
237
 
213
238
  const draggedItemId = state.dragData.id;
214
239
  const originalContainer = state.dragData.initialGroup;
215
-
216
- console.log('[Draggable] handleDrop:', { draggedItemId, container, originalContainer });
217
-
218
- if (!draggedItemId) {
219
- console.warn('[Draggable] handleDrop: No draggedItemId found');
220
- return; // Guard against missing drag data when dropping too quickly
221
- }
222
-
223
- const draggedItem = state.items.find(item => item && item.id === draggedItemId);
224
-
225
- if (!draggedItem) {
226
- console.error('[Draggable] handleDrop: Item not found in state', { draggedItemId, itemsCount: state.items.length });
227
- // Item not found in state: clear drag state and exit
228
- dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
229
- dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
230
- dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
231
- return;
232
- }
233
-
234
- // If dropping in a different container and item hasn't been moved there yet, move to end
235
- if (container !== originalContainer && draggedItem.container !== container) {
236
- console.log('[Draggable] handleDrop: Moving to container end');
237
- dispatch({ type: 'MOVE_TO_CONTAINER_END', payload: { dragId: draggedItemId, newContainer: container } });
238
- }
239
-
240
- // Find items above and below in the same container
241
- const itemsInContainer = state.items.filter(item => item && item.container === container);
242
- const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
243
- const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
244
- const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
245
-
240
+
246
241
  dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
247
242
  dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
248
- // changeCategory will ensure the container is set correctly on drop for cross container and same container drops
249
- changeCategory(draggedItemId, container);
250
-
251
- // Pass enhanced info to onDrop callback so devs have more context
252
- if (onDrop && draggedItem) {
253
- const updatedItem = { ...draggedItem, container };
254
- onDrop(draggedItemId, container, originalContainer, updatedItem, itemAbove, itemBelow);
243
+ changeCategory(state.dragData.id, container);
244
+ if (onDrop) {
245
+ if (!enableCrossContainerPreview) {
246
+ onDrop(container);
247
+ } else {
248
+ const draggedItem = state.items.find(item => item && item.id === draggedItemId);
249
+ const updatedItem = draggedItem ? { ...draggedItem, container } : null;
250
+
251
+ const itemsInContainer = state.items.filter(item => item && item.container === container);
252
+ const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
253
+ const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
254
+ const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
255
+
256
+ onDrop(
257
+ draggedItemId,
258
+ container,
259
+ originalContainer,
260
+ updatedItem,
261
+ itemAbove,
262
+ itemBelow
263
+ );
264
+ }
255
265
  }
256
266
  };
257
267
 
@@ -260,23 +270,20 @@ export const DraggableProvider = ({
260
270
 
261
271
  e.preventDefault();
262
272
  dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
263
-
264
- // Guard against missing drag ID
265
- if (!state.dragData.id) return;
266
-
267
- // Find the dragged item
268
- const draggedItem = state.items.find(item => item && item.id === state.dragData.id);
269
-
270
- // Only move to container end if item exists and is in a different container
271
- if (draggedItem && draggedItem.container !== container) {
272
- console.log('[Draggable] handleDragOver: Moving to container end', { dragId: state.dragData.id, fromContainer: draggedItem.container, toContainer: container });
273
- // Move item to end of target container for preview
274
- dispatch({ type: 'MOVE_TO_CONTAINER_END', payload: { dragId: state.dragData.id, newContainer: container } });
275
- dispatch({ type: 'SET_DRAG_DATA', payload: { id: state.dragData.id, initialGroup: container, originId: providerId } });
276
- } else if (!draggedItem) {
277
- console.error('[Draggable] handleDragOver: Item not found', { dragId: state.dragData.id, itemsCount: state.items.length });
273
+
274
+ if (enableCrossContainerPreview && state.dragData.id) {
275
+ // Only when enableCrossContainerPreview is true: when hovering over a different container, move item to end
276
+ const draggedItem = state.items.find(
277
+ (item) => item && item.id === state.dragData.id
278
+ );
279
+ if (draggedItem && draggedItem.container !== container) {
280
+ dispatch({
281
+ type: "MOVE_TO_CONTAINER_END",
282
+ payload: { dragId: state.dragData.id, newContainer: container },
283
+ });
284
+ }
278
285
  }
279
-
286
+
280
287
  if (onDragOver) onDragOver(e, container);
281
288
  };
282
289
 
@@ -300,4 +307,4 @@ export const DraggableProvider = ({
300
307
  return (
301
308
  <DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
302
309
  );
303
- };
310
+ };
@@ -18,6 +18,7 @@ export type ActionType =
18
18
  } }
19
19
  | { type: 'SET_IS_DRAGGING'; payload: string }
20
20
  | { type: 'SET_ACTIVE_CONTAINER'; payload: string }
21
+ | { type: 'SET_CROSS_CONTAINER_PREVIEW'; payload: boolean }
21
22
  | { type: 'CHANGE_CATEGORY'; payload: { itemId: string; container: string } }
22
23
  | { type: 'REORDER_ITEMS'; payload: { dragId: string; targetId: string } }
23
24
  | { type: 'REORDER_ITEMS_CROSS_CONTAINER'; payload: { dragId: string; targetId: string; newContainer: string } }
@@ -36,9 +37,10 @@ export type ActionType =
36
37
  onReorder: (items: ItemType[]) => void;
37
38
  onDragStart?: (id: string, container: string) => void;
38
39
  onDragEnter?: (id: string, container: string) => void;
39
- onDragEnd?: (draggedItemId: string, finalContainer: string, originalContainer: string, itemAbove: ItemType | null, itemBelow: ItemType | null) => void;
40
- onDrop?: (draggedItemId: string, droppedContainer: string, originalContainer: string, item: ItemType, itemAbove: ItemType | null, itemBelow: ItemType | null) => void;
40
+ onDragEnd?: (...args: any[]) => void;
41
+ onDrop?: (...args: any[]) => void;
41
42
  onDragOver?: (e: Event, container: string) => void;
42
43
  dropZone?: DropZoneConfig | string; // Can accept string for backward compatibility
43
44
  providerId?: string;
45
+ enableCrossContainerPreview?: boolean;
44
46
  }
@@ -83,6 +83,7 @@ const DraggableMultipleContainersDropzone = (props) => {
83
83
  return (
84
84
  <DraggableProvider
85
85
  dropZone={{type: "outline"}}
86
+ enableCrossContainerPreview
86
87
  initialItems={data}
87
88
  onDragEnd={(draggedItemId, finalContainer, originalContainer, itemAbove, itemBelow) => {
88
89
  console.log(`Dragged Item ID: ${draggedItemId}`);
@@ -1,6 +1,8 @@
1
1
  The multiple container functionality also supports customized dropzone styling as shown here.
2
2
 
3
- In addition to this, the `onDrop` and `onDragEnd` event listeners provide several arguments to allow developers more context from the drag event.
3
+ In addition to this, the `enableCrossContainerPreview` prop can be used on the `DraggableProvider` as shown here to enable dropzone preview for cross-container dragging.
4
+
5
+ With `enableCrossContainerPreview`, the `onDrop` and `onDragEnd` event listeners will also provide several arguments to allow developers more context from the drag event.
4
6
 
5
7
  The `onDrop` callback is triggered when an item is successfully dropped into a container. It provides the following arguments:
6
8
 
@@ -1,5 +1,5 @@
1
1
  .pb_file_upload_kit {
2
- .pb_card_kit_deselected_border_radius_md {
2
+ .pb_card_kit {
3
3
  border: 1px #ccc dashed;
4
4
  text-align: center;
5
5
  }
@@ -11,7 +11,7 @@
11
11
  }
12
12
  &.error,
13
13
  &.pb_file_upload_kit_error {
14
- .pb_card_kit_deselected_border_radius_md {
14
+ .pb_card_kit {
15
15
  border-color: $error;
16
16
  }
17
17
  .pb_body_kit_negative {
@@ -30,12 +30,12 @@
30
30
  }
31
31
 
32
32
  .dark .pb_file_upload_kit {
33
- .pb_card_kit_deselected_border_radius_md {
33
+ .pb_card_kit {
34
34
  border: 1px $text_dk_lighter dashed;
35
35
  }
36
36
  &.error,
37
37
  &.pb_file_upload_kit_error {
38
- .pb_card_kit_deselected_border_radius_md {
38
+ .pb_card_kit {
39
39
  border-color: $error_dark;
40
40
  }
41
41
  }
@@ -1,4 +1,4 @@
1
- import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useEffect,useMemo,useContext,createElement,useRef,forwardRef,useState,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{c as getDefaultExportFromCjs,S as filter,T as omit,n as noop$2,u as useCollapsible,U as createPopper,V as uniqueId,W as get,X as flip$2,Y as offset$2,Z as shift$2,$ as arrow$3,a0 as computePosition$1,a1 as createCoords$1,a2 as round$1,a3 as max$1,a4 as min$1,a5 as rectToClientRect$1,g as getAllIcons,h as colors$1,k as highchartsTheme,a6 as merge,l as highchartsDarkTheme,N as typography,a7 as cloneDeep,i as isEmpty$1,a8 as isString}from"./lib-CgpqUb6l.js";import{TrixEditor}from"react-trix";import Trix from"trix";import*as ReactDOM from"react-dom";import ReactDOM__default,{createPortal}from"react-dom";import require$$0 from"react-is";const initialState={items:[],dragData:{id:"",initialGroup:"",originId:""},isDragging:"",activeContainer:""};const reducer=(state,action)=>{switch(action.type){case"SET_ITEMS":return{...state,items:action.payload};case"SET_DRAG_DATA":return{...state,dragData:action.payload};case"SET_IS_DRAGGING":return{...state,isDragging:action.payload};case"SET_ACTIVE_CONTAINER":return{...state,activeContainer:action.payload};case"CHANGE_CATEGORY":return{...state,items:state.items.map((item=>item.id===action.payload.itemId?{...item,container:action.payload.container}:item))};case"REORDER_ITEMS":{const{dragId:dragId,targetId:targetId}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item.id===dragId));const draggedIndex=newItems.indexOf(draggedItem);const targetIndex=newItems.findIndex((item=>item.id===targetId));newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,draggedItem);return{...state,items:newItems}}case"REORDER_ITEMS_CROSS_CONTAINER":{const{dragId:dragId,targetId:targetId,newContainer:newContainer}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item&&item.id===dragId));const draggedIndex=newItems.indexOf(draggedItem);const targetIndex=newItems.findIndex((item=>item&&item.id===targetId));const updatedItem={...draggedItem,container:newContainer};newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,updatedItem);return{...state,items:newItems}}case"MOVE_TO_CONTAINER_END":{const{dragId:dragId,newContainer:newContainer}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item&&item.id===dragId));const draggedIndex=newItems.indexOf(draggedItem);const updatedItem={...draggedItem,container:newContainer};newItems.splice(draggedIndex,1);const lastIndexInContainer=newItems.map((item=>item.container)).lastIndexOf(newContainer);if(lastIndexInContainer===-1){newItems.push(updatedItem)}else{newItems.splice(lastIndexInContainer+1,0,updatedItem)}return{...state,items:newItems}}case"RESET_DRAG_CONTAINER":{const{itemId:itemId,originalContainer:originalContainer}=action.payload;return{...state,items:state.items.map((item=>item.id===itemId?{...item,container:originalContainer}:item))}}default:return state}};const DragContext=createContext({});const DraggableContext=()=>useContext(DragContext);const DraggableProvider=({children:children,initialItems:initialItems,onReorder:onReorder,onDragStart:onDragStart,onDragEnter:onDragEnter,onDragEnd:onDragEnd,onDrop:onDrop,onDragOver:onDragOver,dropZone:dropZone={type:"ghost",color:"neutral",direction:"vertical"},providerId:providerId="default"})=>{const[state,dispatch]=useReducer(reducer,initialState);let dropZoneType="ghost";let dropZoneColor="neutral";let dropZoneDirection="vertical";if(typeof dropZone==="string"){dropZoneType=dropZone}else{dropZoneType=dropZone.type||"ghost";dropZoneColor=dropZone.type==="line"?dropZone.color||"primary":dropZone.color||"neutral";if(dropZoneType==="line"){dropZoneDirection=dropZone.direction||"vertical"}}useEffect((()=>{dispatch({type:"SET_ITEMS",payload:initialItems})}),[initialItems]);useEffect((()=>{onReorder(state.items)}),[state.items]);const handleDragStart=(id,container)=>{console.log("[Draggable] handleDragStart:",{id:id,container:container,providerId:providerId});dispatch({type:"SET_DRAG_DATA",payload:{id:id,initialGroup:container,originId:providerId}});dispatch({type:"SET_IS_DRAGGING",payload:id});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(state.dragData.originId!==providerId)return;if(state.dragData.id!==id){const isCrossContainer=state.dragData.initialGroup!==container;console.log("[Draggable] handleDragEnter:",{id:id,container:container,isCrossContainer:isCrossContainer,draggedId:state.dragData.id});if(isCrossContainer){dispatch({type:"REORDER_ITEMS_CROSS_CONTAINER",payload:{dragId:state.dragData.id,targetId:id,newContainer:container}})}else{dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}})}dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container,originId:providerId}})}if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{const draggedItemId=state.dragData.id;const originalContainer=state.dragData.initialGroup;console.log("[Draggable] handleDragEnd:",{draggedItemId:draggedItemId,originalContainer:originalContainer});if(!draggedItemId){console.warn("[Draggable] handleDragEnd: No draggedItemId found");dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});dispatch({type:"SET_DRAG_DATA",payload:{id:"",initialGroup:"",originId:""}});return}const draggedItem=state.items.find((item=>item&&item.id===draggedItemId));const finalContainer=draggedItem?draggedItem.container:originalContainer;console.log("[Draggable] handleDragEnd item found:",{draggedItem:!!draggedItem,finalContainer:finalContainer});const itemsInContainer=state.items.filter((item=>item&&item.container===finalContainer));const indexInContainer=itemsInContainer.findIndex((item=>item&&item.id===draggedItemId));const itemAbove=indexInContainer>0?itemsInContainer[indexInContainer-1]:null;const itemBelow=indexInContainer<itemsInContainer.length-1?itemsInContainer[indexInContainer+1]:null;dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});dispatch({type:"SET_DRAG_DATA",payload:{id:"",initialGroup:"",originId:""}});if(onDragEnd)onDragEnd(draggedItemId,finalContainer,originalContainer,itemAbove,itemBelow)};const changeCategory=(itemId,container)=>{dispatch({type:"CHANGE_CATEGORY",payload:{itemId:itemId,container:container}})};const handleDrop=container=>{if(state.dragData.originId!==providerId)return;const draggedItemId=state.dragData.id;const originalContainer=state.dragData.initialGroup;console.log("[Draggable] handleDrop:",{draggedItemId:draggedItemId,container:container,originalContainer:originalContainer});if(!draggedItemId){console.warn("[Draggable] handleDrop: No draggedItemId found");return}const draggedItem=state.items.find((item=>item&&item.id===draggedItemId));if(!draggedItem){console.error("[Draggable] handleDrop: Item not found in state",{draggedItemId:draggedItemId,itemsCount:state.items.length});dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});dispatch({type:"SET_DRAG_DATA",payload:{id:"",initialGroup:"",originId:""}});return}if(container!==originalContainer&&draggedItem.container!==container){console.log("[Draggable] handleDrop: Moving to container end");dispatch({type:"MOVE_TO_CONTAINER_END",payload:{dragId:draggedItemId,newContainer:container}})}const itemsInContainer=state.items.filter((item=>item&&item.container===container));const indexInContainer=itemsInContainer.findIndex((item=>item&&item.id===draggedItemId));const itemAbove=indexInContainer>0?itemsInContainer[indexInContainer-1]:null;const itemBelow=indexInContainer<itemsInContainer.length-1?itemsInContainer[indexInContainer+1]:null;dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});changeCategory(draggedItemId,container);if(onDrop&&draggedItem){const updatedItem={...draggedItem,container:container};onDrop(draggedItemId,container,originalContainer,updatedItem,itemAbove,itemBelow)}};const handleDragOver=(e,container)=>{if(state.dragData.originId!==providerId)return;e.preventDefault();dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(!state.dragData.id)return;const draggedItem=state.items.find((item=>item&&item.id===state.dragData.id));if(draggedItem&&draggedItem.container!==container){console.log("[Draggable] handleDragOver: Moving to container end",{dragId:state.dragData.id,fromContainer:draggedItem.container,toContainer:container});dispatch({type:"MOVE_TO_CONTAINER_END",payload:{dragId:state.dragData.id,newContainer:container}});dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container,originId:providerId}})}else if(!draggedItem){console.error("[Draggable] handleDragOver: Item not found",{dragId:state.dragData.id,itemsCount:state.items.length})}if(onDragOver)onDragOver(e,container)};const contextValue=useMemo((()=>({items:state.items,dragData:state.dragData,isDragging:state.isDragging,activeContainer:state.activeContainer,dropZone:dropZoneType,dropZoneColor:dropZoneColor,...dropZoneType==="line"?{direction:dropZoneDirection}:{},handleDragStart:handleDragStart,handleDragEnter:handleDragEnter,handleDragEnd:handleDragEnd,handleDrop:handleDrop,handleDragOver:handleDragOver})),[state,dropZoneType,dropZoneColor,dropZoneDirection]);return jsx$1(DragContext.Provider,{value:contextValue,children:children})};var classnames$1={exports:{}};
1
+ import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useEffect,useMemo,useContext,createElement,useRef,forwardRef,useState,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{c as getDefaultExportFromCjs,S as filter,T as omit,n as noop$2,u as useCollapsible,U as createPopper,V as uniqueId,W as get,X as flip$2,Y as offset$2,Z as shift$2,$ as arrow$3,a0 as computePosition$1,a1 as createCoords$1,a2 as round$1,a3 as max$1,a4 as min$1,a5 as rectToClientRect$1,g as getAllIcons,h as colors$1,k as highchartsTheme,a6 as merge,l as highchartsDarkTheme,N as typography,a7 as cloneDeep,i as isEmpty$1,a8 as isString}from"./lib-CgpqUb6l.js";import{TrixEditor}from"react-trix";import Trix from"trix";import*as ReactDOM from"react-dom";import ReactDOM__default,{createPortal}from"react-dom";import require$$0 from"react-is";const initialState={items:[],dragData:{id:"",initialGroup:"",originId:""},isDragging:"",activeContainer:""};const reducer=(state,action)=>{switch(action.type){case"SET_ITEMS":return{...state,items:action.payload};case"SET_DRAG_DATA":return{...state,dragData:action.payload};case"SET_IS_DRAGGING":return{...state,isDragging:action.payload};case"SET_ACTIVE_CONTAINER":return{...state,activeContainer:action.payload};case"CHANGE_CATEGORY":return{...state,items:state.items.map((item=>item.id===action.payload.itemId?{...item,container:action.payload.container}:item))};case"REORDER_ITEMS":{const{dragId:dragId,targetId:targetId}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item.id===dragId));const draggedIndex=newItems.indexOf(draggedItem);const targetIndex=newItems.findIndex((item=>item.id===targetId));newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,draggedItem);return{...state,items:newItems}}case"REORDER_ITEMS_CROSS_CONTAINER":{const{dragId:dragId,targetId:targetId,newContainer:newContainer}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item&&item.id===dragId));if(!draggedItem)return state;const draggedIndex=newItems.indexOf(draggedItem);const targetIndex=newItems.findIndex((item=>item&&item.id===targetId));if(draggedIndex===-1||targetIndex===-1)return state;const updatedItem={...draggedItem,container:newContainer};newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,updatedItem);return{...state,items:newItems}}case"MOVE_TO_CONTAINER_END":{const{dragId:dragId,newContainer:newContainer}=action.payload;const newItems=[...state.items];const draggedItem=newItems.find((item=>item&&item.id===dragId));if(!draggedItem)return state;const draggedIndex=newItems.indexOf(draggedItem);if(draggedIndex===-1)return state;const updatedItem={...draggedItem,container:newContainer};newItems.splice(draggedIndex,1);const lastIndexInContainer=newItems.map((item=>item&&item.container)).lastIndexOf(newContainer);if(lastIndexInContainer===-1){newItems.push(updatedItem)}else{newItems.splice(lastIndexInContainer+1,0,updatedItem)}return{...state,items:newItems}}default:return state}};const DragContext=createContext({});const DraggableContext=()=>useContext(DragContext);const DraggableProvider=({children:children,initialItems:initialItems,onReorder:onReorder,onDragStart:onDragStart,onDragEnter:onDragEnter,onDragEnd:onDragEnd,onDrop:onDrop,onDragOver:onDragOver,dropZone:dropZone={type:"ghost",color:"neutral",direction:"vertical"},providerId:providerId="default",enableCrossContainerPreview:enableCrossContainerPreview=false})=>{const[state,dispatch]=useReducer(reducer,initialState);let dropZoneType="ghost";let dropZoneColor="neutral";let dropZoneDirection="vertical";if(typeof dropZone==="string"){dropZoneType=dropZone}else{dropZoneType=dropZone.type||"ghost";dropZoneColor=dropZone.type==="line"?dropZone.color||"primary":dropZone.color||"neutral";if(dropZoneType==="line"){dropZoneDirection=dropZone.direction||"vertical"}}useEffect((()=>{dispatch({type:"SET_ITEMS",payload:initialItems})}),[initialItems]);useEffect((()=>{onReorder(state.items)}),[state.items]);const handleDragStart=(id,container)=>{dispatch({type:"SET_DRAG_DATA",payload:{id:id,initialGroup:container,originId:providerId}});dispatch({type:"SET_IS_DRAGGING",payload:id});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(state.dragData.originId!==providerId)return;if(state.dragData.id!==id){if(enableCrossContainerPreview){const draggedItem=state.items.find((item=>item&&item.id===state.dragData.id));const currentContainer=draggedItem&&draggedItem.container?draggedItem.container:state.dragData.initialGroup;const isCrossContainer=currentContainer!==container&&(currentContainer!==void 0||container!==void 0);if(isCrossContainer){dispatch({type:"REORDER_ITEMS_CROSS_CONTAINER",payload:{dragId:state.dragData.id,targetId:id,newContainer:container}})}else{dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}})}}else{dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}})}dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container,originId:providerId}})}if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{const draggedItemId=state.dragData.id;const originalContainer=state.dragData.initialGroup;dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});dispatch({type:"SET_DRAG_DATA",payload:{id:"",initialGroup:"",originId:""}});if(onDragEnd){if(!enableCrossContainerPreview){onDragEnd()}else{const draggedItem=state.items.find((item=>item&&item.id===draggedItemId));const finalContainer=draggedItem?draggedItem.container:originalContainer;const itemsInContainer=state.items.filter((item=>item&&item.container===finalContainer));const indexInContainer=itemsInContainer.findIndex((item=>item&&item.id===draggedItemId));const itemAbove=indexInContainer>0?itemsInContainer[indexInContainer-1]:null;const itemBelow=indexInContainer<itemsInContainer.length-1?itemsInContainer[indexInContainer+1]:null;onDragEnd(draggedItemId,finalContainer,originalContainer,itemAbove,itemBelow)}}};const changeCategory=(itemId,container)=>{dispatch({type:"CHANGE_CATEGORY",payload:{itemId:itemId,container:container}})};const handleDrop=container=>{if(state.dragData.originId!==providerId)return;const draggedItemId=state.dragData.id;const originalContainer=state.dragData.initialGroup;dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});changeCategory(state.dragData.id,container);if(onDrop){if(!enableCrossContainerPreview){onDrop(container)}else{const draggedItem=state.items.find((item=>item&&item.id===draggedItemId));const updatedItem=draggedItem?{...draggedItem,container:container}:null;const itemsInContainer=state.items.filter((item=>item&&item.container===container));const indexInContainer=itemsInContainer.findIndex((item=>item&&item.id===draggedItemId));const itemAbove=indexInContainer>0?itemsInContainer[indexInContainer-1]:null;const itemBelow=indexInContainer<itemsInContainer.length-1?itemsInContainer[indexInContainer+1]:null;onDrop(draggedItemId,container,originalContainer,updatedItem,itemAbove,itemBelow)}}};const handleDragOver=(e,container)=>{if(state.dragData.originId!==providerId)return;e.preventDefault();dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(enableCrossContainerPreview&&state.dragData.id){const draggedItem=state.items.find((item=>item&&item.id===state.dragData.id));if(draggedItem&&draggedItem.container!==container){dispatch({type:"MOVE_TO_CONTAINER_END",payload:{dragId:state.dragData.id,newContainer:container}})}}if(onDragOver)onDragOver(e,container)};const contextValue=useMemo((()=>({items:state.items,dragData:state.dragData,isDragging:state.isDragging,activeContainer:state.activeContainer,dropZone:dropZoneType,dropZoneColor:dropZoneColor,...dropZoneType==="line"?{direction:dropZoneDirection}:{},handleDragStart:handleDragStart,handleDragEnter:handleDragEnter,handleDragEnd:handleDragEnd,handleDrop:handleDrop,handleDragOver:handleDragOver})),[state,dropZoneType,dropZoneColor,dropZoneDirection]);return jsx$1(DragContext.Provider,{value:contextValue,children:children})};var classnames$1={exports:{}};
2
2
  /*!
3
3
  Copyright (c) 2018 Jed Watson.
4
4
  Licensed under the MIT License (MIT), see