svelte-forms-lib
Advanced tools
Comparing version
@@ -98,3 +98,2 @@ 'use strict'; | ||
} | ||
function append(target, node) { | ||
@@ -157,2 +156,11 @@ target.appendChild(node); | ||
} | ||
function select_option(select, value) { | ||
for (let i = 0; i < select.options.length; i += 1) { | ||
const option = select.options[i]; | ||
if (option.__value === value) { | ||
option.selected = true; | ||
return; | ||
} | ||
} | ||
} | ||
function select_options(select, value) { | ||
@@ -208,3 +216,3 @@ for (let i = 0; i < select.options.length; i += 1) { | ||
set_current_component(component); | ||
update(component.$$); | ||
update$1(component.$$); | ||
} | ||
@@ -235,3 +243,3 @@ set_current_component(null); | ||
} | ||
function update($$) { | ||
function update$1($$) { | ||
if ($$.fragment !== null) { | ||
@@ -304,18 +312,20 @@ $$.update(); | ||
} | ||
function mount_component(component, target, anchor) { | ||
function mount_component(component, target, anchor, customElement) { | ||
const { fragment, on_mount, on_destroy, after_update } = component.$$; | ||
fragment && fragment.m(target, anchor); | ||
// onMount happens before the initial afterUpdate | ||
add_render_callback(() => { | ||
const new_on_destroy = on_mount.map(run).filter(is_function); | ||
if (on_destroy) { | ||
on_destroy.push(...new_on_destroy); | ||
} | ||
else { | ||
// Edge case - component was destroyed immediately, | ||
// most likely as a result of a binding initialising | ||
run_all(new_on_destroy); | ||
} | ||
component.$$.on_mount = []; | ||
}); | ||
if (!customElement) { | ||
// onMount happens before the initial afterUpdate | ||
add_render_callback(() => { | ||
const new_on_destroy = on_mount.map(run).filter(is_function); | ||
if (on_destroy) { | ||
on_destroy.push(...new_on_destroy); | ||
} | ||
else { | ||
// Edge case - component was destroyed immediately, | ||
// most likely as a result of a binding initialising | ||
run_all(new_on_destroy); | ||
} | ||
component.$$.on_mount = []; | ||
}); | ||
} | ||
after_update.forEach(add_render_callback); | ||
@@ -342,6 +352,5 @@ } | ||
} | ||
function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) { | ||
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) { | ||
const parent_component = current_component; | ||
set_current_component(component); | ||
const prop_values = options.props || {}; | ||
const $$ = component.$$ = { | ||
@@ -358,13 +367,16 @@ fragment: null, | ||
on_destroy: [], | ||
on_disconnect: [], | ||
before_update: [], | ||
after_update: [], | ||
context: new Map(parent_component ? parent_component.$$.context : []), | ||
context: new Map(parent_component ? parent_component.$$.context : options.context || []), | ||
// everything else | ||
callbacks: blank_object(), | ||
dirty, | ||
skip_bound: false | ||
skip_bound: false, | ||
root: options.target || parent_component.$$.root | ||
}; | ||
append_styles && append_styles($$.root); | ||
let ready = false; | ||
$$.ctx = instance | ||
? instance(component, prop_values, (i, ret, ...rest) => { | ||
? instance(component, options.props || {}, (i, ret, ...rest) => { | ||
const value = rest.length ? rest[0] : ret; | ||
@@ -398,3 +410,3 @@ if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | ||
transition_in(component.$$.fragment); | ||
mount_component(component, options.target, options.anchor); | ||
mount_component(component, options.target, options.anchor, options.customElement); | ||
flush(); | ||
@@ -448,3 +460,3 @@ } | ||
let stop; | ||
const subscribers = []; | ||
const subscribers = new Set(); | ||
function set(new_value) { | ||
@@ -455,6 +467,5 @@ if (safe_not_equal(value, new_value)) { | ||
const run_queue = !subscriber_queue.length; | ||
for (let i = 0; i < subscribers.length; i += 1) { | ||
const s = subscribers[i]; | ||
s[1](); | ||
subscriber_queue.push(s, value); | ||
for (const subscriber of subscribers) { | ||
subscriber[1](); | ||
subscriber_queue.push(subscriber, value); | ||
} | ||
@@ -475,4 +486,4 @@ if (run_queue) { | ||
const subscriber = [run, invalidate]; | ||
subscribers.push(subscriber); | ||
if (subscribers.length === 1) { | ||
subscribers.add(subscriber); | ||
if (subscribers.size === 1) { | ||
stop = start(set) || noop; | ||
@@ -482,7 +493,4 @@ } | ||
return () => { | ||
const index = subscribers.indexOf(subscriber); | ||
if (index !== -1) { | ||
subscribers.splice(index, 1); | ||
} | ||
if (subscribers.length === 0) { | ||
subscribers.delete(subscriber); | ||
if (subscribers.size === 0) { | ||
stop(); | ||
@@ -573,3 +581,3 @@ stop = null; | ||
function update$1(object, path, value) { | ||
function update(object, path, value) { | ||
object.update((o) => { | ||
@@ -692,3 +700,3 @@ set(o, path, value); | ||
subscribeOnce, | ||
update: update$1, | ||
update, | ||
}; | ||
@@ -703,3 +711,3 @@ | ||
const createForm = (config) => { | ||
const createForm = config => { | ||
let initialValues = config.initialValues || {}; | ||
@@ -727,10 +735,8 @@ | ||
const isValid = derived(errors, ($errors) => { | ||
const noErrors = util | ||
.getValues($errors) | ||
.every((field) => field === NO_ERROR); | ||
const isValid = derived(errors, $errors => { | ||
const noErrors = util.getValues($errors).every(field => field === NO_ERROR); | ||
return noErrors; | ||
}); | ||
const modified = derived(form, ($form) => { | ||
const modified = derived(form, $form => { | ||
const object = util.assignDeep($form, false); | ||
@@ -745,4 +751,4 @@ | ||
const isModified = derived(modified, ($modified) => { | ||
return util.getValues($modified).some((field) => field === true); | ||
const isModified = derived(modified, $modified => { | ||
return util.getValues($modified).includes(true); | ||
}); | ||
@@ -753,3 +759,3 @@ | ||
.subscribeOnce(form) | ||
.then((values) => validateFieldValue(field, values[field])); | ||
.then(values => validateFieldValue(field, values[field])); | ||
} | ||
@@ -766,3 +772,3 @@ | ||
.then(() => util.update(errors, field, '')) | ||
.catch((error) => util.update(errors, field, error.message)) | ||
.catch(error => util.update(errors, field, error.message)) | ||
.finally(() => { | ||
@@ -777,3 +783,3 @@ isValidating.set(false); | ||
.then(() => validateFunction({[field]: value})) | ||
.then((errs) => | ||
.then(errs => | ||
util.update(errors, field, !util.isNullish(errs) ? errs[field] : ''), | ||
@@ -809,3 +815,3 @@ ) | ||
return util.subscribeOnce(form).then((values) => { | ||
return util.subscribeOnce(form).then(values => { | ||
if (typeof validateFunction === 'function') { | ||
@@ -816,3 +822,3 @@ isValidating.set(true); | ||
.then(() => validateFunction(values)) | ||
.then((error) => { | ||
.then(error => { | ||
if (util.isNullish(error) || util.getValues(error).length === 0) { | ||
@@ -836,7 +842,7 @@ clearErrorsAndSubmit(values); | ||
// eslint-disable-next-line unicorn/catch-error-name | ||
.catch((yupErrors) => { | ||
.catch(yupErrors => { | ||
if (yupErrors && yupErrors.inner) { | ||
const updatedErrors = getInitial.errors(); | ||
yupErrors.inner.map((error) => | ||
yupErrors.inner.map(error => | ||
util.set(updatedErrors, error.path, error.message), | ||
@@ -944,3 +950,3 @@ ); | ||
/* lib/components/Form.svelte generated by Svelte v3.31.2 */ | ||
/* lib/components/Form.svelte generated by Svelte v3.40.2 */ | ||
const get_default_slot_changes = dirty => ({}); | ||
@@ -962,3 +968,3 @@ | ||
function create_fragment(ctx) { | ||
function create_fragment$4(ctx) { | ||
let form_1; | ||
@@ -999,4 +1005,4 @@ let current; | ||
if (default_slot) { | ||
if (default_slot.p && dirty & /*$$scope*/ 131072) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[17], dirty, get_default_slot_changes, get_default_slot_context); | ||
if (default_slot.p && (!current || dirty & /*$$scope*/ 131072)) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[17], !current ? -1 : dirty, get_default_slot_changes, get_default_slot_context); | ||
} | ||
@@ -1025,3 +1031,3 @@ } | ||
function instance($$self, $$props, $$invalidate) { | ||
function instance$4($$self, $$props, $$invalidate) { | ||
const omit_props_names = ["initialValues","validate","validationSchema","onSubmit","context"]; | ||
@@ -1035,3 +1041,3 @@ let $$restProps = compute_rest_props($$props, omit_props_names); | ||
let { onSubmit = () => { | ||
throw new Error("onSubmit is a required property in <Form /> when using the fallback context"); | ||
throw new Error('onSubmit is a required property in <Form /> when using the fallback context'); | ||
} } = $$props; | ||
@@ -1065,8 +1071,8 @@ | ||
$$invalidate(11, $$restProps = compute_rest_props($$props, omit_props_names)); | ||
if ("initialValues" in $$new_props) $$invalidate(12, initialValues = $$new_props.initialValues); | ||
if ("validate" in $$new_props) $$invalidate(13, validate = $$new_props.validate); | ||
if ("validationSchema" in $$new_props) $$invalidate(14, validationSchema = $$new_props.validationSchema); | ||
if ("onSubmit" in $$new_props) $$invalidate(15, onSubmit = $$new_props.onSubmit); | ||
if ("context" in $$new_props) $$invalidate(16, context = $$new_props.context); | ||
if ("$$scope" in $$new_props) $$invalidate(17, $$scope = $$new_props.$$scope); | ||
if ('initialValues' in $$new_props) $$invalidate(12, initialValues = $$new_props.initialValues); | ||
if ('validate' in $$new_props) $$invalidate(13, validate = $$new_props.validate); | ||
if ('validationSchema' in $$new_props) $$invalidate(14, validationSchema = $$new_props.validationSchema); | ||
if ('onSubmit' in $$new_props) $$invalidate(15, onSubmit = $$new_props.onSubmit); | ||
if ('context' in $$new_props) $$invalidate(16, context = $$new_props.context); | ||
if ('$$scope' in $$new_props) $$invalidate(17, $$scope = $$new_props.$$scope); | ||
}; | ||
@@ -1101,3 +1107,3 @@ | ||
init(this, options, instance, create_fragment, safe_not_equal, { | ||
init(this, options, instance$4, create_fragment$4, safe_not_equal, { | ||
initialValues: 12, | ||
@@ -1112,5 +1118,5 @@ validate: 13, | ||
/* lib/components/Textarea.svelte generated by Svelte v3.31.2 */ | ||
/* lib/components/Textarea.svelte generated by Svelte v3.40.2 */ | ||
function create_fragment$1(ctx) { | ||
function create_fragment$3(ctx) { | ||
let textarea; | ||
@@ -1142,2 +1148,3 @@ let textarea_value_value; | ||
insert(target, textarea, anchor); | ||
if (textarea.autofocus) textarea.focus(); | ||
@@ -1170,3 +1177,3 @@ if (!mounted) { | ||
function instance$1($$self, $$props, $$invalidate) { | ||
function instance$3($$self, $$props, $$invalidate) { | ||
let $form; | ||
@@ -1179,3 +1186,3 @@ let { name } = $$props; | ||
$$invalidate(4, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); | ||
if ("name" in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ('name' in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
}; | ||
@@ -1190,7 +1197,7 @@ | ||
super(); | ||
init(this, options, instance$1, create_fragment$1, safe_not_equal, { name: 0 }); | ||
init(this, options, instance$3, create_fragment$3, safe_not_equal, { name: 0 }); | ||
} | ||
} | ||
/* lib/components/Field.svelte generated by Svelte v3.31.2 */ | ||
/* lib/components/Field.svelte generated by Svelte v3.40.2 */ | ||
@@ -1226,2 +1233,3 @@ function create_fragment$2(ctx) { | ||
input.value = input_data.value; | ||
if (input.autofocus) input.focus(); | ||
@@ -1245,3 +1253,3 @@ if (!mounted) { | ||
if ("value" in input_data) { | ||
if ('value' in input_data) { | ||
input.value = input_data.value; | ||
@@ -1263,3 +1271,3 @@ } | ||
let { name } = $$props; | ||
let { type = "text" } = $$props; | ||
let { type = 'text' } = $$props; | ||
const { form, handleChange } = getContext(key); | ||
@@ -1270,4 +1278,4 @@ component_subscribe($$self, form, value => $$invalidate(2, $form = value)); | ||
$$invalidate(5, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); | ||
if ("name" in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ("type" in $$new_props) $$invalidate(1, type = $$new_props.type); | ||
if ('name' in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ('type' in $$new_props) $$invalidate(1, type = $$new_props.type); | ||
}; | ||
@@ -1286,5 +1294,5 @@ | ||
/* lib/components/Select.svelte generated by Svelte v3.31.2 */ | ||
/* lib/components/Select.svelte generated by Svelte v3.40.2 */ | ||
function create_fragment$3(ctx) { | ||
function create_fragment$1(ctx) { | ||
let select; | ||
@@ -1325,3 +1333,4 @@ let select_value_value; | ||
if (select_data.multiple) select_options(select, select_data.value); | ||
(select_data.multiple ? select_options : select_option)(select, select_data.value); | ||
if (select.autofocus) select.focus(); | ||
current = true; | ||
@@ -1340,4 +1349,4 @@ | ||
if (default_slot) { | ||
if (default_slot.p && dirty & /*$$scope*/ 32) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[5], dirty, null, null); | ||
if (default_slot.p && (!current || dirty & /*$$scope*/ 32)) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[5], !current ? -1 : dirty, null, null); | ||
} | ||
@@ -1352,3 +1361,4 @@ } | ||
if (dirty & /*name, $form, $$props*/ 19 && select_data.multiple) select_options(select, select_data.value); | ||
if (dirty & /*name, $form, $$props*/ 19) (select_data.multiple ? select_options : select_option)(select, select_data.value); | ||
}, | ||
@@ -1373,3 +1383,3 @@ i(local) { | ||
function instance$3($$self, $$props, $$invalidate) { | ||
function instance$1($$self, $$props, $$invalidate) { | ||
let $form; | ||
@@ -1383,4 +1393,4 @@ let { $$slots: slots = {}, $$scope } = $$props; | ||
$$invalidate(4, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); | ||
if ("name" in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ("$$scope" in $$new_props) $$invalidate(5, $$scope = $$new_props.$$scope); | ||
if ('name' in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ('$$scope' in $$new_props) $$invalidate(5, $$scope = $$new_props.$$scope); | ||
}; | ||
@@ -1395,7 +1405,7 @@ | ||
super(); | ||
init(this, options, instance$3, create_fragment$3, safe_not_equal, { name: 0 }); | ||
init(this, options, instance$1, create_fragment$1, safe_not_equal, { name: 0 }); | ||
} | ||
} | ||
/* lib/components/ErrorMessage.svelte generated by Svelte v3.31.2 */ | ||
/* lib/components/ErrorMessage.svelte generated by Svelte v3.40.2 */ | ||
@@ -1433,3 +1443,3 @@ function create_if_block(ctx) { | ||
function create_fragment$4(ctx) { | ||
function create_fragment(ctx) { | ||
let if_block_anchor; | ||
@@ -1470,3 +1480,3 @@ let if_block = /*$errors*/ ctx[1][/*name*/ ctx[0]] && create_if_block(ctx); | ||
function instance$4($$self, $$props, $$invalidate) { | ||
function instance($$self, $$props, $$invalidate) { | ||
let $errors; | ||
@@ -1479,3 +1489,3 @@ let { name } = $$props; | ||
$$invalidate(3, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); | ||
if ("name" in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
if ('name' in $$new_props) $$invalidate(0, name = $$new_props.name); | ||
}; | ||
@@ -1490,3 +1500,3 @@ | ||
super(); | ||
init(this, options, instance$4, create_fragment$4, safe_not_equal, { name: 0 }); | ||
init(this, options, instance, create_fragment, safe_not_equal, { name: 0 }); | ||
} | ||
@@ -1493,0 +1503,0 @@ } |
@@ -11,3 +11,3 @@ import {derived, writable, get} from 'svelte/store'; | ||
export const createForm = (config) => { | ||
export const createForm = config => { | ||
let initialValues = config.initialValues || {}; | ||
@@ -35,10 +35,8 @@ | ||
const isValid = derived(errors, ($errors) => { | ||
const noErrors = util | ||
.getValues($errors) | ||
.every((field) => field === NO_ERROR); | ||
const isValid = derived(errors, $errors => { | ||
const noErrors = util.getValues($errors).every(field => field === NO_ERROR); | ||
return noErrors; | ||
}); | ||
const modified = derived(form, ($form) => { | ||
const modified = derived(form, $form => { | ||
const object = util.assignDeep($form, false); | ||
@@ -53,4 +51,4 @@ | ||
const isModified = derived(modified, ($modified) => { | ||
return util.getValues($modified).some((field) => field === true); | ||
const isModified = derived(modified, $modified => { | ||
return util.getValues($modified).includes(true); | ||
}); | ||
@@ -61,3 +59,3 @@ | ||
.subscribeOnce(form) | ||
.then((values) => validateFieldValue(field, values[field])); | ||
.then(values => validateFieldValue(field, values[field])); | ||
} | ||
@@ -74,3 +72,3 @@ | ||
.then(() => util.update(errors, field, '')) | ||
.catch((error) => util.update(errors, field, error.message)) | ||
.catch(error => util.update(errors, field, error.message)) | ||
.finally(() => { | ||
@@ -85,3 +83,3 @@ isValidating.set(false); | ||
.then(() => validateFunction({[field]: value})) | ||
.then((errs) => | ||
.then(errs => | ||
util.update(errors, field, !util.isNullish(errs) ? errs[field] : ''), | ||
@@ -117,3 +115,3 @@ ) | ||
return util.subscribeOnce(form).then((values) => { | ||
return util.subscribeOnce(form).then(values => { | ||
if (typeof validateFunction === 'function') { | ||
@@ -124,3 +122,3 @@ isValidating.set(true); | ||
.then(() => validateFunction(values)) | ||
.then((error) => { | ||
.then(error => { | ||
if (util.isNullish(error) || util.getValues(error).length === 0) { | ||
@@ -144,7 +142,7 @@ clearErrorsAndSubmit(values); | ||
// eslint-disable-next-line unicorn/catch-error-name | ||
.catch((yupErrors) => { | ||
.catch(yupErrors => { | ||
if (yupErrors && yupErrors.inner) { | ||
const updatedErrors = getInitial.errors(); | ||
yupErrors.inner.map((error) => | ||
yupErrors.inner.map(error => | ||
util.set(updatedErrors, error.path, error.message), | ||
@@ -151,0 +149,0 @@ ); |
{ | ||
"name": "svelte-forms-lib", | ||
"version": "1.10.4", | ||
"version": "1.10.5", | ||
"description": "Svelte forms lib - A lightweight library for managing forms in Svelte v3", | ||
@@ -9,3 +9,3 @@ "typings": "./lib/index.d.ts", | ||
"build": "cross-env NODE_ENV=production && rollup -c rollup.config.js", | ||
"prepare": "npm run build", | ||
"prepare": "npm run build && husky install", | ||
"test": "jest && npm run svelte-check", | ||
@@ -45,42 +45,42 @@ "test:watch": "concurrently \"jest --watchAll\" npm:svelte-check:watch", | ||
"devDependencies": { | ||
"@babel/plugin-transform-react-jsx": "^7.12.13", | ||
"@babel/preset-env": "^7.12.11", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@testing-library/jest-dom": "^5.11.9", | ||
"@babel/plugin-transform-react-jsx": "^7.14.5", | ||
"@babel/preset-env": "^7.14.8", | ||
"@commitlint/cli": "^13.1.0", | ||
"@commitlint/config-conventional": "^13.1.0", | ||
"@rollup/plugin-typescript": "^8.2.3", | ||
"@testing-library/jest-dom": "^5.14.1", | ||
"@testing-library/svelte": "^3.0.3", | ||
"@types/chance": "1.1.1", | ||
"@types/jest": "26.0.20", | ||
"@types/yup": "0.29.11", | ||
"@types/chance": "1.1.3", | ||
"@types/jest": "26.0.24", | ||
"@types/yup": "0.29.13", | ||
"chance": "1.1.7", | ||
"commitizen": "^4.2.3", | ||
"concurrently": "^6.0.0", | ||
"commitizen": "^4.2.4", | ||
"concurrently": "^6.2.0", | ||
"cross-env": "^7.0.3", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-unicorn": "^27.0.0", | ||
"husky": "4.3.8", | ||
"jest": "26.6.3", | ||
"jest-runner-eslint": "^0.10.0", | ||
"eslint": "^7.31.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-unicorn": "^34.0.1", | ||
"husky": "^7.0.0", | ||
"jest": "^26.6.3", | ||
"jest-runner-eslint": "^0.10.1", | ||
"jest-watch-select-projects": "^2.0.0", | ||
"jest-watch-typeahead": "^0.6.1", | ||
"lint-staged": "10.5.3", | ||
"prettier": "^2.2.1", | ||
"prettier-plugin-svelte": "^2.1.1", | ||
"rollup": "2.38.0", | ||
"jest-watch-typeahead": "^0.6.4", | ||
"lint-staged": "11.1.1", | ||
"prettier": "^2.3.2", | ||
"prettier-plugin-svelte": "^2.3.1", | ||
"rollup": "2.54.0", | ||
"rollup-plugin-commonjs": "10.1.0", | ||
"rollup-plugin-node-resolve": "5.2.0", | ||
"rollup-plugin-svelte": "7.1.0", | ||
"semantic-release": "^17.3.6", | ||
"svelte": "3.31.2", | ||
"svelte-check": "^1.2.1", | ||
"semantic-release": "^17.4.4", | ||
"svelte": "3.40.2", | ||
"svelte-check": "^2.2.3", | ||
"svelte-fragment-component": "^1.2.0", | ||
"svelte-jester": "^1.3.0", | ||
"svelte-jester": "^1.7.0", | ||
"svelte-jsx": "^2.0.0", | ||
"svelte-preprocess": "^4.6.9", | ||
"svelte2tsx": "^0.1.189", | ||
"typescript": "^4.2.3", | ||
"yup": "0.32.8" | ||
"svelte-preprocess": "^4.7.4", | ||
"svelte2tsx": "^0.4.2", | ||
"typescript": "^4.3.5", | ||
"yup": "0.32.9" | ||
}, | ||
@@ -87,0 +87,0 @@ "config": { |
Sorry, the diff of this file is not supported yet
99669
1.01%3030
0.6%