@m3ui-vue/m3ui-vue 0.8.4 → 0.8.5

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.
@@ -1,6 +1,6 @@
1
1
  import { r as e } from "./useLocale-DbREg9Zn.js";
2
2
  import { t } from "./MIcon-CaEooCmZ.js";
3
- import { a as n, n as r, o as i, r as a, t as o } from "./MMenuItem-DiilFeDO.js";
3
+ import { a as n, n as r, o as i, r as a, t as o } from "./MMenuItem-BXIxwIdM.js";
4
4
  import { t as s } from "./_plugin-vue_export-helper-B3ysoDQm.js";
5
5
  import { Fragment as c, computed as l, createCommentVNode as u, createElementBlock as d, createElementVNode as f, createTextVNode as p, createVNode as m, defineComponent as h, normalizeClass as g, normalizeStyle as _, onBeforeUnmount as v, onMounted as y, openBlock as b, ref as x, renderList as S, shallowRef as C, toDisplayString as w, watch as T, withCtx as E, withKeys as D } from "vue";
6
6
  //#region src/components/MRichTextEditor.vue?vue&type=script&setup=true&lang.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m3ui-vue/m3ui-vue",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Material 3 component library for Vue 3 + Tailwind CSS v4",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,84 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { defineComponent, h, nextTick, ref } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+ import MMenu from '../components/MMenu.vue'
5
+ import MContextMenu from '../components/MContextMenu.vue'
6
+
7
+ const frame = () => new Promise<void>((r) => requestAnimationFrame(() => r()))
8
+ // Long enough for the open spring to finish, so the close has real distance to cover
9
+ const settle = () => new Promise<void>((r) => setTimeout(r, 400))
10
+
11
+ describe('MMenu', () => {
12
+ beforeEach(() => {
13
+ document.body.innerHTML = ''
14
+ })
15
+
16
+ it('removes its panel from <body> when unmounted mid-close', async () => {
17
+ // e.g. a "Log out" item: close() then router.push() unmounts the menu
18
+ // while its close animation is still playing
19
+ const show = ref(true)
20
+ const menuRef = ref<InstanceType<typeof MMenu> | null>(null)
21
+ mount(
22
+ defineComponent({
23
+ setup: () => () =>
24
+ show.value
25
+ ? h(MMenu, { ref: menuRef }, {
26
+ trigger: () => h('button', { class: 'trigger' }, 'open'),
27
+ default: () => h('span', { class: 'item' }, 'Log out'),
28
+ })
29
+ : null,
30
+ }),
31
+ { attachTo: document.body, global: { stubs: { transition: false } } },
32
+ )
33
+
34
+ document.querySelector<HTMLElement>('.trigger')!.click()
35
+ await nextTick()
36
+ expect(document.querySelector('.item')).not.toBeNull()
37
+ await settle()
38
+
39
+ menuRef.value!.close()
40
+ await nextTick()
41
+ await frame()
42
+ show.value = false
43
+ await nextTick()
44
+
45
+ expect(document.querySelector('.item')).toBeNull()
46
+ })
47
+ })
48
+
49
+ describe('MContextMenu', () => {
50
+ beforeEach(() => {
51
+ document.body.innerHTML = ''
52
+ })
53
+
54
+ it('removes its panel from <body> when unmounted mid-close', async () => {
55
+ const show = ref(true)
56
+ mount(
57
+ defineComponent({
58
+ setup: () => () =>
59
+ show.value
60
+ ? h(MContextMenu, null, {
61
+ trigger: () => h('div', { class: 'area' }, 'right-click me'),
62
+ default: () => h('span', { class: 'item' }, 'Delete'),
63
+ })
64
+ : null,
65
+ }),
66
+ { attachTo: document.body, global: { stubs: { transition: false } } },
67
+ )
68
+
69
+ document.querySelector('.area')!.dispatchEvent(
70
+ new MouseEvent('contextmenu', { bubbles: true, clientX: 10, clientY: 10 }),
71
+ )
72
+ await nextTick()
73
+ expect(document.querySelector('.item')).not.toBeNull()
74
+ await settle()
75
+
76
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
77
+ await nextTick()
78
+ await frame()
79
+ show.value = false
80
+ await nextTick()
81
+
82
+ expect(document.querySelector('.item')).toBeNull()
83
+ })
84
+ })
@@ -177,6 +177,12 @@ function openTrajectory() {
177
177
  // frame) have to live outside this function to survive that interruption.
178
178
  let currentIdx = 0
179
179
  let cancelActive: (() => void) | null = null
180
+ // Set only while a close is playing: stops the loop *and* calls its `done()`.
181
+ // Used on unmount — a menu item that navigates away (e.g. "Log out" ->
182
+ // router.push) unmounts this component mid-close, and Vue only removes the
183
+ // Teleported panel from <body> inside the leave's `done()`, so merely
184
+ // cancelling the loop there left the half-closed panel stranded on screen.
185
+ let finishLeave: (() => void) | null = null
180
186
 
181
187
  function playTrajectory(el: Element, done: () => void, opening: boolean) {
182
188
  cancelActive?.()
@@ -203,6 +209,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
203
209
  apply(currentIdx)
204
210
  if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
205
211
  cancelActive = null
212
+ finishLeave = null
206
213
  done()
207
214
  return
208
215
  }
@@ -210,6 +217,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
210
217
  }
