@invopop/popui 0.0.18 → 0.0.20
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
|
@@ -74,6 +74,13 @@ function unselectRow(row) {
|
|
|
74
74
|
lastSelected = {};
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
function toggleRow(row) {
|
|
78
|
+
if (selectedRows.find((r) => r[selectedTrackedBy] === row[selectedTrackedBy])) {
|
|
79
|
+
unselectRow(row);
|
|
80
|
+
} else {
|
|
81
|
+
selectRow(row);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
77
84
|
function selectRange(to) {
|
|
78
85
|
if (lastSelectedIndex < 0)
|
|
79
86
|
return;
|
|
@@ -90,11 +97,17 @@ function selectRange(to) {
|
|
|
90
97
|
|
|
91
98
|
<svelte:window
|
|
92
99
|
on:keydown={(event) => {
|
|
100
|
+
event.preventDefault()
|
|
101
|
+
|
|
93
102
|
if (event.key === 'Escape' || event.key === 'Esc') {
|
|
94
103
|
selectedRows = []
|
|
95
104
|
lastSelected = {}
|
|
96
105
|
}
|
|
97
106
|
|
|
107
|
+
if ((event.code === 'Space' || event.key === ' ') && lastSelected) {
|
|
108
|
+
toggleRow(lastSelected)
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
metaKeyPressed = event.metaKey
|
|
99
112
|
shiftKeyPressed = event.shiftKey
|
|
100
113
|
|
|
@@ -111,41 +124,49 @@ function selectRange(to) {
|
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
if (event.key === 'ArrowUp') {
|
|
114
|
-
if (!shiftKeyPressed) return
|
|
115
127
|
const toIndex = lastSelectedIndex - 1
|
|
116
128
|
const to = flattedData[toIndex]
|
|
117
129
|
|
|
118
130
|
if (!to) return
|
|
119
131
|
|
|
132
|
+
const previousSelected = { ...lastSelected }
|
|
133
|
+
lastSelected = to
|
|
134
|
+
|
|
135
|
+
if (!shiftKeyPressed) return
|
|
136
|
+
|
|
120
137
|
if (toIndex < selectWithArrowPosition) {
|
|
138
|
+
selectRow(previousSelected)
|
|
121
139
|
selectRow(to)
|
|
122
140
|
} else {
|
|
123
141
|
unselectRow(lastSelected)
|
|
124
142
|
}
|
|
125
|
-
|
|
126
|
-
lastSelected = to
|
|
127
143
|
}
|
|
128
144
|
|
|
129
145
|
if (event.key === 'ArrowDown') {
|
|
130
146
|
if (lastSelectedIndex < 0) {
|
|
131
|
-
|
|
147
|
+
if (shiftKeyPressed) {
|
|
148
|
+
selectRow(flattedData[0])
|
|
149
|
+
}
|
|
132
150
|
lastSelected = flattedData[0]
|
|
151
|
+
return
|
|
133
152
|
}
|
|
134
153
|
|
|
135
|
-
if (!shiftKeyPressed) return
|
|
136
|
-
|
|
137
154
|
const toIndex = lastSelectedIndex + 1
|
|
138
155
|
const to = flattedData[toIndex]
|
|
139
156
|
|
|
140
157
|
if (!to) return
|
|
141
158
|
|
|
159
|
+
const previousSelected = { ...lastSelected }
|
|
160
|
+
lastSelected = to
|
|
161
|
+
|
|
162
|
+
if (!shiftKeyPressed) return
|
|
163
|
+
|
|
142
164
|
if (toIndex > selectWithArrowPosition) {
|
|
165
|
+
selectRow(previousSelected)
|
|
143
166
|
selectRow(to)
|
|
144
167
|
} else {
|
|
145
168
|
unselectRow(lastSelected)
|
|
146
169
|
}
|
|
147
|
-
|
|
148
|
-
lastSelected = to
|
|
149
170
|
}
|
|
150
171
|
}}
|
|
151
172
|
on:keyup={(event) => {
|
|
@@ -227,6 +248,7 @@ function selectRange(to) {
|
|
|
227
248
|
{selectable}
|
|
228
249
|
{selectedRows}
|
|
229
250
|
{selectedTrackedBy}
|
|
251
|
+
selected={lastSelected && row[selectedTrackedBy] === lastSelected[selectedTrackedBy]}
|
|
230
252
|
on:click={() => {
|
|
231
253
|
if (disableRowClick) return
|
|
232
254
|
|
package/dist/BaseTableRow.svelte
CHANGED
|
@@ -12,6 +12,7 @@ export let fields = [];
|
|
|
12
12
|
export let disableRowClick = false;
|
|
13
13
|
export let freeWrap = false;
|
|
14
14
|
export let selectable = false;
|
|
15
|
+
export let selected = false;
|
|
15
16
|
export let selectedTrackedBy = "id";
|
|
16
17
|
export let selectedRows = [];
|
|
17
18
|
$:
|
|
@@ -24,7 +25,7 @@ $:
|
|
|
24
25
|
return field === row[selectedTrackedBy];
|
|
25
26
|
});
|
|
26
27
|
$:
|
|
27
|
-
if (
|
|
28
|
+
if (selected) {
|
|
28
29
|
scrollIntoView();
|
|
29
30
|
}
|
|
30
31
|
function scrollIntoView() {
|
|
@@ -34,7 +35,8 @@ function scrollIntoView() {
|
|
|
34
35
|
|
|
35
36
|
<tr
|
|
36
37
|
class:cursor-pointer={!disableRowClick}
|
|
37
|
-
class:bg-
|
|
38
|
+
class:bg-neutral-50={selected}
|
|
39
|
+
class:bg-workspace-accent-50={checked && !selected}
|
|
38
40
|
class="hover:bg-neutral-50"
|
|
39
41
|
on:click
|
|
40
42
|
on:contextmenu|preventDefault={() => {
|
|
@@ -8,6 +8,7 @@ declare const __propDef: {
|
|
|
8
8
|
disableRowClick?: boolean | undefined;
|
|
9
9
|
freeWrap?: boolean | undefined;
|
|
10
10
|
selectable?: boolean | undefined;
|
|
11
|
+
selected?: boolean | undefined;
|
|
11
12
|
selectedTrackedBy?: string | undefined;
|
|
12
13
|
selectedRows?: TableDataRow[] | undefined;
|
|
13
14
|
};
|
package/dist/helpers.js
CHANGED
|
@@ -59,15 +59,16 @@ export function scrollIntoTableView(element) {
|
|
|
59
59
|
const elementBottom = elementRect.bottom - containerRect.top + container.scrollTop;
|
|
60
60
|
const isAboveView = elementTop - offsetTop < container.scrollTop;
|
|
61
61
|
const isBelowView = elementBottom + offset > container.scrollTop + container.clientHeight;
|
|
62
|
-
if (
|
|
62
|
+
if (isBelowView) {
|
|
63
63
|
container.scrollTo({
|
|
64
|
-
top:
|
|
64
|
+
top: elementBottom - container.clientHeight + offset,
|
|
65
65
|
behavior: 'smooth'
|
|
66
66
|
});
|
|
67
|
+
return;
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
if (isAboveView) {
|
|
69
70
|
container.scrollTo({
|
|
70
|
-
top:
|
|
71
|
+
top: elementTop - offsetTop,
|
|
71
72
|
behavior: 'smooth'
|
|
72
73
|
});
|
|
73
74
|
}
|