Skip to content

Commit 834218e

Browse files
committed
v2.14.0
1 parent 1fbe7b3 commit 834218e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"scripts": {
2323
"prebuild": "rimraf dist",
2424
"build": "rollup --c rollup.config.js && rimraf dist/src",
25-
"docs:build": "cd demo && yarn && yarn serve",
25+
"demo": "cd demo && yarn && yarn serve",
2626
"test": "vitest",
2727
"coverage": "vitest run --coverage",
2828
"lint": "eslint 'src/**/*.{js,vue}'",

src/core.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export function cloneDeep(data: object) {
4444
return JSON.parse(JSON.stringify(data))
4545
}
4646

47+
export function getConfig(el: HTMLInputElement) {
48+
return JSON.parse(el.dataset.config as string) as Config
49+
}
50+
51+
export function setConfig(el: HTMLInputElement, config: any) {
52+
el.dataset.config = JSON.stringify(config)
53+
}
54+
4755
/**
4856
* Creates a CustomEvent('input') with detail = { facade: true }
4957
* used as a way to identify our own input event
@@ -161,7 +169,6 @@ export function inputHandler(event: CustomInputEvent) {
161169
updateCursor(target, positionFromEnd)
162170

163171
if (oldValue !== target.value) {
164-
// target.oldValue = masked
165172
target.dispatchEvent(InputEvent('input'))
166173
}
167174
}
@@ -197,8 +204,14 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
197204
const regExp = new RegExp(`${prefix}|${suffix}`, 'g')
198205
const newValue = el.value.replace(regExp, '')
199206
const canNegativeInput = min === undefined || Number(min) < 0 || Number(min) !== min
200-
if (key === decimal && newValue.includes(decimal)) {
201-
event.preventDefault()
207+
if (key === decimal) {
208+
if (newValue.includes(decimal)) {
209+
event.preventDefault()
210+
} else if (!newValue) {
211+
el.value = '0' + decimal
212+
// trigger input event
213+
el.dispatchEvent(new Event('input'))
214+
}
202215
} else if (key === MINUS && !canNegativeInput) {
203216
event.preventDefault()
204217
} else if (key === 'Backspace') {

src/directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
const options = Object.assign(core.cloneDeep(defaultOptions), value, modifiers)
1010
el.options = options
1111
// set initial value
12-
core.updateValue(el, vnode, { force: options.prefill, clean: true })
12+
core.updateValue(el, vnode, { force: options.prefill, clean: true, emit: false })
1313
},
1414

1515
inserted: (el: core.CustomInputElement) => {

0 commit comments

Comments
 (0)