playbook_ui 15.6.0.pre.alpha.PLAY2611selectinputoptions12951 → 15.6.0.pre.alpha.PLAY2686contactkittextonly13049
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 +4 -4
- data/app/pb_kits/playbook/pb_card/docs/_card_header.md +1 -1
- data/app/pb_kits/playbook/pb_card/docs/_card_highlight.md +1 -1
- data/app/pb_kits/playbook/pb_collapsible/__snapshots__/collapsible.test.js.snap +2 -2
- data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleIcon.tsx +10 -8
- data/app/pb_kits/playbook/pb_collapsible/docs/_collapsible_icons.jsx +0 -1
- data/app/pb_kits/playbook/pb_collapsible/docs/_collapsible_state.jsx +0 -3
- data/app/pb_kits/playbook/pb_contact/_contact.tsx +51 -24
- data/app/pb_kits/playbook/pb_contact/contact.html.erb +53 -19
- data/app/pb_kits/playbook/pb_contact/contact.rb +11 -1
- data/app/pb_kits/playbook/pb_contact/contact.test.js +76 -0
- data/app/pb_kits/playbook/pb_contact/docs/_contact_unstyled.html.erb +33 -0
- data/app/pb_kits/playbook/pb_contact/docs/_contact_unstyled.jsx +46 -0
- data/app/pb_kits/playbook/pb_contact/docs/_contact_unstyled_rails.md +2 -0
- data/app/pb_kits/playbook/pb_contact/docs/_contact_unstyled_react.md +2 -0
- data/app/pb_kits/playbook/pb_contact/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_contact/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +24 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +181 -3
- data/app/pb_kits/playbook/pb_distribution_bar/docs/_distribution_bar_custom_colors.md +1 -1
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +316 -15
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +1 -1
- data/app/pb_kits/playbook/pb_filter/Filter/FilterBackground.tsx +3 -3
- data/app/pb_kits/playbook/pb_table/_table.tsx +187 -33
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant.jsx +134 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant.md +34 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_rails.html.erb +101 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_rails.md +33 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_with_pagination.jsx +180 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_with_pagination.md +3 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_with_pagination_rails.html.erb +122 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_filter_variant_with_pagination_rails.md +3 -0
- data/app/pb_kits/playbook/pb_table/docs/example.yml +4 -0
- data/app/pb_kits/playbook/pb_table/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_table/table.html.erb +68 -12
- data/app/pb_kits/playbook/pb_table/table.rb +22 -3
- data/app/pb_kits/playbook/pb_table/table.test.js +143 -0
- data/app/pb_kits/playbook/pb_timeline/_item.tsx +3 -0
- data/app/pb_kits/playbook/pb_timeline/docs/_timeline_show_current_year.html.erb +60 -0
- data/app/pb_kits/playbook/pb_timeline/docs/_timeline_show_current_year.jsx +118 -0
- data/app/pb_kits/playbook/pb_timeline/docs/_timeline_show_current_year.md +1 -0
- data/app/pb_kits/playbook/pb_timeline/docs/_timeline_with_date.md +1 -1
- data/app/pb_kits/playbook/pb_timeline/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_timeline/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_timeline/item.html.erb +1 -1
- data/app/pb_kits/playbook/pb_timeline/item.rb +2 -0
- data/app/pb_kits/playbook/pb_timeline/label.html.erb +2 -1
- data/app/pb_kits/playbook/pb_timeline/label.rb +2 -0
- data/app/pb_kits/playbook/pb_timeline/subcomponents/Label.tsx +3 -0
- data/app/pb_kits/playbook/pb_timeline/timeline.test.js +51 -0
- data/app/pb_kits/playbook/tokens/_colors.scss +2 -1
- data/app/pb_kits/playbook/utilities/deprecated.ts +73 -0
- data/dist/chunks/_typeahead-CHwm9MTE.js +6 -0
- data/dist/chunks/lib-Cugvy62C.js +29 -0
- data/dist/chunks/vendor.js +3 -3
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/pb_kit_helper.rb +35 -0
- data/lib/playbook/version.rb +1 -1
- metadata +20 -4
- data/dist/chunks/_typeahead-BXM7QUuy.js +0 -6
- data/dist/chunks/lib-CgpqUb6l.js +0 -29
|
@@ -275,6 +275,80 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
275
275
|
|
|
276
276
|
const { setMinDate, setMaxDate } = getMinMaxDates()
|
|
277
277
|
|
|
278
|
+
// Default Date + Min/Max Date Initialization Helper Functions section ----/
|
|
279
|
+
const toDateObject = (dateValue: any): Date | null => {
|
|
280
|
+
if (!dateValue) return null
|
|
281
|
+
if (dateValue instanceof Date) return dateValue
|
|
282
|
+
if (typeof dateValue === 'string') {
|
|
283
|
+
const parsed = new Date(dateValue)
|
|
284
|
+
return isNaN(parsed.getTime()) ? null : parsed
|
|
285
|
+
}
|
|
286
|
+
if (typeof dateValue === 'number') {
|
|
287
|
+
return new Date(dateValue)
|
|
288
|
+
}
|
|
289
|
+
return null
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Formatting Date for Flatpickr
|
|
293
|
+
const formatDateForFlatpickr = (dateValue: any): string | null => {
|
|
294
|
+
const dateObj = toDateObject(dateValue)
|
|
295
|
+
if (!dateObj) return null
|
|
296
|
+
|
|
297
|
+
const year = dateObj.getFullYear()
|
|
298
|
+
const month = String(dateObj.getMonth() + 1).padStart(2, '0')
|
|
299
|
+
const day = String(dateObj.getDate()).padStart(2, '0')
|
|
300
|
+
return `${year}-${month}-${day}`
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Helper to check if defaultDate is earlier than minDate
|
|
304
|
+
const isDefaultDateBeforeMinDate = (defaultDateValue: any, minDateValue: any): boolean => {
|
|
305
|
+
if (!defaultDateValue || !minDateValue) return false
|
|
306
|
+
|
|
307
|
+
const defaultDateObj = toDateObject(defaultDateValue)
|
|
308
|
+
const minDateObj = toDateObject(minDateValue)
|
|
309
|
+
|
|
310
|
+
if (!defaultDateObj || !minDateObj) return false
|
|
311
|
+
|
|
312
|
+
const defaultDateOnly = new Date(defaultDateObj.getFullYear(), defaultDateObj.getMonth(), defaultDateObj.getDate())
|
|
313
|
+
const minDateOnly = new Date(minDateObj.getFullYear(), minDateObj.getMonth(), minDateObj.getDate())
|
|
314
|
+
|
|
315
|
+
return defaultDateOnly < minDateOnly
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Helper to check if defaultDate is later than maxDate
|
|
319
|
+
const isDefaultDateAfterMaxDate = (defaultDateValue: any, maxDateValue: any): boolean => {
|
|
320
|
+
if (!defaultDateValue || !maxDateValue) return false
|
|
321
|
+
|
|
322
|
+
const defaultDateObj = toDateObject(defaultDateValue)
|
|
323
|
+
const maxDateObj = toDateObject(maxDateValue)
|
|
324
|
+
|
|
325
|
+
if (!defaultDateObj || !maxDateObj) return false
|
|
326
|
+
|
|
327
|
+
const defaultDateOnly = new Date(defaultDateObj.getFullYear(), defaultDateObj.getMonth(), defaultDateObj.getDate())
|
|
328
|
+
const maxDateOnly = new Date(maxDateObj.getFullYear(), maxDateObj.getMonth(), maxDateObj.getDate())
|
|
329
|
+
|
|
330
|
+
return defaultDateOnly > maxDateOnly
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const defaultDateValue: any = defaultDateGetter()
|
|
334
|
+
// Only check for and out-of-range if user actually provided minDate/maxDate constraints
|
|
335
|
+
const isBeforeMin = minDate && isDefaultDateBeforeMinDate(defaultDateValue, setMinDate)
|
|
336
|
+
const isAfterMax = maxDate && isDefaultDateAfterMaxDate(defaultDateValue, setMaxDate)
|
|
337
|
+
|
|
338
|
+
// Store these values for use in onClose handler
|
|
339
|
+
const hasOutOfRangeDefault = (isBeforeMin || isAfterMax) && defaultDateValue
|
|
340
|
+
|
|
341
|
+
// Temporarily adjust minDate/maxDate to allow defaultDate to render if it's out of range via user provided minDate/maxDate constraints
|
|
342
|
+
const effectiveMinDate = isBeforeMin && defaultDateValue && minDate
|
|
343
|
+
? formatDateForFlatpickr(defaultDateValue) || setMinDate
|
|
344
|
+
: setMinDate
|
|
345
|
+
|
|
346
|
+
const effectiveMaxDate = isAfterMax && defaultDateValue && maxDate
|
|
347
|
+
? formatDateForFlatpickr(defaultDateValue) || setMaxDate
|
|
348
|
+
: setMaxDate
|
|
349
|
+
|
|
350
|
+
// End of Default Date + Min/Max Date Initialization Helper Functions section ----/
|
|
351
|
+
|
|
278
352
|
flatpickr(`#${pickerId}`, {
|
|
279
353
|
allowInput,
|
|
280
354
|
closeOnSelect,
|
|
@@ -286,11 +360,32 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
286
360
|
locale: {
|
|
287
361
|
rangeSeparator: ' to '
|
|
288
362
|
},
|
|
289
|
-
maxDate:
|
|
290
|
-
minDate:
|
|
363
|
+
maxDate: effectiveMaxDate,
|
|
364
|
+
minDate: effectiveMinDate,
|
|
291
365
|
mode,
|
|
292
366
|
nextArrow: '<i class="far fa-angle-right"></i>',
|
|
293
367
|
onOpen: [(_selectedDates, _dateStr, fp) => {
|
|
368
|
+
// If defaultDate was out of range of a dev set min/max date, restore it when calendar opens (in situation where the input was manually cleared or the calendar was closed without selection)
|
|
369
|
+
if (hasOutOfRangeDefault) {
|
|
370
|
+
const dateObj = toDateObject(defaultDateValue)
|
|
371
|
+
if (dateObj) {
|
|
372
|
+
const inputIsBlank = !fp.input.value || fp.input.value.trim() === ''
|
|
373
|
+
const noSelection = !fp.selectedDates || fp.selectedDates.length === 0
|
|
374
|
+
|
|
375
|
+
if (inputIsBlank || noSelection) {
|
|
376
|
+
const formattedDate = fp.formatDate(dateObj, getDateFormat())
|
|
377
|
+
if (formattedDate) {
|
|
378
|
+
fp.input.value = formattedDate
|
|
379
|
+
}
|
|
380
|
+
fp.selectedDates = [dateObj]
|
|
381
|
+
fp.jumpToDate(dateObj)
|
|
382
|
+
setTimeout(() => {
|
|
383
|
+
yearChangeHook(fp)
|
|
384
|
+
}, 0)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
294
389
|
calendarResizer()
|
|
295
390
|
if (resizeRepositionHandlerRef) {
|
|
296
391
|
window.removeEventListener('resize', resizeRepositionHandlerRef)
|
|
@@ -303,12 +398,30 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
303
398
|
if (!staticPosition && scrollContainer) attachToScroll(scrollContainer)
|
|
304
399
|
positionCalendarIfNeeded(fp)
|
|
305
400
|
}],
|
|
306
|
-
onClose: [(selectedDates, dateStr) => {
|
|
401
|
+
onClose: [(selectedDates, dateStr, fp) => {
|
|
307
402
|
if (resizeRepositionHandlerRef) {
|
|
308
403
|
window.removeEventListener('resize', resizeRepositionHandlerRef)
|
|
309
404
|
resizeRepositionHandlerRef = null
|
|
310
405
|
}
|
|
311
406
|
if (!staticPosition && scrollContainer) detachFromScroll(scrollContainer as HTMLElement)
|
|
407
|
+
|
|
408
|
+
// If defaultDate was out of range and no date was selected, preserve the default date
|
|
409
|
+
if (hasOutOfRangeDefault && (!selectedDates || selectedDates.length === 0)) {
|
|
410
|
+
const dateObj = toDateObject(defaultDateValue)
|
|
411
|
+
if (dateObj && fp.input) {
|
|
412
|
+
const formattedDate = fp.formatDate(dateObj, getDateFormat())
|
|
413
|
+
if (formattedDate) {
|
|
414
|
+
setTimeout(() => {
|
|
415
|
+
if (fp.input && (!fp.selectedDates || fp.selectedDates.length === 0)) {
|
|
416
|
+
fp.input.value = formattedDate
|
|
417
|
+
fp.selectedDates = [dateObj]
|
|
418
|
+
fp.jumpToDate(dateObj)
|
|
419
|
+
}
|
|
420
|
+
}, 0)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
312
425
|
onClose(selectedDates, dateStr)
|
|
313
426
|
}],
|
|
314
427
|
onChange: [(selectedDates, dateStr, fp) => {
|
|
@@ -330,6 +443,71 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
|
|
|
330
443
|
const picker = document.querySelector<HTMLElement & { [x: string]: any }>(`#${pickerId}`)._flatpickr
|
|
331
444
|
picker.innerContainer.parentElement.id = `cal-${pickerId}`
|
|
332
445
|
|
|
446
|
+
// If defaultDate was out of range, restore the original minDate/maxDate after initialization (defaultDate displayed, still cannot select dates outside the actual range via user provided minDate/maxDate constraints)
|
|
447
|
+
if ((isBeforeMin || isAfterMax) && defaultDateValue) {
|
|
448
|
+
const dateObj = toDateObject(defaultDateValue)
|
|
449
|
+
const formattedDate = dateObj ? picker.formatDate(dateObj, getDateFormat()) : null
|
|
450
|
+
|
|
451
|
+
setTimeout(() => {
|
|
452
|
+
if (!dateObj || !picker.input || !formattedDate) return
|
|
453
|
+
|
|
454
|
+
picker.setDate(dateObj, false)
|
|
455
|
+
|
|
456
|
+
if (isBeforeMin && setMinDate && minDate) {
|
|
457
|
+
picker.set('minDate', setMinDate)
|
|
458
|
+
}
|
|
459
|
+
if (isAfterMax && setMaxDate && maxDate) {
|
|
460
|
+
picker.set('maxDate', setMaxDate)
|
|
461
|
+
}
|
|
462
|
+
picker.input.value = formattedDate
|
|
463
|
+
|
|
464
|
+
picker.selectedDates = [dateObj]
|
|
465
|
+
|
|
466
|
+
setTimeout(() => {
|
|
467
|
+
yearChangeHook(picker)
|
|
468
|
+
}, 0)
|
|
469
|
+
|
|
470
|
+
// Restore function for out-of-range default dates
|
|
471
|
+
const restoreOutOfRangeValue = () => {
|
|
472
|
+
if (!picker.input) return
|
|
473
|
+
|
|
474
|
+
const inputIsBlank = !picker.input.value || picker.input.value.trim() === ''
|
|
475
|
+
const noSelection = !picker.selectedDates || picker.selectedDates.length === 0
|
|
476
|
+
|
|
477
|
+
if (inputIsBlank || noSelection) {
|
|
478
|
+
setTimeout(() => {
|
|
479
|
+
if (picker.input && (!picker.input.value || picker.input.value.trim() === '')) {
|
|
480
|
+
picker.input.value = formattedDate
|
|
481
|
+
}
|
|
482
|
+
if (!picker.selectedDates || picker.selectedDates.length === 0) {
|
|
483
|
+
picker.selectedDates = [dateObj]
|
|
484
|
+
if (picker.isOpen) {
|
|
485
|
+
picker.jumpToDate(dateObj)
|
|
486
|
+
picker.redraw()
|
|
487
|
+
setTimeout(() => {
|
|
488
|
+
yearChangeHook(picker)
|
|
489
|
+
}, 0)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}, 0)
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const originalClear = picker.clear.bind(picker)
|
|
497
|
+
picker.clear = function(...args: any[]) {
|
|
498
|
+
const result = originalClear(...args)
|
|
499
|
+
setTimeout(() => restoreOutOfRangeValue(), 0)
|
|
500
|
+
return result
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
picker.input.addEventListener('input', restoreOutOfRangeValue)
|
|
504
|
+
|
|
505
|
+
picker.config.onClose.push(() => {
|
|
506
|
+
restoreOutOfRangeValue()
|
|
507
|
+
})
|
|
508
|
+
}, 10)
|
|
509
|
+
}
|
|
510
|
+
|
|
333
511
|
// replace year selector with dropdown
|
|
334
512
|
picker.yearElements[0].parentElement.innerHTML = `<select class="numInput cur-year" type="number" tabIndex="-1" aria-label="Year" id="year-${pickerId}"></select>`
|
|
335
513
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
You can customize the order of the colors you would like to use by using the `colors` prop. Only the data and status colors will work for Playbook charts. See the [design page](https://playbook.powerapp.cloud/
|
|
1
|
+
You can customize the order of the colors you would like to use by using the `colors` prop. Only the data and status colors will work for Playbook charts. See the [design page](https://playbook.powerapp.cloud/tokens/colors) for reference.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, useReducer, useContext, useEffect, useMemo } from "react";
|
|
1
|
+
import React, { createContext, useReducer, useContext, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { InitialStateType, ActionType, DraggableProviderType } from "./types";
|
|
3
3
|
|
|
4
4
|
const initialState: InitialStateType = {
|
|
@@ -92,6 +92,35 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
|
92
92
|
return { ...state, items: newItems };
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
// Reset item back to its original container and position (e.g., when drag ends without valid drop)
|
|
96
|
+
case "RESET_DRAG_CONTAINER": {
|
|
97
|
+
const { itemId, originalContainer, originalIndex } = action.payload;
|
|
98
|
+
const newItems = [...state.items];
|
|
99
|
+
const draggedItem = newItems.find(item => item && item.id === itemId);
|
|
100
|
+
|
|
101
|
+
if (!draggedItem) return state;
|
|
102
|
+
|
|
103
|
+
const currentIndex = newItems.indexOf(draggedItem);
|
|
104
|
+
|
|
105
|
+
// Remove from current position
|
|
106
|
+
newItems.splice(currentIndex, 1);
|
|
107
|
+
|
|
108
|
+
// Restore container property and insert at original index
|
|
109
|
+
const restoredItem = { ...draggedItem, container: originalContainer };
|
|
110
|
+
|
|
111
|
+
// Insert at original index, or at end if index is invalid
|
|
112
|
+
if (originalIndex !== undefined && originalIndex >= 0) {
|
|
113
|
+
newItems.splice(originalIndex, 0, restoredItem);
|
|
114
|
+
} else {
|
|
115
|
+
newItems.push(restoredItem);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
...state,
|
|
120
|
+
items: newItems
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
95
124
|
default:
|
|
96
125
|
return state;
|
|
97
126
|
}
|
|
@@ -119,6 +148,29 @@ export const DraggableProvider = ({
|
|
|
119
148
|
enableCrossContainerPreview = false,
|
|
120
149
|
}: DraggableProviderType) => {
|
|
121
150
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
151
|
+
|
|
152
|
+
// Track drag state for global listener
|
|
153
|
+
const dragStateRef = useRef<{
|
|
154
|
+
isDragging: boolean;
|
|
155
|
+
draggedItemId: string;
|
|
156
|
+
originalContainer: string;
|
|
157
|
+
originalIndex: number;
|
|
158
|
+
currentContainer: string;
|
|
159
|
+
dropOccurred: boolean;
|
|
160
|
+
}>({
|
|
161
|
+
isDragging: false,
|
|
162
|
+
draggedItemId: '',
|
|
163
|
+
originalContainer: '',
|
|
164
|
+
originalIndex: -1,
|
|
165
|
+
currentContainer: '',
|
|
166
|
+
dropOccurred: false,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Track current state for use in gated event listeners (avoid stale closures)
|
|
170
|
+
const stateRef = useRef(state);
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
stateRef.current = state;
|
|
173
|
+
}, [state]);
|
|
122
174
|
|
|
123
175
|
// Parse dropZone prop - handle both string format (backward compatibility) and object format
|
|
124
176
|
let dropZoneType = 'ghost';
|
|
@@ -148,7 +200,209 @@ export const DraggableProvider = ({
|
|
|
148
200
|
onReorder(state.items);
|
|
149
201
|
}, [state.items]);
|
|
150
202
|
|
|
203
|
+
// Monitor for failed drops by detecting mouse/pointer release during drag (this is needed for cross container preview)
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (!enableCrossContainerPreview) return;
|
|
206
|
+
|
|
207
|
+
// Allow drops anywhere on the document by preventing default dragover
|
|
208
|
+
const handleGlobalDragOver = (e: DragEvent) => {
|
|
209
|
+
if (dragStateRef.current.isDragging) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// Handle drops anywhere on the document (including non-container areas)
|
|
215
|
+
const handleGlobalDrop = (e: DragEvent) => {
|
|
216
|
+
if (!dragStateRef.current.isDragging) return;
|
|
217
|
+
|
|
218
|
+
// If a container already handled the drop, don't process again
|
|
219
|
+
if (dragStateRef.current.dropOccurred) return;
|
|
220
|
+
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
|
|
223
|
+
// If we reach here, it means the drop was NOT on a valid container
|
|
224
|
+
// (otherwise the container's handleDrop would have set dropOccurred = true)
|
|
225
|
+
// So we should ALWAYS reset to original container for invalid drops
|
|
226
|
+
const originalContainer = dragStateRef.current.originalContainer;
|
|
227
|
+
|
|
228
|
+
dispatch({
|
|
229
|
+
type: 'RESET_DRAG_CONTAINER',
|
|
230
|
+
payload: {
|
|
231
|
+
itemId: dragStateRef.current.draggedItemId,
|
|
232
|
+
originalContainer: originalContainer,
|
|
233
|
+
originalIndex: dragStateRef.current.originalIndex,
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
|
238
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
|
239
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
|
|
240
|
+
|
|
241
|
+
// Clear drag state
|
|
242
|
+
dragStateRef.current = {
|
|
243
|
+
isDragging: false,
|
|
244
|
+
draggedItemId: '',
|
|
245
|
+
originalContainer: '',
|
|
246
|
+
originalIndex: -1,
|
|
247
|
+
currentContainer: '',
|
|
248
|
+
dropOccurred: false,
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const handleGlobalMouseUp = () => {
|
|
253
|
+
// If we're dragging and mouse is released, wait a bit to see if drop occurs
|
|
254
|
+
if (dragStateRef.current.isDragging) {
|
|
255
|
+
setTimeout(() => {
|
|
256
|
+
const currentContainer = dragStateRef.current.currentContainer;
|
|
257
|
+
|
|
258
|
+
// If drop still hasn't occurred, check if item is in a different container
|
|
259
|
+
if (dragStateRef.current.isDragging && !dragStateRef.current.dropOccurred) {
|
|
260
|
+
// If item is in a different container than original, treat it as a successful drop
|
|
261
|
+
if (currentContainer && currentContainer !== dragStateRef.current.originalContainer) {
|
|
262
|
+
// Trigger onDrop callback with the current container
|
|
263
|
+
if (onDrop) {
|
|
264
|
+
const draggedItem = stateRef.current.items.find(item => item && item.id === dragStateRef.current.draggedItemId);
|
|
265
|
+
const updatedItem = draggedItem ? { ...draggedItem, container: currentContainer } : null;
|
|
266
|
+
const itemsInContainer = stateRef.current.items.filter(item => item && item.container === currentContainer);
|
|
267
|
+
const indexInContainer = itemsInContainer.findIndex(item => item && item.id === dragStateRef.current.draggedItemId);
|
|
268
|
+
const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
|
|
269
|
+
const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
|
|
270
|
+
|
|
271
|
+
onDrop(
|
|
272
|
+
dragStateRef.current.draggedItemId,
|
|
273
|
+
currentContainer,
|
|
274
|
+
dragStateRef.current.originalContainer,
|
|
275
|
+
updatedItem,
|
|
276
|
+
itemAbove,
|
|
277
|
+
itemBelow
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
dispatch({
|
|
282
|
+
type: 'RESET_DRAG_CONTAINER',
|
|
283
|
+
payload: {
|
|
284
|
+
itemId: dragStateRef.current.draggedItemId,
|
|
285
|
+
originalContainer: dragStateRef.current.originalContainer,
|
|
286
|
+
originalIndex: dragStateRef.current.originalIndex,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
|
291
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
|
292
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
|
|
293
|
+
|
|
294
|
+
// Clear drag state
|
|
295
|
+
dragStateRef.current = {
|
|
296
|
+
isDragging: false,
|
|
297
|
+
draggedItemId: '',
|
|
298
|
+
originalContainer: '',
|
|
299
|
+
originalIndex: -1,
|
|
300
|
+
currentContainer: '',
|
|
301
|
+
dropOccurred: false,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}, 50); // Small delay to let drop event fire if it's going to
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// Detect when drag leaves document boundaries
|
|
309
|
+
const handleDragLeave = (e: DragEvent) => {
|
|
310
|
+
// Check if we're leaving the document (relatedTarget will be null)
|
|
311
|
+
if (!e.relatedTarget && dragStateRef.current.isDragging && !dragStateRef.current.dropOccurred) {
|
|
312
|
+
// Drag left the document: reset to original container immediately
|
|
313
|
+
dispatch({
|
|
314
|
+
type: 'RESET_DRAG_CONTAINER',
|
|
315
|
+
payload: {
|
|
316
|
+
itemId: dragStateRef.current.draggedItemId,
|
|
317
|
+
originalContainer: dragStateRef.current.originalContainer,
|
|
318
|
+
originalIndex: dragStateRef.current.originalIndex,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
|
322
|
+
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
|
323
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
|
|
324
|
+
|
|
325
|
+
// Clear drag state
|
|
326
|
+
dragStateRef.current = {
|
|
327
|
+
isDragging: false,
|
|
328
|
+
draggedItemId: '',
|
|
329
|
+
originalContainer: '',
|
|
330
|
+
originalIndex: -1,
|
|
331
|
+
currentContainer: '',
|
|
332
|
+
dropOccurred: false,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
document.addEventListener('dragover', handleGlobalDragOver);
|
|
338
|
+
document.addEventListener('drop', handleGlobalDrop);
|
|
339
|
+
document.addEventListener('dragleave', handleDragLeave);
|
|
340
|
+
document.addEventListener('mouseup', handleGlobalMouseUp);
|
|
341
|
+
document.addEventListener('pointerup', handleGlobalMouseUp);
|
|
342
|
+
|
|
343
|
+
return () => {
|
|
344
|
+
document.removeEventListener('dragover', handleGlobalDragOver);
|
|
345
|
+
document.removeEventListener('drop', handleGlobalDrop);
|
|
346
|
+
document.removeEventListener('dragleave', handleDragLeave);
|
|
347
|
+
document.removeEventListener('mouseup', handleGlobalMouseUp);
|
|
348
|
+
document.removeEventListener('pointerup', handleGlobalMouseUp);
|
|
349
|
+
};
|
|
350
|
+
}, [enableCrossContainerPreview]);
|
|
351
|
+
|
|
352
|
+
// Detect when dragging stops (isDragging goes from truthy to empty)
|
|
353
|
+
const prevIsDraggingRef = useRef(state.isDragging);
|
|
354
|
+
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
if (!enableCrossContainerPreview) return;
|
|
357
|
+
|
|
358
|
+
const wasDragging = prevIsDraggingRef.current;
|
|
359
|
+
const isNowDragging = state.isDragging;
|
|
360
|
+
|
|
361
|
+
// Drag just ended (was dragging, now not)
|
|
362
|
+
if (wasDragging && !isNowDragging) {
|
|
363
|
+
|
|
364
|
+
// If drop didn't occur, reset to original container
|
|
365
|
+
if (!dragStateRef.current.dropOccurred && dragStateRef.current.draggedItemId) {
|
|
366
|
+
dispatch({
|
|
367
|
+
type: 'RESET_DRAG_CONTAINER',
|
|
368
|
+
payload: {
|
|
369
|
+
itemId: dragStateRef.current.draggedItemId,
|
|
370
|
+
originalContainer: dragStateRef.current.originalContainer,
|
|
371
|
+
originalIndex: dragStateRef.current.originalIndex,
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Clear drag state
|
|
377
|
+
dragStateRef.current = {
|
|
378
|
+
isDragging: false,
|
|
379
|
+
draggedItemId: '',
|
|
380
|
+
originalContainer: '',
|
|
381
|
+
originalIndex: -1,
|
|
382
|
+
currentContainer: '',
|
|
383
|
+
dropOccurred: false,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
prevIsDraggingRef.current = isNowDragging;
|
|
388
|
+
}, [state.isDragging, enableCrossContainerPreview]);
|
|
389
|
+
|
|
151
390
|
const handleDragStart = (id: string, container: string) => {
|
|
391
|
+
// Track drag in ref for global listener
|
|
392
|
+
if (enableCrossContainerPreview) {
|
|
393
|
+
// Find the original index of the item
|
|
394
|
+
const originalIndex = state.items.findIndex(item => item && item.id === id);
|
|
395
|
+
|
|
396
|
+
dragStateRef.current = {
|
|
397
|
+
isDragging: true,
|
|
398
|
+
draggedItemId: id,
|
|
399
|
+
originalContainer: container,
|
|
400
|
+
originalIndex: originalIndex,
|
|
401
|
+
currentContainer: container,
|
|
402
|
+
dropOccurred: false,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
152
406
|
dispatch({ type: 'SET_DRAG_DATA', payload: { id: id, initialGroup: container, originId: providerId } });
|
|
153
407
|
dispatch({ type: 'SET_IS_DRAGGING', payload: id });
|
|
154
408
|
if (onDragStart) onDragStart(id, container);
|
|
@@ -181,6 +435,10 @@ export const DraggableProvider = ({
|
|
|
181
435
|
newContainer: container,
|
|
182
436
|
},
|
|
183
437
|
});
|
|
438
|
+
// Update current container in ref
|
|
439
|
+
if (enableCrossContainerPreview) {
|
|
440
|
+
dragStateRef.current.currentContainer = container;
|
|
441
|
+
}
|
|
184
442
|
} else {
|
|
185
443
|
// Same container: keep original behavior
|
|
186
444
|
dispatch({
|
|
@@ -193,7 +451,10 @@ export const DraggableProvider = ({
|
|
|
193
451
|
dispatch({type: "REORDER_ITEMS", payload: { dragId: state.dragData.id, targetId: id }});
|
|
194
452
|
}
|
|
195
453
|
|
|
196
|
-
|
|
454
|
+
// When enableCrossContainerPreview is true, preserve the original initialGroup
|
|
455
|
+
// Otherwise, update it to track the current container
|
|
456
|
+
const newInitialGroup = enableCrossContainerPreview ? state.dragData.initialGroup : container;
|
|
457
|
+
dispatch({type: "SET_DRAG_DATA",payload: {id: state.dragData.id, initialGroup: newInitialGroup, originId: providerId}});
|
|
197
458
|
}
|
|
198
459
|
if (onDragEnter) onDragEnter(id, container);
|
|
199
460
|
};
|
|
@@ -202,17 +463,29 @@ export const DraggableProvider = ({
|
|
|
202
463
|
const draggedItemId = state.dragData.id;
|
|
203
464
|
const originalContainer = state.dragData.initialGroup;
|
|
204
465
|
|
|
466
|
+
// If enableCrossContainerPreview is true and no drop occurred, reset item to original container
|
|
467
|
+
if (enableCrossContainerPreview && !dragStateRef.current.dropOccurred && draggedItemId && originalContainer) {
|
|
468
|
+
dispatch({ type: 'RESET_DRAG_CONTAINER', payload: { itemId: draggedItemId, originalContainer, originalIndex: dragStateRef.current.originalIndex } });
|
|
469
|
+
}
|
|
470
|
+
|
|
205
471
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
|
206
472
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
|
207
473
|
dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
|
|
474
|
+
|
|
475
|
+
// Only call onDragEnd if drop didn't already occur (for enableCrossContainerPreview)
|
|
476
|
+
// If drop occurred, handleDrop or global drop handler already called onDragEnd
|
|
477
|
+
if (enableCrossContainerPreview && dragStateRef.current.dropOccurred) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
208
481
|
if (onDragEnd) {
|
|
209
482
|
if (!enableCrossContainerPreview) {
|
|
210
483
|
onDragEnd();
|
|
211
484
|
} else {
|
|
212
|
-
const draggedItem =
|
|
485
|
+
const draggedItem = stateRef.current.items.find(item => item && item.id === draggedItemId);
|
|
213
486
|
const finalContainer = draggedItem ? draggedItem.container : originalContainer;
|
|
214
487
|
|
|
215
|
-
const itemsInContainer =
|
|
488
|
+
const itemsInContainer = stateRef.current.items.filter(item => item && item.container === finalContainer);
|
|
216
489
|
const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
|
|
217
490
|
const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
|
|
218
491
|
const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
|
|
@@ -237,32 +510,58 @@ export const DraggableProvider = ({
|
|
|
237
510
|
|
|
238
511
|
const draggedItemId = state.dragData.id;
|
|
239
512
|
const originalContainer = state.dragData.initialGroup;
|
|
513
|
+
|
|
514
|
+
// Mark drop as successful in ref for global listener
|
|
515
|
+
if (enableCrossContainerPreview) {
|
|
516
|
+
dragStateRef.current.dropOccurred = true;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Gather data for callbacks BEFORE clearing state
|
|
520
|
+
const isCrossContainer = container !== originalContainer;
|
|
521
|
+
let callbackData = null;
|
|
522
|
+
|
|
523
|
+
if (enableCrossContainerPreview) {
|
|
524
|
+
const draggedItem = stateRef.current.items.find(item => item && item.id === draggedItemId);
|
|
525
|
+
const updatedItem = draggedItem ? { ...draggedItem, container } : null;
|
|
526
|
+
const itemsInContainer = stateRef.current.items.filter(item => item && item.container === container);
|
|
527
|
+
const indexInContainer = itemsInContainer.findIndex(item => item && item.id === draggedItemId);
|
|
528
|
+
const itemAbove = indexInContainer > 0 ? itemsInContainer[indexInContainer - 1] : null;
|
|
529
|
+
const itemBelow = indexInContainer < itemsInContainer.length - 1 ? itemsInContainer[indexInContainer + 1] : null;
|
|
530
|
+
|
|
531
|
+
callbackData = { updatedItem, itemAbove, itemBelow };
|
|
532
|
+
}
|
|
240
533
|
|
|
241
534
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
|
242
535
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
|
536
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: "", initialGroup: "", originId: "" } });
|
|
243
537
|
changeCategory(state.dragData.id, container);
|
|
538
|
+
|
|
244
539
|
if (onDrop) {
|
|
245
540
|
if (!enableCrossContainerPreview) {
|
|
246
541
|
onDrop(container);
|
|
247
542
|
} 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
543
|
onDrop(
|
|
257
544
|
draggedItemId,
|
|
258
545
|
container,
|
|
259
546
|
originalContainer,
|
|
260
|
-
updatedItem,
|
|
261
|
-
itemAbove,
|
|
262
|
-
itemBelow
|
|
547
|
+
callbackData.updatedItem,
|
|
548
|
+
callbackData.itemAbove,
|
|
549
|
+
callbackData.itemBelow
|
|
263
550
|
);
|
|
264
551
|
}
|
|
265
552
|
}
|
|
553
|
+
|
|
554
|
+
// Trigger onDragEnd ONLY for cross-container drops (dragend doesn't fire reliably in that case)
|
|
555
|
+
// For same-container drops, handleDragEnd will be called normally
|
|
556
|
+
if (enableCrossContainerPreview && isCrossContainer && onDragEnd && callbackData) {
|
|
557
|
+
onDragEnd(
|
|
558
|
+
draggedItemId,
|
|
559
|
+
container,
|
|
560
|
+
originalContainer,
|
|
561
|
+
callbackData.itemAbove,
|
|
562
|
+
callbackData.itemBelow
|
|
563
|
+
);
|
|
564
|
+
}
|
|
266
565
|
};
|
|
267
566
|
|
|
268
567
|
const handleDragOver = (e: Event, container: string) => {
|
|
@@ -281,6 +580,8 @@ export const DraggableProvider = ({
|
|
|
281
580
|
type: "MOVE_TO_CONTAINER_END",
|
|
282
581
|
payload: { dragId: state.dragData.id, newContainer: container },
|
|
283
582
|
});
|
|
583
|
+
// Update current container in ref
|
|
584
|
+
dragStateRef.current.currentContainer = container;
|
|
284
585
|
}
|
|
285
586
|
}
|
|
286
587
|
|
|
@@ -23,7 +23,7 @@ export type ActionType =
|
|
|
23
23
|
| { type: 'REORDER_ITEMS'; payload: { dragId: string; targetId: string } }
|
|
24
24
|
| { type: 'REORDER_ITEMS_CROSS_CONTAINER'; payload: { dragId: string; targetId: string; newContainer: string } }
|
|
25
25
|
| { type: 'MOVE_TO_CONTAINER_END'; payload: { dragId: string; newContainer: string } }
|
|
26
|
-
| { type: 'RESET_DRAG_CONTAINER'; payload: { itemId: string; originalContainer: string } };
|
|
26
|
+
| { type: 'RESET_DRAG_CONTAINER'; payload: { itemId: string; originalContainer: string, originalIndex: number } };
|
|
27
27
|
|
|
28
28
|
export interface DropZoneConfig {
|
|
29
29
|
type?: 'ghost' | 'outline' | 'shadow' | 'line';
|
|
@@ -6,10 +6,10 @@ import { GlobalProps, globalProps } from '../../utilities/globalProps'
|
|
|
6
6
|
import Card from '../../pb_card/_card'
|
|
7
7
|
|
|
8
8
|
export type FilterBackgroundProps = {
|
|
9
|
-
background
|
|
10
|
-
className
|
|
9
|
+
background?: boolean,
|
|
10
|
+
className?: string,
|
|
11
11
|
children?: React.ReactChild[] | React.ReactChild,
|
|
12
|
-
dark
|
|
12
|
+
dark?: boolean,
|
|
13
13
|
} & GlobalProps
|
|
14
14
|
|
|
15
15
|
const FilterBackground = (props: FilterBackgroundProps): React.ReactElement => {
|