notform 1.0.5 → 1.0.7

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/index.d.ts CHANGED
@@ -344,6 +344,10 @@ type NotArrayFieldProps<TSchema extends ArraySchema> = {
344
344
  * @template TSchema The schema of the array field.
345
345
  */
346
346
  type NotArrayFieldContext<TSchema extends ArraySchema> = {
347
+ /** The unique name/path identifying the array field in the form state */
348
+ name: string;
349
+ /** Array-level validation errors for the field path */
350
+ errors: string[];
347
351
  /**
348
352
  * Array of individual field contexts for each item in the collection.
349
353
  * Useful for mapping components to array elements.
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { computed, createBlock, createTextVNode, defineComponent, guardReactiveProps, inject, mergeProps, nextTick, normalizeProps, onMounted, openBlock, provide, reactive, ref, renderSlot, resolveDynamicComponent, toDisplayString, toValue, unref, useAttrs, useId, vShow, withCtx, withDirectives } from "vue";
2
2
  import { getProperty, parsePath, setProperty } from "dot-prop";
3
+ import { isEqual } from "es-toolkit/predicate";
3
4
 
4
5
  //#region src/utils/not-form-context.ts
5
6
  /** Internal registry mapping form IDs to their injection keys */
@@ -235,7 +236,7 @@ var not_array_field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ *
235
236
  */
236
237
  const formID = inject(CURRENT_NOT_FORM_ID_KEY);
237
238
  if (!formID) throw new Error("NotArrayField must be used inside a NotForm component");
238
- const { state, validateField } = withContext(formID);
239
+ const { state, validateField, getFieldErrors } = withContext(formID);
239
240
  /**
240
241
  * Reactive bridge between the form state and the specific array field.
241
242
  */
@@ -310,6 +311,8 @@ var not_array_field_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ *
310
311
  * Reactive context object exposed to the NotArrayField slot.
311
312
  */
312
313
  const context = reactive({
314
+ name: computed(() => props.name),
315
+ errors: computed(() => getFieldErrors(props.name).map((error) => error.message)),
313
316
  fields,
314
317
  append,
315
318
  prepend,
@@ -494,8 +497,9 @@ function useNotForm(options) {
494
497
  ..._state
495
498
  };
496
499
  getObjectPaths(_state).forEach((path) => {
497
- context.dirtyFields.value.add(path);
498
500
  context.touchedFields.value.add(path);
501
+ if (!isEqual(getProperty(context.state.value, path), getProperty(onResetState.value ?? initialState, path))) context.dirtyFields.value.add(path);
502
+ else context.dirtyFields.value.delete(path);
499
503
  if (_validate) context.validateField(path);
500
504
  });
501
505
  },
@@ -517,11 +521,16 @@ function useNotForm(options) {
517
521
  context.touchedFields.value = new Set(paths);
518
522
  },
519
523
  dirtyField(field) {
520
- context.dirtyFields.value.add(field);
524
+ if (!isEqual(getProperty(context.state.value, field), getProperty(onResetState.value ?? initialState, field))) context.dirtyFields.value.add(field);
525
+ else context.dirtyFields.value.delete(field);
521
526
  },
522
527
  dirtyAllFields() {
523
528
  const paths = getObjectPaths(context.state.value);
524
- context.dirtyFields.value = new Set(paths);
529
+ const newDirty = /* @__PURE__ */ new Set();
530
+ paths.forEach((path) => {
531
+ if (!isEqual(getProperty(context.state.value, path), getProperty(onResetState.value ?? initialState, path))) newDirty.add(path);
532
+ });
533
+ context.dirtyFields.value = newDirty;
525
534
  },
526
535
  async submit(event) {
527
536
  context.isSubmitting.value = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notform",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -55,7 +55,8 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@standard-schema/spec": "^1.1.0",
58
- "dot-prop": "^10.1.0"
58
+ "dot-prop": "^10.1.0",
59
+ "es-toolkit": "^1.45.1"
59
60
  },
60
61
  "engines": {
61
62
  "node": ">=24.0.0"