@conform-to/dom 1.6.1 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/formdata.js CHANGED
@@ -141,16 +141,9 @@ function getValue(target, name) {
141
141
  function isPlainObject(obj) {
142
142
  return !!obj && obj.constructor === Object && Object.getPrototypeOf(obj) === Object.prototype;
143
143
  }
144
-
145
- /**
146
- * Check if the value is a File
147
- */
148
- function isFile(obj) {
149
- // Skip checking if File is not defined
150
- if (typeof File === 'undefined') {
151
- return false;
152
- }
153
- return obj instanceof File;
144
+ function isGlobalInstance(obj, className) {
145
+ var Ctor = globalThis[className];
146
+ return typeof Ctor === 'function' && obj instanceof Ctor;
154
147
  }
155
148
 
156
149
  /**
@@ -178,7 +171,7 @@ function normalize(value) {
178
171
  }
179
172
  return value.map(item => normalize(item, acceptFile));
180
173
  }
181
- if (typeof value === 'string' && value === '' || value === null || isFile(value) && (!acceptFile || value.size === 0)) {
174
+ if (typeof value === 'string' && value === '' || value === null || isGlobalInstance(value, 'File') && (!acceptFile || value.size === 0)) {
182
175
  return;
183
176
  }
184
177
  return value;
@@ -213,7 +206,43 @@ function flatten(data) {
213
206
  }
214
207
  return result;
215
208
  }
209
+ function deepEqual(prev, next) {
210
+ if (prev === next) {
211
+ return true;
212
+ }
213
+ if (!prev || !next) {
214
+ return false;
215
+ }
216
+ if (Array.isArray(prev) && Array.isArray(next)) {
217
+ if (prev.length !== next.length) {
218
+ return false;
219
+ }
220
+ for (var i = 0; i < prev.length; i++) {
221
+ if (!deepEqual(prev[i], next[i])) {
222
+ return false;
223
+ }
224
+ }
225
+ return true;
226
+ }
227
+ if (isPlainObject(prev) && isPlainObject(next)) {
228
+ var prevKeys = Object.keys(prev);
229
+ var nextKeys = Object.keys(next);
230
+ if (prevKeys.length !== nextKeys.length) {
231
+ return false;
232
+ }
233
+ for (var key of prevKeys) {
234
+ if (!Object.prototype.hasOwnProperty.call(next, key) ||
235
+ // @ts-expect-error FIXME
236
+ !deepEqual(prev[key], next[key])) {
237
+ return false;
238
+ }
239
+ }
240
+ return true;
241
+ }
242
+ return false;
243
+ }
216
244
 
245
+ exports.deepEqual = deepEqual;
217
246
  exports.flatten = flatten;
218
247
  exports.formatName = formatName;
219
248
  exports.formatPaths = formatPaths;
@@ -221,7 +250,7 @@ exports.getChildPaths = getChildPaths;
221
250
  exports.getFormData = getFormData;
222
251
  exports.getPaths = getPaths;
223
252
  exports.getValue = getValue;
224
- exports.isFile = isFile;
253
+ exports.isGlobalInstance = isGlobalInstance;
225
254
  exports.isPlainObject = isPlainObject;
226
255
  exports.isPrefix = isPrefix;
227
256
  exports.normalize = normalize;
package/dist/formdata.mjs CHANGED
@@ -137,16 +137,9 @@ function getValue(target, name) {
137
137
  function isPlainObject(obj) {
138
138
  return !!obj && obj.constructor === Object && Object.getPrototypeOf(obj) === Object.prototype;
139
139
  }
140
-
141
- /**
142
- * Check if the value is a File
143
- */
144
- function isFile(obj) {
145
- // Skip checking if File is not defined
146
- if (typeof File === 'undefined') {
147
- return false;
148
- }
149
- return obj instanceof File;
140
+ function isGlobalInstance(obj, className) {
141
+ var Ctor = globalThis[className];
142
+ return typeof Ctor === 'function' && obj instanceof Ctor;
150
143
  }
151
144
 
152
145
  /**
@@ -174,7 +167,7 @@ function normalize(value) {
174
167
  }
175
168
  return value.map(item => normalize(item, acceptFile));
176
169
  }
177
- if (typeof value === 'string' && value === '' || value === null || isFile(value) && (!acceptFile || value.size === 0)) {
170
+ if (typeof value === 'string' && value === '' || value === null || isGlobalInstance(value, 'File') && (!acceptFile || value.size === 0)) {
178
171
  return;
179
172
  }
180
173
  return value;
@@ -209,5 +202,40 @@ function flatten(data) {
209
202
  }
210
203
  return result;
211
204
  }
205
+ function deepEqual(prev, next) {
206
+ if (prev === next) {
207
+ return true;
208
+ }
209
+ if (!prev || !next) {
210
+ return false;
211
+ }
212
+ if (Array.isArray(prev) && Array.isArray(next)) {
213
+ if (prev.length !== next.length) {
214
+ return false;
215
+ }
216
+ for (var i = 0; i < prev.length; i++) {
217
+ if (!deepEqual(prev[i], next[i])) {
218
+ return false;
219
+ }
220
+ }
221
+ return true;
222
+ }
223
+ if (isPlainObject(prev) && isPlainObject(next)) {
224
+ var prevKeys = Object.keys(prev);
225
+ var nextKeys = Object.keys(next);
226
+ if (prevKeys.length !== nextKeys.length) {
227
+ return false;
228
+ }
229
+ for (var key of prevKeys) {
230
+ if (!Object.prototype.hasOwnProperty.call(next, key) ||
231
+ // @ts-expect-error FIXME
232
+ !deepEqual(prev[key], next[key])) {
233
+ return false;
234
+ }
235
+ }
236
+ return true;
237
+ }
238
+ return false;
239
+ }
212
240
 
213
- export { flatten, formatName, formatPaths, getChildPaths, getFormData, getPaths, getValue, isFile, isPlainObject, isPrefix, normalize, setValue };
241
+ export { deepEqual, flatten, formatName, formatPaths, getChildPaths, getFormData, getPaths, getValue, isGlobalInstance, isPlainObject, isPrefix, normalize, setValue };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, updateFieldValue as unstable_updateFieldValue, } from './form';
2
- export { type FieldElement, isFieldElement } from './dom';
1
+ export { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form';
2
+ export { type FieldElement, isFieldElement, updateField as unstable_updateField, createFileList, createGlobalFormsObserver as unstable_createGlobalFormsObserver, focus as unstable_focus, change as unstable_change, blur as unstable_blur, } from './dom';
3
3
  export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
4
- export { getPaths, formatPaths, isPrefix } from './formdata';
4
+ export { getPaths, formatPaths, isPrefix, isGlobalInstance, deepEqual as unstable_deepEqual, } from './formdata';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,12 +10,19 @@ var formdata = require('./formdata.js');
10
10
 
11
11
 
12
12
  exports.unstable_createFormContext = form.createFormContext;
13
- exports.unstable_updateFieldValue = form.updateFieldValue;
13
+ exports.createFileList = dom.createFileList;
14
14
  exports.isFieldElement = dom.isFieldElement;
15
+ exports.unstable_blur = dom.blur;
16
+ exports.unstable_change = dom.change;
17
+ exports.unstable_createGlobalFormsObserver = dom.createGlobalFormsObserver;
18
+ exports.unstable_focus = dom.focus;
19
+ exports.unstable_updateField = dom.updateField;
15
20
  exports.INTENT = submission.INTENT;
16
21
  exports.STATE = submission.STATE;
17
22
  exports.parse = submission.parse;
18
23
  exports.serializeIntent = submission.serializeIntent;
19
24
  exports.formatPaths = formdata.formatPaths;
20
25
  exports.getPaths = formdata.getPaths;
26
+ exports.isGlobalInstance = formdata.isGlobalInstance;
21
27
  exports.isPrefix = formdata.isPrefix;
28
+ exports.unstable_deepEqual = formdata.deepEqual;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { createFormContext as unstable_createFormContext, updateFieldValue as unstable_updateFieldValue } from './form.mjs';
2
- export { isFieldElement } from './dom.mjs';
1
+ export { createFormContext as unstable_createFormContext } from './form.mjs';
2
+ export { createFileList, isFieldElement, blur as unstable_blur, change as unstable_change, createGlobalFormsObserver as unstable_createGlobalFormsObserver, focus as unstable_focus, updateField as unstable_updateField } from './dom.mjs';
3
3
  export { INTENT, STATE, parse, serializeIntent } from './submission.mjs';
4
- export { formatPaths, getPaths, isPrefix } from './formdata.mjs';
4
+ export { formatPaths, getPaths, isGlobalInstance, isPrefix, deepEqual as unstable_deepEqual } from './formdata.mjs';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A set of opinionated helpers built on top of the Constraint Validation API",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "1.6.1",
6
+ "version": "1.7.1",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",