webcake-ui-kit 1.2.0 → 1.2.1

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.
Files changed (67) hide show
  1. package/package.json +8 -2
  2. package/src/components/checkbox/Checkbox.vue +1 -1
  3. package/src/components/drawer/Drawer.vue +261 -0
  4. package/src/components/drawer/drawer.css +162 -0
  5. package/src/components/dropdown/Dropdown.vue +15 -9
  6. package/src/components/hover-card/HoverCard.vue +159 -0
  7. package/src/components/hover-card/hover-card.css +10 -0
  8. package/src/components/input-counter/InputCounter.vue +250 -0
  9. package/src/components/input-counter/input-counter.css +209 -0
  10. package/src/components/menu/Menu.vue +4 -2
  11. package/src/components/popover/Popover.vue +144 -0
  12. package/src/components/popover/popover.css +3 -0
  13. package/src/components/table-v2/ColumnDragHandle.vue +103 -0
  14. package/src/components/table-v2/Table.vue +299 -0
  15. package/src/components/table-v2/TableColGroup.vue +55 -0
  16. package/src/components/table-v2/TableEmpty.vue +10 -0
  17. package/src/components/table-v2/TableLoading.vue +25 -0
  18. package/src/components/table-v2/TableResizeObserver.vue +93 -0
  19. package/src/components/table-v2/TableWrapper.vue +193 -0
  20. package/src/components/table-v2/body/DragPreview.vue +65 -0
  21. package/src/components/table-v2/body/MeasureCell.vue +42 -0
  22. package/src/components/table-v2/body/TableBody.vue +126 -0
  23. package/src/components/table-v2/body/TableCell.vue +108 -0
  24. package/src/components/table-v2/body/TableRow.vue +73 -0
  25. package/src/components/table-v2/composables/useColumns.js +19 -0
  26. package/src/components/table-v2/composables/useSorter.js +12 -0
  27. package/src/components/table-v2/composables/useSticky.js +31 -0
  28. package/src/components/table-v2/constants.js +2 -0
  29. package/src/components/table-v2/context/createTableContext.js +79 -0
  30. package/src/components/table-v2/header/TableHeader.vue +15 -0
  31. package/src/components/table-v2/header/TableHeaderCell.vue +89 -0
  32. package/src/components/table-v2/header/TableHeaderRow.vue +107 -0
  33. package/src/components/table-v2/style/table-body.css +0 -0
  34. package/src/components/table-v2/style/table-header.css +0 -0
  35. package/src/components/table-v2/style/table-loading.css +19 -0
  36. package/src/components/table-v2/style/table-wrapper.css +287 -0
  37. package/src/components/table-v2/style/table.css +5 -0
  38. package/src/icons/BoxShadow.vue +35 -0
  39. package/src/icons/Carousel.vue +34 -0
  40. package/src/icons/CloudSync2.vue +42 -0
  41. package/src/icons/CornerBottomLeft.vue +26 -0
  42. package/src/icons/CornerBottomRight.vue +26 -0
  43. package/src/icons/CornerTopLeft.vue +26 -0
  44. package/src/icons/CornerTopRight.vue +26 -0
  45. package/src/icons/DistanceRight.vue +30 -0
  46. package/src/icons/DistanceTop.vue +30 -0
  47. package/src/icons/DropShadow.vue +35 -0
  48. package/src/icons/Fire.vue +26 -0
  49. package/src/icons/GlobeAccess.vue +32 -0
  50. package/src/icons/InnerShadow.vue +33 -0
  51. package/src/icons/Livestream.vue +54 -0
  52. package/src/icons/PaddingBottom.vue +30 -0
  53. package/src/icons/PaddingLeft.vue +30 -0
  54. package/src/icons/PaddingRight.vue +30 -0
  55. package/src/icons/PaddingTop.vue +30 -0
  56. package/src/icons/SkewHeight.vue +32 -0
  57. package/src/icons/SkewWidth.vue +32 -0
  58. package/src/icons/SquareDashedBottomSolid.vue +26 -0
  59. package/src/icons/SquareDashedLeftSolid.vue +26 -0
  60. package/src/icons/SquareDashedRightSolid.vue +26 -0
  61. package/src/icons/StrokeLine.vue +23 -0
  62. package/src/icons/Topline.vue +26 -0
  63. package/src/icons/index.js +25 -0
  64. package/src/index.js +5 -0
  65. package/src/styles/.omc/state/agent-replay-645326b7-372b-463d-ab45-0adaafe31a51.jsonl +2 -0
  66. package/src/styles/.omc/state/subagent-tracking.json +7 -0
  67. package/src/utils/common.js +34 -0
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <div
3
+ :class="['ui-table-v2__cell-resize-handle', dragging && 'dragging', reversed && 'reversed']"
4
+ @mousedown.stop.prevent="handleMouseDown"
5
+ @touchstart.stop.prevent="handleTouchStart"
6
+ @click.stop.prevent
7
+ >
8
+ <div class="ui-table-v2__cell-resize-line"></div>
9
+ </div>
10
+ </template>
11
+
12
+ <script>
13
+ export default {
14
+ name: 'ColumnDragHandle',
15
+ props: {
16
+ column: { type: Object, required: true },
17
+ width: { type: Number, default: 0 },
18
+ minWidth: { type: Number, default: 50 },
19
+ maxWidth: { type: Number, default: Infinity },
20
+ reversed: { type: Boolean, default: false }
21
+ },
22
+ emits: ['resize'],
23
+ data: function () {
24
+ return {
25
+ dragging: false
26
+ }
27
+ },
28
+ created: function () {
29
+ this._startX = 0
30
+ this._baseWidth = 0
31
+ this._rafId = null
32
+ this._moveHandler = null
33
+ this._stopHandler = null
34
+ },
35
+ beforeUnmount: function () {
36
+ this._removeEvents()
37
+ },
38
+ // eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle, vue/no-dupe-keys
39
+ beforeDestroy: function () {
40
+ this._removeEvents()
41
+ },
42
+ methods: {
43
+ _getPageX: function (e) {
44
+ if (e.touches) {
45
+ return e.touches.length ? e.touches[0].pageX : e.changedTouches[0].pageX
46
+ }
47
+ return e.pageX
48
+ },
49
+ _clampWidth: function (w) {
50
+ const min = typeof this.minWidth === 'number' && !isNaN(this.minWidth) ? this.minWidth : 50
51
+ const max = typeof this.maxWidth === 'number' && !isNaN(this.maxWidth) ? this.maxWidth : Infinity
52
+ return Math.min(Math.max(w, min), max)
53
+ },
54
+ _updateWidth: function (e) {
55
+ const deltaX = this._startX - this._getPageX(e)
56
+ const w = this._clampWidth(this.reversed ? this._baseWidth + deltaX : this._baseWidth - deltaX)
57
+ if (this._rafId) cancelAnimationFrame(this._rafId)
58
+ this._rafId = requestAnimationFrame(() => {
59
+ this.$emit('resize', w, this.column)
60
+ })
61
+ },
62
+ _removeEvents: function () {
63
+ if (this._moveHandler) {
64
+ document.documentElement.removeEventListener('mousemove', this._moveHandler)
65
+ document.documentElement.removeEventListener('touchmove', this._moveHandler)
66
+ this._moveHandler = null
67
+ }
68
+ if (this._stopHandler) {
69
+ document.documentElement.removeEventListener('mouseup', this._stopHandler)
70
+ document.documentElement.removeEventListener('touchend', this._stopHandler)
71
+ this._stopHandler = null
72
+ }
73
+ if (this._rafId) {
74
+ cancelAnimationFrame(this._rafId)
75
+ this._rafId = null
76
+ }
77
+ },
78
+ _handleStart: function (e) {
79
+ this.dragging = true
80
+ this._removeEvents()
81
+ this._baseWidth = this.$el.parentNode.getBoundingClientRect().width
82
+ this._startX = this._getPageX(e)
83
+ this._moveHandler = this._updateWidth.bind(this)
84
+ this._stopHandler = e => {
85
+ this.dragging = false
86
+ this._updateWidth(e)
87
+ this._removeEvents()
88
+ }
89
+ document.documentElement.addEventListener('mousemove', this._moveHandler)
90
+ document.documentElement.addEventListener('touchmove', this._moveHandler, { passive: false })
91
+ document.documentElement.addEventListener('mouseup', this._stopHandler)
92
+ document.documentElement.addEventListener('touchend', this._stopHandler)
93
+ },
94
+ handleMouseDown: function (e) {
95
+ if (e.which !== 1) return
96
+ this._handleStart(e)
97
+ },
98
+ handleTouchStart: function (e) {
99
+ this._handleStart(e)
100
+ }
101
+ }
102
+ }
103
+ </script>
@@ -0,0 +1,299 @@
1
+ <template>
2
+ <div class="ui-table-v2">
3
+ <TableLoading>
4
+ <TableResizeObserver @resize="handleContainerResize">
5
+ <TableWrapper>
6
+ <template #bodyCell="slotData">
7
+ <slot name="bodyCell" v-bind="slotData"></slot>
8
+ </template>
9
+ </TableWrapper>
10
+ </TableResizeObserver>
11
+ </TableLoading>
12
+ </div>
13
+ </template>
14
+
15
+ <script>
16
+ import { createTableContext } from './context/createTableContext.js'
17
+ import { flattenColumns } from './composables/useColumns.js'
18
+ import { sortData } from './composables/useSorter.js'
19
+ import { computeOffsets } from './composables/useSticky.js'
20
+ import { SELECTION_COLUMN, DRAGGABLE_COLUMN } from './constants.js'
21
+ import TableWrapper from './TableWrapper.vue'
22
+ import TableEmpty from './TableEmpty.vue'
23
+ import TableLoading from './TableLoading.vue'
24
+ import TableResizeObserver from './TableResizeObserver.vue'
25
+
26
+ export default {
27
+ name: 'TableV2',
28
+
29
+ components: { TableWrapper, TableLoading, TableResizeObserver },
30
+
31
+ provide: function () {
32
+ return { tableContext: this.tableCtx }
33
+ },
34
+
35
+ props: {
36
+ columns: {
37
+ type: Array,
38
+ default: function () {
39
+ return []
40
+ }
41
+ },
42
+ dataSource: {
43
+ type: Array,
44
+ default: function () {
45
+ return []
46
+ }
47
+ },
48
+ bordered: { type: Boolean, default: false },
49
+ size: { type: String, default: 'md' },
50
+ rowKey: { type: String, default: 'key' },
51
+ scroll: { type: Object, default: null },
52
+ loading: { type: Boolean, default: false },
53
+ rowSelection: { type: Object, default: null },
54
+ customRow: { type: Function, default: null },
55
+ customHeaderRow: { type: Function, default: null },
56
+ rowDraggable: { type: Object, default: null },
57
+ enableFixedLeft: { type: Boolean, default: false },
58
+ rowHeight: { type: Number, default: 36 },
59
+ headerHeight: { type: Number, default: 50 },
60
+ emptyText: { type: String, default: '' }
61
+ },
62
+
63
+ emits: ['change', 'sort-change', 'select-change'],
64
+
65
+ data: function () {
66
+ return { tableCtx: createTableContext() }
67
+ },
68
+
69
+ computed: {
70
+ isEmpty: function () {
71
+ return this.tableCtx.data.display.length === 0
72
+ },
73
+
74
+ columnsInput: function () {
75
+ return {
76
+ columns: this.columns,
77
+ rowKey: this.rowKey,
78
+ hasSelection: !!this.rowSelection,
79
+ hasDraggable: !!this.rowDraggable
80
+ }
81
+ },
82
+
83
+ rowsInput: function () {
84
+ return { customRow: this.customRow, customHeaderRow: this.customHeaderRow }
85
+ },
86
+
87
+ layoutInput: function () {
88
+ return {
89
+ bordered: this.bordered,
90
+ size: this.size,
91
+ scroll: this.scroll,
92
+ rowHeight: this.rowHeight,
93
+ headerHeight: this.headerHeight
94
+ }
95
+ },
96
+
97
+ dataInput: function () {
98
+ return {
99
+ source: this.dataSource,
100
+ sortKey: this.tableCtx.sort.columnKey,
101
+ sortOrder: this.tableCtx.sort.order,
102
+ loading: this.loading,
103
+ emptyText: this.emptyText
104
+ }
105
+ },
106
+
107
+ stickyInput: function () {
108
+ return {
109
+ columns: this.tableCtx.columns.flat,
110
+ widths: this.tableCtx.layout.columnWidths
111
+ }
112
+ },
113
+
114
+ selectionInput: function () {
115
+ return this.rowSelection
116
+ },
117
+
118
+ draggableInput: function () {
119
+ return this.rowDraggable
120
+ }
121
+ },
122
+
123
+ watch: {
124
+ columnsInput: {
125
+ immediate: true,
126
+ handler: function (v) {
127
+ var cols = flattenColumns(v.columns)
128
+ const isHasFixedLeft = cols.some(col => col.fixed === 'left')
129
+ if (v.hasSelection) {
130
+ cols.unshift({
131
+ key: '__selection__',
132
+ type: SELECTION_COLUMN,
133
+ width: 36,
134
+ dataIndex: '',
135
+ title: '',
136
+ align: null,
137
+ fixed: isHasFixedLeft || this.enableFixedLeft ? 'left' : null,
138
+ ellipsis: false
139
+ })
140
+ }
141
+ if (v.hasDraggable) {
142
+ cols.unshift({
143
+ key: '__draggable__',
144
+ type: DRAGGABLE_COLUMN,
145
+ width: 36,
146
+ dataIndex: '',
147
+ title: '',
148
+ align: null,
149
+ fixed: isHasFixedLeft || this.enableFixedLeft ? 'left' : null,
150
+ ellipsis: false
151
+ })
152
+ }
153
+ this.tableCtx.columns.flat = cols
154
+ this.tableCtx.layout.rowKey = v.rowKey
155
+ }
156
+ },
157
+
158
+ rowsInput: {
159
+ immediate: true,
160
+ handler: function (v) {
161
+ this.tableCtx.rows.customRow = v.customRow
162
+ this.tableCtx.rows.customHeaderRow = v.customHeaderRow
163
+ }
164
+ },
165
+
166
+ layoutInput: {
167
+ immediate: true,
168
+ deep: true,
169
+ handler: function (v) {
170
+ this.tableCtx.layout.bordered = v.bordered
171
+ this.tableCtx.layout.size = v.size
172
+ this.tableCtx.layout.scroll = v.scroll
173
+ this.tableCtx.layout.tableLayout = v.scroll && v.scroll.y ? 'fixed' : 'auto'
174
+ }
175
+ },
176
+
177
+ dataInput: {
178
+ immediate: true,
179
+ handler: function (v) {
180
+ this.tableCtx.data.source = v.source
181
+ ;((this.tableCtx.data.display = v.sortKey ? sortData(v.source, v.sortKey, v.sortOrder) : v.source),
182
+ (this.tableCtx.data.loading = v.loading))
183
+ this.tableCtx.data.emptyText = v.emptyText
184
+ console.log(this.tableCtx.data.emptyText)
185
+ }
186
+ },
187
+
188
+ stickyInput: {
189
+ deep: true,
190
+ immediate: true,
191
+ handler: function (v) {
192
+ if (!v.columns.length) return
193
+ var offsets = computeOffsets(v.columns, v.widths)
194
+ this.tableCtx.sticky.leftOffsets = offsets.left
195
+ this.tableCtx.sticky.rightOffsets = offsets.right
196
+ }
197
+ },
198
+
199
+ selectionInput: {
200
+ immediate: true,
201
+ deep: true,
202
+ handler: function (v) {
203
+ if (!v) return
204
+ this.tableCtx.selection.selectedRowKeys = v.selectedRowKeys || []
205
+ this.tableCtx.selection.hideSelectAll = v.hideSelectAll
206
+ this.tableCtx.selection.columnWidth = v.columnWidth
207
+ this.tableCtx.selection.type = v.type
208
+ this.tableCtx.selection.onChange = v.onChange
209
+ this.tableCtx.selection.onSelect = v.onSelect
210
+ this.tableCtx.selection.onSelectAll = v.onSelectAll
211
+ this.tableCtx.selection.onSelectNone = v.onSelectNone
212
+ }
213
+ },
214
+
215
+ draggableInput: {
216
+ immediate: true,
217
+ deep: true,
218
+ handler: function (v) {
219
+ this.tableCtx.draggable.enabled = !!v
220
+ if (!v) return
221
+ this.tableCtx.draggable.columnWidth = v.columnWidth || 36
222
+ this.tableCtx.draggable.handleReorder = v.handleReorder || null
223
+ this.tableCtx.draggable.enableAnimationFlip = v.enableAnimationFlip || false
224
+ }
225
+ }
226
+ },
227
+
228
+ created: function () {
229
+ this.tableCtx.actions.sort = this.handleSort
230
+ this.tableCtx.actions.select = this.handleSelect
231
+ this.tableCtx.actions.resize = this.handleResize
232
+ this.tableCtx.actions.reorder = this.handleReorder
233
+ },
234
+
235
+ methods: {
236
+ handleSort: function (columnKey, order) {
237
+ this.tableCtx.sort.columnKey = columnKey
238
+ this.tableCtx.sort.order = order
239
+ this.$emit('sort-change', { columnKey: columnKey, order: order })
240
+ this.$emit('change', { sort: { columnKey: columnKey, order: order } })
241
+ },
242
+
243
+ handleSelect: function (keys, meta) {
244
+ var prevKeys = this.tableCtx.selection.selectedRowKeys
245
+ var display = this.tableCtx.data.display
246
+ var rowKey = this.tableCtx.layout.rowKey
247
+ var rs = this.rowSelection || {}
248
+
249
+ this.tableCtx.selection.checkAll = keys.length === display.length && display.length > 0
250
+
251
+ var selectedRows = display.filter(function (r) {
252
+ return keys.indexOf(r[rowKey]) !== -1
253
+ })
254
+
255
+ if (rs.onChange) rs.onChange(keys, selectedRows)
256
+
257
+ if (!meta) return
258
+
259
+ if (meta.type === 'row') {
260
+ if (rs.onSelect) rs.onSelect(meta.record, meta.selected, selectedRows, meta.nativeEvent)
261
+ } else if (meta.type === 'all') {
262
+ // changeRows = rows mới được check (chưa có trong prevKeys)
263
+ var changeRows = display.filter(function (r) {
264
+ return prevKeys.indexOf(r[rowKey]) === -1
265
+ })
266
+ if (rs.onSelectAll) rs.onSelectAll(true, selectedRows, changeRows)
267
+ } else if (meta.type === 'none') {
268
+ // changeRows = rows bị uncheck (đang có trong prevKeys)
269
+ changeRows = display.filter(function (r) {
270
+ return prevKeys.indexOf(r[rowKey]) !== -1
271
+ })
272
+ if (rs.onSelectAll) rs.onSelectAll(false, [], changeRows)
273
+ if (rs.onSelectNone) rs.onSelectNone()
274
+ }
275
+ },
276
+
277
+ handleResize: function (colKey, width) {
278
+ var widths = new Map(this.tableCtx.layout.columnWidths)
279
+ widths.set(colKey, width)
280
+ this.tableCtx.layout.columnWidths = widths
281
+ },
282
+
283
+ handleReorder: function (oldIndex, newIndex) {
284
+ const display = this.tableCtx.data.display.slice()
285
+ const moved = display.splice(oldIndex, 1)[0]
286
+ display.splice(newIndex, 0, moved)
287
+
288
+ const cb = this.tableCtx.draggable.handleReorder
289
+ if (typeof cb === 'function') cb(oldIndex, newIndex, display)
290
+ },
291
+
292
+ handleContainerResize: function (size) {
293
+ this.tableCtx.layout.containerWidth = size.width
294
+ }
295
+ }
296
+ }
297
+ </script>
298
+
299
+ <style src="./style/table.css" scoped></style>
@@ -0,0 +1,55 @@
1
+ <template>
2
+ <colgroup>
3
+ <col
4
+ v-for="col in tableContext.columns.flat"
5
+ :key="col.key"
6
+ :class="isSelectionCol(col) ? 'ui-table-v2__selection-col' : ''"
7
+ :style="colStyle(col)"
8
+ />
9
+ <col v-if="hasScrollBar" :style="{ width: tableContext.layout.scrollBarWidth }" />
10
+ </colgroup>
11
+ </template>
12
+
13
+ <script>
14
+ import { toCssSize } from '../../utils/common'
15
+ import { SELECTION_COLUMN, DRAGGABLE_COLUMN } from './constants.js'
16
+
17
+ export default {
18
+ name: 'TableV2ColGroup',
19
+ inject: ['tableContext'],
20
+ props: {
21
+ isHeader: { type: Boolean, default: false }
22
+ },
23
+ methods: {
24
+ toCssSize,
25
+ colStyle: function (col) {
26
+ const res = {}
27
+ res.width = (this.tableContext.layout.columnWidths.get(col.key) || col.width) + 'px'
28
+ if (col.type === SELECTION_COLUMN) {
29
+ const w = (this.tableContext.selection.columnWidth || 36) + 'px'
30
+ res.width = w
31
+ res.minWidth = w
32
+ res.maxWidth = w
33
+ }
34
+ if (col.type === DRAGGABLE_COLUMN) {
35
+ const w = (this.tableContext.draggable.columnWidth || 36) + 'px'
36
+ res.width = w
37
+ res.minWidth = w
38
+ res.maxWidth = w
39
+ }
40
+ return res
41
+ },
42
+ isSelectionCol: function (col) {
43
+ return col.type === SELECTION_COLUMN
44
+ },
45
+ isDraggableCol: function (col) {
46
+ return col.key === DRAGGABLE_COLUMN
47
+ }
48
+ },
49
+ computed: {
50
+ hasScrollBar: function () {
51
+ return this.isHeader && this.tableContext.layout.scrollBarWidth != '0px'
52
+ }
53
+ }
54
+ }
55
+ </script>
@@ -0,0 +1,10 @@
1
+ <template>
2
+ <div class="ui-table-v2__empty"></div>
3
+ </template>
4
+
5
+ <script>
6
+ export default {
7
+ name: 'TableV2Empty',
8
+ inject: ['tableContext']
9
+ }
10
+ </script>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div class="ui-table-v2__loading-wrap" :class="{ 'ui-table-v2__loading-wrap--loading': isLoading }">
3
+ <slot />
4
+ <div v-if="isLoading" class="ui-table-v2__loading-overlay">
5
+ <Spinner size="md" />
6
+ </div>
7
+ </div>
8
+ </template>
9
+
10
+ <script>
11
+ import Spinner from '../spinner/Spinner.vue'
12
+
13
+ export default {
14
+ name: 'TableV2Loading',
15
+ components: { Spinner },
16
+ inject: ['tableContext'],
17
+ computed: {
18
+ isLoading: function () {
19
+ return this.tableContext.data.loading
20
+ }
21
+ }
22
+ }
23
+ </script>
24
+
25
+ <style src="./style/table-loading.css" scoped></style>
@@ -0,0 +1,93 @@
1
+ <script>
2
+ import { getCurrentInstance } from 'vue'
3
+ import { findDOMNode } from '../../utils/common'
4
+
5
+ export default {
6
+ name: 'TableResizeObserver',
7
+ emits: ['resize'],
8
+
9
+ data() {
10
+ return {
11
+ state: {
12
+ width: 0,
13
+ height: 0,
14
+ offsetHeight: 0,
15
+ offsetWidth: 0
16
+ },
17
+ instance: getCurrentInstance(),
18
+ currentElement: null,
19
+ resizeObserver: null
20
+ }
21
+ },
22
+
23
+ render() {
24
+ // eslint-disable-next-line vue/require-slots-as-functions
25
+ const slot = this.$slots.default
26
+ if (typeof slot === 'function') {
27
+ return slot()
28
+ }
29
+ return (slot && slot[0]) || null
30
+ },
31
+
32
+ methods: {
33
+ registerObserver() {
34
+ const element = findDOMNode(this)
35
+ const elementChanged = element !== this.currentElement
36
+ if (elementChanged) {
37
+ this.destroyObserver()
38
+ this.currentElement = element
39
+ }
40
+ if (!element) return
41
+ this.resizeObserver = new ResizeObserver(entries => {
42
+ this.handleEmitResize(entries)
43
+ })
44
+ this.resizeObserver.observe(this.currentElement)
45
+ },
46
+ handleEmitResize(entries) {
47
+ const target = entries[0].target
48
+
49
+ const { width, height } = target.getBoundingClientRect()
50
+ const { offsetWidth, offsetHeight } = target
51
+
52
+ const fixedWidth = Math.floor(width)
53
+ const fixedHeight = Math.floor(height)
54
+
55
+ if (
56
+ this.state.width !== fixedWidth ||
57
+ this.state.height !== fixedHeight ||
58
+ this.state.offsetWidth !== offsetWidth ||
59
+ this.state.offsetHeight !== offsetHeight
60
+ ) {
61
+ const size = { width: fixedWidth, height: fixedHeight, offsetWidth, offsetHeight }
62
+
63
+ Object.assign(this.state, size)
64
+ Promise.resolve().then(() => {
65
+ this.$emit('resize', {
66
+ ...size,
67
+ offsetWidth,
68
+ offsetHeight
69
+ })
70
+ })
71
+ }
72
+ },
73
+ destroyObserver() {
74
+ if (this.resizeObserver) {
75
+ this.resizeObserver.disconnect()
76
+ this.resizeObserver = null
77
+ }
78
+ }
79
+ },
80
+
81
+ mounted() {
82
+ this.registerObserver()
83
+ },
84
+
85
+ beforeUnmount() {
86
+ this.destroyObserver()
87
+ },
88
+ // eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle, vue/no-dupe-keys
89
+ beforeDestroy() {
90
+ this.destroyObserver()
91
+ }
92
+ }
93
+ </script>