@felte/preact
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,3 +5,2 @@ export { useAccessor } from './use-accessor.js'; | ||
export { FelteSubmitError } from './packages/core/dist/esm/error.js'; | ||
export { FelteErrorEvent, FelteSuccessEvent } from './packages/core/dist/esm/events.js'; | ||
//# sourceMappingURL=index.js.map |
import { __rest } from './external/.pnpm/tslib@2.3.1/external/tslib/tslib.es6.js'; | ||
import { get } from './get.js'; | ||
import { FelteSubmitEvent, FelteSuccessEvent, FelteErrorEvent } from './events.js'; | ||
import { createEventConstructors } from './events.js'; | ||
import { FelteSubmitError } from './error.js'; | ||
@@ -67,3 +67,4 @@ import { deepSetTouched } from './deep-set-touched.js'; | ||
const formNode = _getFormNode(); | ||
const submitEvent = new FelteSubmitEvent(); | ||
const { createErrorEvent, createSubmitEvent, createSuccessEvent, } = createEventConstructors(); | ||
const submitEvent = createSubmitEvent(); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(submitEvent); | ||
@@ -105,7 +106,7 @@ const onError = (_b = (_a = submitEvent.onError) !== null && _a !== void 0 ? _a : altConfig === null || altConfig === void 0 ? void 0 : altConfig.onError) !== null && _b !== void 0 ? _b : config.onError; | ||
const response = await onSubmit(currentData, context); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(new FelteSuccessEvent(Object.assign({ response }, context))); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(createSuccessEvent(Object.assign({ response }, context))); | ||
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, context)); | ||
} | ||
catch (e) { | ||
const errorEvent = new FelteErrorEvent(Object.assign({ error: e }, context)); | ||
const errorEvent = createErrorEvent(Object.assign({ error: e }, context)); | ||
formNode === null || formNode === void 0 ? void 0 : formNode.dispatchEvent(errorEvent); | ||
@@ -112,0 +113,0 @@ if (!onError && !errorEvent.defaultPrevented) { |
@@ -1,31 +0,38 @@ | ||
class FelteSuccessEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('feltesuccess', { detail }); | ||
function createEventConstructors() { | ||
class SuccessEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('feltesuccess', { detail }); | ||
} | ||
} | ||
} | ||
class FelteErrorEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('felteerror', { detail, cancelable: true }); | ||
class ErrorEvent extends CustomEvent { | ||
constructor(detail) { | ||
super('felteerror', { detail, cancelable: true }); | ||
} | ||
setErrors(errors) { | ||
this.preventDefault(); | ||
this.errors = errors; | ||
} | ||
} | ||
setErrors(errors) { | ||
this.preventDefault(); | ||
this.errors = errors; | ||
class SubmitEvent extends Event { | ||
constructor() { | ||
super('feltesubmit', { cancelable: true }); | ||
} | ||
handleSubmit(onSubmit) { | ||
this.onSubmit = onSubmit; | ||
} | ||
handleError(onError) { | ||
this.onError = onError; | ||
} | ||
handleSuccess(onSuccess) { | ||
this.onSuccess = onSuccess; | ||
} | ||
} | ||
return { | ||
createErrorEvent: (detail) => new ErrorEvent(detail), | ||
createSubmitEvent: () => new SubmitEvent(), | ||
createSuccessEvent: (detail) => new SuccessEvent(detail), | ||
}; | ||
} | ||
class FelteSubmitEvent extends Event { | ||
constructor() { | ||
super('feltesubmit', { cancelable: true }); | ||
} | ||
handleSubmit(onSubmit) { | ||
this.onSubmit = onSubmit; | ||
} | ||
handleError(onError) { | ||
this.onError = onError; | ||
} | ||
handleSuccess(onSuccess) { | ||
this.onSuccess = onSuccess; | ||
} | ||
} | ||
export { FelteErrorEvent, FelteSubmitEvent, FelteSuccessEvent }; | ||
export { createEventConstructors }; | ||
//# sourceMappingURL=events.js.map |
@@ -41,6 +41,6 @@ import { Obj, Errors, Touched, TransWritable, Traverse, Paths, Keyed, KeyedWritable, CreateSubmitHandlerConfig, KnownHelpers, UnknownHelpers, FormConfigWithTransformFn, FormConfigWithoutTransformFn, FieldConfig } from "@felte/core"; | ||
declare function useField(config: FieldConfig): Field; | ||
export type { FelteSuccessDetail, FelteErrorDetail, FieldConfig } from '@felte/core'; | ||
export { FelteSubmitError, FelteSuccessEvent, FelteErrorEvent } from '@felte/core'; | ||
export type { FelteSuccessDetail, FelteErrorDetail, FelteSubmitEvent, FelteSuccessEvent, FelteErrorEvent, FieldConfig } from '@felte/core'; | ||
export { FelteSubmitError } from '@felte/core'; | ||
export { useAccessor, useForm, useField }; | ||
export type { Field }; | ||
//# sourceMappingURL=index.cjs.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export type { FelteSuccessDetail, FelteErrorDetail } from '@felte/core'; | ||
export { FelteSubmitError, FelteSuccessEvent, FelteErrorEvent } from '@felte/core'; | ||
export type { FelteSuccessDetail, FelteErrorDetail, FelteSubmitEvent, FelteSuccessEvent, FelteErrorEvent } from '@felte/core'; | ||
export { FelteSubmitError } from '@felte/core'; | ||
export { useAccessor } from "./use-accessor"; | ||
@@ -4,0 +4,0 @@ export { useForm } from "./use-form"; |
{ | ||
"name": "@felte/preact", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "An extensible form library for Preact", | ||
@@ -28,3 +28,3 @@ "main": "dist/cjs/index.cjs", | ||
"dependencies": { | ||
"@felte/core": "1.1.0" | ||
"@felte/core": "1.1.1" | ||
}, | ||
@@ -31,0 +31,0 @@ "publishConfig": { |
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
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
Sorry, the diff of this file is not supported yet
540124
4195
+ Added@felte/core@1.1.1(transitive)
- Removed@felte/core@1.1.0(transitive)
Updated@felte/core@1.1.1