Skip to content

Commit

Permalink
v2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dipaksarkar committed Apr 7, 2023
1 parent 1fbe7b3 commit 834218e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"scripts": {
"prebuild": "rimraf dist",
"build": "rollup --c rollup.config.js && rimraf dist/src",
"docs:build": "cd demo && yarn && yarn serve",
"demo": "cd demo && yarn && yarn serve",
"test": "vitest",
"coverage": "vitest run --coverage",
"lint": "eslint 'src/**/*.{js,vue}'",
Expand Down
19 changes: 16 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export function cloneDeep(data: object) {
return JSON.parse(JSON.stringify(data))
}

export function getConfig(el: HTMLInputElement) {
return JSON.parse(el.dataset.config as string) as Config
}

export function setConfig(el: HTMLInputElement, config: any) {
el.dataset.config = JSON.stringify(config)
}

/**
* Creates a CustomEvent('input') with detail = { facade: true }
* used as a way to identify our own input event
Expand Down Expand Up @@ -161,7 +169,6 @@ export function inputHandler(event: CustomInputEvent) {
updateCursor(target, positionFromEnd)

if (oldValue !== target.value) {
// target.oldValue = masked
target.dispatchEvent(InputEvent('input'))
}
}
Expand Down Expand Up @@ -197,8 +204,14 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
const regExp = new RegExp(`${prefix}|${suffix}`, 'g')
const newValue = el.value.replace(regExp, '')
const canNegativeInput = min === undefined || Number(min) < 0 || Number(min) !== min
if (key === decimal && newValue.includes(decimal)) {
event.preventDefault()
if (key === decimal) {
if (newValue.includes(decimal)) {
event.preventDefault()
} else if (!newValue) {
el.value = '0' + decimal
// trigger input event
el.dispatchEvent(new Event('input'))
}
} else if (key === MINUS && !canNegativeInput) {
event.preventDefault()
} else if (key === 'Backspace') {
Expand Down
2 changes: 1 addition & 1 deletion src/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
const options = Object.assign(core.cloneDeep(defaultOptions), value, modifiers)
el.options = options
// set initial value
core.updateValue(el, vnode, { force: options.prefill, clean: true })
core.updateValue(el, vnode, { force: options.prefill, clean: true, emit: false })
},

inserted: (el: core.CustomInputElement) => {
Expand Down

0 comments on commit 834218e

Please sign in to comment.