211
218
 
212
219
  cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
220
+ finishLeave = opening ? null : () => { cancelActive?.(); cancelActive = null; finishLeave = null; done() }
213
221
  apply(currentIdx)
214
222
  rafId = requestAnimationFrame(step)
215
223
  }
@@ -323,7 +331,8 @@ onUnmounted(() => {
323
331
  document.removeEventListener('mousedown', onDocMouseDown)
324
332
  document.removeEventListener('keydown', onKeydown)
325
333
  window.removeEventListener('scroll', onScroll, true)
326
- cancelActive?.()
334
+ if (finishLeave) finishLeave()
335
+ else cancelActive?.()
327
336
  })
328
337
  </script>
329
338
 
@@ -163,6 +163,12 @@ function openTrajectory() {
163
163
  // frame) have to live outside this function to survive that interruption.
164
164
  let currentIdx = 0
165
165
  let cancelActive: (() => void) | null = null
166
+ // Set only while a close is playing: stops the loop *and* calls its `done()`.
167
+ // Used on unmount — a menu item that navigates away (e.g. "Log out" ->
168
+ // router.push) unmounts this component mid-close, and Vue only removes the
169
+ // Teleported panel from <body> inside the leave's `done()`, so merely
170
+ // cancelling the loop there left the half-closed panel stranded on screen.
171
+ let finishLeave: (() => void) | null = null
166
172
 
167
173
  function playTrajectory(el: Element, done: () => void, opening: boolean) {
168
174
  cancelActive?.()
@@ -189,6 +195,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
189
195
  apply(currentIdx)
190
196
  if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
191
197
  cancelActive = null
198
+ finishLeave = null
192
199
  done()
193
200
  return
194
201
  }
@@ -196,6 +203,7 @@ function playTrajectory(el: Element, done: () => void, opening: boolean) {
196
203
  }
197
204
 
198
205
  cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
206
+ finishLeave = opening ? null : () => { cancelActive?.(); cancelActive = null; finishLeave = null; done() }
199
207
  apply(currentIdx)
200
208
  rafId = requestAnimationFrame(step)
201
209
  }
@@ -367,7 +375,8 @@ onUnmounted(() => {
367
375
  document.removeEventListener('mousedown', onOutsideClick)
368
376
  document.removeEventListener('keydown', onKeydown)
369
377
  window.removeEventListener('scroll', onScroll, true)
370
- cancelActive?.()
378
+ if (finishLeave) finishLeave()
379
+ else cancelActive?.()
371
380
  })
372
381
 
373
382
  const origin = computed(() =>
@@ -34,6 +34,11 @@ const props = withDefaults(
34
34
  emptyText?: string
35
35
  rowKey?: string
36
36
  selectable?: boolean
37
+ /** Con `selectable`, que el click en cualquier parte de la fila la marque/desmarque (en vez de
38
+ * emitir `rowClick`). Default false: sólo el checkbox selecciona y el click en la fila emite
39
+ * `rowClick`, así una tabla puede seleccionar filas y a la vez abrirlas al click.
40
+ */
41
+ selectOnRowClick?: boolean
37
42
  modelValue?: Record<string, any>[]
38
43
  perPage?: number
39
44
  searchable?: boolean
@@ -48,6 +53,7 @@ const props = withDefaults(
48
53
  loading: false,
49
54
  rowKey: 'id',
50
55
  selectable: false,
56
+ selectOnRowClick: false,
51
57
  modelValue: () => [],
52
58
  perPage: 10,
53
59
  searchable: true,
@@ -61,6 +67,7 @@ const emit = defineEmits<{
61
67
  'update:modelValue': [Record<string, any>[]]
62
68
  'update:page': [number]
63
69
  fetch: [TableFetchParams]
70
+ rowClick: [Record<string, any>]
64
71
  }>()
65
72
 
66
73
  // ── Search ─────────────────────────────────────────────────────────────────
@@ -365,11 +372,11 @@ const hasActions = computed(() => !!slots['row-actions'])
365
372
  'border-t border-outline-variant transition-colors duration-100',
366
373
  'hover:bg-on-surface/4',
367
374
  selectable && isSelected(row) ? 'bg-primary/6' : '',
368
- selectable ? 'cursor-pointer' : '',
375
+ selectable && selectOnRowClick ? 'cursor-pointer' : '',
369
376
  ]"
370
- @click="selectable ? toggleRow(row) : undefined"
377
+ @click="selectable && selectOnRowClick ? toggleRow(row) : emit('rowClick', row)"
371
378
  >
372
- <td v-if="selectable" class="px-4 py-3" @click.stop="toggleRow(row)">
379
+ <td v-if="selectable" class="px-4 py-3" @click.stop>
373
380
  <MCheckbox
374
381
  :model-value="isSelected(row)"
375
382
  @update:model-value="toggleRow(row)"