directix 1.10.0 → 2.0.0

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
  /*!
2
- * directix v1.10.0
3
- * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3
2
+ * directix v2.0.0
3
+ * A comprehensive, easy-to-use, and high-performance Vue custom directives library supporting both Vue 2 and Vue 3, with Web Components support
4
4
  * (c) 2021-present saqqdy <https://github.com/saqqdy>
5
5
  * Released under the MIT License.
6
6
  */
@@ -198,21 +198,22 @@ function normalizeBinding(binding) {
198
198
  }
199
199
 
200
200
  // packages/core/src/adapter/vue3.ts
201
+ import { markRaw, shallowReactive } from "vue";
201
202
  function createVue3Directive(hooks) {
202
- const directive = {
203
+ return {
203
204
  created(el, binding, vnode) {
204
- const state = {
205
- value: binding.value,
205
+ const state = shallowReactive({
206
+ value: binding.value != null ? markRaw(binding.value) : binding.value,
206
207
  vnode,
207
208
  cleanup: []
208
- };
209
+ });
209
210
  el.__directix_state__ = state;
210
211
  },
211
212
  beforeMount(_el, _binding, _vnode) {
212
213
  },
213
214
  mounted(el, binding, vnode) {
214
215
  if (hooks.mounted) {
215
- hooks.mounted(el, normalizeBindingVue3(binding), vnode);
216
+ hooks.mounted(el, normalizeBinding2(binding), vnode);
216
217
  }
217
218
  },
218
219
  beforeUpdate(_el, _binding, _vnode, _prevVnode) {
@@ -222,14 +223,14 @@ function createVue3Directive(hooks) {
222
223
  if (hooks.updated) {
223
224
  hooks.updated(
224
225
  el,
225
- normalizeBindingVue3(binding),
226
+ normalizeBinding2(binding),
226
227
  vnode,
227
- normalizeBindingVue3({ ...binding, value: binding.oldValue }),
228
+ normalizeBinding2({ ...binding, value: binding.oldValue }),
228
229
  prevVnode
229
230
  );
230
231
  }
231
232
  if (state) {
232
- state.value = binding.value;
233
+ state.value = binding.value != null ? markRaw(binding.value) : binding.value;
233
234
  state.vnode = vnode;
234
235
  }
235
236
  },
@@ -237,7 +238,7 @@ function createVue3Directive(hooks) {
237
238
  },
238
239
  unmounted(el, binding, vnode) {
239
240
  if (hooks.unmounted) {
240
- hooks.unmounted(el, normalizeBindingVue3(binding), vnode);
241
+ hooks.unmounted(el, normalizeBinding2(binding), vnode);
241
242
  }
242
243
  const state = el.__directix_state__;
243
244
  if (state?.cleanup) {
@@ -246,9 +247,8 @@ function createVue3Directive(hooks) {
246
247
  delete el.__directix_state__;
247
248
  }
248
249
  };
249
- return directive;
250
250
  }
251
- function normalizeBindingVue3(binding) {
251
+ function normalizeBinding2(binding) {
252
252
  return {
253
253
  value: binding.value,
254
254
  oldValue: binding.oldValue ?? null,
@@ -2972,7 +2972,7 @@ function createEntry(key, modifiers, handler, options = {}) {
2972
2972
  disabled: options.disabled ?? false
2973
2973
  };
2974
2974
  }
2975
- function normalizeBinding2(binding, arg, modifiers) {
2975
+ function normalizeBinding3(binding, arg, modifiers) {
2976
2976
  if (arg) {
2977
2977
  const argLower = arg.toLowerCase();
2978
2978
  const argIsModifier = MODIFIER_KEYS.has(argLower);
@@ -3056,12 +3056,12 @@ var vHotkey = defineDirective({
3056
3056
  name: "hotkey",
3057
3057
  ssr: true,
3058
3058
  mounted(el, binding) {
3059
- const entries = normalizeBinding2(binding.value, binding.arg, binding.modifiers);
3059
+ const entries = normalizeBinding3(binding.value, binding.arg, binding.modifiers);
3060
3060
  setupState(el, entries);
3061
3061
  },
3062
3062
  updated(el, binding) {
3063
3063
  const state = el.__hotkey;
3064
- const newEntries = normalizeBinding2(binding.value, binding.arg, binding.modifiers);
3064
+ const newEntries = normalizeBinding3(binding.value, binding.arg, binding.modifiers);
3065
3065
  if (state) {
3066
3066
  state.entries = newEntries;
3067
3067
  } else {