jails.stdlib 1.0.0 โ 1.2.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/channel/README.md +97 -0
- package/channel/index.d.ts +9 -0
- package/channel/index.js +30 -0
- package/channel/index.ts +39 -0
- package/channel/index.umd.js +1 -0
- 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/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/messenger/README.md +0 -109
- package/messenger/index.d.ts +0 -9
- package/messenger/index.js +0 -39
- package/messenger/index.ts +0 -38
- package/messenger/index.umd.js +0 -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) => {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# channel
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
Channel({
|
|
5
|
+
target?: Window | HTMLIFrameElement,
|
|
6
|
+
accept?: string[],
|
|
7
|
+
origin?: string
|
|
8
|
+
})
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# ๐ฌ Channel API Documentation
|
|
13
|
+
|
|
14
|
+
The `channel` utility provides a lightweight, secure interface for sending and receiving messages between windows or iframes using `postMessage`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## โ
Features
|
|
19
|
+
|
|
20
|
+
* Easy dispatch and subscription to custom message actions.
|
|
21
|
+
* Secure origin validation.
|
|
22
|
+
* Works with iframes or separate window contexts.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ๐งช Usage
|
|
27
|
+
|
|
28
|
+
### Parent Page
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { Channel } from 'jails.stdlib/channel'
|
|
32
|
+
|
|
33
|
+
const channel = Channel({
|
|
34
|
+
target: document.getElementById('myIframe'), // <iframe id="myIframe" />
|
|
35
|
+
accept: ['*'] // Allowed origins
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Send message to iframe
|
|
39
|
+
channel.send('hello', { user: 'Alice' })
|
|
40
|
+
|
|
41
|
+
// Add more listeners later
|
|
42
|
+
channel.on('hi', (data) => {
|
|
43
|
+
console.log('Iframe said hi!', data)
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Iframe Page
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const channel = Channel({
|
|
51
|
+
target: window.parent,
|
|
52
|
+
accept: ['*']
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## ๐งน API
|
|
59
|
+
|
|
60
|
+
### `Channel(options)`
|
|
61
|
+
|
|
62
|
+
Creates a new Channel instance.
|
|
63
|
+
|
|
64
|
+
#### Options:
|
|
65
|
+
|
|
66
|
+
| Option | Type | Description |
|
|
67
|
+
| --------- | ----------------------------- | --------------------------------------- |
|
|
68
|
+
| `target` | `Window \| HTMLIFrameElement` | Target to send messages to |
|
|
69
|
+
| `accept` | `string[]` | Allowed origins (`['*']` to accept all) |
|
|
70
|
+
| `origin` | `string` | The origin used when sending messages, `default`: location.origin |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### `.emit(event: string, payload?: any)`
|
|
75
|
+
|
|
76
|
+
Sends a message to the target window.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
channel.emit('say:hi', { name: 'Bob' })
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
### `.on(event: string, callback: function )`
|
|
85
|
+
|
|
86
|
+
Listen to an event from the target window.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
channel.on('logout', () => console.log('Logging out...'))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## ๐ Security Notes
|
|
95
|
+
|
|
96
|
+
* Always **specify allowed origins** in `accept` to avoid cross-site scripting risks.
|
|
97
|
+
* Avoid using `'*'` unless absolutely necessary (e.g., during development).
|
package/channel/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const a = ({
|
|
2
|
+
target: o = null,
|
|
3
|
+
accept: i = [],
|
|
4
|
+
origin: d = location.origin
|
|
5
|
+
}) => {
|
|
6
|
+
const t = (o == null ? void 0 : o.contentWindow) || o, s = {};
|
|
7
|
+
return window.addEventListener("message", (n) => {
|
|
8
|
+
if (i.includes("*") || i.includes(n.origin)) {
|
|
9
|
+
const { payload: e, event: l } = n.data;
|
|
10
|
+
s[l] && s[l].apply(null, e);
|
|
11
|
+
} else
|
|
12
|
+
throw {
|
|
13
|
+
type: "ACCESS DENIED",
|
|
14
|
+
message: "Cant receive message from: " + n.origin
|
|
15
|
+
};
|
|
16
|
+
}), {
|
|
17
|
+
on(n, e) {
|
|
18
|
+
s[n] = e;
|
|
19
|
+
},
|
|
20
|
+
emit(n, ...e) {
|
|
21
|
+
t.postMessage({ event: n, payload: e }, d);
|
|
22
|
+
},
|
|
23
|
+
remove(n) {
|
|
24
|
+
delete s[n];
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
a as Channel
|
|
30
|
+
};
|
package/channel/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
export const Channel = ({
|
|
3
|
+
target = null as any,
|
|
4
|
+
accept = [] as any,
|
|
5
|
+
origin = location.origin
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const win = target?.contentWindow || target
|
|
9
|
+
const events = {}
|
|
10
|
+
|
|
11
|
+
window.addEventListener('message', (e) => {
|
|
12
|
+
if( accept.includes('*') || accept.includes(e.origin) ) {
|
|
13
|
+
const { payload, event } = e.data
|
|
14
|
+
if( events[event] ) {
|
|
15
|
+
events[event].apply(null, payload)
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
throw {
|
|
19
|
+
type : 'ACCESS DENIED',
|
|
20
|
+
message : 'Cant receive message from: ' + e.origin
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
|
|
27
|
+
on(name, callback) {
|
|
28
|
+
events[name] = callback
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
emit(event, ...payload) {
|
|
32
|
+
win.postMessage({ event, payload }, origin)
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
remove(name) {
|
|
36
|
+
delete events[name]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n.channel={}))})(this,(function(n){"use strict";const i=({target:s=null,accept:d=[],origin:f=location.origin})=>{const u=(s==null?void 0:s.contentWindow)||s,t={};return window.addEventListener("message",e=>{if(d.includes("*")||d.includes(e.origin)){const{payload:o,event:l}=e.data;t[l]&&t[l].apply(null,o)}else throw{type:"ACCESS DENIED",message:"Cant receive message from: "+e.origin}}),{on(e,o){t[e]=o},emit(e,...o){u.postMessage({event:e,payload:o},f)},remove(e){delete t[e]}}};n.Channel=i,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|
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/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')
|
package/messenger/README.md
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# messenger
|
|
2
|
-
|
|
3
|
-
```ts
|
|
4
|
-
messenger({
|
|
5
|
-
target?: Window | HTMLIFrameElement,
|
|
6
|
-
accept?: string[],
|
|
7
|
-
actions?: Record<string, (payload: any) => void>,
|
|
8
|
-
origin?: string
|
|
9
|
-
})
|
|
10
|
-
```
|
|
11
|
-
# ๐ฌ Messenger API Documentation
|
|
12
|
-
|
|
13
|
-
The `messenger` utility provides a lightweight, secure interface for sending and receiving messages between windows or iframes using `postMessage`.
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## โ
Features
|
|
18
|
-
|
|
19
|
-
* Easy dispatch and subscription to custom message actions.
|
|
20
|
-
* Secure origin validation.
|
|
21
|
-
* Works with iframes or separate window contexts.
|
|
22
|
-
* Extensible via `subscribe`.
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## ๐งช Usage
|
|
27
|
-
|
|
28
|
-
### Parent Page
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
import { messenger } from 'jails.std/messenger'
|
|
32
|
-
|
|
33
|
-
const msg = messenger({
|
|
34
|
-
target: document.getElementById('myIframe'), // <iframe id="myIframe" />
|
|
35
|
-
accept: ['https://child-app.com'], // Allowed origins
|
|
36
|
-
actions: {
|
|
37
|
-
reply(data) {
|
|
38
|
-
console.log('Received from iframe:', data)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// Send message to iframe
|
|
44
|
-
msg.dispatch('init', { user: 'Alice' })
|
|
45
|
-
|
|
46
|
-
// Add more listeners later
|
|
47
|
-
msg.subscribe({
|
|
48
|
-
status: (msg) => console.log('Status update:', msg)
|
|
49
|
-
})
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Iframe Page
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const msg = messenger({
|
|
56
|
-
target: window.parent,
|
|
57
|
-
accept: ['https://parent-app.com'],
|
|
58
|
-
actions: {
|
|
59
|
-
init(data){
|
|
60
|
-
console.log('Init from parent:', data)
|
|
61
|
-
msg.dispatch('reply', { received: true })
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
## ๐งน API
|
|
70
|
-
|
|
71
|
-
### `messenger(options)`
|
|
72
|
-
|
|
73
|
-
Creates a new Messenger instance.
|
|
74
|
-
|
|
75
|
-
#### Options:
|
|
76
|
-
|
|
77
|
-
| Option | Type | Description |
|
|
78
|
-
| --------- | ----------------------------- | --------------------------------------- |
|
|
79
|
-
| `target` | `Window \| HTMLIFrameElement` | Target to send messages to |
|
|
80
|
-
| `accept` | `string[]` | Allowed origins (`['*']` to accept all) |
|
|
81
|
-
| `actions` | `Record<string, Function>` | Message handlers keyed by action name |
|
|
82
|
-
| `origin` | `string` | The origin used when sending messages |
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
### `.dispatch(action: string, payload?: any)`
|
|
87
|
-
|
|
88
|
-
Sends a message to the target window.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
msg.dispatch('sayHello', { name: 'Bob' })
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
### `.subscribe(newActions: Record<string, Function>)`
|
|
97
|
-
|
|
98
|
-
Adds more actions to the messenger at runtime.
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
msg.subscribe({ logout: () => console.log('Logging out...') })
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## ๐ Security Notes
|
|
107
|
-
|
|
108
|
-
* Always **specify allowed origins** in `accept` to avoid cross-site scripting risks.
|
|
109
|
-
* Avoid using `'*'` unless absolutely necessary (e.g., during development).
|
package/messenger/index.d.ts
DELETED
package/messenger/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
var w = Object.defineProperty;
|
|
2
|
-
var l = Object.getOwnPropertySymbols;
|
|
3
|
-
var a = Object.prototype.hasOwnProperty, p = Object.prototype.propertyIsEnumerable;
|
|
4
|
-
var r = (n, i, s) => i in n ? w(n, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[i] = s, d = (n, i) => {
|
|
5
|
-
for (var s in i || (i = {}))
|
|
6
|
-
a.call(i, s) && r(n, s, i[s]);
|
|
7
|
-
if (l)
|
|
8
|
-
for (var s of l(i))
|
|
9
|
-
p.call(i, s) && r(n, s, i[s]);
|
|
10
|
-
return n;
|
|
11
|
-
};
|
|
12
|
-
const f = ({
|
|
13
|
-
target: n = null,
|
|
14
|
-
accept: i = [],
|
|
15
|
-
actions: s = {},
|
|
16
|
-
origin: c = location.origin
|
|
17
|
-
} = {}) => {
|
|
18
|
-
const m = (n == null ? void 0 : n.contentWindow) || n;
|
|
19
|
-
return window.addEventListener("message", (e) => {
|
|
20
|
-
if (i.includes("*") || i.includes(e.origin)) {
|
|
21
|
-
const { action: o, payload: u } = e.data;
|
|
22
|
-
o in s && s[o](u);
|
|
23
|
-
} else
|
|
24
|
-
throw {
|
|
25
|
-
type: "ACCESS DENIED",
|
|
26
|
-
message: "Cant receive message from: " + e.origin
|
|
27
|
-
};
|
|
28
|
-
}), {
|
|
29
|
-
dispatch(e, o) {
|
|
30
|
-
m.postMessage({ action: e, payload: o }, c);
|
|
31
|
-
},
|
|
32
|
-
subscribe(e) {
|
|
33
|
-
s = d(d({}, e), s);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
f as messenger
|
|
39
|
-
};
|
package/messenger/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export const messenger = ({
|
|
3
|
-
|
|
4
|
-
target = null as any,
|
|
5
|
-
accept = [] as any,
|
|
6
|
-
actions = {} as any,
|
|
7
|
-
origin = location.origin
|
|
8
|
-
|
|
9
|
-
} = {}) => {
|
|
10
|
-
|
|
11
|
-
const win = target?.contentWindow || target
|
|
12
|
-
|
|
13
|
-
window.addEventListener('message', ( event ) => {
|
|
14
|
-
|
|
15
|
-
if( accept.includes('*') || accept.includes(event.origin) ) {
|
|
16
|
-
const { action, payload } = event.data
|
|
17
|
-
if( action in actions ) {
|
|
18
|
-
actions[ action ]( payload as any )
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
throw {
|
|
22
|
-
type : 'ACCESS DENIED',
|
|
23
|
-
message : 'Cant receive message from: ' + event.origin
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
dispatch( action: string, payload?: any ) {
|
|
31
|
-
win.postMessage({ action, payload }, origin)
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
subscribe( actions_: any ) {
|
|
35
|
-
actions = { ...actions_, ...actions }
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
package/messenger/index.umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(i,e){typeof exports=="object"&&typeof module!="undefined"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(i=typeof globalThis!="undefined"?globalThis:i||self,e(i.messenger={}))})(this,(function(i){"use strict";var p=Object.defineProperty;var u=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var l=(i,e,n)=>e in i?p(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,f=(i,e)=>{for(var n in e||(e={}))g.call(e,n)&&l(i,n,e[n]);if(u)for(var n of u(e))y.call(e,n)&&l(i,n,e[n]);return i};const e=({target:n=null,accept:t=[],actions:o={},origin:r=location.origin}={})=>{const c=(n==null?void 0:n.contentWindow)||n;return window.addEventListener("message",s=>{if(t.includes("*")||t.includes(s.origin)){const{action:d,payload:m}=s.data;d in o&&o[d](m)}else throw{type:"ACCESS DENIED",message:"Cant receive message from: "+s.origin}}),{dispatch(s,d){c.postMessage({action:s,payload:d},r)},subscribe(s){o=f(f({},s),o)}}};i.messenger=e,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|