playbook_ui 14.21.2.pre.alpha.PLAY21898327 → 14.21.2.pre.alpha.PLAY22558410

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +4 -1
  3. data/app/pb_kits/playbook/pb_advanced_table/Components/RegularTableView.tsx +8 -0
  4. data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableState.ts +30 -5
  5. data/app/pb_kits/playbook/pb_advanced_table/Utilities/CellRendererUtils.tsx +4 -1
  6. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +4 -0
  7. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +25 -1
  8. data/app/pb_kits/playbook/pb_advanced_table/advanced_table_action_bar.js +36 -0
  9. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_pinned_rows.jsx +1 -1
  10. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_pinned_rows_react.md +5 -3
  11. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling.jsx +64 -0
  12. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling.md +7 -0
  13. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +1 -0
  14. data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +1 -0
  15. data/app/pb_kits/playbook/pb_advanced_table/flat_advanced_table.js +60 -84
  16. data/app/pb_kits/playbook/pb_advanced_table/index.js +114 -223
  17. data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.html.erb +1 -1
  18. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_blank_selection.html.erb +3 -3
  19. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_blank_selection.jsx +7 -4
  20. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.jsx +6 -3
  21. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +6 -3
  22. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default_rails.html.erb +3 -3
  23. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default_value.html.erb +3 -3
  24. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default_value.jsx +7 -4
  25. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.html.erb +3 -3
  26. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_error.jsx +7 -4
  27. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select.jsx +19 -10
  28. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display.jsx +19 -10
  29. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display_rails.html.erb +10 -10
  30. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_rails.html.erb +10 -10
  31. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_autocomplete.html.erb +10 -10
  32. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_autocomplete.jsx +20 -11
  33. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_custom_options.html.erb +3 -3
  34. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_custom_options.jsx +8 -8
  35. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_default.html.erb +10 -10
  36. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_default.jsx +23 -14
  37. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_separators_hidden.html.erb +3 -3
  38. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_separators_hidden.jsx +6 -3
  39. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.jsx +6 -3
  40. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure_rails.html.erb +3 -3
  41. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.html.erb +3 -3
  42. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subtle_variant.jsx +6 -3
  43. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.html.erb +3 -3
  44. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +3 -3
  45. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_with_subcomponents.html.erb +4 -4
  46. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_with_subcomponents.jsx +4 -4
  47. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +4 -4
  48. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display_rails.html.erb +4 -4
  49. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_icon_options.html.erb +52 -0
  50. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_icon_options.jsx +99 -0
  51. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_icon_options_rails.md +1 -0
  52. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_icon_options_react.md +1 -0
  53. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +3 -3
  54. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options_rails.html.erb +3 -3
  55. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.html.erb +3 -3
  56. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.jsx +3 -3
  57. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_radio_options.html.erb +28 -0
  58. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_radio_options.jsx +47 -0
  59. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_radio_options_rails.md +1 -0
  60. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_radio_options_react.md +1 -0
  61. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.jsx +3 -3
  62. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger_rails.html.erb +3 -3
  63. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_external_control.jsx +3 -3
  64. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.html.erb +3 -3
  65. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.jsx +6 -3
  66. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_search.jsx +3 -3
  67. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_search_rails.html.erb +3 -3
  68. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +4 -0
  69. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +3 -1
  70. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_columns.html.erb +8 -8
  71. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_columns_rails.md +1 -1
  72. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_left_columns.html.erb +12 -12
  73. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_left_columns_rails.md +2 -2
  74. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_right_columns.html.erb +12 -12
  75. data/app/pb_kits/playbook/pb_table/docs/_table_sticky_right_columns_rails.md +2 -2
  76. data/app/pb_kits/playbook/pb_table/index.ts +4 -4
  77. data/app/pb_kits/playbook/pb_table/styles/_vertical_border.scss +4 -0
  78. data/dist/chunks/{_typeahead-BXD634Vm.js → _typeahead-B80UsDrG.js} +1 -1
  79. data/dist/chunks/_weekday_stacked-D1bqIne1.js +45 -0
  80. data/dist/chunks/{lib-9VvC3Rp0.js → lib-CTkMyvfQ.js} +1 -1
  81. data/dist/chunks/{pb_form_validation-CbyL4Bqa.js → pb_form_validation-BVF3TmcL.js} +1 -1
  82. data/dist/chunks/vendor.js +1 -1
  83. data/dist/playbook-doc.js +1 -1
  84. data/dist/playbook-rails-react-bindings.js +1 -1
  85. data/dist/playbook-rails.js +1 -1
  86. data/dist/playbook.css +1 -1
  87. data/lib/playbook/version.rb +1 -1
  88. metadata +17 -6
  89. data/dist/chunks/_weekday_stacked-BxnkrDBG.js +0 -45
