playbook_ui 14.20.0.pre.alpha.PLAY22297981 → 14.20.0.pre.alpha.play2168firstcolumnborderbug7988
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_advanced_table/_advanced_table.scss +18 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.jsx +5 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.html.erb +1 -1
- data/app/pb_kits/playbook/pb_checkbox/checkbox.html.erb +8 -12
- data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +3 -6
- data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_indeterminate.html.erb +2 -48
- data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_indeterminate_rails.md +1 -0
- data/app/pb_kits/playbook/pb_checkbox/index.js +56 -0
- data/app/pb_kits/playbook/pb_popover/index.ts +4 -9
- data/dist/chunks/{_typeahead-DsBjTkC_.js → _typeahead-CRW6dJbW.js} +1 -1
- data/dist/chunks/{_weekday_stacked-P46uSudZ.js → _weekday_stacked-DoXl8xrB.js} +2 -2
- data/dist/chunks/{lib-D7Va7yqa.js → lib-D5R1BjUn.js} +1 -1
- data/dist/chunks/{pb_form_validation-DSkdRDMf.js → pb_form_validation-BZ2AVAi_.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +1 -1
- data/dist/playbook-doc.js +1 -1
- 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/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f7067bfc157238eeed0411dd4b7a72a2a147c63a0351d56ce847ddf99ff341e
|
4
|
+
data.tar.gz: b9eac90295c410baff2682a428b5474e5253718513e7b4d67e7586e1178f0725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd89e4bdb8529b2cb909479f5d93dcc523059333930c977d23db6cea56d23431818ffb68ff2aadef3a31f0622b47dcddac9c68f8fe6fb6d2b280ebe18547d89
|
7
|
+
data.tar.gz: 6bba82a8c0f4c84a56597e5b3cfe85461fa9c65adcfac0c39c31a699502d09d284c48285e844be9c845aaa30655b04fc30af3f3cd1c8ad203747cd893f0ad581
|
@@ -87,6 +87,16 @@
|
|
87
87
|
}
|
88
88
|
}
|
89
89
|
|
90
|
+
&.advanced-table-hide-scrollbar {
|
91
|
+
&::-webkit-scrollbar {
|
92
|
+
display: none !important;
|
93
|
+
}
|
94
|
+
|
95
|
+
-ms-overflow-style: none !important;
|
96
|
+
scrollbar-width: none !important;
|
97
|
+
}
|
98
|
+
|
99
|
+
|
90
100
|
.row-selection-actions-card {
|
91
101
|
border-bottom-right-radius: 0px !important;
|
92
102
|
border-bottom-left-radius: 0px !important;
|
@@ -368,6 +378,10 @@
|
|
368
378
|
box-shadow: 1px 0px 0px 0px var(--column-border-color) !important;
|
369
379
|
}
|
370
380
|
|
381
|
+
.pb_table_td:nth-child(2) {
|
382
|
+
box-shadow: inset 1px 0px 0px 0px var(--column-border-color) !important;
|
383
|
+
}
|
384
|
+
|
371
385
|
// Color for collapsible trail
|
372
386
|
.collapsible-trail {
|
373
387
|
background-color: $border_light !important;
|
@@ -564,6 +578,10 @@
|
|
564
578
|
box-shadow: $shadow_deep !important;
|
565
579
|
}
|
566
580
|
|
581
|
+
.pb_table_td:nth-child(2) {
|
582
|
+
box-shadow: 0 0 0 0 !important;
|
583
|
+
}
|
584
|
+
|
567
585
|
.pb_advanced_table_header,
|
568
586
|
.pb_advanced_table_body {
|
569
587
|
th.sticky-left,
|
@@ -53,6 +53,7 @@ type AdvancedTableProps = {
|
|
53
53
|
pagination?: boolean,
|
54
54
|
paginationProps?: GenericObject
|
55
55
|
responsive?: "scroll" | "none",
|
56
|
+
scrollBarNone?: boolean,
|
56
57
|
selectableRows?: boolean,
|
57
58
|
showActionsBar?: boolean,
|
58
59
|
sortControl?: GenericObject
|
@@ -92,6 +93,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
92
93
|
pagination = false,
|
93
94
|
paginationProps,
|
94
95
|
responsive = "scroll",
|
96
|
+
scrollBarNone= false,
|
95
97
|
showActionsBar = true,
|
96
98
|
selectableRows,
|
97
99
|
sortControl,
|
@@ -245,6 +247,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
245
247
|
},
|
246
248
|
{'advanced-table-sticky-left-columns': stickyLeftColumn && stickyLeftColumn.length > 0},
|
247
249
|
columnGroupBorderColor ? `column-group-border-${columnGroupBorderColor}` : '',
|
250
|
+
scrollBarNone ? 'advanced-table-hide-scrollbar' : '',
|
248
251
|
globalProps(props),
|
249
252
|
className
|
250
253
|
);
|
@@ -39,9 +39,13 @@ const AdvancedTableDefault = (props) => {
|
|
39
39
|
<div>
|
40
40
|
<AdvancedTable
|
41
41
|
columnDefinitions={columnDefinitions}
|
42
|
+
maxHeight="xs"
|
43
|
+
overflow="auto"
|
44
|
+
responsive="scroll"
|
45
|
+
scrollBarNone
|
42
46
|
tableData={MOCK_DATA}
|
43
47
|
{...props}
|
44
|
-
|
48
|
+
/>
|
45
49
|
</div>
|
46
50
|
)
|
47
51
|
}
|
@@ -30,4 +30,4 @@
|
|
30
30
|
}
|
31
31
|
] %>
|
32
32
|
|
33
|
-
<%= pb_rails("advanced_table", props: { id: "table_props_table", table_data: @table_data, column_definitions: column_definitions
|
33
|
+
<%= pb_rails("advanced_table", props: { id: "table_props_table", table_data: @table_data, column_definitions: column_definitions responsive }) %>
|
@@ -1,16 +1,12 @@
|
|
1
|
-
<%= pb_content_tag(:label
|
1
|
+
<%= pb_content_tag(:label, data: {
|
2
|
+
pb_checkbox_indeterminate_main: object.indeterminate_main,
|
3
|
+
pb_checkbox_indeterminate_parent: object.indeterminate_parent,
|
4
|
+
}) do %>
|
2
5
|
<%= content.presence || object.input %>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
</span>
|
8
|
-
<% else %>
|
9
|
-
<span data-pb-checkbox-icon-span="true" class="pb_checkbox_checkmark">
|
10
|
-
<%= pb_rails("icon", props: { icon: "check", classname: "check_icon", fixed_width: true}) %>
|
11
|
-
<%= pb_rails("icon", props: { icon: "minus", classname: "indeterminate_icon hidden", fixed_width: true}) %>
|
12
|
-
</span>
|
13
|
-
<% end %>
|
6
|
+
<span data-pb-checkbox-icon-span="true" class="pb_checkbox_checkmark">
|
7
|
+
<%= pb_rails("icon", props: { icon: "check", classname: "check_icon", fixed_width: true}) %>
|
8
|
+
<%= pb_rails("icon", props: { icon: "minus", classname: "indeterminate_icon hidden", fixed_width: true}) %>
|
9
|
+
</span>
|
14
10
|
<span class="pb_checkbox_label">
|
15
11
|
<%= pb_rails("body", props: { status: object.checkbox_label_status, text: object.text, dark: object.dark, margin_right: object.form_spacing ? "xs" : "" }) %>
|
16
12
|
</span>
|
@@ -5,7 +5,8 @@ module Playbook
|
|
5
5
|
class Checkbox < Playbook::KitBase
|
6
6
|
prop :error, type: Playbook::Props::Boolean, default: false
|
7
7
|
prop :checked, type: Playbook::Props::Boolean, default: false
|
8
|
-
prop :
|
8
|
+
prop :indeterminate_main, type: Playbook::Props::Boolean, default: false
|
9
|
+
prop :indeterminate_parent
|
9
10
|
prop :text
|
10
11
|
prop :value
|
11
12
|
prop :name
|
@@ -19,7 +20,7 @@ module Playbook
|
|
19
20
|
default: false
|
20
21
|
|
21
22
|
def classname
|
22
|
-
generate_classname("pb_checkbox_kit", checked_class) +
|
23
|
+
generate_classname("pb_checkbox_kit", checked_class) + error_class
|
23
24
|
end
|
24
25
|
|
25
26
|
def input
|
@@ -39,10 +40,6 @@ module Playbook
|
|
39
40
|
def checked_class
|
40
41
|
checked ? "on" : "off"
|
41
42
|
end
|
42
|
-
|
43
|
-
def indeterminate_class
|
44
|
-
indeterminate ? " indeterminate" : ""
|
45
|
-
end
|
46
43
|
end
|
47
44
|
end
|
48
45
|
end
|
@@ -9,11 +9,10 @@
|
|
9
9
|
<tr>
|
10
10
|
<th>
|
11
11
|
<%= pb_rails("checkbox", props: {
|
12
|
-
checked: true,
|
13
12
|
text: "Uncheck All",
|
14
13
|
value: "checkbox-value",
|
15
14
|
name: "main-checkbox",
|
16
|
-
|
15
|
+
indeterminate_main: true,
|
17
16
|
id: "indeterminate-checkbox"
|
18
17
|
}) %>
|
19
18
|
</th>
|
@@ -30,55 +29,10 @@
|
|
30
29
|
value: checkbox[:id],
|
31
30
|
name: "#{checkbox[:id]}-indeterminate-checkbox",
|
32
31
|
id: "#{checkbox[:id]}-indeterminate-checkbox",
|
32
|
+
indeterminate_parent: "indeterminate-checkbox",
|
33
33
|
}) %>
|
34
34
|
</td>
|
35
35
|
</tr>
|
36
36
|
<% end %>
|
37
37
|
</tbody>
|
38
38
|
<% end %>
|
39
|
-
|
40
|
-
<script>
|
41
|
-
document.addEventListener('DOMContentLoaded', function() {
|
42
|
-
const mainCheckboxWrapper = document.getElementById('indeterminate-checkbox');
|
43
|
-
const mainCheckbox = document.getElementsByName("main-checkbox")[0];
|
44
|
-
const childCheckboxes = document.querySelectorAll('input[type="checkbox"][id$="indeterminate-checkbox"]');
|
45
|
-
|
46
|
-
const updateMainCheckbox = () => {
|
47
|
-
// Count the number of checked child checkboxes
|
48
|
-
const checkedCount = Array.from(childCheckboxes).filter(cb => cb.checked).length;
|
49
|
-
// Determine if the main checkbox should be in an indeterminate state
|
50
|
-
const indeterminate = checkedCount > 0 && checkedCount < childCheckboxes.length;
|
51
|
-
|
52
|
-
// Set the main checkbox states
|
53
|
-
mainCheckbox.indeterminate = indeterminate;
|
54
|
-
mainCheckbox.checked = checkedCount > 0;
|
55
|
-
|
56
|
-
// Determine the main checkbox label based on the number of checked checkboxes
|
57
|
-
const text = checkedCount === 0 ? 'Check All' : 'Uncheck All';
|
58
|
-
|
59
|
-
// Determine the icon class to add and remove based on the number of checked checkboxes
|
60
|
-
const iconClassToAdd = checkedCount === 0 ? 'pb_checkbox_checkmark' : 'pb_checkbox_indeterminate';
|
61
|
-
const iconClassToRemove = checkedCount === 0 ? 'pb_checkbox_indeterminate' : 'pb_checkbox_checkmark';
|
62
|
-
|
63
|
-
// Update main checkbox label
|
64
|
-
mainCheckboxWrapper.getElementsByClassName('pb_body_kit')[0].textContent = text;
|
65
|
-
|
66
|
-
// Add and remove the icon class to the main checkbox wrapper
|
67
|
-
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.add(iconClassToAdd);
|
68
|
-
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.remove(iconClassToRemove);
|
69
|
-
|
70
|
-
// Toggle the visibility of the checkbox icon based on the indeterminate state
|
71
|
-
mainCheckboxWrapper.getElementsByClassName("indeterminate_icon")[0].classList.toggle('hidden', !indeterminate);
|
72
|
-
mainCheckboxWrapper.getElementsByClassName("check_icon")[0].classList.toggle('hidden', indeterminate);
|
73
|
-
};
|
74
|
-
|
75
|
-
mainCheckbox.addEventListener('change', function() {
|
76
|
-
childCheckboxes.forEach(cb => cb.checked = this.checked);
|
77
|
-
updateMainCheckbox();
|
78
|
-
});
|
79
|
-
|
80
|
-
childCheckboxes.forEach(cb => {
|
81
|
-
cb.addEventListener('change', updateMainCheckbox);
|
82
|
-
});
|
83
|
-
});
|
84
|
-
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
If you want to use indeterminate, "check/uncheck all" checkboxes, add `indeterminate_main: true` and an `id` to the main checkbox. Then, add an `indeterminate_parent` prop with the main checkbox's `id` to the children checkboxes.
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import PbEnhancedElement from "../pb_enhanced_element"
|
2
|
+
|
3
|
+
const INDETERMINATE_MAIN_CHECKBOX_SELECTOR = "[data-pb-checkbox-indeterminate-main='true']"
|
4
|
+
|
5
|
+
export default class PbCheckbox extends PbEnhancedElement {
|
6
|
+
static get selector() {
|
7
|
+
return INDETERMINATE_MAIN_CHECKBOX_SELECTOR
|
8
|
+
}
|
9
|
+
|
10
|
+
connect() {
|
11
|
+
const mainCheckboxWrapper = this.element;
|
12
|
+
const mainCheckbox = mainCheckboxWrapper.querySelector('input')
|
13
|
+
const childCheckboxes = document.querySelectorAll(`[data-pb-checkbox-indeterminate-parent="${this.element.id}"] input[type="checkbox"]`);
|
14
|
+
|
15
|
+
const updateMainCheckbox = () => {
|
16
|
+
// Count the number of checked child checkboxes
|
17
|
+
const checkedCount = Array.from(childCheckboxes).filter(cb => cb.checked).length;
|
18
|
+
// Determine if the main checkbox should be in an indeterminate state
|
19
|
+
const indeterminate = checkedCount > 0 && checkedCount < childCheckboxes.length;
|
20
|
+
|
21
|
+
// Set the main checkbox states
|
22
|
+
mainCheckbox.indeterminate = indeterminate;
|
23
|
+
mainCheckbox.checked = checkedCount > 0;
|
24
|
+
|
25
|
+
// Determine the main checkbox label based on the number of checked checkboxes
|
26
|
+
const text = checkedCount === 0 ? 'Check All' : 'Uncheck All';
|
27
|
+
|
28
|
+
// Determine the icon class to add and remove based on the number of checked checkboxes
|
29
|
+
const iconClassToAdd = checkedCount === 0 ? 'pb_checkbox_checkmark' : 'pb_checkbox_indeterminate';
|
30
|
+
const iconClassToRemove = checkedCount === 0 ? 'pb_checkbox_indeterminate' : 'pb_checkbox_checkmark';
|
31
|
+
|
32
|
+
// Update main checkbox label
|
33
|
+
mainCheckboxWrapper.getElementsByClassName('pb_body_kit')[0].textContent = text;
|
34
|
+
|
35
|
+
// Add and remove the icon class to the main checkbox wrapper
|
36
|
+
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.add(iconClassToAdd);
|
37
|
+
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.remove(iconClassToRemove);
|
38
|
+
|
39
|
+
// Toggle the visibility of the checkbox icon based on the indeterminate state
|
40
|
+
mainCheckboxWrapper.getElementsByClassName("indeterminate_icon")[0].classList.toggle('hidden', !indeterminate);
|
41
|
+
mainCheckboxWrapper.getElementsByClassName("check_icon")[0].classList.toggle('hidden', indeterminate);
|
42
|
+
};
|
43
|
+
|
44
|
+
// Set indeterminate icon on main checkbox if initial children checkboxes are checked
|
45
|
+
updateMainCheckbox();
|
46
|
+
|
47
|
+
this.element.querySelector('input').addEventListener('change', function() {
|
48
|
+
childCheckboxes.forEach(cb => cb.checked = this.checked);
|
49
|
+
updateMainCheckbox();
|
50
|
+
});
|
51
|
+
|
52
|
+
childCheckboxes.forEach(cb => {
|
53
|
+
cb.addEventListener('change', updateMainCheckbox);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
@@ -13,24 +13,19 @@ export default class PbPopover extends PbEnhancedElement {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
moveTooltip() {
|
16
|
-
let container: HTMLElement | null
|
16
|
+
let container: HTMLElement | null;
|
17
17
|
|
18
18
|
if (this.appendTo === "parent") {
|
19
|
-
container = this.element.parentElement
|
19
|
+
container = this.element.parentElement;
|
20
20
|
} else if (this.appendTo) {
|
21
|
-
container = document.querySelector(this.appendTo)
|
21
|
+
container = document.querySelector(this.appendTo);
|
22
22
|
}
|
23
23
|
|
24
|
-
container.appendChild(this.tooltip);
|
24
|
+
(container || document.body).appendChild(this.tooltip);
|
25
25
|
}
|
26
26
|
|
27
27
|
connect() {
|
28
|
-
if (!this.triggerElement || !this.tooltip) {
|
29
|
-
console.warn('Popover requires both trigger and tooltip elements to be defined.')
|
30
|
-
return
|
31
|
-
}
|
32
28
|
this.moveTooltip()
|
33
|
-
|
34
29
|
this.popper = createPopper (this.triggerElement, this.tooltip, {
|
35
30
|
placement: this.position as Placement,
|
36
31
|
strategy: 'fixed',
|
@@ -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,useRef,useState,useEffect,useMemo,useContext,createElement,forwardRef,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{t as getDefaultExportFromCjs,w as filter,x as omit,r as noop$2,u as useCollapsible,y as createPopper,z as uniqueId,A as get,B as offset$2,C as shift$2,E as flip$2,F as computePosition$1,G as arrow$3,H as createCoords$1,I as round$1,J as max$1,K as min$1,L as rectToClientRect$1,j as getAllIcons,v as commonjsGlobal,s as colors$1,M as highchartsTheme,N as merge,O as highchartsDarkTheme,Q as getAugmentedNamespace,S as typography,T as cloneDeep,m as isEmpty$1,U as isString}from"./lib-
|
1
|
+
import{jsx as jsx$1,Fragment,jsxs}from"react/jsx-runtime";import*as React from"react";import React__default,{createContext,useReducer,useRef,useState,useEffect,useMemo,useContext,createElement,forwardRef,useLayoutEffect,useCallback,useImperativeHandle,Component,Fragment as Fragment$1}from"react";import{t as getDefaultExportFromCjs,w as filter,x as omit,r as noop$2,u as useCollapsible,y as createPopper,z as uniqueId,A as get,B as offset$2,C as shift$2,E as flip$2,F as computePosition$1,G as arrow$3,H as createCoords$1,I as round$1,J as max$1,K as min$1,L as rectToClientRect$1,j as getAllIcons,v as commonjsGlobal,s as colors$1,M as highchartsTheme,N as merge,O as highchartsDarkTheme,Q as getAugmentedNamespace,S as typography,T as cloneDeep,m as isEmpty$1,U as isString}from"./lib-D5R1BjUn.js";import*as ReactDOM from"react-dom";import ReactDOM__default,{createPortal}from"react-dom";import{TrixEditor}from"react-trix";import Trix from"trix";import require$$0 from"react-is";const initialState={items:[],dragData:{id:"",initialGroup:""},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 targetItem=newItems.find((item=>item.id===targetId));if(!draggedItem||!targetItem||draggedItem.container!==targetItem.container){return state}if(dragId===targetId){return state}const draggedIndex=newItems.findIndex((item=>item.id===dragId));const targetIndex=newItems.findIndex((item=>item.id===targetId));if(draggedIndex===-1||targetIndex===-1){return state}newItems.splice(draggedIndex,1);newItems.splice(targetIndex,0,draggedItem);return{...state,items:newItems}}default:return state}};const DragContext=createContext({});const DraggableContext=()=>{const context=useContext(DragContext);if(context===void 0){throw new Error("DraggableContext must be used within a DraggableProvider")}return context};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"}})=>{const[state,dispatch]=useReducer(reducer,initialState);const initialItemsRef=useRef(initialItems);const[isDragging,setIsDragging]=useState(false);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});initialItemsRef.current=initialItems}),[initialItems]);useEffect((()=>{if(onReorder){onReorder(state.items)}}),[state.items,onReorder]);const handleDragStart=(id,container)=>{setIsDragging(true);dispatch({type:"SET_DRAG_DATA",payload:{id:id,initialGroup:container}});dispatch({type:"SET_IS_DRAGGING",payload:id});dispatch({type:"SET_ACTIVE_CONTAINER",payload:container});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(!isDragging||container!==state.activeContainer)return;if(state.dragData.id===id)return;const draggedItem=state.items.find((item=>item.id===state.dragData.id));const targetItem=state.items.find((item=>item.id===id));if(!draggedItem||!targetItem||draggedItem.container!==targetItem.container){return}dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}});if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{setIsDragging(false);dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});if(onDragEnd)onDragEnd()};const handleDrop=container=>{const draggedItem=state.items.find((item=>item.id===state.dragData.id));if(draggedItem&&draggedItem.container!==container){dispatch({type:"CHANGE_CATEGORY",payload:{itemId:state.dragData.id,container:container}})}dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});setIsDragging(false);if(onDrop)onDrop(container)};const handleDragOver=(e,container)=>{e.preventDefault();e.stopPropagation();dispatch({type:"SET_ACTIVE_CONTAINER",payload: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,handleDragStart,handleDragEnter,handleDragEnd,handleDrop,handleDragOver]);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
|