playbook_ui 14.20.0.pre.alpha.play2168firstcolumnborderbug7950 → 14.20.0.pre.alpha.revert4453PBNTR933reactdraggablebugdragbtwnexamples7854
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 +0 -8
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +8 -16
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +0 -9
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.md +2 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.html.erb +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_advanced_table/index.js +12 -155
- data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +0 -4
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +17 -58
- data/app/pb_kits/playbook/pb_select/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_select/docs/index.js +0 -1
- data/dist/chunks/{_typeahead-BmOWdDtp.js → _typeahead-C-CI5Vgw.js} +1 -1
- data/dist/chunks/{_weekday_stacked-CvcuQyr9.js → _weekday_stacked-BCiM3zWM.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +2 -2
- 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 +4 -13
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.html.erb +0 -137
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.md +0 -3
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.html.erb +0 -40
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.md +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.html.erb +0 -23
- data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.rb +0 -19
- data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.html.erb +0 -12
- data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.jsx +0 -31
- data/app/pb_kits/playbook/pb_select/docs/_select_custom_select_subheaders.md +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d810ce992ce83180c727b57ffd2015356b7860a523383f4a8810b4b964c6ea1e
|
4
|
+
data.tar.gz: 7674cda91f367bc7ad377806520109d2ffd1cd9076e51c34fb5f1e3baf37120c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d3b8da029137dbf003df505ec900c151d0986db08089339e685d89a7a38ba4b830bf745ea5701aa439bdd2df0f9febcd5728caf65a642be9f1e58579fca37e
|
7
|
+
data.tar.gz: 8304eed6d900e0a9f052b7dec2066c713606a906b7f749bd47b36553dfb0ac2df3e8ecf4f76ca1c15d80a88398dfa0b5efc954d7ca0ca109d94eb8aa5292c01f
|
@@ -368,10 +368,6 @@
|
|
368
368
|
box-shadow: 1px 0px 0px 0px var(--column-border-color) !important;
|
369
369
|
}
|
370
370
|
|
371
|
-
.pb_table_td:nth-child(2) {
|
372
|
-
box-shadow: inset 1px 0px 0px 0px var(--column-border-color) !important;
|
373
|
-
}
|
374
|
-
|
375
371
|
// Color for collapsible trail
|
376
372
|
.collapsible-trail {
|
377
373
|
background-color: $border_light !important;
|
@@ -568,10 +564,6 @@
|
|
568
564
|
box-shadow: $shadow_deep !important;
|
569
565
|
}
|
570
566
|
|
571
|
-
.pb_table_td:nth-child(2) {
|
572
|
-
box-shadow: 0 0 0 0 !important;
|
573
|
-
}
|
574
|
-
|
575
567
|
.pb_advanced_table_header,
|
576
568
|
.pb_advanced_table_body {
|
577
569
|
th.sticky-left,
|
@@ -1,18 +1,10 @@
|
|
1
1
|
<%= pb_content_tag do %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
<%= pb_rails("table", props: { size: "sm", data_table: true, number_spacing:"tabular", responsive:"none", dark: dark, classname: object.loading ? "content-loading" : "" }.merge(object.table_props)) do %>
|
11
|
-
<% if content.present? %>
|
12
|
-
<% content.presence %>
|
13
|
-
<% else %>
|
14
|
-
<%= pb_rails("advanced_table/table_header", props: { column_definitions: object.column_definitions, enable_toggle_expansion: object.enable_toggle_expansion, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, show_actions_bar: object.show_actions_bar }) %>
|
15
|
-
<%= pb_rails("advanced_table/table_body", props: { id: object.id, table_data: object.table_data, column_definitions: object.column_definitions, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, enable_toggle_expansion: object.enable_toggle_expansion }) %>
|
16
|
-
<% end %>
|
17
|
-
<% end %>
|
2
|
+
<%= pb_rails("table", props: { size: "sm", data_table: true, number_spacing:"tabular", responsive:"none", dark: dark, classname: object.loading ? "content-loading" : "" }.merge(object.table_props)) do %>
|
3
|
+
<% if content.present? %>
|
4
|
+
<% content.presence %>
|
5
|
+
<% else %>
|
6
|
+
<%= pb_rails("advanced_table/table_header", props: { column_definitions: object.column_definitions, enable_toggle_expansion: object.enable_toggle_expansion, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows }) %>
|
7
|
+
<%= pb_rails("advanced_table/table_body", props: { id: object.id, table_data: object.table_data, column_definitions: object.column_definitions, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, enable_toggle_expansion: object.enable_toggle_expansion }) %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
18
10
|
<% end %>
|
@@ -25,10 +25,6 @@ module Playbook
|
|
25
25
|
default: "auto"
|
26
26
|
prop :selectable_rows, type: Playbook::Props::Boolean,
|
27
27
|
default: false
|
28
|
-
prop :show_actions_bar, type: Playbook::Props::Boolean,
|
29
|
-
default: true
|
30
|
-
prop :actions, type: Playbook::Props::Array,
|
31
|
-
default: []
|
32
28
|
|
33
29
|
def classname
|
34
30
|
additional_classes = [responsive_classname, max_height_classname]
|
@@ -51,11 +47,6 @@ module Playbook
|
|
51
47
|
def selected_rows_length
|
52
48
|
selected_rows.length
|
53
49
|
end
|
54
|
-
|
55
|
-
def is_action_bar_visible
|
56
|
-
# Action bar visibility is controlled by JS based on selection
|
57
|
-
false
|
58
|
-
end
|
59
50
|
end
|
60
51
|
end
|
61
52
|
end
|
@@ -1,8 +1,4 @@
|
|
1
|
-
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has
|
2
|
-
|
3
|
-
### id
|
4
|
-
|
5
|
-
A unique `id` is required to allow the table functionality to work properly. Without it, certain functions like the action bar will not be able to properly reference the correct table.
|
1
|
+
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
6
2
|
|
7
3
|
### table_data
|
8
4
|
|
@@ -17,6 +13,6 @@ Column definitions are the single most important part of building a table as the
|
|
17
13
|
- `accessor`: this is the key from your data for the value you want rendered in that column
|
18
14
|
- `label`: this is what will be rendered as the column header label
|
19
15
|
|
20
|
-
There is also one optional item that is only required if the table has nested data:
|
16
|
+
There is also one optional item that is only required if the table has nested data:
|
21
17
|
|
22
18
|
- `cellAccessors`: This is an array of strings that represent keys from your data object. This is only required for the first column in case of nested data. If you have nested data, the AdvancedTable needs to know what to render in that first column for nested items. This array represents the nested data in the order you want it rendered.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<br />
|
4
4
|
<br />
|
5
5
|
|
6
|
-
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
6
|
+
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
7
7
|
|
8
8
|
### tableData
|
9
9
|
|
@@ -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, table_props: { container: false }}) %>
|
33
|
+
<%= pb_rails("advanced_table", props: { id: "table_props_table", table_data: @table_data, column_definitions: column_definitions, table_props: { vertical_border: true, container: false }}) %>
|
@@ -15,8 +15,6 @@ examples:
|
|
15
15
|
- advanced_table_column_border_color_rails: Column Group Border Color
|
16
16
|
- advanced_table_selectable_rows_rails: Selectable Rows
|
17
17
|
- advanced_table_selectable_rows_no_subrows_rails: Selectable Rows (No Subrows)
|
18
|
-
- advanced_table_selectable_rows_actions_rails: Selectable Rows (With Actions)
|
19
|
-
- advanced_table_selectable_rows_header_rails: Selectable Rows (No Actions Bar)
|
20
18
|
|
21
19
|
react:
|
22
20
|
- advanced_table_default: Default (Required Props)
|
@@ -79,7 +79,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
79
79
|
}
|
80
80
|
if (!allChildrenChecked) {
|
81
81
|
parentRow.classList.remove("bg-row-selection");
|
82
|
-
|
82
|
+
|
83
83
|
if (this.isRowExpanded(parentRow)) {
|
84
84
|
parentRow.classList.remove("bg-silver");
|
85
85
|
parentRow.classList.add("bg-white");
|
@@ -201,15 +201,15 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
201
201
|
this.toggleElement(this.target);
|
202
202
|
}
|
203
203
|
});
|
204
|
-
|
204
|
+
|
205
205
|
this.hideCloseIcon();
|
206
|
-
|
206
|
+
|
207
207
|
const table = this.element.closest("table");
|
208
|
-
|
208
|
+
|
209
209
|
// Prevent duplicate initialization
|
210
210
|
if (table.dataset.pbAdvancedTableInitialized) return;
|
211
211
|
table.dataset.pbAdvancedTableInitialized = "true";
|
212
|
-
|
212
|
+
|
213
213
|
// Bind checkbox change handlers for all row checkboxes
|
214
214
|
const checkboxLabels = table.querySelectorAll("label[data-row-id]");
|
215
215
|
checkboxLabels.forEach((label) => {
|
@@ -219,7 +219,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
219
219
|
this.handleCheckboxClick(event);
|
220
220
|
});
|
221
221
|
});
|
222
|
-
|
222
|
+
|
223
223
|
// Bind nested row expansion logic
|
224
224
|
const nestedButtons = table.querySelectorAll("[data-advanced-table]");
|
225
225
|
nestedButtons.forEach((button) => {
|
@@ -233,18 +233,18 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
233
233
|
}
|
234
234
|
});
|
235
235
|
});
|
236
|
-
|
236
|
+
|
237
237
|
// Bind select-all logic for this table
|
238
238
|
const selectAllCheckbox = table.querySelector("#select-all-rows");
|
239
239
|
if (selectAllCheckbox) {
|
240
240
|
selectAllCheckbox.addEventListener("change", () => {
|
241
241
|
const checkboxInput = selectAllCheckbox.querySelector('input[type="checkbox"]');
|
242
242
|
const checkAll = checkboxInput.checked;
|
243
|
-
|
243
|
+
|
244
244
|
const checkboxes = Array.from(
|
245
245
|
table.querySelectorAll("label[data-row-id] input[type='checkbox']")
|
246
246
|
);
|
247
|
-
|
247
|
+
|
248
248
|
checkboxes.forEach((cb) => {
|
249
249
|
cb.checked = checkAll;
|
250
250
|
const rowId = cb.id;
|
@@ -260,14 +260,14 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
260
260
|
rowEl?.classList.add("bg-white");
|
261
261
|
}
|
262
262
|
});
|
263
|
-
|
263
|
+
|
264
264
|
checkboxes.forEach((cb) => this.updateParentCheckboxes(cb));
|
265
|
-
|
265
|
+
|
266
266
|
this.updateTableSelectedRowsAttribute();
|
267
267
|
});
|
268
268
|
}
|
269
269
|
}
|
270
|
-
|
270
|
+
|
271
271
|
|
272
272
|
hideCloseIcon() {
|
273
273
|
const closeIcon = this.element.querySelector(UP_ARROW_SELECTOR);
|
@@ -449,149 +449,6 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
449
449
|
}
|
450
450
|
}
|
451
451
|
|
452
|
-
// Isolate action bar functionality so it doesn't mix with existing functionality
|
453
|
-
class PbAdvancedTableActionBar {
|
454
|
-
constructor() {
|
455
|
-
this.init();
|
456
|
-
}
|
457
|
-
|
458
|
-
init() {
|
459
|
-
// Initialize action bars for all advanced tables with action bars
|
460
|
-
document.addEventListener('DOMContentLoaded', () => {
|
461
|
-
this.setupActionBars();
|
462
|
-
});
|
463
|
-
|
464
|
-
// Also run immediately in case DOM is already loaded
|
465
|
-
if (document.readyState === 'loading') {
|
466
|
-
// DOM is still loading
|
467
|
-
} else {
|
468
|
-
// DOM is already loaded
|
469
|
-
this.setupActionBars();
|
470
|
-
}
|
471
|
-
}
|
472
|
-
|
473
|
-
setupActionBars() {
|
474
|
-
const advancedTables = document.querySelectorAll('.pb_advanced_table');
|
475
|
-
|
476
|
-
advancedTables.forEach(table => {
|
477
|
-
// Only proceed if this table has both selectable rows AND an action bar
|
478
|
-
if (!this.shouldEnableActionBar(table)) return;
|
479
|
-
|
480
|
-
const actionBar = table.querySelector('.row-selection-actions-card');
|
481
|
-
if (!actionBar) return; // Skip tables without action bars
|
482
|
-
|
483
|
-
// Initialize action bar styles
|
484
|
-
this.initializeActionBar(actionBar);
|
485
|
-
|
486
|
-
// Set up checkbox listeners for this table
|
487
|
-
this.setupCheckboxListeners(table, actionBar);
|
488
|
-
});
|
489
|
-
}
|
490
|
-
|
491
|
-
shouldEnableActionBar(table) {
|
492
|
-
// Check if the table has selectable rows
|
493
|
-
const hasSelectableRows = table.querySelector('input[type="checkbox"]') !== null;
|
494
|
-
|
495
|
-
// Check if the table has a row selection action bar (not other types of action bars)
|
496
|
-
const hasRowSelectionActionBar = table.querySelector('.row-selection-actions-card') !== null;
|
497
|
-
|
498
|
-
// Additional check: look for the presence of row checkboxes with data-row-id
|
499
|
-
const hasRowCheckboxes = table.querySelector('label[data-row-id] input[type="checkbox"]') !== null;
|
500
|
-
|
501
|
-
// Only enable if ALL conditions are met:
|
502
|
-
// 1. Has selectable checkboxes
|
503
|
-
// 2. Has the specific row selection action bar
|
504
|
-
// 3. Has row checkboxes (not just other types of checkboxes)
|
505
|
-
return hasSelectableRows && hasRowSelectionActionBar && hasRowCheckboxes;
|
506
|
-
}
|
507
|
-
|
508
|
-
initializeActionBar(actionBar) {
|
509
|
-
// Set initial hidden state
|
510
|
-
Object.assign(actionBar.style, {
|
511
|
-
height: '0px',
|
512
|
-
overflow: 'hidden',
|
513
|
-
display: 'block',
|
514
|
-
opacity: '0'
|
515
|
-
});
|
516
|
-
|
517
|
-
// Remove any visibility classes
|
518
|
-
actionBar.classList.remove("p_xs", "is-visible", "show-action-card");
|
519
|
-
actionBar.classList.add("p_none");
|
520
|
-
}
|
521
|
-
|
522
|
-
setupCheckboxListeners(table, actionBar) {
|
523
|
-
// Only listen to row checkboxes (those with data-row-id), not all checkboxes
|
524
|
-
const rowCheckboxes = table.querySelectorAll('label[data-row-id] input[type="checkbox"]');
|
525
|
-
|
526
|
-
rowCheckboxes.forEach(checkbox => {
|
527
|
-
checkbox.addEventListener('change', () => {
|
528
|
-
// Use setTimeout to ensure this runs after the main checkbox logic
|
529
|
-
setTimeout(() => {
|
530
|
-
this.updateActionBarVisibility(table, actionBar);
|
531
|
-
}, 0);
|
532
|
-
});
|
533
|
-
});
|
534
|
-
|
535
|
-
// Special handling for select-all checkbox (only if it exists)
|
536
|
-
const selectAllCheckbox = table.querySelector("#select-all-rows");
|
537
|
-
if (selectAllCheckbox) {
|
538
|
-
const selectAllInput = selectAllCheckbox.querySelector('input[type="checkbox"]');
|
539
|
-
if (selectAllInput) {
|
540
|
-
selectAllInput.addEventListener('change', () => {
|
541
|
-
// Use setTimeout to ensure this runs after the main select-all logic
|
542
|
-
setTimeout(() => {
|
543
|
-
this.updateActionBarVisibility(table, actionBar);
|
544
|
-
}, 10); // Slightly longer delay for select-all to ensure all row checkboxes are updated
|
545
|
-
});
|
546
|
-
}
|
547
|
-
}
|
548
|
-
}
|
549
|
-
|
550
|
-
updateActionBarVisibility(table, actionBar) {
|
551
|
-
// Only count row checkboxes (those with data-row-id), not all checkboxes
|
552
|
-
const rowCheckboxes = table.querySelectorAll('label[data-row-id] input[type="checkbox"]');
|
553
|
-
|
554
|
-
// Get all checked row checkboxes
|
555
|
-
const selectedRowCheckboxes = Array.from(rowCheckboxes).filter(cb => cb.checked);
|
556
|
-
|
557
|
-
// Get the selected count
|
558
|
-
const selectedCount = selectedRowCheckboxes.length;
|
559
|
-
|
560
|
-
if (selectedCount > 0) {
|
561
|
-
this.showActionBar(actionBar, selectedCount);
|
562
|
-
} else {
|
563
|
-
this.hideActionBar(actionBar);
|
564
|
-
}
|
565
|
-
}
|
566
|
-
|
567
|
-
showActionBar(actionBar, selectedCount) {
|
568
|
-
// Show action bar directly
|
569
|
-
actionBar.style.height = 'auto';
|
570
|
-
actionBar.style.overflow = 'visible';
|
571
|
-
actionBar.style.opacity = '1';
|
572
|
-
actionBar.classList.remove("p_none");
|
573
|
-
actionBar.classList.add("p_xs", "is-visible", "show-action-card");
|
574
|
-
|
575
|
-
// Update the count
|
576
|
-
const countElement = actionBar.querySelector(".selected-count");
|
577
|
-
if (countElement) {
|
578
|
-
countElement.textContent = `${selectedCount} Selected`;
|
579
|
-
}
|
580
|
-
}
|
581
|
-
|
582
|
-
hideActionBar(actionBar) {
|
583
|
-
// Hide action bar directly
|
584
|
-
actionBar.style.height = '0px';
|
585
|
-
actionBar.style.overflow = 'hidden';
|
586
|
-
actionBar.style.opacity = '0';
|
587
|
-
actionBar.classList.add("p_none");
|
588
|
-
actionBar.classList.remove("p_xs", "is-visible", "show-action-card");
|
589
|
-
}
|
590
|
-
}
|
591
|
-
|
592
|
-
// Initialize the isolated action bar functionality
|
593
|
-
new PbAdvancedTableActionBar();
|
594
|
-
|
595
452
|
window.expandAllRows = (element) => {
|
596
453
|
PbAdvancedTable.handleToggleAllHeaders(element);
|
597
454
|
};
|
@@ -15,8 +15,6 @@ module Playbook
|
|
15
15
|
default: "scroll"
|
16
16
|
prop :selectable_rows, type: Playbook::Props::Boolean,
|
17
17
|
default: false
|
18
|
-
prop :show_actions_bar, type: Playbook::Props::Boolean,
|
19
|
-
default: true
|
20
18
|
|
21
19
|
def classname
|
22
20
|
additional_classes = []
|
@@ -29,7 +27,6 @@ module Playbook
|
|
29
27
|
def th_classname(is_first_column: false)
|
30
28
|
additional_classes = []
|
31
29
|
additional_classes << "pinned-left" if is_first_column && responsive == "scroll" && !selectable_rows
|
32
|
-
additional_classes << "header-cells-with-actions" if selectable_rows && show_actions_bar
|
33
30
|
|
34
31
|
generate_classname("table-header-cells", *additional_classes, separator: " ")
|
35
32
|
end
|
@@ -49,7 +46,6 @@ module Playbook
|
|
49
46
|
if selectable_rows
|
50
47
|
additional_classes = []
|
51
48
|
additional_classes << "table-header-cells-custom"
|
52
|
-
additional_classes << "header-cells-with-actions" if show_actions_bar
|
53
49
|
additional_classes << "checkbox-cell-header"
|
54
50
|
additional_classes << "pinned-left" if responsive == "scroll"
|
55
51
|
pb_rails("table/table_header", props: {
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import React, { createContext, useReducer, useContext, useEffect, useMemo
|
1
|
+
import React, { createContext, useReducer, useContext, useEffect, useMemo } from "react";
|
2
2
|
import { InitialStateType, ActionType, DraggableProviderType } from "./types";
|
3
3
|
|
4
4
|
const initialState: InitialStateType = {
|
5
5
|
items: [],
|
6
6
|
dragData: { id: "", initialGroup: "" },
|
7
7
|
isDragging: "",
|
8
|
-
activeContainer: ""
|
8
|
+
activeContainer: ""
|
9
9
|
};
|
10
10
|
|
11
11
|
const reducer = (state: InitialStateType, action: ActionType) => {
|
@@ -31,23 +31,9 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
31
31
|
const { dragId, targetId } = action.payload;
|
32
32
|
const newItems = [...state.items];
|
33
33
|
const draggedItem = newItems.find(item => item.id === dragId);
|
34
|
-
const
|
35
|
-
|
36
|
-
if (!draggedItem || !targetItem || draggedItem.container !== targetItem.container) {
|
37
|
-
return state;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (dragId === targetId) {
|
41
|
-
return state;
|
42
|
-
}
|
43
|
-
|
44
|
-
const draggedIndex = newItems.findIndex(item => item.id === dragId);
|
34
|
+
const draggedIndex = newItems.indexOf(draggedItem);
|
45
35
|
const targetIndex = newItems.findIndex(item => item.id === targetId);
|
46
36
|
|
47
|
-
if (draggedIndex === -1 || targetIndex === -1) {
|
48
|
-
return state;
|
49
|
-
}
|
50
|
-
|
51
37
|
newItems.splice(draggedIndex, 1);
|
52
38
|
newItems.splice(targetIndex, 0, draggedItem);
|
53
39
|
|
@@ -62,11 +48,7 @@ const reducer = (state: InitialStateType, action: ActionType) => {
|
|
62
48
|
const DragContext = createContext<any>({});
|
63
49
|
|
64
50
|
export const DraggableContext = () => {
|
65
|
-
|
66
|
-
if (context === undefined) {
|
67
|
-
throw new Error('DraggableContext must be used within a DraggableProvider');
|
68
|
-
}
|
69
|
-
return context;
|
51
|
+
return useContext(DragContext);
|
70
52
|
};
|
71
53
|
|
72
54
|
export const DraggableProvider = ({
|
@@ -81,11 +63,7 @@ export const DraggableProvider = ({
|
|
81
63
|
dropZone = { type: 'ghost', color: 'neutral', direction: 'vertical' }
|
82
64
|
}: DraggableProviderType) => {
|
83
65
|
const [state, dispatch] = useReducer(reducer, initialState);
|
84
|
-
|
85
|
-
// Store initial items in a ref to use if needed (for consistency when needed in future updates)
|
86
|
-
const initialItemsRef = useRef(initialItems);
|
87
|
-
const [isDragging, setIsDragging] = useState(false);
|
88
|
-
|
66
|
+
|
89
67
|
// Parse dropZone prop - handle both string format (backward compatibility) and object format
|
90
68
|
let dropZoneType = 'ghost';
|
91
69
|
let dropZoneColor = 'neutral';
|
@@ -108,64 +86,45 @@ export const DraggableProvider = ({
|
|
108
86
|
|
109
87
|
useEffect(() => {
|
110
88
|
dispatch({ type: 'SET_ITEMS', payload: initialItems });
|
111
|
-
initialItemsRef.current = initialItems;
|
112
89
|
}, [initialItems]);
|
113
90
|
|
114
91
|
useEffect(() => {
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
}, [state.items, onReorder]);
|
92
|
+
onReorder(state.items);
|
93
|
+
}, [state.items]);
|
119
94
|
|
120
95
|
const handleDragStart = (id: string, container: string) => {
|
121
|
-
|
122
|
-
dispatch({ type: 'SET_DRAG_DATA', payload: { id, initialGroup: container } });
|
96
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: id, initialGroup: container } });
|
123
97
|
dispatch({ type: 'SET_IS_DRAGGING', payload: id });
|
124
|
-
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
125
98
|
if (onDragStart) onDragStart(id, container);
|
126
99
|
};
|
127
100
|
|
128
101
|
const handleDragEnter = (id: string, container: string) => {
|
129
|
-
if (
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
const draggedItem = state.items.find(item => item.id === state.dragData.id);
|
134
|
-
const targetItem = state.items.find(item => item.id === id);
|
135
|
-
|
136
|
-
if (!draggedItem || !targetItem || draggedItem.container !== targetItem.container) {
|
137
|
-
return;
|
102
|
+
if (state.dragData.id !== id) {
|
103
|
+
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
104
|
+
dispatch({ type: 'SET_DRAG_DATA', payload: { id: state.dragData.id, initialGroup: container } });
|
138
105
|
}
|
139
|
-
|
140
|
-
dispatch({ type: 'REORDER_ITEMS', payload: { dragId: state.dragData.id, targetId: id } });
|
141
|
-
|
142
106
|
if (onDragEnter) onDragEnter(id, container);
|
143
107
|
};
|
144
108
|
|
145
109
|
const handleDragEnd = () => {
|
146
|
-
setIsDragging(false);
|
147
110
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
148
111
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
149
112
|
if (onDragEnd) onDragEnd();
|
150
113
|
};
|
151
114
|
|
152
|
-
const
|
153
|
-
|
154
|
-
|
155
|
-
if (draggedItem && draggedItem.container !== container) {
|
156
|
-
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId: state.dragData.id, container } });
|
157
|
-
}
|
115
|
+
const changeCategory = (itemId: string, container: string) => {
|
116
|
+
dispatch({ type: 'CHANGE_CATEGORY', payload: { itemId, container } });
|
117
|
+
};
|
158
118
|
|
119
|
+
const handleDrop = (container: string) => {
|
159
120
|
dispatch({ type: 'SET_IS_DRAGGING', payload: "" });
|
160
121
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: "" });
|
161
|
-
|
162
|
-
setIsDragging(false);
|
122
|
+
changeCategory(state.dragData.id, container);
|
163
123
|
if (onDrop) onDrop(container);
|
164
124
|
};
|
165
125
|
|
166
126
|
const handleDragOver = (e: Event, container: string) => {
|
167
127
|
e.preventDefault();
|
168
|
-
e.stopPropagation();
|
169
128
|
dispatch({ type: 'SET_ACTIVE_CONTAINER', payload: container });
|
170
129
|
if (onDragOver) onDragOver(e, container);
|
171
130
|
};
|
@@ -185,7 +144,7 @@ export const DraggableProvider = ({
|
|
185
144
|
handleDragEnd,
|
186
145
|
handleDrop,
|
187
146
|
handleDragOver
|
188
|
-
}), [state, dropZoneType, dropZoneColor, dropZoneDirection
|
147
|
+
}), [state, dropZoneType, dropZoneColor, dropZoneDirection]);
|
189
148
|
|
190
149
|
return (
|
191
150
|
<DragContext.Provider value={contextValue}>{children}</DragContext.Provider>
|
@@ -8,7 +8,6 @@ examples:
|
|
8
8
|
- select_required: Required Select Field
|
9
9
|
- select_value_text_same: Equal option value and value text
|
10
10
|
- select_custom_select: Custom Select
|
11
|
-
- select_custom_select_subheaders: Custom Select Subheaders
|
12
11
|
- select_error: Select w/ Error
|
13
12
|
- select_inline: Select Inline
|
14
13
|
- select_inline_show_arrow: Select Inline (Always Show Arrow)
|
@@ -26,7 +25,6 @@ examples:
|
|
26
25
|
- select_required: Required Select Field
|
27
26
|
- select_value_text_same: Equal option value and value text
|
28
27
|
- select_custom_select: Custom Select
|
29
|
-
- select_custom_select_subheaders: Custom Select Subheaders
|
30
28
|
- select_error: Select w/ Error
|
31
29
|
- select_inline: Select Inline
|
32
30
|
- select_inline_show_arrow: Select Inline (Always Show Arrow)
|
@@ -11,4 +11,3 @@ export { default as SelectInlineShowArrow } from './_select_inline_show_arrow.js
|
|
11
11
|
export { default as SelectInlineCompact } from './_select_inline_compact.jsx'
|
12
12
|
export { default as SelectMultiple } from './_select_multiple.jsx'
|
13
13
|
export { default as SelectReactHook } from './_select_react_hook.jsx'
|
14
|
-
export { default as SelectCustomSelectSubheaders } from './_select_custom_select_subheaders.jsx'
|
@@ -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,
|
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{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 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
|