@@ -1,9 +1,9 @@
1
1
  <%= pb_rails("table", props: { size: "md", responsive: "scroll", sticky_left_column: ["1", "2", "3"] }) do %>
2
2
  <thead>
3
3
  <tr>
4
- <th id="1">Column 1</th>
5
- <th id="2">Column 2</th>
6
- <th id="3">Column 3</th>
4
+ <th data-sticky-id="1">Column 1</th>
5
+ <th data-sticky-id="2">Column 2</th>
6
+ <th data-sticky-id="3">Column 3</th>
7
7
  <th>Column 4</th>
8
8
  <th>Column 5</th>
9
9
  <th>Column 6</th>
@@ -20,9 +20,9 @@
20
20
  </thead>
21
21
  <tbody>
22
22
  <tr>
23
- <td id="1">Value 1</td>
24
- <td id="2">Value 2</td>
25
- <td id="3">Value 3</td>
23
+ <td data-sticky-id="1">Value 1</td>
24
+ <td data-sticky-id="2">Value 2</td>
25
+ <td data-sticky-id="3">Value 3</td>
26
26
  <td>Value 4</td>
27
27
  <td>Value 5</td>
28
28
  <td>Value 6</td>
@@ -38,9 +38,9 @@
38
38
 
39
39
  </tr>
40
40
  <tr>
41
- <td id="1">Value 1</td>
42
- <td id="2">Value 2</td>
43
- <td id="3">Value 3</td>
41
+ <td data-sticky-id="1">Value 1</td>
42
+ <td data-sticky-id="2">Value 2</td>
43
+ <td data-sticky-id="3">Value 3</td>
44
44
  <td>Value 4</td>
45
45
  <td>Value 5</td>
46
46
  <td>Value 6</td>
@@ -56,9 +56,9 @@
56
56
 
57
57
  </tr>
58
58
  <tr>
59
- <td id="1">Value 1</td>
60
- <td id="2">Value 2</td>
61
- <td id="3">Value 3</td>
59
+ <td data-sticky-id="1">Value 1</td>
60
+ <td data-sticky-id="2">Value 2</td>
61
+ <td data-sticky-id="3">Value 3</td>
62
62
  <td>Value 4</td>
63
63
  <td>Value 5</td>
64
64
  <td>Value 6</td>
@@ -1,3 +1,3 @@
1
- The `sticky_left_column` prop expects an array of the column ids you want to be sticky. Make sure to add the corresponding id to the `<th>` and `<td>`.
1
+ The `sticky_left_column` prop expects an array of the column `data-sticky-id`s you want to be sticky. Make sure to add the corresponding `data-sticky-id` to the `<th>` and `<td>`.
2
2
 
3
- Please ensure that unique ids are used for all columns across multiple tables. Using the same columns ids on multiple tables can lead to issues when using the `sticky_left_column`.
3
+ Please ensure that unique `data-sticky-id`s are used for all columns across multiple tables. Using the same columns `data-sticky-id`s on multiple tables can lead to issues when using the `sticky_left_column`.
@@ -13,9 +13,9 @@
13
13
  <th>Column 10</th>
