@chalabi/svelte-sheets 2.0.5 → 2.0.6
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/Sheet.svelte +85 -1
- package/dist/defaultconfig.d.ts +2 -0
- package/dist/defaultconfig.js +4 -0
- package/package.json +1 -1
package/dist/Sheet.svelte
CHANGED
|
@@ -190,6 +190,51 @@ export function onInputChange(value, row, column) {
|
|
|
190
190
|
data[row.i][column.i] = value;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
+
function isBooleanCell(colIndex, rowIndex) {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
// Don't treat first row as boolean (headers)
|
|
196
|
+
if (rowIndex === 0)
|
|
197
|
+
return false;
|
|
198
|
+
return (((_a = config.booleanColumns) === null || _a === void 0 ? void 0 : _a.includes(colIndex)) ||
|
|
199
|
+
((_b = config.booleanRows) === null || _b === void 0 ? void 0 : _b.includes(rowIndex)));
|
|
200
|
+
}
|
|
201
|
+
function toggleBooleanCell(colIndex, rowIndex) {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
if (isReadOnly)
|
|
204
|
+
return;
|
|
205
|
+
if ((_a = columns[colIndex]) === null || _a === void 0 ? void 0 : _a.readOnly)
|
|
206
|
+
return;
|
|
207
|
+
if (!isBooleanCell(colIndex, rowIndex))
|
|
208
|
+
return;
|
|
209
|
+
cmdz = true;
|
|
210
|
+
const currentValue = (_b = data[rowIndex]) === null || _b === void 0 ? void 0 : _b[colIndex];
|
|
211
|
+
const newValue = !currentValue;
|
|
212
|
+
if (rowIndex > data.length - 1) {
|
|
213
|
+
data = [
|
|
214
|
+
...data,
|
|
215
|
+
...Array.from({ length: rowIndex - data.length + 1 }, (v, i) => {
|
|
216
|
+
if (i == rowIndex) {
|
|
217
|
+
return Array.from({ length: columns.length }, (_, i) => {
|
|
218
|
+
if (i == colIndex) {
|
|
219
|
+
return newValue;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
return "";
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
return Array.from({ length: columns.length }, (_) => "");
|
|
228
|
+
}
|
|
229
|
+
}),
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
data[rowIndex][colIndex] = newValue;
|
|
234
|
+
}
|
|
235
|
+
historyPush(data, rows, columns, style);
|
|
236
|
+
cmdz = false;
|
|
237
|
+
}
|
|
193
238
|
function refresh(data, viewport_height, viewport_width) {
|
|
194
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
240
|
if (!viewport)
|
|
@@ -990,6 +1035,7 @@ function historyPush(data, rows, columns, style) {
|
|
|
990
1035
|
on:dblclick={(_) =>
|
|
991
1036
|
!isReadOnly &&
|
|
992
1037
|
!(columns[x.i] && columns[x.i].readOnly) &&
|
|
1038
|
+
!isBooleanCell(x.i, r.i) &&
|
|
993
1039
|
(edition = [x.i, r.i])}
|
|
994
1040
|
class:readonly={columns[x.i] && columns[x.i].readOnly}
|
|
995
1041
|
style={computeStyles(
|
|
@@ -1002,7 +1048,7 @@ function historyPush(data, rows, columns, style) {
|
|
|
1002
1048
|
r.data && r.data[x.i + 1]
|
|
1003
1049
|
)}
|
|
1004
1050
|
>
|
|
1005
|
-
{#if String(edition) == String([x.i, r.i])}
|
|
1051
|
+
{#if String(edition) == String([x.i, r.i]) && !isBooleanCell(x.i, r.i)}
|
|
1006
1052
|
<input
|
|
1007
1053
|
autofocus
|
|
1008
1054
|
on:blur={(e) => {
|
|
@@ -1015,6 +1061,20 @@ function historyPush(data, rows, columns, style) {
|
|
|
1015
1061
|
x.i
|
|
1016
1062
|
)}px; height: ${getRowHeight(r.i)}px; min-height: 22px;`}
|
|
1017
1063
|
/>
|
|
1064
|
+
{:else if isBooleanCell(x.i, r.i)}
|
|
1065
|
+
<span
|
|
1066
|
+
class="boolean-cell"
|
|
1067
|
+
class:readonly={columns[x.i] && columns[x.i].readOnly}
|
|
1068
|
+
on:click|stopPropagation={() => toggleBooleanCell(x.i, r.i)}
|
|
1069
|
+
role="button"
|
|
1070
|
+
tabindex="-1"
|
|
1071
|
+
>
|
|
1072
|
+
{#if r.data && r.data[x.i]}
|
|
1073
|
+
<span class="checkmark">✓</span>
|
|
1074
|
+
{:else}
|
|
1075
|
+
<span class="crossmark">⦻</span>
|
|
1076
|
+
{/if}
|
|
1077
|
+
</span>
|
|
1018
1078
|
{:else}{(r.data && r.data[x.i]) || ""}{/if}
|
|
1019
1079
|
</td>
|
|
1020
1080
|
{/each}
|
|
@@ -1243,4 +1303,28 @@ function historyPush(data, rows, columns, style) {
|
|
|
1243
1303
|
.hidden {
|
|
1244
1304
|
display: none;
|
|
1245
1305
|
}
|
|
1306
|
+
.boolean-cell {
|
|
1307
|
+
display: flex;
|
|
1308
|
+
align-items: center;
|
|
1309
|
+
justify-content: center;
|
|
1310
|
+
width: 100%;
|
|
1311
|
+
height: 100%;
|
|
1312
|
+
cursor: pointer;
|
|
1313
|
+
user-select: none;
|
|
1314
|
+
}
|
|
1315
|
+
.boolean-cell.readonly {
|
|
1316
|
+
cursor: default;
|
|
1317
|
+
}
|
|
1318
|
+
.checkmark {
|
|
1319
|
+
font-size: 18px;
|
|
1320
|
+
font-weight: bold;
|
|
1321
|
+
color: var(--sheet-accent);
|
|
1322
|
+
line-height: 1;
|
|
1323
|
+
}
|
|
1324
|
+
.crossmark {
|
|
1325
|
+
font-size: 18px;
|
|
1326
|
+
font-weight: bold;
|
|
1327
|
+
color: #ef4444;
|
|
1328
|
+
line-height: 1;
|
|
1329
|
+
}
|
|
1246
1330
|
</style>
|
package/dist/defaultconfig.d.ts
CHANGED
package/dist/defaultconfig.js
CHANGED
|
@@ -17,6 +17,10 @@ export const defaultconfig = {
|
|
|
17
17
|
// Column width that is used by default
|
|
18
18
|
defaultColWidth: 50,
|
|
19
19
|
defaultColAlign: "center",
|
|
20
|
+
// Boolean columns for checkbox mode
|
|
21
|
+
booleanColumns: [],
|
|
22
|
+
// Boolean rows for checkbox mode
|
|
23
|
+
booleanRows: [],
|
|
20
24
|
// Spare rows and columns
|
|
21
25
|
minSpareRows: 0,
|
|
22
26
|
minSpareCols: 0,
|