@studio-west/component-sw 0.12.24 → 0.12.25
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/README.md +0 -2
- package/package.json +2 -5
- package/src/Alert.ts +0 -70
- package/src/components/SwAlert.vue +0 -70
- package/src/components/SwButton.vue +0 -57
- package/src/components/SwButtonGroup.vue +0 -68
- package/src/components/SwCollapse.vue +0 -13
- package/src/components/SwDatePicker.vue +0 -375
- package/src/components/SwDropdown.vue +0 -195
- package/src/components/SwDropdownItem.vue +0 -26
- package/src/components/SwDropdownNew.vue +0 -175
- package/src/components/SwFormItem.vue +0 -21
- package/src/components/SwGide.vue +0 -128
- package/src/components/SwIcon.vue +0 -36
- package/src/components/SwInput.vue +0 -106
- package/src/components/SwMenu.vue +0 -217
- package/src/components/SwMessage.vue +0 -53
- package/src/components/SwSection.vue +0 -17
- package/src/components/SwSelect.vue +0 -153
- package/src/components/SwSkeleton.vue +0 -13
- package/src/components/SwSkeletonItem.vue +0 -27
- package/src/components/SwSlider.vue +0 -281
- package/src/components/SwSwitch.vue +0 -53
- package/src/components/SwTable.vue +0 -481
- package/src/components/SwTableColumn.vue +0 -88
- package/src/components/SwTabs.vue +0 -42
- package/src/components/SwTabsPane.vue +0 -44
- package/src/index.ts +0 -38
- package/src/utils/index.ts +0 -149
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<!-- Скрытый рендер слота: монтирует SwTableColumn, которые регистрируют себя через inject -->
|
|
3
|
-
<div style="display: none;" aria-hidden="true"><slot /></div>
|
|
4
|
-
<div
|
|
5
|
-
ref="wrapperRef"
|
|
6
|
-
class="sw-table-wrapper"
|
|
7
|
-
:class="{ 'fixed-active': isFixedActive }"
|
|
8
|
-
:style="wrapperStyle"
|
|
9
|
-
>
|
|
10
|
-
<table ref="tableRef" class="sw-table" :class="{ 'resizing': isResizing }">
|
|
11
|
-
<thead>
|
|
12
|
-
<tr v-for="(row, rowIndex) in headerRows" :key="rowIndex">
|
|
13
|
-
<th
|
|
14
|
-
v-for="cell in row"
|
|
15
|
-
:key="cell.key"
|
|
16
|
-
:colspan="cell.colspan"
|
|
17
|
-
:rowspan="cell.rowspan"
|
|
18
|
-
:class="getHeaderCellClass(cell)"
|
|
19
|
-
:style="getHeaderCellStyle(cell)"
|
|
20
|
-
@mouseenter="onHeaderEnter(cell)"
|
|
21
|
-
@mouseleave="onHeaderLeave"
|
|
22
|
-
>
|
|
23
|
-
{{ cell.label }}
|
|
24
|
-
<span
|
|
25
|
-
v-if="isResizableLeaf(cell)"
|
|
26
|
-
class="resize-handle"
|
|
27
|
-
@mousedown.prevent="startResize($event, cell)"
|
|
28
|
-
/>
|
|
29
|
-
</th>
|
|
30
|
-
</tr>
|
|
31
|
-
</thead>
|
|
32
|
-
<tbody>
|
|
33
|
-
<tr
|
|
34
|
-
v-for="(row, rowIndex) in processedTableData"
|
|
35
|
-
:key="rowIndex"
|
|
36
|
-
@mouseenter="hoveredRowIndex = rowIndex"
|
|
37
|
-
@mouseleave="hoveredRowIndex = null"
|
|
38
|
-
>
|
|
39
|
-
<td
|
|
40
|
-
v-for="cell in row"
|
|
41
|
-
:key="cell.key"
|
|
42
|
-
:colspan="cell.colspan"
|
|
43
|
-
:rowspan="cell.rowspan"
|
|
44
|
-
:class="getBodyCellClass(cell, rowIndex)"
|
|
45
|
-
:style="getBodyCellStyle(cell)"
|
|
46
|
-
>
|
|
47
|
-
<!-- Именованный слот по prop колонки -->
|
|
48
|
-
<slot
|
|
49
|
-
v-if="cell.prop && slots[cell.prop]"
|
|
50
|
-
:name="cell.prop"
|
|
51
|
-
:row="cell.originalRow"
|
|
52
|
-
:$index="cell.rowIndex"
|
|
53
|
-
:value="cell.label"
|
|
54
|
-
/>
|
|
55
|
-
<!-- Универсальный слот для всех колонок -->
|
|
56
|
-
<slot
|
|
57
|
-
v-else-if="slots.cell"
|
|
58
|
-
name="cell"
|
|
59
|
-
:row="cell.originalRow"
|
|
60
|
-
:$index="cell.rowIndex"
|
|
61
|
-
:column="cell.prop"
|
|
62
|
-
:value="cell.label"
|
|
63
|
-
/>
|
|
64
|
-
<!-- Fallback на простое значение -->
|
|
65
|
-
<template v-else>
|
|
66
|
-
{{ cell.label }}
|
|
67
|
-
</template>
|
|
68
|
-
</td>
|
|
69
|
-
</tr>
|
|
70
|
-
</tbody>
|
|
71
|
-
</table>
|
|
72
|
-
</div>
|
|
73
|
-
</template>
|
|
74
|
-
|
|
75
|
-
<script setup>
|
|
76
|
-
import {
|
|
77
|
-
ref, useSlots, computed, watchEffect, provide, reactive,
|
|
78
|
-
onMounted, onUnmounted, nextTick, watch
|
|
79
|
-
} from 'vue'
|
|
80
|
-
|
|
81
|
-
const props = defineProps({
|
|
82
|
-
data: { type: Array, required: true },
|
|
83
|
-
resizable: { type: Boolean, default: true },
|
|
84
|
-
maxWidth: { type: [String, Number], default: undefined }
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const emit = defineEmits(['column-resize'])
|
|
88
|
-
|
|
89
|
-
const slots = useSlots()
|
|
90
|
-
const columnTree = reactive([])
|
|
91
|
-
const columnWidths = ref({})
|
|
92
|
-
const isResizing = ref(false)
|
|
93
|
-
const hoveredColIndices = ref(null)
|
|
94
|
-
const hoveredRowIndex = ref(null)
|
|
95
|
-
const wrapperRef = ref(null)
|
|
96
|
-
const tableRef = ref(null)
|
|
97
|
-
const isOverflowing = ref(false)
|
|
98
|
-
const isClient = typeof window !== 'undefined' && typeof document !== 'undefined'
|
|
99
|
-
let columnOrder = 0
|
|
100
|
-
let resizeObserver = null
|
|
101
|
-
|
|
102
|
-
provide('swTableColumns', columnTree)
|
|
103
|
-
provide('swTableAllocColumnOrder', () => columnOrder++)
|
|
104
|
-
|
|
105
|
-
function parseWidth(width) {
|
|
106
|
-
if (width == null || width === 'auto') return null
|
|
107
|
-
if (typeof width === 'number') return width
|
|
108
|
-
const parsed = parseInt(width, 10)
|
|
109
|
-
return Number.isNaN(parsed) ? null : parsed
|
|
110
|
-
}
|
|
111
|
-
function formatWidth(width) {
|
|
112
|
-
return width == null ? undefined : `${width}px`
|
|
113
|
-
}
|
|
114
|
-
function getColumnWidth(prop, defaultWidth) {
|
|
115
|
-
if (columnWidths.value[prop] != null) return columnWidths.value[prop]
|
|
116
|
-
return parseWidth(defaultWidth)
|
|
117
|
-
}
|
|
118
|
-
function getColumnWidthStyle(prop, defaultWidth) {
|
|
119
|
-
const width = getColumnWidth(prop, defaultWidth)
|
|
120
|
-
if (width == null) return {}
|
|
121
|
-
const formatted = formatWidth(width)
|
|
122
|
-
return { width: formatted, minWidth: formatted }
|
|
123
|
-
}
|
|
124
|
-
function getColumnPixelWidth(column) {
|
|
125
|
-
if (!column?.prop) return parseWidth(column?.width) ?? parseWidth(column?.minWidth) ?? 80
|
|
126
|
-
return getColumnWidth(column.prop, column.width)
|
|
127
|
-
?? parseWidth(column.minWidth) ?? 80
|
|
128
|
-
}
|
|
129
|
-
function getLeftOffsetForColIndex(colIndex) {
|
|
130
|
-
let offset = 0
|
|
131
|
-
for (let i = 0; i < colIndex; i++) {
|
|
132
|
-
offset += getColumnPixelWidth(flatColumns.value[i])
|
|
133
|
-
}
|
|
134
|
-
return offset
|
|
135
|
-
}
|
|
136
|
-
function getRightOffsetForColIndex(colIndex) {
|
|
137
|
-
let offset = 0
|
|
138
|
-
const columns = flatColumns.value
|
|
139
|
-
for (let i = columns.length - 1; i > colIndex; i--) {
|
|
140
|
-
offset += getColumnPixelWidth(columns[i])
|
|
141
|
-
}
|
|
142
|
-
return offset
|
|
143
|
-
}
|
|
144
|
-
function getCellFixedSide(cell) {
|
|
145
|
-
if (cell.fixed) return cell.fixed
|
|
146
|
-
if (cell.prop) return flatColumns.value.find((col) => col.prop === cell.prop)?.fixed
|
|
147
|
-
if (!cell.colIndices?.length) return null
|
|
148
|
-
const sides = cell.colIndices.map((i) => flatColumns.value[i]?.fixed).filter(Boolean)
|
|
149
|
-
if (sides.length && sides.every((side) => side === 'left')) return 'left'
|
|
150
|
-
if (sides.length && sides.every((side) => side === 'right')) return 'right'
|
|
151
|
-
return null
|
|
152
|
-
}
|
|
153
|
-
function getFixedPositionStyle(cell, inHeader = false) {
|
|
154
|
-
const side = getCellFixedSide(cell)
|
|
155
|
-
if (!side) return {}
|
|
156
|
-
const startIndex = cell.colIndex ?? cell.colIndices[0]
|
|
157
|
-
const endIndex = cell.colIndex != null
|
|
158
|
-
? cell.colIndex + (cell.colspan || 1) - 1
|
|
159
|
-
: cell.colIndices[cell.colIndices.length - 1]
|
|
160
|
-
const zBase = inHeader ? 100 : 0
|
|
161
|
-
if (side === 'left') {
|
|
162
|
-
return {
|
|
163
|
-
position: 'sticky',
|
|
164
|
-
left: `${getLeftOffsetForColIndex(startIndex)}px`,
|
|
165
|
-
zIndex: zBase + startIndex + 1
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
position: 'sticky',
|
|
170
|
-
right: `${getRightOffsetForColIndex(endIndex)}px`,
|
|
171
|
-
zIndex: zBase + flatColumns.value.length - endIndex
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function getHeaderCellStyle(cell) {
|
|
175
|
-
const style = { minHeight: cell.height && cell.height !== 'auto' ? cell.height : undefined}
|
|
176
|
-
if (cell.prop) Object.assign(style, getColumnWidthStyle(cell.prop, cell.width))
|
|
177
|
-
else if (cell.width && cell.width !== 'auto') style.minWidth = formatWidth(parseWidth(cell.width)) || cell.width
|
|
178
|
-
if (isFixedActive.value) Object.assign(style, getFixedPositionStyle(cell, true))
|
|
179
|
-
return style
|
|
180
|
-
}
|
|
181
|
-
function getBodyCellStyle(cell) {
|
|
182
|
-
const style = { ...cell.style }
|
|
183
|
-
if (isFixedActive.value) Object.assign(style, getFixedPositionStyle(cell))
|
|
184
|
-
return style
|
|
185
|
-
}
|
|
186
|
-
function isResizableLeaf(cell) {
|
|
187
|
-
if (!props.resizable || !cell.prop) return false
|
|
188
|
-
return cell.resizable !== false
|
|
189
|
-
}
|
|
190
|
-
function onHeaderEnter(cell) {hoveredColIndices.value = new Set(cell.colIndices)}
|
|
191
|
-
function onHeaderLeave() {hoveredColIndices.value = null}
|
|
192
|
-
function cellCoversHoveredColumn(cell) {
|
|
193
|
-
if (!hoveredColIndices.value) return false
|
|
194
|
-
const start = cell.colIndex
|
|
195
|
-
const end = start + (cell.colspan || 1) - 1
|
|
196
|
-
for (let i = start; i <= end; i++) {
|
|
197
|
-
if (hoveredColIndices.value.has(i)) return true
|
|
198
|
-
}
|
|
199
|
-
return false
|
|
200
|
-
}
|
|
201
|
-
function isRowHoveredForCell(cell, rowIndex) {
|
|
202
|
-
const hover = hoveredRowIndex.value
|
|
203
|
-
if (hover === null) return false
|
|
204
|
-
return rowIndex <= hover && hover < rowIndex + (cell.rowspan || 1)
|
|
205
|
-
}
|
|
206
|
-
function getFixedCellClass(cell) {
|
|
207
|
-
const side = getCellFixedSide(cell)
|
|
208
|
-
return {
|
|
209
|
-
'fixed-left': isFixedActive.value && side === 'left',
|
|
210
|
-
'fixed-right': isFixedActive.value && side === 'right'
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function getBodyCellClass(cell, rowIndex) {
|
|
214
|
-
const colHover = cellCoversHoveredColumn(cell)
|
|
215
|
-
const rowHover = isRowHoveredForCell(cell, rowIndex)
|
|
216
|
-
return {
|
|
217
|
-
...getFixedCellClass(cell),
|
|
218
|
-
'col-hover': colHover && !rowHover,
|
|
219
|
-
'row-hover': rowHover && !colHover
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function getHeaderCellClass(cell) {
|
|
223
|
-
return {
|
|
224
|
-
...getFixedCellClass(cell),
|
|
225
|
-
'resizable': isResizableLeaf(cell),
|
|
226
|
-
'col-hover': cellCoversHoveredColumn(cell)
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function getMinResizeWidth(cell) {
|
|
230
|
-
return parseWidth(cell.minWidth) ?? 48
|
|
231
|
-
}
|
|
232
|
-
function startResize(event, cell) {
|
|
233
|
-
if (!isClient) return
|
|
234
|
-
const th = event.currentTarget.closest('th')
|
|
235
|
-
if (!th || !cell.prop) return
|
|
236
|
-
const prop = cell.prop
|
|
237
|
-
const startX = event.clientX
|
|
238
|
-
const startWidth = getColumnWidth(prop, cell.width) ?? th.offsetWidth
|
|
239
|
-
const minWidth = getMinResizeWidth(cell)
|
|
240
|
-
isResizing.value = true
|
|
241
|
-
document.body.style.cursor = 'col-resize'
|
|
242
|
-
document.body.style.userSelect = 'none'
|
|
243
|
-
const onMouseMove = (e) => {
|
|
244
|
-
const nextWidth = Math.max(minWidth, startWidth + (e.clientX - startX))
|
|
245
|
-
columnWidths.value = { ...columnWidths.value, [prop]: nextWidth }
|
|
246
|
-
}
|
|
247
|
-
const onMouseUp = () => {
|
|
248
|
-
document.removeEventListener('mousemove', onMouseMove)
|
|
249
|
-
document.removeEventListener('mouseup', onMouseUp)
|
|
250
|
-
document.body.style.cursor = ''
|
|
251
|
-
document.body.style.userSelect = ''
|
|
252
|
-
isResizing.value = false
|
|
253
|
-
emit('column-resize', { prop, width: columnWidths.value[prop] })
|
|
254
|
-
nextTick(updateOverflowState)
|
|
255
|
-
}
|
|
256
|
-
document.addEventListener('mousemove', onMouseMove)
|
|
257
|
-
document.addEventListener('mouseup', onMouseUp)
|
|
258
|
-
}
|
|
259
|
-
function sortColumns(columns) {
|
|
260
|
-
return [...columns].sort((a, b) => a.order - b.order)
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Получение максимальной глубины дерева
|
|
264
|
-
function getMaxDepth(columns) {
|
|
265
|
-
if (!columns || columns.length === 0) return 1
|
|
266
|
-
let maxDepth = 1
|
|
267
|
-
for (const column of columns) {
|
|
268
|
-
if (column.children && column.children.length > 0) {
|
|
269
|
-
const childDepth = getMaxDepth(column.children)
|
|
270
|
-
maxDepth = Math.max(maxDepth, 1 + childDepth)
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return maxDepth
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Преобразование дерева в строки для thead
|
|
277
|
-
function buildHeaderRows(columns, depth) {
|
|
278
|
-
const rows = Array.from({ length: depth }, () => [])
|
|
279
|
-
let leafColIndex = 0
|
|
280
|
-
function processColumns(cols, rowIndex, parentKey = '') {
|
|
281
|
-
const sortedCols = sortColumns(cols)
|
|
282
|
-
for (let i = 0; i < sortedCols.length; i++) {
|
|
283
|
-
const col = sortedCols[i]
|
|
284
|
-
const key = parentKey ? `${parentKey}-${col.prop || i}` : (col.prop || i)
|
|
285
|
-
if (col.children && col.children.length > 0) {
|
|
286
|
-
const startIndex = leafColIndex
|
|
287
|
-
const leafCount = countLeafColumns(col.children)
|
|
288
|
-
processColumns(col.children, rowIndex + 1, key)
|
|
289
|
-
rows[rowIndex].push({
|
|
290
|
-
key,
|
|
291
|
-
label: col.label,
|
|
292
|
-
colspan: leafCount,
|
|
293
|
-
rowspan: 1,
|
|
294
|
-
width: col.width,
|
|
295
|
-
height: col.height,
|
|
296
|
-
colIndices: Array.from({ length: leafCount }, (_, j) => startIndex + j)
|
|
297
|
-
})
|
|
298
|
-
} else {
|
|
299
|
-
const colIndex = leafColIndex++
|
|
300
|
-
rows[rowIndex].push({
|
|
301
|
-
key: col.prop,
|
|
302
|
-
label: col.label,
|
|
303
|
-
colspan: 1,
|
|
304
|
-
rowspan: depth - rowIndex,
|
|
305
|
-
width: col.width,
|
|
306
|
-
height: col.height,
|
|
307
|
-
prop: col.prop,
|
|
308
|
-
resizable: col.resizable,
|
|
309
|
-
minWidth: col.minWidth,
|
|
310
|
-
colIndex,
|
|
311
|
-
colIndices: [colIndex]
|
|
312
|
-
})
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
processColumns(columns, 0)
|
|
317
|
-
return rows
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Подсчет количества листовых колонок
|
|
321
|
-
function countLeafColumns(columns) {
|
|
322
|
-
let count = 0
|
|
323
|
-
function traverse(cols) {
|
|
324
|
-
for (const col of sortColumns(cols)) {
|
|
325
|
-
if (col.children && col.children.length > 0) traverse(col.children)
|
|
326
|
-
else count++
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
traverse(columns)
|
|
330
|
-
return count
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Извлечение плоского списка конечных колонок
|
|
334
|
-
function extractLeafColumns(columns) {
|
|
335
|
-
const result = []
|
|
336
|
-
function traverse(cols) {
|
|
337
|
-
for (const col of sortColumns(cols)) {
|
|
338
|
-
if (col.children && col.children.length > 0) traverse(col.children)
|
|
339
|
-
else result.push(col)
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
traverse(columns)
|
|
343
|
-
return result
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Обработка данных для tbody с поддержкой colspan
|
|
347
|
-
function processBodyData(data, columns) {
|
|
348
|
-
|
|
349
|
-
// Защита от undefined/null значений
|
|
350
|
-
if (!data || !Array.isArray(data)) return []
|
|
351
|
-
if (!columns || !Array.isArray(columns)) return []
|
|
352
|
-
|
|
353
|
-
// Функция для получения значения по пути (например, "gant.0")
|
|
354
|
-
function getValueByPath(obj, path) {
|
|
355
|
-
if (!obj || !path) return undefined
|
|
356
|
-
|
|
357
|
-
// Разбиваем путь по точкам
|
|
358
|
-
const keys = path.split('.')
|
|
359
|
-
let value = obj
|
|
360
|
-
for (const key of keys) {
|
|
361
|
-
if (value === null || value === undefined) return undefined
|
|
362
|
-
|
|
363
|
-
// Пробуем обратиться как к свойству объекта или элементу массива
|
|
364
|
-
value = value[key]
|
|
365
|
-
}
|
|
366
|
-
return value
|
|
367
|
-
}
|
|
368
|
-
const processedRows = []
|
|
369
|
-
const cellMap = new Map() // Для отслеживания объединенных ячеек
|
|
370
|
-
data.forEach((row, rowIndex) => {
|
|
371
|
-
const processedRow = []
|
|
372
|
-
columns.forEach((column, colIndex) => {
|
|
373
|
-
const key = `${rowIndex}-${colIndex}`
|
|
374
|
-
|
|
375
|
-
// Проверяем, не занята ли эта ячейка из-за rowspan/colspan
|
|
376
|
-
if (cellMap.has(key)) return
|
|
377
|
-
|
|
378
|
-
// Получаем значение по пути (поддержка "gant.0", "gant.1" и т.д.)
|
|
379
|
-
const cellData = getValueByPath(row, column.prop)
|
|
380
|
-
let cellValue = cellData
|
|
381
|
-
let colspan = 1
|
|
382
|
-
let rowspan = 1
|
|
383
|
-
let style = {}
|
|
384
|
-
|
|
385
|
-
// Проверяем, есть ли у значения свойства rowspan/colspan
|
|
386
|
-
if (cellData && typeof cellData === 'object' && cellData !== null) {
|
|
387
|
-
cellValue = cellData.label || cellData.value || ''
|
|
388
|
-
colspan = cellData.colspan || 1
|
|
389
|
-
rowspan = cellData.rowspan || 1
|
|
390
|
-
style = cellData.style || {}
|
|
391
|
-
}
|
|
392
|
-
style = {
|
|
393
|
-
...style,
|
|
394
|
-
...getColumnWidthStyle(column.prop, column.width)
|
|
395
|
-
}
|
|
396
|
-
const cell = {
|
|
397
|
-
key,
|
|
398
|
-
label: cellValue,
|
|
399
|
-
prop: column.prop,
|
|
400
|
-
fixed: column.fixed,
|
|
401
|
-
colIndex,
|
|
402
|
-
colspan,
|
|
403
|
-
rowspan,
|
|
404
|
-
style,
|
|
405
|
-
originalRow: row,
|
|
406
|
-
rowIndex
|
|
407
|
-
}
|
|
408
|
-
processedRow.push(cell)
|
|
409
|
-
// Помечаем объединенные ячейки
|
|
410
|
-
for (let r = 0; r < rowspan; r++) {
|
|
411
|
-
for (let c = 0; c < colspan; c++) {
|
|
412
|
-
if (r === 0 && c === 0) continue // Основная ячейка
|
|
413
|
-
const cellKey = `${rowIndex + r}-${colIndex + c}`
|
|
414
|
-
cellMap.set(cellKey, true)
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
})
|
|
418
|
-
if (processedRow.length > 0) {
|
|
419
|
-
processedRows.push(processedRow)
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
return processedRows
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Вычисляемые свойства
|
|
426
|
-
const maxDepth = computed(() => getMaxDepth(columnTree))
|
|
427
|
-
const headerRows = computed(() => buildHeaderRows(columnTree, maxDepth.value))
|
|
428
|
-
const flatColumns = computed(() => extractLeafColumns(columnTree))
|
|
429
|
-
const processedTableData = computed(() => processBodyData(props.data, flatColumns.value))
|
|
430
|
-
const hasFixedColumns = computed(() => flatColumns.value.some((col) => col.fixed))
|
|
431
|
-
const wrapperStyle = computed(() => {
|
|
432
|
-
if (props.maxWidth == null) return undefined
|
|
433
|
-
const width = typeof props.maxWidth === 'number'
|
|
434
|
-
? `${props.maxWidth}px`
|
|
435
|
-
: props.maxWidth
|
|
436
|
-
return { maxWidth: width }
|
|
437
|
-
})
|
|
438
|
-
const isFixedActive = computed(() => (
|
|
439
|
-
props.maxWidth != null && hasFixedColumns.value && isOverflowing.value
|
|
440
|
-
))
|
|
441
|
-
function updateOverflowState() {
|
|
442
|
-
if (!isClient) {
|
|
443
|
-
isOverflowing.value = false
|
|
444
|
-
return
|
|
445
|
-
}
|
|
446
|
-
const wrapper = wrapperRef.value
|
|
447
|
-
const table = tableRef.value
|
|
448
|
-
if (!wrapper || !table) {
|
|
449
|
-
isOverflowing.value = false
|
|
450
|
-
return
|
|
451
|
-
}
|
|
452
|
-
isOverflowing.value = table.scrollWidth > wrapper.clientWidth + 1
|
|
453
|
-
}
|
|
454
|
-
function initColumnWidths() {
|
|
455
|
-
const widths = {}
|
|
456
|
-
for (const column of flatColumns.value) {
|
|
457
|
-
const width = parseWidth(column.width)
|
|
458
|
-
if (column.prop && width != null) widths[column.prop] = width
|
|
459
|
-
}
|
|
460
|
-
columnWidths.value = widths
|
|
461
|
-
}
|
|
462
|
-
watchEffect(() => {
|
|
463
|
-
flatColumns.value
|
|
464
|
-
initColumnWidths()
|
|
465
|
-
})
|
|
466
|
-
watch(
|
|
467
|
-
[() => props.data, () => props.maxWidth, flatColumns, columnWidths, processedTableData],
|
|
468
|
-
() => nextTick(updateOverflowState)
|
|
469
|
-
)
|
|
470
|
-
onMounted(() => {
|
|
471
|
-
updateOverflowState()
|
|
472
|
-
if (!isClient || typeof ResizeObserver === 'undefined') return
|
|
473
|
-
resizeObserver = new ResizeObserver(() => updateOverflowState())
|
|
474
|
-
if (wrapperRef.value) resizeObserver.observe(wrapperRef.value)
|
|
475
|
-
if (tableRef.value) resizeObserver.observe(tableRef.value)
|
|
476
|
-
})
|
|
477
|
-
onUnmounted(() => {
|
|
478
|
-
resizeObserver?.disconnect()
|
|
479
|
-
resizeObserver = null
|
|
480
|
-
})
|
|
481
|
-
</script>
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div style="display: none;"><slot /></div>
|
|
3
|
-
</template>
|
|
4
|
-
|
|
5
|
-
<script setup>
|
|
6
|
-
import { inject, provide, onUnmounted, reactive, watch } from 'vue'
|
|
7
|
-
|
|
8
|
-
const props = defineProps({
|
|
9
|
-
prop: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: undefined
|
|
12
|
-
},
|
|
13
|
-
label: {
|
|
14
|
-
type: String,
|
|
15
|
-
default: ''
|
|
16
|
-
},
|
|
17
|
-
width: {
|
|
18
|
-
type: [String, Number],
|
|
19
|
-
default: 'auto'
|
|
20
|
-
},
|
|
21
|
-
height: {
|
|
22
|
-
type: [String, Number],
|
|
23
|
-
default: 'auto'
|
|
24
|
-
},
|
|
25
|
-
resizable: {
|
|
26
|
-
type: Boolean,
|
|
27
|
-
default: undefined
|
|
28
|
-
},
|
|
29
|
-
minWidth: {
|
|
30
|
-
type: [String, Number],
|
|
31
|
-
default: 48
|
|
32
|
-
},
|
|
33
|
-
fixed: {
|
|
34
|
-
type: String,
|
|
35
|
-
default: undefined,
|
|
36
|
-
validator: (value) => value == null || value === 'left' || value === 'right'
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const tableColumns = inject('swTableColumns', null)
|
|
41
|
-
const parentColumn = inject('swTableParentColumn', null)
|
|
42
|
-
const allocColumnOrder = inject('swTableAllocColumnOrder', null)
|
|
43
|
-
|
|
44
|
-
const column = reactive({
|
|
45
|
-
order: allocColumnOrder?.() ?? 0,
|
|
46
|
-
prop: props.prop,
|
|
47
|
-
label: props.label,
|
|
48
|
-
width: props.width,
|
|
49
|
-
height: props.height,
|
|
50
|
-
resizable: props.resizable,
|
|
51
|
-
minWidth: props.minWidth,
|
|
52
|
-
fixed: props.fixed,
|
|
53
|
-
children: []
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
watch(() => props, (nextProps) => {
|
|
57
|
-
column.prop = nextProps.prop
|
|
58
|
-
column.label = nextProps.label
|
|
59
|
-
column.width = nextProps.width
|
|
60
|
-
column.height = nextProps.height
|
|
61
|
-
column.resizable = nextProps.resizable
|
|
62
|
-
column.minWidth = nextProps.minWidth
|
|
63
|
-
column.fixed = nextProps.fixed
|
|
64
|
-
}, { deep: true })
|
|
65
|
-
|
|
66
|
-
provide('swTableParentColumn', column)
|
|
67
|
-
|
|
68
|
-
function registerColumn() {
|
|
69
|
-
if (parentColumn) {
|
|
70
|
-
parentColumn.children.push(column)
|
|
71
|
-
} else if (tableColumns) {
|
|
72
|
-
tableColumns.push(column)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function unregisterColumn() {
|
|
77
|
-
const list = parentColumn ? parentColumn.children : tableColumns
|
|
78
|
-
if (!list) return
|
|
79
|
-
const index = list.indexOf(column)
|
|
80
|
-
if (index > -1) list.splice(index, 1)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
registerColumn()
|
|
84
|
-
|
|
85
|
-
onUnmounted(() => {
|
|
86
|
-
unregisterColumn()
|
|
87
|
-
})
|
|
88
|
-
</script>
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import {ref, provide} from 'vue'
|
|
3
|
-
const activeTab = ref(0);
|
|
4
|
-
const tabs = ref([]);
|
|
5
|
-
|
|
6
|
-
const props = defineProps({
|
|
7
|
-
class: {type:String, default: ''}
|
|
8
|
-
})
|
|
9
|
-
const model = defineModel()
|
|
10
|
-
const emit = defineEmits(['tab-click'])
|
|
11
|
-
|
|
12
|
-
function registerTab(tab) {
|
|
13
|
-
tabs.value.push(tab)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function unregisterTab(tab) {
|
|
17
|
-
tabs.value = tabs.value.filter(t => t !== tab)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
provide('registerTab', registerTab)
|
|
21
|
-
provide('unregisterTab', unregisterTab)
|
|
22
|
-
provide('activeTab', model)
|
|
23
|
-
provide('tabs', tabs)
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
<template>
|
|
27
|
-
<div :class="'sw-tabs ' + props.class">
|
|
28
|
-
<header v-if="tabs.length !== 0">
|
|
29
|
-
<span
|
|
30
|
-
v-for="(tab, index) in tabs"
|
|
31
|
-
:key="index"
|
|
32
|
-
:class="[{ active: model === index }]"
|
|
33
|
-
@click="model = index; emit('tab-click', index)"
|
|
34
|
-
>
|
|
35
|
-
{{ tab.label || tab.title }}
|
|
36
|
-
</span>
|
|
37
|
-
<slot name="header"></slot>
|
|
38
|
-
</header>
|
|
39
|
-
<slot />
|
|
40
|
-
</div>
|
|
41
|
-
</template>
|
|
42
|
-
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import {computed, onMounted, onUnmounted, inject} from 'vue'
|
|
3
|
-
|
|
4
|
-
const props = defineProps({
|
|
5
|
-
title: {
|
|
6
|
-
type: String,
|
|
7
|
-
required: true
|
|
8
|
-
},
|
|
9
|
-
label: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: ''
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const registerTab = inject('registerTab')
|
|
16
|
-
const unregisterTab = inject('unregisterTab')
|
|
17
|
-
// Регистрируем вкладку при монтировании
|
|
18
|
-
onMounted(() => {
|
|
19
|
-
registerTab({
|
|
20
|
-
title: props.title,
|
|
21
|
-
label: props.label
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
// Отменяем регистрацию при удалении
|
|
26
|
-
onUnmounted(() => {
|
|
27
|
-
unregisterTab({
|
|
28
|
-
title: props.title,
|
|
29
|
-
label: props.label
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const activeTab = inject('activeTab')
|
|
34
|
-
const tabs = inject('tabs') // Если понадобится индекс
|
|
35
|
-
|
|
36
|
-
const tabIndex = computed(() => tabs.value.findIndex(tab => tab.title === props.title))
|
|
37
|
-
const isActive = computed(() => activeTab.value === tabIndex.value)
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<template>
|
|
41
|
-
<div v-if="isActive" class="tab-content">
|
|
42
|
-
<slot></slot>
|
|
43
|
-
</div>
|
|
44
|
-
</template>
|
package/src/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
import { defineAsyncComponent, type App, type Component } from 'vue'
|
|
3
|
-
import './styles/main.scss'
|
|
4
|
-
import { Alert } from './Alert'
|
|
5
|
-
|
|
6
|
-
// Import all Vue components
|
|
7
|
-
const modules = import.meta.glob<{ default: Component }>('./components/*.vue')
|
|
8
|
-
|
|
9
|
-
// Create components object with proper typing
|
|
10
|
-
const components: Record<string, ReturnType<typeof defineAsyncComponent>> = {}
|
|
11
|
-
|
|
12
|
-
// Extract component name and register asynchronously
|
|
13
|
-
for (const path in modules) {
|
|
14
|
-
const componentName = path
|
|
15
|
-
.split('/')
|
|
16
|
-
.pop()!
|
|
17
|
-
.replace('.vue', '')
|
|
18
|
-
.replace(/-(\w)/g, (_, c) => c.toUpperCase())
|
|
19
|
-
|
|
20
|
-
components[componentName] = defineAsyncComponent(() => modules[path]())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Plugin installation function
|
|
24
|
-
const Library = {
|
|
25
|
-
install(app: App) {
|
|
26
|
-
// Register all components globally
|
|
27
|
-
Object.keys(components).forEach(key => {
|
|
28
|
-
app.component(key, components[key])
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Register Alert globally
|
|
32
|
-
app.config.globalProperties.$Alert = Alert
|
|
33
|
-
app.provide('Alert', Alert)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Named exports
|
|
38
|
-
export { components, Alert, Library }
|