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 CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  <div align="center">
3
- <h1>jails.std</h1>
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.std
12
+ npm install jails.stdlib
13
13
  ```
14
14
  or
15
15
 
16
16
  ```
17
- yarn add jails.std
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.
@@ -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.std/cancelable'
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).
@@ -0,0 +1,9 @@
1
+ export declare const Channel: ({ target, accept, origin }: {
2
+ target?: any;
3
+ accept?: any;
4
+ origin?: string;
5
+ }) => {
6
+ on(name: any, callback: any): void;
7
+ emit(event: any, ...payload: any[]): void;
8
+ remove(name: any): void;
9
+ };
@@ -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
+ };
@@ -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"})}));
@@ -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.std/debounce'
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
@@ -8,7 +8,7 @@ Delays the next `.then` promise chain.
8
8
  ### Usage
9
9
 
10
10
  ```js
11
- import { delay } from 'jails.std/delay'
11
+ import { delay } from 'jails.stdlib/delay'
12
12
 
13
13
  fetch('https://jsonplaceholder.typicode.com/todos/1')
14
14
  .then( response => response.json() )
@@ -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, b = (a, r) => {
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", v = "[data-validation]", J = "[data-mask]";
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: m,
19
+ emit: v,
20
20
  dependencies: y,
21
21
  trigger: F
22
22
  }) {
23
- var V;
24
- const { validations: g, masks: E } = y, f = (V = r.querySelector("input,select,textarea")) == null ? void 0 : V.form;
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", v, h("input")), n("change", v, h("change")), n("blur", v, h("blur")), n("focus", "input, textarea, select", N), n("blur", "input, textarea, select", O), f.addEventListener("reset", j), f.addEventListener("submit", _), I();
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 (!g)
32
+ if (!h)
31
33
  throw new Error(
32
34
  "<form-validation> - No validations provided in dependencies"
33
35
  );
34
- const t = k();
35
- e.set((o) => o.form.values = t);
36
- }, k = () => {
36
+ const t = V();
37
+ e.set((s) => s.form.values = t);
38
+ }, V = () => {
37
39
  const t = {};
38
- return u.forEach((o) => t[o] = ""), t;
40
+ return u.forEach((s) => t[s] = ""), t;
39
41
  }, N = (t) => {
40
- const o = t.target.name;
41
- e.set((s) => {
42
- s.form.touched[o] = !0, s.form.focused[o] = !0;
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 o = t.target.name;
46
- e.set((s) => {
47
- s.form.focused[o] = !1;
47
+ const s = t.target.name;
48
+ e.set((o) => {
49
+ o.form.focused[s] = !1;
48
50
  });
49
- }, h = (t) => (o) => {
50
- const s = o.target, l = s.name, c = w(s, f), p = s.dataset.validation.split(/\s/), d = [], x = e.get();
51
- p.forEach((i) => {
52
- if (i in g) {
53
- const { ok: q, message: K } = g[i](
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
- s,
57
+ o,
56
58
  f
57
59
  );
58
60
  q || d.push(K);
59
61
  }
60
- }), d.length ? t === "input" ? (u.add(s.name), e.set((i) => {
61
- i.form.isValid = !1, x.form.errors[l] && d[0] != x.form.errors[l] && (i.form.errors[l] = d[0]);
62
- })) : (t === "blur" || t === "change") && (u.add(s.name), e.set((i) => {
63
- i.form.errors[l] = d[0], i.form.isValid = !1;
64
- })) : (u.delete(s.name), e.set((i) => {
65
- delete i.form.errors[l], u.size || (i.form.isValid = !0);
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: o } = t.target, s = w(t.target, f);
69
- e.set((l) => l.form.values[o] = s);
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", v);
72
- const s = e.get().form.errors;
73
- if (Object.keys(s).length)
74
- m(`${M}:error`, { errors: s });
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
- m(`${M}:submit`, b({}, c));
79
+ v(`${M}:submit`, m({}, c));
78
80
  }
79
81
  }, $ = (t) => {
80
- let o = t.target.value;
81
- const { mask: s } = t.target.dataset;
82
- s.split(/s/).forEach((c) => {
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 p = E[c];
85
- o = p(o, t.target, t.target.form);
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] = o || "");
89
+ }), e.set((c) => c.form.values[t.target.name] = s || "");
88
90
  }, j = () => {
89
91
  u = S(f), e.set({
90
- form: L(b({}, P.form), {
91
- values: k()
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, m] of r)
107
- e[n] = m;
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;
@@ -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(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o["form-validation"]={}))})(this,(function(o){"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=(o,r,n)=>r in o?H(o,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[r]=n,k=(o,r)=>{for(var n in r||(r={}))R.call(r,n)&&w(o,n,r[n]);if(L)for(var n of L(r))U.call(r,n)&&w(o,n,r[n]);return o},O=(o,r)=>J(o,Q(r));const r="form-validation",n="[data-validation]",T="[data-mask]";function _({main:c,elm:f,state:t,on:i,emit:p,dependencies:F,trigger:I}){var S;const{validations:h,masks:y}=F,m=(S=f.querySelector("input,select,textarea"))==null?void 0:S.form;let v=x(m);c(e=>{i("input","input, textarea, select",q),i("input",T,P),i("input",n,b("input")),i("change",n,b("change")),i("blur",n,b("blur")),i("focus","input, textarea, select",z),i("blur","input, textarea, select",$),m.addEventListener("reset",B),m.addEventListener("submit",K),N()});const N=()=>{if(!h)throw new Error("<form-validation> - No validations provided in dependencies");const e=D();t.set(a=>a.form.values=e)},D=()=>{const e={};return v.forEach(a=>e[a]=""),e},z=e=>{const a=e.target.name;t.set(s=>{s.form.touched[a]=!0,s.form.focused[a]=!0})},$=e=>{const a=e.target.name;t.set(s=>{s.form.focused[a]=!1})},b=e=>a=>{const s=a.target,u=s.name,d=M(s,m),E=s.dataset.validation.split(/\s/),g=[],A=t.get();E.forEach(l=>{if(l in h){const{ok:C,message:G}=h[l](d,s,m);C||g.push(G)}}),g.length?e==="input"?(v.add(s.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(s.name),t.set(l=>{l.form.errors[u]=g[0],l.form.isValid=!1})):(v.delete(s.name),t.set(l=>{delete l.form.errors[u],v.size||(l.form.isValid=!0)}))},q=e=>{const{name:a}=e.target,s=M(e.target,m);t.set(u=>u.form.values[a]=s)},K=e=>{e.preventDefault(),I("blur",n);const s=t.get().form.errors;if(Object.keys(s).length)p(`${r}:error`,{errors:s});else{const d=j(e.target);p(`${r}:submit`,k({},d))}},P=e=>{let a=e.target.value;const{mask:s}=e.target.dataset;s.split(/s/).forEach(d=>{if(d&&d in y){const E=y[d];a=E(a,e.target,e.target.form)}}),t.set(d=>d.form.values[e.target.name]=a||"")},B=()=>{v=x(m),t.set({form:O(k({},V.form),{values:D()})})}}const V={form:{errors:{},values:{},touched:{},isValid:!1,focused:{}}},j=c=>{const f=new FormData(c),t={};for(let[i,p]of f)t[i]=p;return{formData:f,data:t}},M=(c,f)=>{const{name:t,type:i}=c;return i=="checkbox"?c.checked?c.value:"":f[t].value},x=c=>{const f=new Set;return Array.from(c.elements).filter(t=>t.name&&t.dataset.validation).forEach(t=>f.add(t.name)),f};o.default=_,o.model=V,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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.std/form-validation'
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
+ ```
@@ -10,7 +10,7 @@ Returns a promise when Css is loaded
10
10
  ### Usage
