@innertia-solutions/innertia-nuxt 0.1.83 → 0.1.84

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,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed, watch, nextTick } from 'vue'
2
+ import { ref, computed, watch, nextTick, useAttrs } from 'vue'
3
3
 
4
4
  /*
5
5
  * CurrencyInput — input de moneda con formato SOLO visual.
@@ -72,15 +72,29 @@ function onBlur() {
72
72
  const baseClasses = computed(() =>
73
73
  `innertia-field${props.size === 'sm' ? ' innertia-field-sm' : ''}`,
74
74
  )
75
+ // Los atributos no declarados (maxlength, min, max, step, required, inputmode,
76
+ // name, id, aria-*, data-*) y los listeners (@blur, @keydown, @focus…) van al
77
+ // <input>; solo class/style quedan en el <div> raíz para no romper el layout.
78
+ defineOptions({ inheritAttrs: false })
79
+ const attrs = useAttrs()
80
+ // Funciones (no computed): useAttrs() no es reactivo, el render sí se re-ejecuta.
81
+ function rootAttrs() {
82
+ return { class: attrs.class, style: attrs.style }
83
+ }
84
+ function inputAttrs() {
85
+ const { class: _class, style: _style, ...rest } = attrs
86
+ return rest
87
+ }
75
88
  </script>
76
89
 
77
90
  <template>
78
- <div class="w-full">
91
+ <div class="w-full" v-bind="rootAttrs()">
79
92
  <label v-if="label" class="block text-sm font-medium text-foreground mb-1.5">
80
93
  {{ label }}
81
94
  </label>
82
95
 
83
96
  <input
97
+ v-bind="inputAttrs()"
84
98
  ref="inputEl"
85
99
  type="text"
86
100
  inputmode="numeric"
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed } from 'vue'
2
+ import { ref, computed, useAttrs } from 'vue'
3
3
  import { IconEye, IconEyeOff } from '@tabler/icons-vue'
4
4
 
5
5
  const props = defineProps<{
@@ -27,10 +27,23 @@ const inputType = computed(() => {
27
27
  const baseClasses = computed(() =>
28
28
  `innertia-field${props.size === 'sm' ? ' innertia-field-sm' : ''}`
29
29
  )
30
+ // Los atributos no declarados (maxlength, min, max, step, required, inputmode,
31
+ // name, id, aria-*, data-*) y los listeners (@blur, @keydown, @focus…) van al
32
+ // <input>; solo class/style quedan en el <div> raíz para no romper el layout.
33
+ defineOptions({ inheritAttrs: false })
34
+ const attrs = useAttrs()
35
+ // Funciones (no computed): useAttrs() no es reactivo, el render sí se re-ejecuta.
36
+ function rootAttrs() {
37
+ return { class: attrs.class, style: attrs.style }
38
+ }
39
+ function inputAttrs() {
40
+ const { class: _class, style: _style, ...rest } = attrs
41
+ return rest
42
+ }
30
43
  </script>
31
44
 
32
45
  <template>
33
- <div class="w-full">
46
+ <div class="w-full" v-bind="rootAttrs()">
34
47
  <label v-if="label" class="block text-sm font-medium text-foreground mb-1.5">
35
48
  {{ label }}
36
49
  </label>
@@ -42,6 +55,7 @@ const baseClasses = computed(() =>
42
55
  </div>
43
56
 
44
57
  <input
58
+ v-bind="inputAttrs()"
45
59
  v-model="modelValue"
46
60
  :type="inputType"
47
61
  :placeholder="placeholder"
@@ -0,0 +1,137 @@
1
+ import { describe, it, expect, vi } from 'vitest'
2
+ import { createRenderer, h, nextTick, ref } from 'vue'
3
+ import Input from '../Input.vue'
4
+ import CurrencyInput from '../CurrencyInput.vue'
5
+
6
+ /*
7
+ * Renderer mínimo (sin DOM): cada nodo guarda su tag y los props/listeners que
8
+ * Vue le aplica. Basta para verificar a qué elemento llegan los $attrs.
9
+ */
10
+ type TestNode = {
11
+ tag: string
12
+ props: Record<string, any>
13
+ children: TestNode[]
14
+ parent: TestNode | null
15
+ text?: string
16
+ value?: any
17
+ /** vModelText registra listeners nativos; aquí basta con aceptarlos. */
18
+ addEventListener: () => void
19
+ }
20
+
21
+ function makeNode(tag: string): TestNode {
22
+ return { tag, props: {}, children: [], parent: null, addEventListener: () => {} }
23
+ }
24
+
25
+ function remove(child: TestNode) {
26
+ const p = child.parent
27
+ if (!p) return
28
+ const i = p.children.indexOf(child)
29
+ if (i > -1) p.children.splice(i, 1)
30
+ child.parent = null
31
+ }
32
+
33
+ const { createApp } = createRenderer<TestNode, TestNode>({
34
+ createElement: tag => makeNode(tag),
35
+ createText: text => ({ ...makeNode('#text'), text }),
36
+ createComment: text => ({ ...makeNode('#comment'), text }),
37
+ setText: (node, text) => { node.text = text },
38
+ setElementText: (node, text) => { node.children = []; node.text = text },
39
+ insert: (child, parent, anchor) => {
40
+ remove(child)
41
+ const i = anchor ? parent.children.indexOf(anchor) : -1
42
+ if (i > -1) parent.children.splice(i, 0, child)
43
+ else parent.children.push(child)
44
+ child.parent = parent
45
+ },
46
+ remove,
47
+ parentNode: node => node.parent,
48
+ nextSibling: (node) => {
49
+ const p = node.parent
50
+ if (!p) return null
51
+ return p.children[p.children.indexOf(node) + 1] ?? null
52
+ },
53
+ patchProp: (el, key, _prev, next) => {
54
+ if (next == null) delete el.props[key]
55
+ else el.props[key] = next
56
+ },
57
+ })
58
+
59
+ function find(node: TestNode, tag: string): TestNode | undefined {
60
+ if (node.tag === tag) return node
61
+ for (const c of node.children) {
62
+ const hit = find(c, tag)
63
+ if (hit) return hit
64
+ }
65
+ }
66
+
67
+ /**
68
+ /** Sin DOM ni SSR: monta la app sobre el renderer de prueba. */
69
+ function mountApp(render: () => any, root: TestNode) {
70
+ createApp({ render }).mount(root)
71
+ }
72
+
73
+ function mount(component: any, props: Record<string, any>) {
74
+ const root = makeNode('root')
75
+ mountApp(() => h(component, props), root)
76
+ const wrapper = root.children.find(c => c.tag === 'div')!
77
+ const input = find(root, 'input')!
78
+ return { root, wrapper, input }
79
+ }
80
+
81
+ /** Vue puede guardar un listener como función o como array (merge de listeners). */
82
+ function call(listener: any, ...args: any[]) {
83
+ if (Array.isArray(listener)) listener.forEach(fn => fn(...args))
84
+ else listener(...args)
85
+ }
86
+
87
+ describe('Forms.Input reenvía $attrs al <input>', () => {
88
+ it('pone maxlength/required/inputmode en el input y no en el div raíz', () => {
89
+ const { wrapper, input } = mount(Input, { maxlength: 20, required: true, inputmode: 'numeric', name: 'code' })
90
+ expect(input.props.maxlength).toBe(20)
91
+ expect(input.props.required).toBe(true)
92
+ expect(input.props.inputmode).toBe('numeric')
93
+ expect(input.props.name).toBe('code')
94
+ expect(wrapper.props.maxlength).toBeUndefined()
95
+ })
96
+
97
+ it('ejecuta @blur y @keydown del consumidor sobre el input', () => {
98
+ const onBlur = vi.fn()
99
+ const onKeydown = vi.fn()
100
+ const { wrapper, input } = mount(Input, { onBlur, onKeydown })
101
+ expect(wrapper.props.onBlur).toBeUndefined()
102
+ call(input.props.onBlur, { type: 'blur' })
103
+ call(input.props.onKeydown, { type: 'keydown' })
104
+ expect(onBlur).toHaveBeenCalledOnce()
105
+ expect(onKeydown).toHaveBeenCalledOnce()
106
+ })
107
+
108
+ it('mantiene class y style en el div raíz', () => {
109
+ const { wrapper, input } = mount(Input, { class: 'col-span-2', style: { width: '10px' } })
110
+ expect(wrapper.props.class).toContain('col-span-2')
111
+ expect(wrapper.props.class).toContain('w-full')
112
+ expect(wrapper.props.style).toMatchObject({ width: '10px' })
113
+ expect(input.props.class).not.toContain('col-span-2')
114
+ expect(input.props.style).toBeUndefined()
115
+ })
116
+
117
+ it('actualiza los attrs reenviados cuando cambian', async () => {
118
+ const max = ref(10)
119
+ const root = makeNode('root')
120
+ mountApp(() => h(Input, { maxlength: max.value }), root)
121
+ expect(find(root, 'input')!.props.maxlength).toBe(10)
122
+ max.value = 30
123
+ await nextTick()
124
+ expect(find(root, 'input')!.props.maxlength).toBe(30)
125
+ })
126
+ })
127
+
128
+ describe('Forms.CurrencyInput reenvía $attrs al <input>', () => {
129
+ it('combina el @blur del consumidor con el blur interno', () => {
130
+ const onBlur = vi.fn()
131
+ const { wrapper, input } = mount(CurrencyInput, { onBlur, maxlength: 15, class: 'mb-2' })
132
+ expect(input.props.maxlength).toBe(15)
133
+ expect(wrapper.props.class).toContain('mb-2')
134
+ call(input.props.onBlur, { type: 'blur' })
135
+ expect(onBlur).toHaveBeenCalledOnce()
136
+ })
137
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innertia-solutions/innertia-nuxt",
3
- "version": "0.1.83",
3
+ "version": "0.1.84",
4
4
  "description": "Innertia Solutions — Nuxt layer unificada: core, auth, multitenancy, theme y app contexts",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -63,6 +63,7 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@pinia/nuxt": "^0.11.3",
66
+ "@vitejs/plugin-vue": "^5.2.4",
66
67
  "nuxt": "^4.4.2",
67
68
  "pinia": "^3.0.4",
68
69
  "pinia-plugin-persistedstate": "^4.7.1",
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from 'vitest/config'
2
+ import vue from '@vitejs/plugin-vue'
3
+
4
+ export default defineConfig({
5
+ plugins: [clientOnlyVue()],
6
+ test: {
7
+ include: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
8
+ environment: 'node',
9
+ },
10
+ })
11
+
12
+ /**
13
+ * plugin-vue para importar SFC en tests. En entorno node vitest los transforma
14
+ * en modo SSR (solo ssrRender); aquí se fuerza la compilación cliente para
15
+ * poder montarlos con un renderer propio.
16
+ */
17
+ function clientOnlyVue() {
18
+ const plugin = vue()
19
+ const transform = plugin.transform as any
20
+ const load = plugin.load as any
21
+ return {
22
+ ...plugin,
23
+ load(this: any, id: string, opts?: any) {
24
+ return load?.call(this, id, { ...opts, ssr: false })
25
+ },
26
+ transform(this: any, code: string, id: string, opts?: any) {
27
+ return transform.call(this, code, id, { ...opts, ssr: false })
28
+ },
29
+ }
30
+ }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
6
- environment: 'node',
7
- },
8
- })