Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@conform-to/dom

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conform-to/dom - npm Package Compare versions

Comparing version 0.4.0-pre.2 to 0.4.0-pre.3

8

index.d.ts

@@ -26,3 +26,3 @@ export declare type Primitive = null | undefined | string | number | boolean | Date;

export declare type Submission<Schema = unknown> = {
context: string;
type: string;
intent?: string;

@@ -33,8 +33,8 @@ value: FieldValue<Schema>;

export declare function isFieldElement(element: unknown): element is FieldElement;
export declare function getFormElements(form: HTMLFormElement): FieldElement[];
export declare function getPaths(name: string): Array<string | number>;
export declare function getFormData(form: HTMLFormElement, submitter?: HTMLInputElement | HTMLButtonElement | null): FormData;
export declare function getName(paths: Array<string | number>): string;
export declare function shouldValidate(submission: Submission, name: string): boolean;
export declare function hasError(error: Array<[string, string]>, names?: string[]): boolean;
export declare function getFormError(form: HTMLFormElement, getFieldError?: (field: FieldElement) => Array<[string, string]>): Array<[string, string]>;
export declare function shouldValidate(submission: Submission, name?: string): boolean;
export declare function hasError(error: Array<[string, string]>, name?: string): boolean;
export declare function setFormError(form: HTMLFormElement, submission: Submission): void;

@@ -41,0 +41,0 @@ export declare function setValue<T>(target: any, paths: Array<string | number>, valueFn: (prev?: T) => T): void;

@@ -10,2 +10,5 @@ 'use strict';

}
function getFormElements(form) {
return Array.from(form.elements).filter(isFieldElement);
}
function getPaths(name) {

@@ -55,23 +58,10 @@ var pattern = /(\w*)\[(\d+)\]/;

function shouldValidate(submission, name) {
return submission.context === 'submit' || submission.context === 'validate' && submission.intent === name;
return submission.type === 'submit' || submission.type === 'validate' && (typeof name === 'undefined' || submission.intent === name);
}
function hasError(error, names) {
function hasError(error, name) {
return typeof error.find(_ref => {
var [fieldName, message] = _ref;
return (typeof names === 'undefined' || names.includes(fieldName)) && message !== '';
return (typeof name === 'undefined' || name === fieldName) && message !== '';
}) !== 'undefined';
}
function getFormError(form, getFieldError) {
var error = [];
for (var element of form.elements) {
if (isFieldElement(element) && element.willValidate) {
var _getFieldError;
error.push(...((_getFieldError = getFieldError === null || getFieldError === void 0 ? void 0 : getFieldError(element)) !== null && _getFieldError !== void 0 ? _getFieldError : [[element.name, element.validationMessage]]));
}
}
return error;
}
function setFormError(form, submission) {

@@ -140,8 +130,7 @@ var firstErrorByName = Object.fromEntries([...submission.error].reverse());

for (var _field of form.elements) {
if (isFieldElement(_field)) {
for (var field of form.elements) {
if (isFieldElement(field)) {
// Focus on the first non button field
if (!_field.validity.valid && _field.dataset.conformTouched && _field.tagName !== 'BUTTON') {
_field.focus();
if (!field.validity.valid && field.dataset.conformTouched && field.tagName !== 'BUTTON') {
field.focus();
break;

@@ -164,3 +153,3 @@ }

var submission = {
context: 'submit',
type: 'submit',
value: {},

@@ -184,3 +173,3 @@ error: []

submission = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, submission), {}, {
context: submissionType,
type: submissionType,
intent: value

@@ -205,3 +194,3 @@ });

switch (submission.context) {
switch (submission.type) {
case 'list':

@@ -267,3 +256,3 @@ submission = handleList(submission);

if (submission.context !== 'list') {
if (submission.type !== 'list') {
return submission;

@@ -287,3 +276,3 @@ }

exports.getFormElement = getFormElement;
exports.getFormError = getFormError;
exports.getFormElements = getFormElements;
exports.getName = getName;

@@ -290,0 +279,0 @@ exports.getPaths = getPaths;

@@ -6,2 +6,5 @@ import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.js';

}
function getFormElements(form) {
return Array.from(form.elements).filter(isFieldElement);
}
function getPaths(name) {

@@ -51,23 +54,10 @@ var pattern = /(\w*)\[(\d+)\]/;

function shouldValidate(submission, name) {
return submission.context === 'submit' || submission.context === 'validate' && submission.intent === name;
return submission.type === 'submit' || submission.type === 'validate' && (typeof name === 'undefined' || submission.intent === name);
}
function hasError(error, names) {
function hasError(error, name) {
return typeof error.find(_ref => {
var [fieldName, message] = _ref;
return (typeof names === 'undefined' || names.includes(fieldName)) && message !== '';
return (typeof name === 'undefined' || name === fieldName) && message !== '';
}) !== 'undefined';
}
function getFormError(form, getFieldError) {
var error = [];
for (var element of form.elements) {
if (isFieldElement(element) && element.willValidate) {
var _getFieldError;
error.push(...((_getFieldError = getFieldError === null || getFieldError === void 0 ? void 0 : getFieldError(element)) !== null && _getFieldError !== void 0 ? _getFieldError : [[element.name, element.validationMessage]]));
}
}
return error;
}
function setFormError(form, submission) {

@@ -136,8 +126,7 @@ var firstErrorByName = Object.fromEntries([...submission.error].reverse());

for (var _field of form.elements) {
if (isFieldElement(_field)) {
for (var field of form.elements) {
if (isFieldElement(field)) {
// Focus on the first non button field
if (!_field.validity.valid && _field.dataset.conformTouched && _field.tagName !== 'BUTTON') {
_field.focus();
if (!field.validity.valid && field.dataset.conformTouched && field.tagName !== 'BUTTON') {
field.focus();
break;

@@ -160,3 +149,3 @@ }

var submission = {
context: 'submit',
type: 'submit',
value: {},

@@ -180,3 +169,3 @@ error: []

submission = _objectSpread2(_objectSpread2({}, submission), {}, {
context: submissionType,
type: submissionType,
intent: value

@@ -201,3 +190,3 @@ });

switch (submission.context) {
switch (submission.type) {
case 'list':

@@ -263,3 +252,3 @@ submission = handleList(submission);

if (submission.context !== 'list') {
if (submission.type !== 'list') {
return submission;

@@ -280,2 +269,2 @@ }

export { focusFirstInvalidField, getFormData, getFormElement, getFormError, getName, getPaths, getSubmissionType, handleList, hasError, isFieldElement, parse, parseListCommand, requestSubmit, requestValidate, setFormError, setValue, shouldValidate, updateList };
export { focusFirstInvalidField, getFormData, getFormElement, getFormElements, getName, getPaths, getSubmissionType, handleList, hasError, isFieldElement, parse, parseListCommand, requestSubmit, requestValidate, setFormError, setValue, shouldValidate, updateList };

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "0.4.0-pre.2",
"version": "0.4.0-pre.3",
"main": "index.js",

@@ -8,0 +8,0 @@ "module": "module/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc