jails.stdlib 1.0.0 → 1.1.0
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 +4 -4
- package/cancelable/README.md +1 -1
- package/debounce/README.md +1 -1
- package/delay/README.md +1 -1
- package/form-validation/index.js +49 -47
- package/form-validation/index.ts +4 -0
- package/form-validation/index.umd.js +1 -1
- package/form-validation/readme.md +22 -2
- package/import-css/README.md +1 -1
- package/import-html/README.md +1 -1
- package/import-js/README.md +1 -1
- package/is-touch/README.md +1 -1
- package/is-visible/README.md +1 -1
- package/lazyload-image/README.md +1 -1
- package/messenger/README.md +1 -1
- package/mfe/README.md +4 -4
- package/outlet/README.md +1 -1
- package/package.json +1 -1
- package/querystring/README.md +1 -1
- package/router/README.md +1 -1
- package/storage/README.md +1 -1
- package/store/README.md +1 -1
- package/third-party/README.md +1 -1
- package/throttle/README.md +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
<div align="center">
|
|
3
|
-
<h1>jails.
|
|
3
|
+
<h1>jails.stdlib</h1>
|
|
4
4
|
<h4>The Jails Standard Library</h4>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
## Installing
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
-
npm install jails.
|
|
12
|
+
npm install jails.stdlib
|
|
13
13
|
```
|
|
14
14
|
or
|
|
15
15
|
|
|
16
16
|
```
|
|
17
|
-
yarn add jails.
|
|
17
|
+
yarn add jails.stdlib
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
<br />
|
|
21
21
|
|
|
22
|
-
See more details about each module inside their respective folders.
|
|
22
|
+
See more details about each module inside their respective folders.
|
package/cancelable/README.md
CHANGED
|
@@ -10,7 +10,7 @@ TIt ensures only the latest async call resolves, ignoring all previous ones, so
|
|
|
10
10
|
### Usage
|
|
11
11
|
|
|
12
12
|
```js
|
|
13
|
-
import { cancelable } from 'jails.
|
|
13
|
+
import { cancelable } from 'jails.stdlib/cancelable'
|
|
14
14
|
|
|
15
15
|
export const getService = () => {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
package/debounce/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Delays a function's execution until after a specified pause in activity.
|
|
|
10
10
|
### Usage
|
|
11
11
|
|
|
12
12
|
```js
|
|
13
|
-
import { debounce } from 'jails.
|
|
13
|
+
import { debounce } from 'jails.stdlib/debounce'
|
|
14
14
|
|
|
15
15
|
const oninput = debounce(() => {
|
|
16
16
|
console.log('debouncing input')
|
package/delay/README.md
CHANGED
package/form-validation/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var T = Object.defineProperty, B = Object.defineProperties;
|
|
|
2
2
|
var C = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var D = Object.getOwnPropertySymbols;
|
|
4
4
|
var G = Object.prototype.hasOwnProperty, H = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var A = (a, r, e) => r in a ? T(a, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[r] = e,
|
|
5
|
+
var A = (a, r, e) => r in a ? T(a, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[r] = e, m = (a, r) => {
|
|
6
6
|
for (var e in r || (r = {}))
|
|
7
7
|
G.call(r, e) && A(a, e, r[e]);
|
|
8
8
|
if (D)
|
|
@@ -10,85 +10,87 @@ var A = (a, r, e) => r in a ? T(a, r, { enumerable: !0, configurable: !0, writab
|
|
|
10
10
|
H.call(r, e) && A(a, e, r[e]);
|
|
11
11
|
return a;
|
|
12
12
|
}, L = (a, r) => B(a, C(r));
|
|
13
|
-
const M = "form-validation",
|
|
13
|
+
const M = "form-validation", g = "[data-validation]", J = "[data-mask]";
|
|
14
14
|
function U({
|
|
15
15
|
main: a,
|
|
16
16
|
elm: r,
|
|
17
17
|
state: e,
|
|
18
18
|
on: n,
|
|
19
|
-
emit:
|
|
19
|
+
emit: v,
|
|
20
20
|
dependencies: y,
|
|
21
21
|
trigger: F
|
|
22
22
|
}) {
|
|
23
|
-
var
|
|
24
|
-
const { validations:
|
|
23
|
+
var k;
|
|
24
|
+
const { validations: h, masks: E } = y, f = (k = r.querySelector("input,select,textarea")) == null ? void 0 : k.form;
|
|
25
25
|
let u = S(f);
|
|
26
26
|
a((t) => {
|
|
27
|
-
n("input", "input, textarea, select", z), n("input", J, $), n("input",
|
|
28
|
-
})
|
|
27
|
+
n("input", "input, textarea, select", z), n("input", J, $), n("input", g, p("input")), n("change", g, p("change")), n("blur", g, p("blur")), n("focus", "input, textarea, select", N), n("blur", "input, textarea, select", O), f.addEventListener("reset", j), f.addEventListener("submit", _), I();
|
|
28
|
+
}), r.setValues = (t) => {
|
|
29
|
+
e.set((s) => s.form.values = m(m({}, s.form.values), t));
|
|
30
|
+
};
|
|
29
31
|
const I = () => {
|
|
30
|
-
if (!
|
|
32
|
+
if (!h)
|
|
31
33
|
throw new Error(
|
|
32
34
|
"<form-validation> - No validations provided in dependencies"
|
|
33
35
|
);
|
|
34
|
-
const t =
|
|
35
|
-
e.set((
|
|
36
|
-
},
|
|
36
|
+
const t = V();
|
|
37
|
+
e.set((s) => s.form.values = t);
|
|
38
|
+
}, V = () => {
|
|
37
39
|
const t = {};
|
|
38
|
-
return u.forEach((
|
|
40
|
+
return u.forEach((s) => t[s] = ""), t;
|
|
39
41
|
}, N = (t) => {
|
|
40
|
-
const
|
|
41
|
-
e.set((
|
|
42
|
-
|
|
42
|
+
const s = t.target.name;
|
|
43
|
+
e.set((o) => {
|
|
44
|
+
o.form.touched[s] = !0, o.form.focused[s] = !0;
|
|
43
45
|
});
|
|
44
46
|
}, O = (t) => {
|
|
45
|
-
const
|
|
46
|
-
e.set((
|
|
47
|
-
|
|
47
|
+
const s = t.target.name;
|
|
48
|
+
e.set((o) => {
|
|
49
|
+
o.form.focused[s] = !1;
|
|
48
50
|
});
|
|
49
|
-
},
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
const { ok: q, message: K } =
|
|
51
|
+
}, p = (t) => (s) => {
|
|
52
|
+
const o = s.target, i = o.name, c = w(o, f), b = o.dataset.validation.split(/\s/), d = [], x = e.get();
|
|
53
|
+
b.forEach((l) => {
|
|
54
|
+
if (l in h) {
|
|
55
|
+
const { ok: q, message: K } = h[l](
|
|
54
56
|
c,
|
|
55
|
-
|
|
57
|
+
o,
|
|
56
58
|
f
|
|
57
59
|
);
|
|
58
60
|
q || d.push(K);
|
|
59
61
|
}
|
|
60
|
-
}), d.length ? t === "input" ? (u.add(
|
|
61
|
-
|
|
62
|
-
})) : (t === "blur" || t === "change") && (u.add(
|
|
63
|
-
|
|
64
|
-
})) : (u.delete(
|
|
65
|
-
delete
|
|
62
|
+
}), d.length ? t === "input" ? (u.add(o.name), e.set((l) => {
|
|
63
|
+
l.form.isValid = !1, x.form.errors[i] && d[0] != x.form.errors[i] && (l.form.errors[i] = d[0]);
|
|
64
|
+
})) : (t === "blur" || t === "change") && (u.add(o.name), e.set((l) => {
|
|
65
|
+
l.form.errors[i] = d[0], l.form.isValid = !1;
|
|
66
|
+
})) : (u.delete(o.name), e.set((l) => {
|
|
67
|
+
delete l.form.errors[i], u.size || (l.form.isValid = !0);
|
|
66
68
|
}));
|
|
67
69
|
}, z = (t) => {
|
|
68
|
-
const { name:
|
|
69
|
-
e.set((
|
|
70
|
+
const { name: s } = t.target, o = w(t.target, f);
|
|
71
|
+
e.set((i) => i.form.values[s] = o);
|
|
70
72
|
}, _ = (t) => {
|
|
71
|
-
t.preventDefault(), F("blur",
|
|
72
|
-
const
|
|
73
|
-
if (Object.keys(
|
|
74
|
-
|
|
73
|
+
t.preventDefault(), F("blur", g);
|
|
74
|
+
const o = e.get().form.errors;
|
|
75
|
+
if (Object.keys(o).length)
|
|
76
|
+
v(`${M}:error`, { errors: o });
|
|
75
77
|
else {
|
|
76
78
|
const c = Q(t.target);
|
|
77
|
-
|
|
79
|
+
v(`${M}:submit`, m({}, c));
|
|
78
80
|
}
|
|
79
81
|
}, $ = (t) => {
|
|
80
|
-
let
|
|
81
|
-
const { mask:
|
|
82
|
-
|
|
82
|
+
let s = t.target.value;
|
|
83
|
+
const { mask: o } = t.target.dataset;
|
|
84
|
+
o.split(/s/).forEach((c) => {
|
|
83
85
|
if (c && c in E) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
+
const b = E[c];
|
|
87
|
+
s = b(s, t.target, t.target.form);
|
|
86
88
|
}
|
|
87
|
-
}), e.set((c) => c.form.values[t.target.name] =
|
|
89
|
+
}), e.set((c) => c.form.values[t.target.name] = s || "");
|
|
88
90
|
}, j = () => {
|
|
89
91
|
u = S(f), e.set({
|
|
90
|
-
form: L(
|
|
91
|
-
values:
|
|
92
|
+
form: L(m({}, P.form), {
|
|
93
|
+
values: V()
|
|
92
94
|
})
|
|
93
95
|
});
|
|
94
96
|
};
|
|
@@ -103,8 +105,8 @@ const P = {
|
|
|
103
105
|
}
|
|
104
106
|
}, Q = (a) => {
|
|
105
107
|
const r = new FormData(a), e = {};
|
|
106
|
-
for (let [n,
|
|
107
|
-
e[n] =
|
|
108
|
+
for (let [n, v] of r)
|
|
109
|
+
e[n] = v;
|
|
108
110
|
return { formData: r, data: e };
|
|
109
111
|
}, w = (a, r) => {
|
|
110
112
|
const { name: e, type: n } = a;
|
package/form-validation/index.ts
CHANGED
|
@@ -31,6 +31,10 @@ export default function formValidation({
|
|
|
31
31
|
initialValues()
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
+
elm.setValues = ( values ) => {
|
|
35
|
+
state.set(s => (s.form.values = { ...s.form.values, ...values }))
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
const initialValues = () => {
|
|
35
39
|
if (!validations) {
|
|
36
40
|
throw new Error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(a,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis!="undefined"?globalThis:a||self,r(a["form-validation"]={}))})(this,(function(a){"use strict";var H=Object.defineProperty,J=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var R=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var w=(a,r,n)=>r in a?H(a,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):a[r]=n,p=(a,r)=>{for(var n in r||(r={}))R.call(r,n)&&w(a,n,r[n]);if(L)for(var n of L(r))U.call(r,n)&&w(a,n,r[n]);return a},O=(a,r)=>J(a,Q(r));const r="form-validation",n="[data-validation]",T="[data-mask]";function _({main:f,elm:c,state:t,on:i,emit:h,dependencies:F,trigger:I}){var S;const{validations:b,masks:y}=F,m=(S=c.querySelector("input,select,textarea"))==null?void 0:S.form;let v=x(m);f(e=>{i("input","input, textarea, select",q),i("input",T,P),i("input",n,E("input")),i("change",n,E("change")),i("blur",n,E("blur")),i("focus","input, textarea, select",z),i("blur","input, textarea, select",$),m.addEventListener("reset",B),m.addEventListener("submit",K),N()}),c.setValues=e=>{t.set(s=>s.form.values=p(p({},s.form.values),e))};const N=()=>{if(!b)throw new Error("<form-validation> - No validations provided in dependencies");const e=D();t.set(s=>s.form.values=e)},D=()=>{const e={};return v.forEach(s=>e[s]=""),e},z=e=>{const s=e.target.name;t.set(o=>{o.form.touched[s]=!0,o.form.focused[s]=!0})},$=e=>{const s=e.target.name;t.set(o=>{o.form.focused[s]=!1})},E=e=>s=>{const o=s.target,u=o.name,d=M(o,m),V=o.dataset.validation.split(/\s/),g=[],A=t.get();V.forEach(l=>{if(l in b){const{ok:C,message:G}=b[l](d,o,m);C||g.push(G)}}),g.length?e==="input"?(v.add(o.name),t.set(l=>{l.form.isValid=!1,A.form.errors[u]&&g[0]!=A.form.errors[u]&&(l.form.errors[u]=g[0])})):(e==="blur"||e==="change")&&(v.add(o.name),t.set(l=>{l.form.errors[u]=g[0],l.form.isValid=!1})):(v.delete(o.name),t.set(l=>{delete l.form.errors[u],v.size||(l.form.isValid=!0)}))},q=e=>{const{name:s}=e.target,o=M(e.target,m);t.set(u=>u.form.values[s]=o)},K=e=>{e.preventDefault(),I("blur",n);const o=t.get().form.errors;if(Object.keys(o).length)h(`${r}:error`,{errors:o});else{const d=j(e.target);h(`${r}:submit`,p({},d))}},P=e=>{let s=e.target.value;const{mask:o}=e.target.dataset;o.split(/s/).forEach(d=>{if(d&&d in y){const V=y[d];s=V(s,e.target,e.target.form)}}),t.set(d=>d.form.values[e.target.name]=s||"")},B=()=>{v=x(m),t.set({form:O(p({},k.form),{values:D()})})}}const k={form:{errors:{},values:{},touched:{},isValid:!1,focused:{}}},j=f=>{const c=new FormData(f),t={};for(let[i,h]of c)t[i]=h;return{formData:c,data:t}},M=(f,c)=>{const{name:t,type:i}=f;return i=="checkbox"?f.checked?f.value:"":c[t].value},x=f=>{const c=new Set;return Array.from(f.elements).filter(t=>t.name&&t.dataset.validation).forEach(t=>c.add(t.name)),c};a.default=_,a.model=k,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -43,7 +43,7 @@ on('form-validation:error', ({ errors }) => {})
|
|
|
43
43
|
|
|
44
44
|
##### main.ts
|
|
45
45
|
```ts
|
|
46
|
-
import * as formValidation from 'jails.
|
|
46
|
+
import * as formValidation from 'jails.stdlib/form-validation'
|
|
47
47
|
import rules from './my-custom-rules'
|
|
48
48
|
|
|
49
49
|
jails.register('form-validation', formValidation, { ...rules })
|
|
@@ -114,4 +114,24 @@ export default {
|
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
To see how to inject this dependency, go back to the [usage](#usage) section.
|
|
117
|
+
To see how to inject this dependency, go back to the [usage](#usage) section.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
##### element.setValues(...data)
|
|
121
|
+
|
|
122
|
+
If you want to set programatically values to the fields, you just have to get the node of `form-validation` element and use the public method `setValues()` passing data with `name` and `value` pairs.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
export default function myComponent({ main, elm }) {
|
|
127
|
+
|
|
128
|
+
const formValidation = elm.querySelector('form-validation')
|
|
129
|
+
|
|
130
|
+
main(() => {
|
|
131
|
+
formValidation.setValues({
|
|
132
|
+
'username': 'John Doe',
|
|
133
|
+
'age': '41'
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
```
|
package/import-css/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Returns a promise when Css is loaded
|
|
|
10
10
|
### Usage
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { importCss } from 'jails.
|
|
13
|
+
import { importCss } from 'jails.stdlib/import-css'
|
|
14
14
|
|
|
15
15
|
importCss('https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css')
|
|
16
16
|
.then( (event) => {
|
package/import-html/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Returns a promise when Html is loaded. It accepts options from `fetch` api.
|
|
|
9
9
|
### Usage
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
import { importHtml } from 'jails.
|
|
12
|
+
import { importHtml } from 'jails.stdlib/import-html'
|
|
13
13
|
|
|
14
14
|
importHtml('https://html-mock.fly.dev/tag/table?class=table%20table-bordered')
|
|
15
15
|
.then( ({ response: Response, html: string }) => {
|
package/import-js/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Returns a promise when script is loaded
|
|
|
10
10
|
### Usage
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { importJs } from 'jails.
|
|
13
|
+
import { importJs } from 'jails.stdlib/import-js'
|
|
14
14
|
|
|
15
15
|
importJs('https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js')
|
|
16
16
|
.then( (event) => {
|
package/is-touch/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A simple version to detect if device has touch. It checks if it has `touchstart`
|
|
|
9
9
|
### Usage
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
import { isTouch } from 'jails.
|
|
12
|
+
import { isTouch } from 'jails.stdlib/is-touch'
|
|
13
13
|
|
|
14
14
|
async function main () {
|
|
15
15
|
console.log( isTouch() ) // true if there's touchstart on window, or false otherwise.
|
package/is-visible/README.md
CHANGED
package/lazyload-image/README.md
CHANGED
package/messenger/README.md
CHANGED
|
@@ -28,7 +28,7 @@ The `messenger` utility provides a lightweight, secure interface for sending and
|
|
|
28
28
|
### Parent Page
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
import { messenger } from 'jails.
|
|
31
|
+
import { messenger } from 'jails.stdlib/messenger'
|
|
32
32
|
|
|
33
33
|
const msg = messenger({
|
|
34
34
|
target: document.getElementById('myIframe'), // <iframe id="myIframe" />
|
package/mfe/README.md
CHANGED
|
@@ -14,7 +14,7 @@ It can embed a full html, css, js from an external url.
|
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
|
|
17
|
-
import { mfe } from 'jails.
|
|
17
|
+
import { mfe } from 'jails.stdlib/mfe'
|
|
18
18
|
|
|
19
19
|
function main () {
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ It can also embed a single page app from a external `.js` file.
|
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
|
|
37
|
-
import { mfe } from 'jails.
|
|
37
|
+
import { mfe } from 'jails.stdlib/mfe'
|
|
38
38
|
|
|
39
39
|
function main () {
|
|
40
40
|
|
|
@@ -63,7 +63,7 @@ Example:
|
|
|
63
63
|
`main.ts`
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
import { Shell } from 'jails.
|
|
66
|
+
import { Shell } from 'jails.stdlib/mfe'
|
|
67
67
|
|
|
68
68
|
export const shell = Shell({
|
|
69
69
|
somevariable,
|
|
@@ -79,7 +79,7 @@ export const shell = Shell({
|
|
|
79
79
|
`main.ts`
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
import { Shell } from 'jails.
|
|
82
|
+
import { Shell } from 'jails.stdlib/mfe'
|
|
83
83
|
|
|
84
84
|
export const shell = Shell({
|
|
85
85
|
somevariable,
|
package/outlet/README.md
CHANGED
|
@@ -17,7 +17,7 @@ render( url: string ) : Promise<target: HTMLElement>
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
|
-
import { Oultet } from 'jails.
|
|
20
|
+
import { Oultet } from 'jails.stdlib/outlet'
|
|
21
21
|
|
|
22
22
|
const target = document.querySelector('[data-outlet]')
|
|
23
23
|
const outlet = Outlet({ target })
|
package/package.json
CHANGED
package/querystring/README.md
CHANGED
package/router/README.md
CHANGED
package/storage/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The storage is a wrapper for the localStorage and sessionStorage global objects.
|
|
|
8
8
|
### For local storage
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
|
-
import { storage } from 'jails.
|
|
11
|
+
import { storage } from 'jails.stdlib/storage'
|
|
12
12
|
|
|
13
13
|
//Save data
|
|
14
14
|
storage.local.set('item', { my :'item' }); // Save data and return { my:'item' }
|
package/store/README.md
CHANGED
package/third-party/README.md
CHANGED
|
@@ -28,7 +28,7 @@ The `thirdParty` will execute the text script code and then will load the cdn li
|
|
|
28
28
|
This way you can have the control of third party code execution and when it should be executed inside your application flow.
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
|
-
import { thirdParty } from 'jails.
|
|
31
|
+
import { thirdParty } from 'jails.stdlib/third-party'
|
|
32
32
|
|
|
33
33
|
export const analytics = thirdParty('analytics')
|
|
34
34
|
|
package/throttle/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Limits a function's execution to at most once per specified time interval.
|
|
|
9
9
|
### Usage
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
import { throttle } from 'jails.
|
|
12
|
+
import { throttle } from 'jails.stdlib/throttle'
|
|
13
13
|
|
|
14
14
|
const onscroll = throttle(() => {
|
|
15
15
|
console.log('throttling scroll')
|