@steveesamson/microform 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -31,8 +31,7 @@ import uform from "@steveesamson/microform";
31
31
  let defaultData:any = $props();
32
32
 
33
33
  // Instatiate microform
34
- // const { form, values, errors, submit, sanity } = uform({
35
- const { form, values, errors, submit, sanity, setValue, setError } = uform({
34
+ const { form, values, errors, submit, sanity } = uform({
36
35
  // Set default form data
37
36
  data:{...defaultData},
38
37
  // Set a global event for validation, can be overriden on a each field.
@@ -64,8 +63,6 @@ On the instantiation of `microform`, we have access to:
64
63
  - `sanity`, a `FormSanity`, which tells us if a form is clean/without errors by it's `ok` property.
65
64
  - `reset`, a function to reset form
66
65
  - `onsubmit`, a function to handle form submission.
67
- - `setValue`, a function to mutate state in order to avoid `ownership_invalid_mutation` errors, especially, when values is fed as props to other components that intend to mutate `values` states.
68
- - `setError`, is a function introduced for the same reason `setValue` was added; it give privileges to components authored on `microform` that may mutate the `errors` state.
69
66
 
70
67
  ### In the view Html
71
68
 
@@ -70,7 +70,7 @@ export const formAction = (values, errors, unfits, isdirty, options, validationM
70
70
  else if (isCheckbox(node)) {
71
71
  const { checked, value: val } = node;
72
72
  const { [name]: fieldValue } = get(values);
73
- let current = fieldValue;
73
+ let current = fieldValue.split(',');
74
74
  if (checked) {
75
75
  current.push(val);
76
76
  }
@@ -78,7 +78,7 @@ export const formAction = (values, errors, unfits, isdirty, options, validationM
78
78
  current = current.filter((next) => next !== val);
79
79
  }
80
80
  values.update((data) => {
81
- return { ...data, [name]: [...new Set(current)] };
81
+ return { ...data, [name]: [...new Set(current)].join(',') };
82
82
  });
83
83
  }
84
84
  else if (isRadio(node)) {
@@ -2,6 +2,7 @@ import { writable, derived, get } from 'svelte/store';
2
2
  import { formAction } from './form-action.js';
3
3
  import { bindStateToStore } from "./utils.js";
4
4
  const microform = (props) => {
5
+ // form default values
5
6
  const data = props?.data || {};
6
7
  // form values
7
8
  const _values = writable({ ...data });
@@ -61,12 +62,6 @@ const microform = (props) => {
61
62
  const values = $state({ ...data });
62
63
  const errors = $state({});
63
64
  const sanity = $state({ ok: get(_valid) });
64
- const setValue = (field, value) => {
65
- values[field] = value;
66
- };
67
- const setError = (field, value) => {
68
- errors[field] = value;
69
- };
70
65
  bindStateToStore(values, _values);
71
66
  bindStateToStore(errors, _errors);
72
67
  _valid.subscribe((changes) => {
@@ -80,8 +75,6 @@ const microform = (props) => {
80
75
  submit,
81
76
  onsubmit,
82
77
  reset,
83
- setError,
84
- setValue
85
78
  };
86
79
  };
87
80
  export default microform;
package/dist/types.d.ts CHANGED
@@ -61,7 +61,5 @@ export type MicroFormReturn = {
61
61
  submit: (formNode: HTMLFormElement, handler: FormSubmit) => void;
62
62
  onsubmit: (handler: FormSubmit) => (e: Event) => Promise<void>;
63
63
  reset: () => void;
64
- setValue: (key: string, value: unknown) => void;
65
- setError: (key: string, value: unknown) => void;
66
64
  };
67
65
  export type Microform = (props?: MicroFormProps) => MicroFormReturn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steveesamson/microform",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "postbuild": "touch ./docs/.nojekyll",