react-flatpickr
Advanced tools
Comparing version
@@ -1,5 +0,5 @@ | ||
import { jsx as k } from "react/jsx-runtime"; | ||
import { useMemo as v, useRef as D, useImperativeHandle as E, useEffect as F, useCallback as H } from "react"; | ||
import A from "flatpickr"; | ||
const N = ["onCreate", "onDestroy"], m = [ | ||
import { jsx as D } from "react/jsx-runtime"; | ||
import { useMemo as k, useRef as v, useImperativeHandle as F, useEffect as H, useCallback as A } from "react"; | ||
import b from "flatpickr"; | ||
const R = ["onCreate", "onDestroy"], m = [ | ||
"onChange", | ||
@@ -13,16 +13,16 @@ "onOpen", | ||
"onDayCreate" | ||
], R = (e, c) => (m.forEach((r) => { | ||
const s = c[r], a = e[r]; | ||
if (s) { | ||
a && !Array.isArray(a) ? e[r] = [e[r]] : e[r] || (e[r] = []); | ||
const n = Array.isArray(s) ? s : [s]; | ||
e[r].length === 0 ? e[r] = n : e[r].push(...n); | ||
], S = (e, c) => (m.forEach((n) => { | ||
const o = c[n], r = e[n]; | ||
if (o) { | ||
r && !Array.isArray(r) ? e[n] = [e[n]] : e[n] || (e[n] = []); | ||
const u = Array.isArray(o) ? o : [o]; | ||
e[n].length === 0 ? e[n] = u : e[n].push(...u); | ||
} | ||
}), m.forEach((r) => { | ||
delete c[r]; | ||
}), N.forEach((r) => { | ||
delete c[r]; | ||
}), e), w = (e) => { | ||
const c = v(() => ({ ...e }), [e]), { defaultValue: r, className: s, options: a = {}, value: n, children: b, render: C } = c, f = v(() => R(a, c), [a, c]), u = D(null), t = D(void 0); | ||
E( | ||
}), m.forEach((n) => { | ||
delete c[n]; | ||
}), R.forEach((n) => { | ||
delete c[n]; | ||
}), e), j = (e) => { | ||
const c = k(() => ({ ...e }), [e]), { defaultValue: n, options: o = {}, value: r, children: u, render: d } = c, s = k(() => S(o, c), [o, c]), g = v(null), t = v(void 0); | ||
F( | ||
e.ref, | ||
@@ -35,34 +35,51 @@ () => ({ | ||
[] | ||
), F(() => { | ||
), H(() => { | ||
var h; | ||
const g = () => { | ||
const f = () => { | ||
var l; | ||
f.onClose = f.onClose || (() => { | ||
s.onClose = s.onClose || (() => { | ||
var i; | ||
(i = u.current) != null && i.blur && u.current.blur(); | ||
}), t.current = (((l = A) == null ? void 0 : l.default) || A)(u.current, f), t.current && n !== void 0 && t.current.setDate(n, !1), e.onCreate && e.onCreate(t.current); | ||
}, x = () => { | ||
(i = g.current) != null && i.blur && g.current.blur(); | ||
}), t.current = (((l = b) == null ? void 0 : l.default) || b)(g.current, s), t.current && r !== void 0 && t.current.setDate(r, !1), e.onCreate && e.onCreate(t.current); | ||
}, E = () => { | ||
e.onDestroy && e.onDestroy(t.current), t.current && t.current.destroy(), t.current = void 0; | ||
}; | ||
if (g(), t.current) { | ||
const l = Object.getOwnPropertyNames(f); | ||
if (f(), t.current) { | ||
const l = Object.getOwnPropertyNames(s); | ||
for (let i = l.length - 1; i >= 0; i--) { | ||
const d = l[i]; | ||
let o = f[d]; | ||
(o == null ? void 0 : o.toString()) !== ((h = t.current.config[d]) == null ? void 0 : h.toString()) && (m.includes(d) && !Array.isArray(o) && (o = [o]), t.current.set(d, o)); | ||
const y = l[i]; | ||
let a = s[y]; | ||
(a == null ? void 0 : a.toString()) !== ((h = t.current.config[y]) == null ? void 0 : h.toString()) && (m.includes(y) && !Array.isArray(a) && (a = [a]), t.current.set(y, a)); | ||
} | ||
n !== void 0 && n !== t.current.input.value && t.current.setDate(n, !1); | ||
r !== void 0 && r !== t.current.input.value && t.current.setDate(r, !1); | ||
} | ||
return () => { | ||
x(); | ||
E(); | ||
}; | ||
}, [f, a, c, n, e]); | ||
const y = H((g) => { | ||
u.current = g; | ||
}, [s, o, c, r, e]); | ||
const C = A((f) => { | ||
g.current = f; | ||
}, []); | ||
return C ? C({ ...c, defaultValue: r, value: n }, y) : a.wrap ? /* @__PURE__ */ k("div", { className: "flatpickr", ref: y, children: b }) : /* @__PURE__ */ k("input", { value: n == null ? void 0 : n.toString(), className: s, defaultValue: r, ref: y }); | ||
if (d) | ||
return d({ ...c, defaultValue: n, value: r }, C); | ||
const x = A( | ||
(f) => { | ||
e && e.onChange && e.onChange([new Date(f.target.value)], (r == null ? void 0 : r.toString()) || "", t.current); | ||
}, | ||
[e, r] | ||
); | ||
return o.wrap ? /* @__PURE__ */ D("div", { className: "flatpickr", ref: C, children: u }) : /* @__PURE__ */ D( | ||
"input", | ||
{ | ||
onChange: x, | ||
...c, | ||
value: r == null ? void 0 : r.toString(), | ||
defaultValue: n, | ||
ref: C | ||
} | ||
); | ||
}; | ||
export { | ||
w as default | ||
j as default | ||
}; | ||
//# sourceMappingURL=react-flatpickr.js.map |
{ | ||
"name": "react-flatpickr", | ||
"version": "4.0.7", | ||
"version": "4.0.8", | ||
"description": "flatpickr for React", | ||
@@ -22,4 +22,4 @@ "exports": { | ||
"scripts": { | ||
"lint": "eslint lib example test --quiet --fix", | ||
"format": "prettier --config .prettierrc 'lib/*.{ts,tsx}' 'example/*' 'test/*.{ts,tsx}' --write", | ||
"lint": "eslint --quiet --fix lib example test", | ||
"format": "prettier --config .prettierrc --write 'lib/*.{ts,tsx}' 'example/*' 'test/*.{ts,tsx}'", | ||
"build": "tsc -b && vite build", | ||
@@ -30,4 +30,11 @@ "test": "jest --config=jest.config.ts --env=jsdom", | ||
"prepublishOnly": "npm run build", | ||
"examples": "vite --port 3000 --open" | ||
"examples": "vite --port 3000 --open", | ||
"prepare": "husky" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx,js,css}": [ | ||
"eslint --fix", | ||
"prettier --config .prettierrc --write" | ||
] | ||
}, | ||
"repository": "haoxins/react-flatpickr", | ||
@@ -72,4 +79,6 @@ "keywords": [ | ||
"globals": "^16.0.0", | ||
"husky": "^9.1.7", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"lint-staged": "^15.5.1", | ||
"prettier": "^3.5.3", | ||
@@ -76,0 +85,0 @@ "react": "^19.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31548
6.42%126
15.6%36
5.88%