14
14
  <th>Column 11</th>
15
15
  <th>Column 12</th>
16
- <th id="13">Column 13</th>
17
- <th id="14">Column 14</th>
18
- <th id="15">Column 15</th>
16
+ <th data-sticky-id="13">Column 13</th>
17
+ <th data-sticky-id="14">Column 14</th>
18
+ <th data-sticky-id="15">Column 15</th>
19
19
  </tr>
20
20
  </thead>
21
21
  <tbody>
@@ -32,9 +32,9 @@
32
32
  <td>Value 10</td>
33
33
  <td>Value 11</td>
34
34
  <td>Value 12</td>
35
- <td id="13">Value 13</td>
36
- <td id="14">Value 14</td>
37
- <td id="15">Value 15</td>
35
+ <td data-sticky-id="13">Value 13</td>
36
+ <td data-sticky-id="14">Value 14</td>
37
+ <td data-sticky-id="15">Value 15</td>
38
38
  </tr>
39
39
  <tr>
40
40
  <td>Value 1</td>
@@ -49,9 +49,9 @@
49
49
  <td>Value 10</td>
50
50
  <td>Value 11</td>
51
51
  <td>Value 12</td>
52
- <td id="13">Value 13</td>
53
- <td id="14">Value 14</td>
54
- <td id="15">Value 15</td>
52
+ <td data-sticky-id="13">Value 13</td>
53
+ <td data-sticky-id="14">Value 14</td>
54
+ <td data-sticky-id="15">Value 15</td>
55
55
  </tr>
56
56
  <tr>
57
57
  <td>Value 1</td>
@@ -66,9 +66,9 @@
66
66
  <td>Value 10</td>
67
67
  <td>Value 11</td>
68
68
  <td>Value 12</td>
69
- <td id="13">Value 13</td>
70
- <td id="14">Value 14</td>
71
- <td id="15">Value 15</td>
69
+ <td data-sticky-id="13">Value 13</td>
70
+ <td data-sticky-id="14">Value 14</td>
71
+ <td data-sticky-id="15">Value 15</td>
72
72
  </tr>
73
73
  </tbody>
74
74
  <% end %>
@@ -1,3 +1,3 @@
1
- The `sticky_right_column` prop works in the same way as the above `sticky_left_column` prop. It expects an array of the column ids you want to be sticky. Make sure to add the corresponding id to the `<th>` and `<td>`.
1
+ The `sticky_right_column` prop works in the same way as the above `sticky_left_column` prop. It expects an array of the column `data-sticky-id`s you want to be sticky. Make sure to add the corresponding `data-sticky-id` to the `<th>` and `<td>`.
2
2
 