11
11
 
12
12
  ```ts
13
- import { importCss } from 'jails.std/import-css'
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) => {
@@ -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.std/import-html'
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 }) => {
@@ -10,7 +10,7 @@ Returns a promise when script is loaded
10
10
  ### Usage
11
11
 
12
12
  ```ts
13
- import { importJs } from 'jails.std/import-js'
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) => {
@@ -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.std/is-touch'
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.
@@ -11,7 +11,7 @@ It also wraps it in `Promise` so it can be used with `await` for more convinienc
11
11
  ### Usage
12
12
 
13
13
  ```js
14
- import { isVisible } from 'jails.std/is-visible'
14
+ import { isVisible } from 'jails.stdlib/is-visible'
15
15
 
16
16
  async function main () {
17
17
 
@@ -11,7 +11,7 @@ It's in fact the [vanilla-lazyload](https://github.com/verlok/vanilla-lazyload)
11
11
 
12
12
  ```ts
13
13
 
14
- import { Lazyload } from 'jails.std/lazyload-image'
14
+ import { Lazyload } from 'jails.stdlib/lazyload-image'
15
15
 
16
16
  function main () {
17
17
 
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.std/mfe'
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.std/mfe'
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.std/mfe'
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.std/mfe'
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.std/outlet'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jails.stdlib",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "The Jails Standard Library",
5
5
  "types": "index.d.ts",
6
6
  "repository": {
@@ -9,7 +9,7 @@ Returns a query string value.
9
9
  ### Usage
10
10
 
11
11
  ```js
12
- import { querystring } from 'jails.std/querystring'
12
+ import { querystring } from 'jails.stdlib/querystring'
13
13
 
14
14
  // https://my-awesome-site.com?search=david
15
15
  const { search } = querystring()
package/router/README.md CHANGED
@@ -11,7 +11,7 @@ Documentation : https://github.com/baseprime/grapnel
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- import { Router } from 'jails.std/router'
14
+ import { Router } from 'jails.stdlib/router'
15
15
 
16
16
  const router = new Router()
17
17
 
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.std/storage'
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
@@ -12,7 +12,7 @@ Store( initialState: Object , actions: Object )
12
12
  ## Usage
13
13
 
14
14
  ```js
15
- import { Store } from 'jails.std/store'
15
+ import { Store } from 'jails.stdlib/store'
16
16
 
17
17
  const initialState = {
18
18
  loading: false,
@@ -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.std/third-party'
31
+ import { thirdParty } from 'jails.stdlib/third-party'
32
32
 
33
33
  export const analytics = thirdParty('analytics')
34
34
 
@@ -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.std/throttle'
12
+ import { throttle } from 'jails.stdlib/throttle'
13
13
 
14
14
  const onscroll = throttle(() => {
15
15
  console.log('throttling scroll')
@@ -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).
@@ -1,9 +0,0 @@
1
- export declare const messenger: ({ target, accept, actions, origin }?: {
2
- target?: any;
3
- accept?: any;
4
- actions?: any;
5
- origin?: string;
6
- }) => {
7
- dispatch(action: string, payload?: any): void;
8
- subscribe(actions_: any): void;
9
- };
@@ -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
- };
@@ -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
- }
@@ -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"})}));