@wishbone-media/spark 0.46.0 → 0.47.0
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/index.js +3671 -3635
- package/package.json +1 -1
- package/src/assets/css/spark-table.css +9 -3
- package/src/components/SparkTable.vue +90 -32
package/package.json
CHANGED
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
td {
|
|
40
|
-
@apply
|
|
40
|
+
@apply whitespace-nowrap text-gray-500 text-sm align-middle h-auto;
|
|
41
|
+
padding: var(--spark-table-cell-py, 16px) var(--spark-table-cell-px, 24px);
|
|
41
42
|
@apply !border-l-0 !border-r-0 !border-gray-200;
|
|
42
43
|
|
|
43
44
|
&:not(.read-only) {
|
|
@@ -48,6 +49,10 @@
|
|
|
48
49
|
td:not(:last-child) {
|
|
49
50
|
@apply !border-r-0;
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
td.spark-table-word-wrap {
|
|
54
|
+
@apply whitespace-normal break-words;
|
|
55
|
+
}
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -66,7 +71,7 @@
|
|
|
66
71
|
@apply text-left text-xs font-semibold bg-gray-50 text-gray-800 whitespace-normal
|
|
67
72
|
tracking-wider focus:outline-hidden filter flex items-center;
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
padding: var(--spark-table-header-py, 12px) var(--spark-table-header-px, 20px) !important;
|
|
70
75
|
|
|
71
76
|
.fa-sort-up,
|
|
72
77
|
.fa-sort-down {
|
|
@@ -119,7 +124,8 @@
|
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
.spark-table-head-sorting {
|
|
122
|
-
@apply absolute
|
|
127
|
+
@apply absolute w-5 h-5 border border-gray-200 rounded-md grid place-items-center;
|
|
128
|
+
right: var(--spark-table-header-px, 20px);
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
.spark-table-head-title-wrapper {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="spark-table">
|
|
2
|
+
<div class="spark-table" :style="spacingStyles">
|
|
3
3
|
<!-- Header Toolbar: All plugins flow left to right -->
|
|
4
4
|
<SparkTableToolbar
|
|
5
5
|
v-if="sparkTable.computed.ready && headerPlugins && headerPlugins.length"
|
|
@@ -75,6 +75,12 @@ const defaultTableSettings = {
|
|
|
75
75
|
readOnlyCellClassName: 'read-only',
|
|
76
76
|
licenseKey: 'non-commercial-and-evaluation',
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
const spacingPresets = {
|
|
80
|
+
sm: { cellPx: 12, cellPy: 8, headerPx: 12, headerPy: 12 },
|
|
81
|
+
base: { cellPx: 24, cellPy: 16, headerPx: 20, headerPy: 12 },
|
|
82
|
+
lg: { cellPx: 32, cellPy: 20, headerPx: 24, headerPy: 16 },
|
|
83
|
+
}
|
|
78
84
|
</script>
|
|
79
85
|
<script setup>
|
|
80
86
|
import { computed, onMounted, onUnmounted, ref, reactive, inject, watch } from 'vue'
|
|
@@ -178,6 +184,23 @@ const props = defineProps({
|
|
|
178
184
|
type: Boolean,
|
|
179
185
|
default: false,
|
|
180
186
|
},
|
|
187
|
+
|
|
188
|
+
spacing: {
|
|
189
|
+
type: [String, Object],
|
|
190
|
+
default: null,
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const spacingStyles = computed(() => {
|
|
195
|
+
if (!props.spacing) return {}
|
|
196
|
+
const values = typeof props.spacing === 'string' ? spacingPresets[props.spacing] : props.spacing
|
|
197
|
+
if (!values) return {}
|
|
198
|
+
const styles = {}
|
|
199
|
+
if (values.cellPx !== undefined) styles['--spark-table-cell-px'] = `${values.cellPx}px`
|
|
200
|
+
if (values.cellPy !== undefined) styles['--spark-table-cell-py'] = `${values.cellPy}px`
|
|
201
|
+
if (values.headerPx !== undefined) styles['--spark-table-header-px'] = `${values.headerPx}px`
|
|
202
|
+
if (values.headerPy !== undefined) styles['--spark-table-header-py'] = `${values.headerPy}px`
|
|
203
|
+
return styles
|
|
181
204
|
})
|
|
182
205
|
|
|
183
206
|
registerAllCellTypes()
|
|
@@ -356,40 +379,75 @@ const sparkTable = reactive({
|
|
|
356
379
|
...props.options,
|
|
357
380
|
})),
|
|
358
381
|
|
|
359
|
-
tableSettings: computed(() =>
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
beforeStretchingColumnWidth: (stretchedWidth, column) => {
|
|
368
|
-
const columns = get(props.settings, 'columns', [])
|
|
369
|
-
const columnSettings = columns[column]
|
|
370
|
-
if (columnSettings && columnSettings.width !== undefined) {
|
|
371
|
-
return columnSettings.width
|
|
382
|
+
tableSettings: computed(() => {
|
|
383
|
+
const columns = get(props.settings, 'columns', [])
|
|
384
|
+
|
|
385
|
+
const transformedColumns = columns.map((col) => {
|
|
386
|
+
if (!col.wordWrap) return col
|
|
387
|
+
return {
|
|
388
|
+
...col,
|
|
389
|
+
className: [col.className, 'spark-table-word-wrap'].filter(Boolean).join(' '),
|
|
372
390
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
const hasClampedColumns = columns.some(
|
|
394
|
+
(col) => typeof col.wordWrap === 'object' && col.wordWrap?.maxLines,
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
const userAfterRenderer = props.settings.afterRenderer
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
...defaultTableSettings,
|
|
401
|
+
nestedHeaders: get(props.settings, 'nestedHeaders', []),
|
|
402
|
+
...(!get(props.settings, 'nestedHeaders') && {
|
|
403
|
+
afterGetColHeader: (col, th) => customiseHeader(col, th, sparkTable),
|
|
404
|
+
}),
|
|
405
|
+
afterChange: (changes, source) => updateRow(changes, source, sparkTable),
|
|
406
|
+
afterRender: () => syncSortClasses(sparkTable),
|
|
407
|
+
beforeStretchingColumnWidth: (stretchedWidth, column) => {
|
|
408
|
+
const columnSettings = columns[column]
|
|
409
|
+
if (columnSettings && columnSettings.width !== undefined) {
|
|
410
|
+
return columnSettings.width
|
|
411
|
+
}
|
|
412
|
+
return stretchedWidth
|
|
413
|
+
},
|
|
414
|
+
beforeCopy: (data, coords) => {
|
|
415
|
+
const hot = table.value?.hotInstance
|
|
416
|
+
if (!hot) return
|
|
417
|
+
coords.forEach((range) => {
|
|
418
|
+
for (let row = range.startRow; row <= range.endRow; row++) {
|
|
419
|
+
for (let col = range.startCol; col <= range.endCol; col++) {
|
|
420
|
+
const td = hot.getCell(row, col)
|
|
421
|
+
if (td) {
|
|
422
|
+
const dataRow = row - coords[0].startRow
|
|
423
|
+
const dataCol = col - coords[0].startCol
|
|
424
|
+
data[dataRow][dataCol] = td.dataset.copyValue ?? td.textContent ?? ''
|
|
425
|
+
}
|
|
386
426
|
}
|
|
387
427
|
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
428
|
+
})
|
|
429
|
+
},
|
|
430
|
+
...props.settings,
|
|
431
|
+
columns: transformedColumns,
|
|
432
|
+
...(hasClampedColumns && {
|
|
433
|
+
afterRenderer: (td, row, col) => {
|
|
434
|
+
userAfterRenderer?.(td, row, col)
|
|
435
|
+
const colConfig = columns[col]
|
|
436
|
+
const wordWrap = colConfig?.wordWrap
|
|
437
|
+
if (!wordWrap || wordWrap === true || !wordWrap.maxLines) return
|
|
438
|
+
|
|
439
|
+
const wrapper = document.createElement('div')
|
|
440
|
+
wrapper.style.display = '-webkit-box'
|
|
441
|
+
wrapper.style.webkitBoxOrient = 'vertical'
|
|
442
|
+
wrapper.style.webkitLineClamp = wordWrap.maxLines
|
|
443
|
+
wrapper.style.overflow = 'hidden'
|
|
444
|
+
|
|
445
|
+
while (td.firstChild) wrapper.appendChild(td.firstChild)
|
|
446
|
+
td.appendChild(wrapper)
|
|
447
|
+
},
|
|
448
|
+
}),
|
|
449
|
+
}
|
|
450
|
+
}),
|
|
393
451
|
})
|
|
394
452
|
|
|
395
453
|
// Empty state detection - true when data has loaded but contains no records
|