3
- Please ensure that unique ids are used for all columns across multiple tables. Using the same columns ids on multiple tables can lead to issues when using the `sticky_right_column` prop.
3
+ Please ensure that unique `data-sticky-id`s are used for all columns across multiple tables. Using the same columns `data-sticky-id`s on multiple tables can lead to issues when using the `sticky_right_column` prop.
@@ -64,8 +64,8 @@ export default class PbTable extends PbEnhancedElement {
64
64
 
65
65
  this.stickyLeftColumns.forEach((colId, index) => {
66
66
  const isLastColumn = index === this.stickyLeftColumns.length - 1;
67
- const header = this.element.querySelector(`th[id="${colId}"]`);
68
- const cells = this.element.querySelectorAll(`td[id="${colId}"]`);
67
+ const header = this.element.querySelector(`th[data-sticky-id="${colId}"]`);
68
+ const cells = this.element.querySelectorAll(`td[data-sticky-id="${colId}"]`);
69
69
 
70
70
  if (header) {
71
71
  header.classList.add('sticky');
@@ -125,8 +125,8 @@ export default class PbTable extends PbEnhancedElement {
125
125
 
126
126
  this.stickyRightColumnsReversed.forEach((colId, index) => {
127
127
  const isLastColumn = index === this.stickyRightColumns.length - 1;
128
- const header = this.element.querySelector(`th[id="${colId}"]`);
129
- const cells = this.element.querySelectorAll(`td[id="${colId}"]`);
128
+ const header = this.element.querySelector(`th[data-sticky-id="${colId}"]`);
129
+ const cells = this.element.querySelectorAll(`td[data-sticky-id="${colId}"]`);
130
130
 
131
131
  if (header) {
132
132
  header.classList.add('sticky');
@@ -4,6 +4,10 @@
4
4
  border-right: 1px solid $border_light !important;
5
5
  }
6
6
 
7
+ thead tr:not(:first-child) th {
8
+ border-right: 1px solid $border_light !important;
9
+ }
10
+
7
11
  @media screen and (min-width: $screen-xs-min) {
8
12
  tr:hover, .pb_table_tr:hover {
9
13
  td:last-child, .pb_table_td:last-child {
@@ -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{g as getDefaultExportFromCjs,v as filter,w as omit,s as noop$2,u as useCollapsible,x as createPopper,y as uniqueId,z as get,A as flip$2,B as offset$2,C as shift$2,E as arrow$3,F as computePosition$1,G as createCoords$1,H as round$1,I as max$1,J as min$1,K as rectToClientRect$1,k as getAllIcons,t as colors$1,L as highchartsTheme,M as merge,N as highchartsDarkTheme,O as getAugmentedNamespace,Q as typography,S as cloneDeep,n as isEmpty$1,T as isString}from"./lib-9VvC3Rp0.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 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}}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"}})=>{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}});dispatch({type:"SET_IS_DRAGGING",payload:id});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(state.dragData.id!==id){dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}});dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container}})}if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});if(onDragEnd)onDragEnd()};const changeCategory=(itemId,container)=>{dispatch({type:"CHANGE_CATEGORY",payload:{itemId:itemId,container:container}})};const handleDrop=container=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});changeCategory(state.dragData.id,container);if(onDrop)onDrop(container)};const handleDragOver=(e,container)=>{e.preventDefault();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]);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{g as getDefaultExportFromCjs,v as filter,w as omit,s as noop$2,u as useCollapsible,x as createPopper,y as uniqueId,z as get,A as flip$2,B as offset$2,C as shift$2,E as arrow$3,F as computePosition$1,G as createCoords$1,H as round$1,I as max$1,J as min$1,K as rectToClientRect$1,k as getAllIcons,t as colors$1,L as highchartsTheme,M as merge,N as highchartsDarkTheme,O as getAugmentedNamespace,Q as typography,S as cloneDeep,n as isEmpty$1,T as isString}from"./lib-CTkMyvfQ.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 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}}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"}})=>{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}});dispatch({type:"SET_IS_DRAGGING",payload:id});if(onDragStart)onDragStart(id,container)};const handleDragEnter=(id,container)=>{if(state.dragData.id!==id){dispatch({type:"REORDER_ITEMS",payload:{dragId:state.dragData.id,targetId:id}});dispatch({type:"SET_DRAG_DATA",payload:{id:state.dragData.id,initialGroup:container}})}if(onDragEnter)onDragEnter(id,container)};const handleDragEnd=()=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});if(onDragEnd)onDragEnd()};const changeCategory=(itemId,container)=>{dispatch({type:"CHANGE_CATEGORY",payload:{itemId:itemId,container:container}})};const handleDrop=container=>{dispatch({type:"SET_IS_DRAGGING",payload:""});dispatch({type:"SET_ACTIVE_CONTAINER",payload:""});changeCategory(state.dragData.id,container);if(onDrop)onDrop(container)};const handleDragOver=(e,container)=>{e.preventDefault();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]);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