effector-final-form
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -6,22 +6,6 @@ import type { Config as FFConfig } from 'final-form'; | ||
}) => { | ||
$formState: import("effector").Store<Pick<Omit<import("final-form").FormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
active: Exclude<keyof FormValues, undefined> | null; | ||
errors: import("final-form").AnyObject | null; | ||
modified: { | ||
[key: string]: boolean; | ||
} | null; | ||
submitErrors: import("final-form").AnyObject | null; | ||
touched: { | ||
[key: string]: boolean; | ||
} | null; | ||
visited: { | ||
[key: string]: boolean; | ||
} | null; | ||
}, T[number]> & { | ||
isValidationPaused: boolean; | ||
}>; | ||
api: { | ||
reValidateFx: import("effector").Effect<void, void, Error>; | ||
revalidateFx: import("effector").Effect<void, void, Error>; | ||
setSubmitFn: (fn: (params: FormValues) => void | import("final-form").SubmissionErrors | Promise<void | import("final-form").SubmissionErrors>) => void; | ||
setValidationFn: (fn: (params: FormValues) => import("final-form").ValidationErrors | Promise<import("final-form").ValidationErrors>) => void; | ||
setSubmitFn: (fn: (params: FormValues) => void | import("final-form").SubmissionErrors | Promise<void | import("final-form").SubmissionErrors>) => void; | ||
blurFx: import("effector").Effect<keyof FormValues, void, Error>; | ||
@@ -47,4 +31,20 @@ changeFx: import("effector").Effect<{ | ||
$fields: import("effector").Store<{ [T_1 in keyof FormValues]: import("final-form").FieldState<FormValues[keyof FormValues]>; }>; | ||
$formState: import("effector").Store<Pick<Omit<import("final-form").FormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
active: Exclude<keyof FormValues, undefined> | null; | ||
errors: import("final-form").AnyObject | null; | ||
modified: { | ||
[key: string]: boolean; | ||
} | null; | ||
submitErrors: import("final-form").AnyObject | null; | ||
touched: { | ||
[key: string]: boolean; | ||
} | null; | ||
visited: { | ||
[key: string]: boolean; | ||
} | null; | ||
}, T[number]> & { | ||
isValidationPaused: boolean; | ||
}>; | ||
$registeredFields: import("effector").Store<[] | (keyof FormValues)[]>; | ||
}; | ||
export { createForm }; |
@@ -1,33 +0,33 @@ | ||
import { createEffect as a, createEvent as g, createStore as O, sample as j } from "effector"; | ||
import { fieldSubscriptionItems as E, formSubscriptionItems as P, createForm as h } from "final-form"; | ||
function S(t) { | ||
if (t === null) | ||
import { createEffect as l, createEvent as F, createStore as O, sample as E, is as P } from "effector"; | ||
import { fieldSubscriptionItems as h, formSubscriptionItems as x, createForm as $ } from "final-form"; | ||
function S(e) { | ||
if (e === null) | ||
return "Null"; | ||
if (t === void 0) | ||
if (e === void 0) | ||
return "Undefined"; | ||
if (Number.isNaN(t)) | ||
if (Number.isNaN(e)) | ||
return "NaN"; | ||
const e = Object.prototype.toString.call(t).slice(8, -1); | ||
return e === "AsyncFunction" ? "Promise" : e; | ||
const t = Object.prototype.toString.call(e).slice(8, -1); | ||
return t === "AsyncFunction" ? "Promise" : t; | ||
} | ||
const b = (t) => { | ||
const e = t.__proto__.toString(); | ||
return ["Error", "TypeError"].includes(e) ? [e, t.message] : []; | ||
}, V = (t) => t.toDateString ? [!0, t.getTime()] : [!1], y = (t) => t.constructor !== RegExp ? [!1] : [!0, t.toString()], F = (t, e) => { | ||
const r = S(t); | ||
if (r !== S(e)) | ||
const b = (e) => { | ||
const t = e.__proto__.toString(); | ||
return ["Error", "TypeError"].includes(t) ? [t, e.message] : []; | ||
}, V = (e) => e.toDateString ? [!0, e.getTime()] : [!1], y = (e) => e.constructor !== RegExp ? [!1] : [!0, e.toString()], g = (e, t) => { | ||
const r = S(e); | ||
if (r !== S(t)) | ||
return !1; | ||
if (r === "Function") | ||
return t.name === void 0 ? !1 : t.name === e.name; | ||
return e.name === void 0 ? !1 : e.name === t.name; | ||
if (["NaN", "Undefined", "Null"].includes(r)) | ||
return !0; | ||
if (r === "Number") | ||
return Object.is(-0, t) !== Object.is(-0, e) ? !1 : t - e === 0; | ||
return Object.is(-0, e) !== Object.is(-0, t) ? !1 : e - t === 0; | ||
if (["String", "Boolean"].includes(r)) | ||
return t.toString() === e.toString(); | ||
return e.toString() === t.toString(); | ||
if (r === "Array") { | ||
const o = Array.from(t), u = Array.from(e); | ||
return o.toString() !== u.toString() ? !1 : o.every((f, p) => f === u[p] || F(f, u[p])); | ||
const o = Array.from(e), u = Array.from(t); | ||
return o.toString() !== u.toString() ? !1 : o.every((f, p) => f === u[p] || g(f, u[p])); | ||
} | ||
const s = y(t), n = y(e); | ||
const s = y(e), n = y(t); | ||
if (s[0]) | ||
@@ -37,3 +37,3 @@ return n[0] ? s[1] === n[1] : !1; | ||
return !1; | ||
const c = V(t), i = V(e); | ||
const c = V(e), i = V(t); | ||
if (c[0]) | ||
@@ -43,21 +43,21 @@ return i[0] ? c[1] === i[1] : !1; | ||
return !1; | ||
const l = b(t), d = b(e); | ||
if (l[0]) | ||
return d[0] ? l[0] === d[0] && l[1] === d[1] : !1; | ||
const a = b(e), d = b(t); | ||
if (a[0]) | ||
return d[0] ? a[0] === d[0] && a[1] === d[1] : !1; | ||
if (r === "Object") { | ||
const o = Object.keys(t); | ||
return o.length !== Object.keys(e).length ? !1 : o.every((u) => { | ||
const f = t[u], p = e[u]; | ||
return f === p || F(f, p); | ||
const o = Object.keys(e); | ||
return o.length !== Object.keys(t).length ? !1 : o.every((u) => { | ||
const f = e[u], p = t[u]; | ||
return f === p || g(f, p); | ||
}); | ||
} | ||
return !1; | ||
}, _ = (t) => t == null, x = (t, e) => ( | ||
}, v = (e) => e == null, k = (e, t) => ( | ||
// @ts-expect-error | ||
_(e) ? {} : t.reduce( | ||
(r, s) => Object.prototype.hasOwnProperty.call(e, s) ? { ...r, [s]: e[s] } : r, | ||
v(t) ? {} : e.reduce( | ||
(r, s) => Object.prototype.hasOwnProperty.call(t, s) ? { ...r, [s]: t[s] } : r, | ||
{} | ||
) | ||
), v = (t, e) => t.reduce((r, s) => ({ ...r, [s]: e.includes(s) }), {}), A = (t, e) => !F(t, e), $ = (t) => { | ||
const { finalForm: e, fieldsApi: r, formStateApi: s } = t, n = ({ name: o, value: u }) => e.change(o, u), c = ({ | ||
), A = (e, t) => e.reduce((r, s) => ({ ...r, [s]: t.includes(s) }), {}), _ = (e, t) => !g(e, t), z = (e) => { | ||
const { finalForm: t, fieldsApi: r, formStateApi: s } = e, n = ({ name: o, value: u }) => t.change(o, u), c = ({ | ||
name: o, | ||
@@ -67,64 +67,65 @@ subscribeOn: u, | ||
}) => { | ||
e.registerField( | ||
t.registerField( | ||
o, | ||
r.update, | ||
v(E, [...u, "value"]), | ||
A(h, [...u, "value"]), | ||
f | ||
); | ||
}, i = () => { | ||
e.pauseValidation(), s.setValidationPaused(!0); | ||
}, l = () => { | ||
e.resumeValidation(), s.setValidationPaused(!1); | ||
t.pauseValidation(), s.setValidationPaused(!0); | ||
}, a = () => { | ||
t.resumeValidation(), s.setValidationPaused(!1); | ||
}; | ||
return { | ||
blurFx: a(e.blur), | ||
changeFx: a(n), | ||
focusFx: a(e.focus), | ||
initialize: a(e.initialize), | ||
pauseValidation: a(i), | ||
registerField: a(c), | ||
reset: a(e.reset), | ||
resetFieldState: a(e.resetFieldState), | ||
restart: a(e.restart), | ||
resumeValidation: a(l), | ||
submitFx: a(e.submit) | ||
blurFx: l(t.blur), | ||
changeFx: l(n), | ||
focusFx: l(t.focus), | ||
initialize: l(t.initialize), | ||
pauseValidation: l(i), | ||
registerField: l(c), | ||
reset: l(t.reset), | ||
resetFieldState: l(t.resetFieldState), | ||
restart: l(t.restart), | ||
resumeValidation: l(a), | ||
submitFx: l(t.submit) | ||
}; | ||
}, k = (t) => { | ||
const e = { | ||
update: g() | ||
}, H = (e) => { | ||
const t = { | ||
update: F() | ||
}, r = O( | ||
// @ts-expect-error | ||
{}, | ||
{ updateFilter: A } | ||
{ updateFilter: _ } | ||
), s = r.map((n) => Object.keys(n)); | ||
return j({ | ||
clock: e.update, | ||
return E({ | ||
clock: t.update, | ||
source: r, | ||
fn: (n, c) => ({ ...n, [c.name]: c }), | ||
target: r | ||
}), { $fields: r, fieldsApi: e, $registeredFields: s }; | ||
}, z = (t) => { | ||
const { finalForm: e, subscribeOn: r } = t, s = x([...r, "isValidationPaused"], { | ||
...e.getState(), | ||
}), { $fields: r, fieldsApi: t, $registeredFields: s }; | ||
}, R = (e) => { | ||
const { finalForm: t, subscribeOn: r } = e, s = k([...r, "isValidationPaused"], { | ||
...t.getState(), | ||
isValidationPaused: !1 | ||
}), n = { | ||
update: g(), | ||
setValidationPaused: g() | ||
update: F(), | ||
setValidationPaused: F() | ||
}, c = O(s, { | ||
updateFilter: A | ||
}).on(n.update, (i, l) => Object.assign({}, i, l)).on(n.setValidationPaused, (i, l) => Object.assign({}, i, { isValidationPaused: l })); | ||
return e.subscribe((i) => { | ||
const l = r.reduce((d, o) => _(i[o]) ? { ...d, [o]: null } : d, i); | ||
n.update(l); | ||
}, v(P, r)), { $formState: c, formStateApi: n }; | ||
}, H = () => { | ||
}, w = (t) => { | ||
const { subscribeOn: e, ...r } = t, s = a(r.validate ?? H), n = a(r.onSubmit), c = h({ | ||
updateFilter: _ | ||
}).on(n.update, (i, a) => Object.assign({}, i, a)).on(n.setValidationPaused, (i, a) => Object.assign({}, i, { isValidationPaused: a })); | ||
return t.subscribe((i) => { | ||
const a = r.reduce((d, o) => v(i[o]) ? { ...d, [o]: null } : d, i); | ||
n.update(a); | ||
}, A(x, r)), { $formState: c, formStateApi: n }; | ||
}, D = () => { | ||
}, U = (e) => { | ||
const { subscribeOn: t, ...r } = e, s = P.store(e.initialValues) ? e.initialValues.getState() : e.initialValues, n = l(r.validate ?? D), c = l(r.onSubmit), i = $({ | ||
...r, | ||
validate: s, | ||
initialValues: s, | ||
validate: n, | ||
onSubmit: async (m) => { | ||
try { | ||
return await n(m); | ||
} catch (N) { | ||
return N; | ||
return await c(m); | ||
} catch (j) { | ||
return j; | ||
} | ||
@@ -136,26 +137,26 @@ }, | ||
} | ||
}), i = a(() => { | ||
c.mutators.__update__(); | ||
}), { $fields: l, $registeredFields: d, fieldsApi: o } = k(), { $formState: u, formStateApi: f } = z({ | ||
finalForm: c, | ||
subscribeOn: e | ||
}), p = $({ finalForm: c, fieldsApi: o, formStateApi: f }); | ||
return i(), { | ||
$formState: u, | ||
}), a = l(() => { | ||
i.mutators.__update__(); | ||
}), { $fields: d, $registeredFields: o, fieldsApi: u } = H(), { $formState: f, formStateApi: p } = R({ | ||
finalForm: i, | ||
subscribeOn: t | ||
}), N = z({ finalForm: i, fieldsApi: u, formStateApi: p }); | ||
return a(), { | ||
api: { | ||
...p, | ||
reValidateFx: i, | ||
...N, | ||
revalidateFx: a, | ||
setSubmitFn: (m) => { | ||
c.use(m); | ||
}, | ||
setValidationFn: (m) => { | ||
s.use(m), i(); | ||
}, | ||
setSubmitFn: (m) => { | ||
n.use(m); | ||
n.use(m), a(); | ||
} | ||
}, | ||
$fields: l, | ||
$registeredFields: d | ||
$fields: d, | ||
$formState: f, | ||
$registeredFields: o | ||
}; | ||
}; | ||
export { | ||
w as createForm | ||
U as createForm | ||
}; |
{ | ||
"name": "effector-final-form", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "☄️ Effector bindings for Final Form", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -9,3 +9,3 @@ # effector-final-form | ||
The goal of this project is to combine [Final Form](https://final-form.org/) and [Effector](https://effector.dev/) to achieve the goal described above. | ||
The goal of this project is to combine [Final Form](https://final-form.org/) and [Effector](https://effector.dev/) to achieve the above. | ||
@@ -12,0 +12,0 @@ ## Installation |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23262
345