authscape 1.0.358 → 1.0.370

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.
@@ -1,851 +0,0 @@
1
- import React, {useCallback, useEffect, useRef, useState} from 'react';
2
- import {createPortal, unstable_batchedUpdates} from 'react-dom';
3
- import {
4
- CancelDrop,
5
- closestCenter,
6
- pointerWithin,
7
- rectIntersection,
8
- CollisionDetection,
9
- DndContext,
10
- DragOverlay,
11
- DropAnimation,
12
- getFirstCollision,
13
- KeyboardSensor,
14
- MouseSensor,
15
- TouchSensor,
16
- Modifiers,
17
- useDroppable,
18
- UniqueIdentifier,
19
- useSensors,
20
- useSensor,
21
- MeasuringStrategy,
22
- KeyboardCoordinateGetter,
23
- defaultDropAnimationSideEffects,
24
- } from '@dnd-kit/core';
25
- import {
26
- AnimateLayoutChanges,
27
- SortableContext,
28
- useSortable,
29
- arrayMove,
30
- defaultAnimateLayoutChanges,
31
- verticalListSortingStrategy,
32
- SortingStrategy,
33
- horizontalListSortingStrategy,
34
- } from '@dnd-kit/sortable';
35
- import {CSS} from '@dnd-kit/utilities';
36
- // import {coordinateGetter as multipleContainersCoordinateGetter} from './multipleContainersKeyboardCoordinates';
37
-
38
- // import { Item } from './item';
39
- // import { Container } from './container';
40
- import { Box } from '@mui/material';
41
-
42
- const animateLayoutChanges = (args) =>
43
- defaultAnimateLayoutChanges({...args, wasDragging: true});
44
-
45
- function DroppableContainer({
46
- children,
47
- columns = 1,
48
- disabled,
49
- id,
50
- items,
51
- style,
52
- ...props
53
- }) {
54
- const {
55
- active,
56
- attributes,
57
- isDragging,
58
- listeners,
59
- over,
60
- setNodeRef,
61
- transition,
62
- transform,
63
- } = useSortable({
64
- id,
65
- data: {
66
- type: 'container',
67
- children: items,
68
- },
69
- animateLayoutChanges,
70
- });
71
- const isOverContainer = over
72
- ? (id === over.id && active?.data.current?.type !== 'container') ||
73
- items.includes(over.id)
74
- : false;
75
-
76
- return (
77
- <Container
78
- ref={disabled ? undefined : setNodeRef}
79
- style={{
80
- ...style,
81
- transition,
82
- transform: CSS.Translate.toString(transform),
83
- opacity: isDragging ? 0.5 : undefined,
84
- }}
85
- hover={isOverContainer}
86
- handleProps={{
87
- ...attributes,
88
- ...listeners,
89
- }}
90
- columns={columns}
91
- {...props}
92
- >
93
- {children}
94
- </Container>
95
- );
96
- }
97
-
98
- const dropAnimation = {
99
- sideEffects: defaultDropAnimationSideEffects({
100
- styles: {
101
- active: {
102
- opacity: '0.5',
103
- },
104
- },
105
- }),
106
- };
107
-
108
- export const TRASH_ID = 'void';
109
- const PLACEHOLDER_ID = 'placeholder';
110
- const empty = [];
111
-
112
- export function Kanban({
113
- adjustScale = false,
114
- itemCount = 3,
115
- cancelDrop,
116
- Menu = null,
117
- columns,
118
- loadedUser,
119
- handle = false,
120
- CardTemplate = null,
121
- items: initialItems,
122
- containerStyle,
123
- coordinateGetter = multipleContainersCoordinateGetter,
124
- getItemStyles = () => ({}),
125
- wrapperStyle = () => ({}),
126
- minimal = false,
127
- modifiers,
128
- renderItem,
129
- strategy = verticalListSortingStrategy,
130
- trashable = false,
131
- vertical = false,
132
- scrollable,
133
- }) {
134
-
135
- const [initItems, setInitItems] = useState(null);
136
- const [cards, setCards] = useState(null);
137
- const [items, setItems] = useState();
138
- const [containers, setContainers] = useState();
139
-
140
- useEffect(() => {
141
-
142
- if (loadedUser)
143
- {
144
- const fetchData = async () => {
145
-
146
- let response = await apiService().get("/Kanban/GetKanban");
147
- if (response != null && response.status == 200)
148
- {
149
- let containers = [];
150
- let initItems = response.data;
151
- let cardNames = [];
152
- let container = {};
153
-
154
- initItems.forEach(element => {
155
-
156
- containers.push(element.id);
157
-
158
- let cards = [];
159
- element.cards.forEach((card) => {
160
- cards.push(card.id);
161
- cardNames.push(card);
162
- });
163
-
164
- container[element.id] = cards;
165
- });
166
-
167
- setInitItems(initItems);
168
- setCards(cardNames);
169
- setItems(container);
170
- setContainers(containers);
171
- }
172
- }
173
- fetchData();
174
- }
175
-
176
- }, [loadedUser]);
177
-
178
- const getContainerName = (containerId) => {
179
-
180
- let name = "";
181
- initItems.forEach(element => {
182
- if (containerId == element.id)
183
- {
184
- name = element.name;
185
- }
186
- });
187
-
188
- return name;
189
- }
190
-
191
- const getCardName = (cardId) => {
192
-
193
- let name = "";
194
- if (cards != null)
195
- {
196
- cards.forEach(card => {
197
- if (cardId == card.id)
198
- {
199
- name = card.name;
200
- }
201
- });
202
- }
203
-
204
- return name;
205
- }
206
-
207
- const getCardDetails = (cardId) => {
208
-
209
- let cardDetail = {};
210
- if (cards != null)
211
- {
212
- cards.forEach(card => {
213
- if (cardId == card.id)
214
- {
215
- cardDetail = card;
216
- }
217
- });
218
- }
219
-
220
- return cardDetail;
221
- }
222
-
223
-
224
- const [activeId, setActiveId] = useState(null);
225
- const lastOverId = useRef(null);
226
- const recentlyMovedToNewContainer = useRef(false);
227
- const isSortingContainer = activeId ? containers.includes(activeId) : false;
228
-
229
- /**
230
- * Custom collision detection strategy optimized for multiple containers
231
- *
232
- * - First, find any droppable containers intersecting with the pointer.
233
- * - If there are none, find intersecting containers with the active draggable.
234
- * - If there are no intersecting containers, return the last matched intersection
235
- *
236
- */
237
- const collisionDetectionStrategy = useCallback(
238
- (args) => {
239
- if (activeId && activeId in items) {
240
- return closestCenter({
241
- ...args,
242
- droppableContainers: args.droppableContainers.filter(
243
- (container) => container.id in items
244
- ),
245
- });
246
- }
247
-
248
- // Start by finding any intersecting droppable
249
- const pointerIntersections = pointerWithin(args);
250
- const intersections =
251
- pointerIntersections.length > 0
252
- ? // If there are droppables intersecting with the pointer, return those
253
- pointerIntersections
254
- : rectIntersection(args);
255
- let overId = getFirstCollision(intersections, 'id');
256
-
257
- if (overId != null) {
258
- if (overId === TRASH_ID) {
259
- // If the intersecting droppable is the trash, return early
260
- // Remove this if you're not using trashable functionality in your app
261
- return intersections;
262
- }
263
-
264
- if (overId in items) {
265
- const containerItems = items[overId];
266
-
267
- // If a container is matched and it contains items (columns 'A', 'B', 'C')
268
- if (containerItems.length > 0) {
269
- // Return the closest droppable within that container
270
- overId = closestCenter({
271
- ...args,
272
- droppableContainers: args.droppableContainers.filter(
273
- (container) =>
274
- container.id !== overId &&
275
- containerItems.includes(container.id)
276
- ),
277
- })[0]?.id;
278
- }
279
- }
280
-
281
- lastOverId.current = overId;
282
-
283
- return [{id: overId}];
284
- }
285
-
286
- // When a draggable item moves to a new container, the layout may shift
287
- // and the `overId` may become `null`. We manually set the cached `lastOverId`
288
- // to the id of the draggable item that was moved to the new container, otherwise
289
- // the previous `overId` will be returned which can cause items to incorrectly shift positions
290
- if (recentlyMovedToNewContainer.current) {
291
- lastOverId.current = activeId;
292
- }
293
-
294
- // If no droppable is matched, return the last match
295
- return lastOverId.current ? [{id: lastOverId.current}] : [];
296
- },
297
- [activeId, items]
298
- );
299
- const [clonedItems, setClonedItems] = useState(null);
300
- const sensors = useSensors(
301
- useSensor(MouseSensor, {
302
- activationConstraint: { distance: 8 }
303
- }),
304
- useSensor(TouchSensor, {
305
- activationConstraint: { distance: 8 }
306
- }),
307
- useSensor(KeyboardSensor, {
308
- coordinateGetter,
309
- activationConstraint: { distance: 8 }
310
- })
311
- );
312
- const findContainer = (id) => {
313
- if (id in items) {
314
- return id;
315
- }
316
-
317
- return Object.keys(items).find((key) => items[key].includes(id));
318
- };
319
-
320
- const getIndex = (id) => {
321
- const container = findContainer(id);
322
-
323
- if (!container) {
324
- return -1;
325
- }
326
-
327
- const index = items[container].indexOf(id);
328
-
329
- return index;
330
- };
331
-
332
- const onDragCancel = () => {
333
- if (clonedItems) {
334
- // Reset items to their original state in case items have been
335
- // Dragged across containers
336
- setItems(clonedItems);
337
- }
338
-
339
- setActiveId(null);
340
- setClonedItems(null);
341
- };
342
-
343
- useEffect(() => {
344
- requestAnimationFrame(() => {
345
- recentlyMovedToNewContainer.current = false;
346
- });
347
- }, [items]);
348
-
349
-
350
- const [anchorEl, setAnchorEl] = useState(null);
351
- const open = Boolean(anchorEl);
352
- const handleMoreClick = (event) => {
353
- setAnchorEl(event.currentTarget);
354
- };
355
- const handleMoreClose = () => {
356
- setAnchorEl(null);
357
- };
358
-
359
- return (
360
- <Box>
361
- {(loadedUser && containers != null && cards != null && items != null) &&
362
- <>
363
- <DndContext
364
- sensors={sensors}
365
- collisionDetection={collisionDetectionStrategy}
366
- measuring={{
367
- droppable: {
368
- strategy: MeasuringStrategy.Always,
369
- },
370
- }}
371
- onDragStart={({active}) => {
372
- setActiveId(active.id);
373
- setClonedItems(items);
374
- }}
375
- onDragOver={({active, over}) => {
376
- const overId = over?.id;
377
-
378
- if (overId == null || overId === TRASH_ID || active.id in items) {
379
- return;
380
- }
381
-
382
- const overContainer = findContainer(overId);
383
- const activeContainer = findContainer(active.id);
384
-
385
- if (!overContainer || !activeContainer) {
386
- return;
387
- }
388
-
389
- if (activeContainer !== overContainer) {
390
- setItems((items) => {
391
- const activeItems = items[activeContainer];
392
- const overItems = items[overContainer];
393
- const overIndex = overItems.indexOf(overId);
394
- const activeIndex = activeItems.indexOf(active.id);
395
-
396
- let newIndex;
397
-
398
- if (overId in items) {
399
- newIndex = overItems.length + 1;
400
- } else {
401
- const isBelowOverItem =
402
- over &&
403
- active.rect.current.translated &&
404
- active.rect.current.translated.top >
405
- over.rect.top + over.rect.height;
406
-
407
- const modifier = isBelowOverItem ? 1 : 0;
408
-
409
- newIndex =
410
- overIndex >= 0 ? overIndex + modifier : overItems.length + 1;
411
- }
412
-
413
- recentlyMovedToNewContainer.current = true;
414
-
415
- return {
416
- ...items,
417
- [activeContainer]: items[activeContainer].filter(
418
- (item) => item !== active.id
419
- ),
420
- [overContainer]: [
421
- ...items[overContainer].slice(0, newIndex),
422
- items[activeContainer][activeIndex],
423
- ...items[overContainer].slice(
424
- newIndex,
425
- items[overContainer].length
426
- ),
427
- ],
428
- };
429
- });
430
- }
431
- }}
432
- onDragEnd={({active, over}) => {
433
- if (active.id in items && over?.id) {
434
- setContainers((containers) => {
435
- const activeIndex = containers.indexOf(active.id);
436
- const overIndex = containers.indexOf(over.id);
437
-
438
- let array = arrayMove(containers, activeIndex, overIndex);
439
-
440
- apiService().put("/Kanban/SetColumnOrder", {
441
- columnsIds: array
442
- });
443
-
444
- return array;
445
- });
446
- }
447
-
448
- const activeContainer = findContainer(active.id);
449
-
450
- if (!activeContainer) {
451
- setActiveId(null);
452
- return;
453
- }
454
-
455
- const overId = over?.id;
456
-
457
- if (overId == null) {
458
- setActiveId(null);
459
- return;
460
- }
461
-
462
- if (overId === TRASH_ID) {
463
- setItems((items) => ({
464
- ...items,
465
- [activeContainer]: items[activeContainer].filter(
466
- (id) => id !== activeId
467
- ),
468
- }));
469
- setActiveId(null);
470
- return;
471
- }
472
-
473
- if (overId === PLACEHOLDER_ID) {
474
- const newContainerId = getNextContainerId();
475
-
476
- unstable_batchedUpdates(() => {
477
- setContainers((containers) => [...containers, newContainerId]);
478
- setItems((items) => ({
479
- ...items,
480
- [activeContainer]: items[activeContainer].filter(
481
- (id) => id !== activeId
482
- ),
483
- [newContainerId]: [active.id],
484
- }));
485
- setActiveId(null);
486
- });
487
- return;
488
- }
489
-
490
- const overContainer = findContainer(overId);
491
-
492
- if (overContainer) {
493
-
494
- // you can't get the item from the key in an array, you need to search for it
495
-
496
- var name = getContainerName(overContainer);
497
-
498
- //alert(activeContainer + " \n" + overContainer)
499
-
500
- const activeIndex = items[activeContainer].indexOf(active.id);
501
- const overIndex = items[overContainer].indexOf(overId);
502
-
503
- //alert(activeIndex + " - " + active.id + " !== " + overId + " - " + overIndex)
504
-
505
-
506
-
507
- if (activeIndex !== overIndex) {
508
-
509
- let newArray = arrayMove(
510
- items[overContainer],
511
- activeIndex,
512
- overIndex
513
- );
514
-
515
- setItems((items) => ({
516
- ...items,
517
- [overContainer]: newArray,
518
- }));
519
-
520
- // get the items we need to rearrange
521
- // alert(JSON.stringify(newArray))
522
-
523
- apiService().put("/Kanban/AssignCardsBasedOnOrder", {
524
- cardId: active.id,
525
- columnId: overContainer,
526
- cards: newArray
527
- });
528
-
529
- }
530
- else
531
- {
532
- // assign the order of the cards
533
- apiService().put("/Kanban/AssignColumnForCard", {
534
- columnId: overContainer,
535
- cardId: active.id,
536
- orderId: 0
537
- });
538
- }
539
- }
540
-
541
- setActiveId(null);
542
- }}
543
- cancelDrop={cancelDrop}
544
- onDragCancel={onDragCancel}
545
- modifiers={modifiers}
546
- >
547
- <div
548
- style={{
549
- display: 'inline-grid',
550
- boxSizing: 'border-box',
551
- padding: 20,
552
- gridAutoFlow: vertical ? 'row' : 'column',
553
- }}
554
- >
555
- <SortableContext
556
- items={[...containers, PLACEHOLDER_ID]}
557
- strategy={
558
- vertical
559
- ? verticalListSortingStrategy
560
- : horizontalListSortingStrategy
561
- }
562
- >
563
- {containers.map((containerId) => {
564
-
565
- let containerName = getContainerName(containerId);
566
-
567
- return (
568
- <DroppableContainer
569
- key={containerId}
570
- id={containerId}
571
- label={containerName}
572
- columns={columns}
573
- items={items[containerId]}
574
- scrollable={scrollable}
575
- style={containerStyle}
576
- unstyled={minimal}
577
- onRemove={() => handleRemove(containerId)}
578
- >
579
- <SortableContext items={items[containerId]} strategy={strategy}>
580
- {items[containerId].map((value, index) => {
581
-
582
- return (
583
- <SortableItem
584
- disabled={isSortingContainer}
585
- key={value}
586
- id={value}
587
- cardDetail={getCardDetails(value)}
588
- CardTemplate={CardTemplate}
589
- handleMoreClick={handleMoreClick}
590
- handleMoreClose={handleMoreClose}
591
- name={getCardName(value)}
592
- index={index}
593
- handle={handle}
594
- style={getItemStyles}
595
- wrapperStyle={wrapperStyle}
596
- renderItem={renderItem}
597
- containerId={containerId}
598
- getIndex={getIndex}
599
- />
600
- );
601
- })}
602
- </SortableContext>
603
- </DroppableContainer>
604
- )})}
605
- {minimal ? undefined : (
606
- <DroppableContainer
607
- id={PLACEHOLDER_ID}
608
- disabled={isSortingContainer}
609
- items={empty}
610
- onClick={handleAddColumn}
611
- placeholder
612
- >
613
- + Add column
614
- </DroppableContainer>
615
- )}
616
- </SortableContext>
617
-
618
-
619
-
620
- </div>
621
- {createPortal(
622
- <DragOverlay adjustScale={adjustScale} dropAnimation={dropAnimation}>
623
- {activeId
624
- ? containers.includes(activeId)
625
- ? renderContainerDragOverlay(CardTemplate, activeId)
626
- : renderSortableItemDragOverlay(CardTemplate, activeId)
627
- : null}
628
- </DragOverlay>,
629
- document.body
630
- )}
631
- {trashable && activeId && !containers.includes(activeId) ? (
632
- <Trash id={TRASH_ID} />
633
- ) : null}
634
- </DndContext>
635
- {Menu != null &&
636
- <Menu anchorEl={anchorEl} open={open} handleMoreClose={handleMoreClose} />
637
- }
638
- </>
639
- }
640
- </Box>
641
- );
642
-
643
- function renderSortableItemDragOverlay(CardTemplate, id) {
644
- return (
645
- <Item
646
- value={id}
647
- name={getCardName(id)}
648
- cardDetail={getCardDetails(id)}
649
- CardTemplate={CardTemplate}
650
- handle={handle}
651
- style={getItemStyles({
652
- containerId: findContainer(id),
653
- overIndex: -1,
654
- index: getIndex(id),
655
- value: id,
656
- isSorting: true,
657
- isDragging: true,
658
- isDragOverlay: true,
659
- })}
660
- color={getColor(id)}
661
- wrapperStyle={wrapperStyle({index: 0})}
662
- renderItem={renderItem}
663
- dragOverlay
664
- />
665
- );
666
- }
667
-
668
- function renderContainerDragOverlay(CardTemplate, containerId) {
669
- return (
670
- <Container
671
- label={getContainerName(containerId)}
672
- columns={columns}
673
- style={{
674
- height: '100%',
675
- paddingRight:"10px"
676
- }}
677
- shadow
678
- unstyled={false}
679
- >
680
- {items[containerId].map((item, index) => (
681
- <Item
682
- key={item}
683
- value={item}
684
- CardTemplate={CardTemplate}
685
- cardDetail={getCardDetails(item)}
686
- name={getCardName(item)}
687
- handle={handle}
688
- style={getItemStyles({
689
- containerId,
690
- overIndex: -1,
691
- index: getIndex(item),
692
- value: item,
693
- isDragging: false,
694
- isSorting: false,
695
- isDragOverlay: false,
696
- })}
697
- color={getColor(item)}
698
- wrapperStyle={wrapperStyle({index})}
699
- renderItem={renderItem}
700
- />
701
- ))}
702
- </Container>
703
- );
704
- }
705
-
706
- function handleRemove(containerID) {
707
- setContainers((containers) =>
708
- containers.filter((id) => id !== containerID)
709
- );
710
- }
711
-
712
- function handleAddColumn() {
713
- const newContainerId = getNextContainerId();
714
-
715
- unstable_batchedUpdates(() => {
716
- setContainers((containers) => [...containers, newContainerId]);
717
- setItems((items) => ({
718
- ...items,
719
- [newContainerId]: [],
720
- }));
721
- });
722
- }
723
-
724
- function getNextContainerId() {
725
- const containerIds = Object.keys(items);
726
- const lastContainerId = containerIds[containerIds.length - 1];
727
-
728
- return String.fromCharCode(lastContainerId.charCodeAt(0) + 1);
729
- }
730
- }
731
-
732
-
733
- function getColor(id) {
734
- switch (String(id)[0]) {
735
- case 'A':
736
- return '#7193f1';
737
- case 'B':
738
- return '#ffda6c';
739
- case 'C':
740
- return '#00bcd4';
741
- case 'D':
742
- return '#ef769f';
743
- }
744
-
745
- return undefined;
746
- }
747
-
748
- function Trash({id}) {
749
- const {setNodeRef, isOver} = useDroppable({
750
- id,
751
- });
752
-
753
- return (
754
- <div
755
- ref={setNodeRef}
756
- style={{
757
- display: 'flex',
758
- alignItems: 'center',
759
- justifyContent: 'center',
760
- position: 'fixed',
761
- left: '50%',
762
- marginLeft: -150,
763
- bottom: 20,
764
- width: 300,
765
- height: 60,
766
- borderRadius: 5,
767
- border: '1px solid',
768
- borderColor: isOver ? 'red' : '#DDD',
769
- }}
770
- >
771
- Drop here to delete
772
- </div>
773
- );
774
- }
775
-
776
- function SortableItem({
777
- disabled,
778
- id,
779
- index,
780
- handle,
781
- name,
782
- renderItem,
783
- CardTemplate,
784
- cardDetail,
785
- handleMoreClick,
786
- handleMoreClose,
787
- style,
788
- containerId,
789
- getIndex,
790
- wrapperStyle,
791
- }) {
792
- const {
793
- setNodeRef,
794
- setActivatorNodeRef,
795
- listeners,
796
- isDragging,
797
- isSorting,
798
- over,
799
- overIndex,
800
- transform,
801
- transition,
802
- } = useSortable({
803
- id,
804
- });
805
- const mounted = useMountStatus();
806
- const mountedWhileDragging = isDragging && !mounted;
807
-
808
- return (
809
- <Item
810
- ref={disabled ? undefined : setNodeRef}
811
- value={id}
812
- dragging={isDragging}
813
- sorting={isSorting}
814
- cardDetail={cardDetail}
815
- CardTemplate={CardTemplate}
816
- handleMoreClick={handleMoreClick}
817
- handleMoreClose={handleMoreClose}
818
- name={name}
819
- handle={handle}
820
- handleProps={handle ? {ref: setActivatorNodeRef} : undefined}
821
- index={index}
822
- wrapperStyle={wrapperStyle({index})}
823
- style={style({
824
- index,
825
- value: id,
826
- isDragging,
827
- isSorting,
828
- overIndex: over ? getIndex(over.id) : overIndex,
829
- containerId,
830
- })}
831
- color={getColor(id)}
832
- transition={transition}
833
- transform={transform}
834
- fadeIn={mountedWhileDragging}
835
- listeners={listeners}
836
- renderItem={renderItem}
837
- />
838
- );
839
- }
840
-
841
- function useMountStatus() {
842
- const [isMounted, setIsMounted] = useState(false);
843
-
844
- useEffect(() => {
845
- const timeout = setTimeout(() => setIsMounted(true), 500);
846
-
847
- return () => clearTimeout(timeout);
848
- }, []);
849
-
850
- return isMounted;
851
- }