@maas/vue-equipment 0.7.7 → 0.7.8

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
  {
2
2
  "name": "@maas/vue-equipment",
3
3
  "configKey": "vueEquipment",
4
- "version": "0.7.6"
4
+ "version": "0.7.7"
5
5
  }
@@ -60,13 +60,22 @@ import {
60
60
  type MaybeRef,
61
61
  } from 'vue'
62
62
  import { onKeyStroke } from '@vueuse/core'
63
- import { defu } from 'defu'
64
63
  import { defaultOptions } from './../utils/defaultOptions'
65
64
  import { useModalApi } from './../composables/useModalApi'
66
65
  import { useModalCallback } from '../composables/private/useModalCallback'
67
66
 
68
67
  import type { Options } from './../types/index'
69
68
 
69
+ import { createDefu } from 'defu'
70
+
71
+ // Prevent keys array from being merged with default
72
+ const customDefu = createDefu((obj, key, value) => {
73
+ if (key === 'keys') {
74
+ obj[key] = value
75
+ return true
76
+ }
77
+ })
78
+
70
79
  interface MagicModalProps {
71
80
  id: MaybeRef<string>
72
81
  component?: Component
@@ -80,7 +89,7 @@ const props = withDefaults(defineProps<MagicModalProps>(), {
80
89
 
81
90
  const modal = ref<HTMLElement | undefined>(undefined)
82
91
  const modalApi = useModalApi(props.id, { focusTarget: modal })
83
- const mappedOptions = defu(props.options, defaultOptions)
92
+ const mappedOptions = customDefu(props.options, defaultOptions)
84
93
 
85
94
  const {
86
95
  isActive,
@@ -127,10 +136,14 @@ function onClose() {
127
136
  innerActive.value = false
128
137
  }
129
138
 
130
- onKeyStroke('Escape', (e) => {
131
- e.preventDefault()
132
- close()
133
- })
139
+ if (mappedOptions.keys) {
140
+ for (const key of mappedOptions.keys) {
141
+ onKeyStroke(key, (e) => {
142
+ e.preventDefault()
143
+ close()
144
+ })
145
+ }
146
+ }
134
147
 
135
148
  watch(isActive, async (value) => {
136
149
  if (value) {
@@ -11,6 +11,7 @@ type Options = {
11
11
  content?: string;
12
12
  backdrop?: string;
13
13
  };
14
+ keys?: string[] | false;
14
15
  };
15
16
  type ModalEvents = {
16
17
  beforeEnter: string;
@@ -10,6 +10,7 @@ const defaultOptions = {
10
10
  transitions: {
11
11
  content: "magic-modal--content",
12
12
  backdrop: "magic-modal--backdrop"
13
- }
13
+ },
14
+ keys: ["Escape"]
14
15
  };
15
16
  export { defaultOptions };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment",
3
3
  "description": "A magic collection of Vue composables, plugins, components and directives",
4
- "version": "0.7.7",
4
+ "version": "0.7.8",
5
5
  "author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
6
6
  "devDependencies": {
7
7
  "@antfu/ni": "^0.21.5",