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

@conform-to/react

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/react - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

2

helpers.d.ts
/// <reference types="react" />
import type { FormMetadata, FieldMetadata, Metadata, Pretty } from './context';
type FormControlProps = {
key?: string;
key: string | undefined;
id: string;

@@ -6,0 +6,0 @@ name: string;

@@ -76,2 +76,3 @@ 'use strict';

return simplify(_rollupPluginBabelHelpers.objectSpread2({
key: metadata.key,
required: metadata.required || undefined

@@ -78,0 +79,0 @@ }, getFieldsetProps(metadata, options)));

@@ -59,57 +59,6 @@ 'use strict';

});
var subjectRef = context.useSubjectRef({
key: {
// Subscribe to all key changes so it will re-render and
// update the field value as soon as the DOM is updated
prefix: ['']
}
});
var subjectRef = context.useSubjectRef();
var stateSnapshot = context.useFormState(context$1, subjectRef);
var noValidate = useNoValidate(options.defaultNoValidate);
var form = context.getFormMetadata(context$1, subjectRef, stateSnapshot, noValidate);
react.useEffect(() => {
var formElement = document.forms.namedItem(formId);
if (!formElement) {
return;
}
var getAll = value => {
if (typeof value === 'string') {
return [value];
}
if (Array.isArray(value) && value.every(item => typeof item === 'string')) {
return value;
}
return undefined;
};
var get = value => {
var _getAll;
return (_getAll = getAll(value)) === null || _getAll === void 0 ? void 0 : _getAll[0];
};
for (var element of formElement.elements) {
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
var prev = element.dataset.conform;
var next = stateSnapshot.key[element.name];
var defaultValue = stateSnapshot.initialValue[element.name];
if (prev === 'managed' || element.type === 'submit' || element.type === 'reset' || element.type === 'button') {
// Skip buttons and fields managed by useInputControl()
continue;
}
if (typeof prev === 'undefined' || prev !== next) {
element.dataset.conform = next;
if ('options' in element) {
var _getAll2;
var value = (_getAll2 = getAll(defaultValue)) !== null && _getAll2 !== void 0 ? _getAll2 : [];
for (var option of element.options) {
option.selected = value.includes(option.value);
}
} else if ('checked' in element && (element.type === 'checkbox' || element.type === 'radio')) {
element.checked = get(defaultValue) === element.value;
} else {
var _get;
element.value = (_get = get(defaultValue)) !== null && _get !== void 0 ? _get : '';
}
}
}
}
}, [formId, stateSnapshot]);
return [form, form.getFieldset()];

@@ -116,0 +65,0 @@ }

@@ -34,3 +34,3 @@ 'use strict';

select.multiple = true;
select.dataset.conform = 'managed';
select.dataset.conform = 'true';

@@ -56,3 +56,3 @@ // To make sure the input is hidden but still focusable

function isDummySelect(element) {
return element.dataset.conform === 'managed';
return element.dataset.conform === 'true';
}

@@ -221,4 +221,17 @@ function updateFieldValue(element, value) {

};
var refCallback = element => {
var _meta$key;
register(element);
if (!element) {
return;
}
var prevKey = element.dataset.conform;
var nextKey = "".concat((_meta$key = meta.key) !== null && _meta$key !== void 0 ? _meta$key : '');
if (prevKey !== nextKey) {
element.dataset.conform = nextKey;
updateFieldValue(element, value !== null && value !== void 0 ? value : '');
}
};
return {
register,
register: refCallback,
value,

@@ -225,0 +238,0 @@ change: handleChange,

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.2.1",
"version": "1.2.2",
"main": "index.js",

@@ -34,3 +34,3 @@ "module": "index.mjs",

"dependencies": {
"@conform-to/dom": "1.2.1"
"@conform-to/dom": "1.2.2"
},

@@ -37,0 +37,0 @@ "devDependencies": {

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

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