@invopop/popui 0.0.5 → 0.0.7
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.
package/dist/BaseTable.svelte
CHANGED
|
@@ -13,6 +13,9 @@ const callback = (entry) => {
|
|
|
13
13
|
};
|
|
14
14
|
const intersectOptions = { callback };
|
|
15
15
|
let metaKeyPressed = false;
|
|
16
|
+
let shiftKeyPressed = false;
|
|
17
|
+
let lastSelected = {};
|
|
18
|
+
let selectWithArrowPosition = -1;
|
|
16
19
|
export let sortBy = "";
|
|
17
20
|
export let sortDirection = "";
|
|
18
21
|
export let fields = [];
|
|
@@ -25,10 +28,21 @@ export let freeWrap = false;
|
|
|
25
28
|
export let selectable = false;
|
|
26
29
|
export let selectedRows = [];
|
|
27
30
|
export let selectedTrackedBy = "id";
|
|
31
|
+
export let hideSelectAll = false;
|
|
28
32
|
$:
|
|
29
33
|
groupedData = groupData(data);
|
|
30
34
|
$:
|
|
31
35
|
addExtraCell = getActions instanceof Function;
|
|
36
|
+
$:
|
|
37
|
+
indeterminate = selectedRows.length > 0 && selectedRows.length < data.length;
|
|
38
|
+
$:
|
|
39
|
+
allChecked = selectedRows.length === data.length;
|
|
40
|
+
$:
|
|
41
|
+
flattedData = groupedData.flatMap((d) => d.rows);
|
|
42
|
+
$:
|
|
43
|
+
lastSelectedIndex = flattedData.findIndex(
|
|
44
|
+
(d) => d[selectedTrackedBy] === lastSelected[selectedTrackedBy]
|
|
45
|
+
);
|
|
32
46
|
function groupData(rows) {
|
|
33
47
|
if (rows.length === 0)
|
|
34
48
|
return [];
|
|
@@ -46,18 +60,94 @@ function groupData(rows) {
|
|
|
46
60
|
}
|
|
47
61
|
function toggleAllSelected(selected) {
|
|
48
62
|
selectedRows = [];
|
|
63
|
+
lastSelected = {};
|
|
49
64
|
if (!selected)
|
|
50
65
|
return;
|
|
51
66
|
selectedRows = data;
|
|
52
67
|
}
|
|
68
|
+
function selectRow(row) {
|
|
69
|
+
selectedRows = [.../* @__PURE__ */ new Set([...selectedRows, row])];
|
|
70
|
+
}
|
|
71
|
+
function unselectRow(row) {
|
|
72
|
+
selectedRows = selectedRows.filter((r) => r[selectedTrackedBy] !== row[selectedTrackedBy]);
|
|
73
|
+
if (!selectedRows.length) {
|
|
74
|
+
lastSelected = {};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function selectRange(to) {
|
|
78
|
+
if (lastSelectedIndex < 0)
|
|
79
|
+
return;
|
|
80
|
+
let fromIndex = lastSelectedIndex;
|
|
81
|
+
let toIndex = flattedData.findIndex((d) => d[selectedTrackedBy] === to[selectedTrackedBy]);
|
|
82
|
+
if (fromIndex > toIndex) {
|
|
83
|
+
;
|
|
84
|
+
[fromIndex, toIndex] = [toIndex, fromIndex];
|
|
85
|
+
}
|
|
86
|
+
const itemsToSelect = flattedData.slice(fromIndex, toIndex + 1);
|
|
87
|
+
selectedRows = [.../* @__PURE__ */ new Set([...selectedRows, ...itemsToSelect])];
|
|
88
|
+
}
|
|
53
89
|
</script>
|
|
54
90
|
|
|
55
91
|
<svelte:window
|
|
56
92
|
on:keydown={(event) => {
|
|
93
|
+
if (event.key === 'Escape' || event.key === 'Esc') {
|
|
94
|
+
selectedRows = []
|
|
95
|
+
lastSelected = {}
|
|
96
|
+
}
|
|
97
|
+
|
|
57
98
|
metaKeyPressed = event.metaKey
|
|
99
|
+
shiftKeyPressed = event.shiftKey
|
|
100
|
+
|
|
101
|
+
if (event.key === 'Shift') {
|
|
102
|
+
selectWithArrowPosition = lastSelectedIndex
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (event.key === 'ArrowUp') {
|
|
107
|
+
if (!shiftKeyPressed) return
|
|
108
|
+
const toIndex = lastSelectedIndex - 1
|
|
109
|
+
const to = flattedData[toIndex]
|
|
110
|
+
|
|
111
|
+
if (!to) return
|
|
112
|
+
|
|
113
|
+
if (toIndex < selectWithArrowPosition) {
|
|
114
|
+
selectRow(to)
|
|
115
|
+
} else {
|
|
116
|
+
unselectRow(lastSelected)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
lastSelected = to
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (event.key === 'ArrowDown') {
|
|
123
|
+
if (lastSelectedIndex < 0) {
|
|
124
|
+
selectRow(flattedData[0])
|
|
125
|
+
lastSelected = flattedData[0]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!shiftKeyPressed) return
|
|
129
|
+
|
|
130
|
+
const toIndex = lastSelectedIndex + 1
|
|
131
|
+
const to = flattedData[toIndex]
|
|
132
|
+
|
|
133
|
+
if (!to) return
|
|
134
|
+
|
|
135
|
+
if (toIndex > selectWithArrowPosition) {
|
|
136
|
+
selectRow(to)
|
|
137
|
+
} else {
|
|
138
|
+
unselectRow(lastSelected)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
lastSelected = to
|
|
142
|
+
}
|
|
58
143
|
}}
|
|
59
|
-
on:keyup={() => {
|
|
144
|
+
on:keyup={(event) => {
|
|
60
145
|
metaKeyPressed = false
|
|
146
|
+
shiftKeyPressed = false
|
|
147
|
+
|
|
148
|
+
if (!event.shiftKey) {
|
|
149
|
+
selectWithArrowPosition = -1
|
|
150
|
+
}
|
|
61
151
|
}}
|
|
62
152
|
/>
|
|
63
153
|
|
|
@@ -68,11 +158,15 @@ function toggleAllSelected(selected) {
|
|
|
68
158
|
{#if selectable}
|
|
69
159
|
<!-- if table is selectable we need to add an extra header with a checkbox -->
|
|
70
160
|
<th scope="col" class="bg-white sticky top-0 z-10 rounded-tr-md pl-1.5">
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
161
|
+
{#if !hideSelectAll}
|
|
162
|
+
<InputCheckbox
|
|
163
|
+
checked={allChecked}
|
|
164
|
+
{indeterminate}
|
|
165
|
+
on:change={(event) => {
|
|
166
|
+
toggleAllSelected(event.detail)
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
{/if}
|
|
76
170
|
</th>
|
|
77
171
|
{/if}
|
|
78
172
|
{#each fields as field, i (i)}
|
|
@@ -131,11 +225,14 @@ function toggleAllSelected(selected) {
|
|
|
131
225
|
}}
|
|
132
226
|
on:checked={(event) => {
|
|
133
227
|
if (event.detail) {
|
|
134
|
-
|
|
228
|
+
if (shiftKeyPressed) {
|
|
229
|
+
selectRange(row)
|
|
230
|
+
} else {
|
|
231
|
+
selectRow(row)
|
|
232
|
+
}
|
|
233
|
+
lastSelected = row
|
|
135
234
|
} else {
|
|
136
|
-
|
|
137
|
-
(r) => r[selectedTrackedBy] !== row[selectedTrackedBy]
|
|
138
|
-
)
|
|
235
|
+
unselectRow(row)
|
|
139
236
|
}
|
|
140
237
|
}}
|
|
141
238
|
on:action
|
package/dist/BaseTableRow.svelte
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from "svelte";
|
|
2
2
|
import { dispatchWcEvent } from "./wcdispatch.js";
|
|
3
3
|
export let checked = false;
|
|
4
|
+
export let indeterminate = false;
|
|
4
5
|
const dispatch = createEventDispatcher();
|
|
5
6
|
function updateInput(event) {
|
|
6
7
|
if (event instanceof CustomEvent)
|
|
@@ -15,6 +16,7 @@ function updateInput(event) {
|
|
|
15
16
|
<input
|
|
16
17
|
type="checkbox"
|
|
17
18
|
{checked}
|
|
19
|
+
{indeterminate}
|
|
18
20
|
class="form-checkbox w-5 h-5 text-workspace-accent focus:text-workspace-accent rounded border border-neutral-200 focus:ring-0 focus:ring-offset-0"
|
|
19
21
|
on:change={updateInput}
|
|
20
22
|
on:click|stopPropagation
|