2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-17 19:21:21 +03:00

fix(vue): use defineExpose to set argument value

This commit is contained in:
Alexander Shabunevich
2024-06-11 10:17:10 +03:00
parent 0285532bfc
commit e6b2799880
9 changed files with 54 additions and 38 deletions
+6 -6
View File
@@ -5,16 +5,16 @@ type MaskaDirective = Directive<HTMLElement, MaskInputOptions | undefined>
const masks = new WeakMap<HTMLInputElement, MaskInput>()
// hacky way to update binding.arg without using defineExposed
const setArg = (binding: DirectiveBinding, value: string | boolean): void => {
if (binding.arg == null || (binding.instance == null)) return
const inst = binding.instance as any
const isComposition = 'setup' in binding.instance.$.type
if (binding.arg in inst) {
inst[binding.arg] = value // options api
} else if (inst.$?.setupState != null && binding.arg in inst.$.setupState) {
inst.$.setupState[binding.arg] = value // composition api
if (binding.arg in binding.instance) {
// @ts-expect-error
binding.instance[binding.arg] = value
} else if (isComposition) {
console.warn('Maska: please expose `%s` using defineExpose', binding.arg)
}
}