mono-jsx 0.10.0-beta.13 → 0.10.0-beta.14

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
@@ -1340,11 +1340,6 @@ const routes = {
1340
1340
  }
1341
1341
  ```
1342
1342
 
1343
- > [!TIP]
1344
- > You can use `:invalid` CSS selector to style the form elements with invalid state.
1345
-
1346
- ### Handling Route Form Submissions
1347
-
1348
1343
  You can return regular HTML elements in the form handler function, by default it will be appended to the form element. You can add the `mode` attribute on the `<form route>` element to decide where the content should be inserted.
1349
1344
 
1350
1345
  - **"append"** (default): Append the handler output into the form element.
@@ -1366,7 +1361,12 @@ MyRoute.FormHandler = function(this: FC, data: FormData) {
1366
1361
  }
1367
1362
  ```
1368
1363
 
1369
- mono-jsx also provides a built-in `<formslot>` element that is used to control where the form handler content should be inserted. If any `<formslot>` element exists the `mode` attribute on the `<form route>` element will be ignored. It accepts the following modes:
1364
+ > [!TIP]
1365
+ > You can use `:invalid` CSS selector to style the form elements with invalid state.
1366
+
1367
+ ### Using `<formslot>` element
1368
+
1369
+ mono-jsx provides a built-in `<formslot>` element that is used to control where the form handler content should be inserted. If any `<formslot>` element exists the `mode` attribute on the `<form route>` element will be ignored. It accepts the following modes:
1370
1370
 
1371
1371
  - **"replaceChildren"** (default): Replace children of the `<formslot>` element with the returned HTML.
1372
1372
  - **"insertafter"**: Insert HTML after the `<formslot>` element.
@@ -1393,26 +1393,28 @@ MyRoute.FormHandler = function(this: FC, data: FormData) {
1393
1393
  }
1394
1394
  ```
1395
1395
 
1396
- You can add the `name` prop to specify the name of the formslot element. And `formslot` prop to specify the name of the slot to insert the HTML into.
1396
+ You can add the `name` prop to specify the name of the formslot element. And use `formslot` prop in the form handler function to specify the name of the slot to insert the HTML into.
1397
1397
 
1398
1398
  ```tsx
1399
1399
  function MyRoute(this: FC) {
1400
1400
  return (
1401
1401
  <div>
1402
- <formslot name="info" /> { /* <- "This is info message" will be inserted into the formslot element after submitting the form */ }
1403
1402
  <form route>
1404
1403
  <button type="submit">Send</button>
1405
- <formslot name="error" /> { /* <- "This is error message" will be inserted into the formslot element after submitting the form */ }
1404
+ <formslot name="info" /> { /* <- "This is info message" will be inserted here */ }
1405
+ <formslot name="error" /> { /* <- "This is error message" will be inserted here */ }
1406
1406
  </form>
1407
1407
  </div>
1408
1408
  )
1409
1409
  }
1410
1410
 
1411
1411
  MyRoute.FormHandler = function(this: FC, data: FormData) {
1412
- return <>
1413
- <p formslot="info">This is info message</p>
1414
- <p formslot="error">This is error message</p>
1415
- </>
1412
+ return (
1413
+ <>
1414
+ <p formslot="info">This is info message</p>
1415
+ <p formslot="error">This is error message</p>
1416
+ </>
1417
+ )
1416
1418
  }
1417
1419
  ```
1418
1420
 
@@ -1424,7 +1426,7 @@ function MyRoute(this: FC) {
1424
1426
  <form>
1425
1427
  <input type="text" name="message" placeholder="Type Message..." />
1426
1428
  <button type="submit">Send</button>
1427
- <formslot hiddenonUpdate={(evt) => console.log("message updated:", evt.target.textContent)} />
1429
+ <formslot hidden onUpdate={(evt) => console.log("message updated:", evt.target.textContent)} />
1428
1430
  </form>
1429
1431
  )
1430
1432
  }
package/jsx-runtime.mjs CHANGED
@@ -16,7 +16,7 @@ var $setup = /* @__PURE__ */ Symbol.for("mono.setup");
16
16
  var $rpc = /* @__PURE__ */ Symbol.for("mono.rpc");
17
17
 
18
18
  // version.ts
19
- var VERSION = "0.10.0-beta.13";
19
+ var VERSION = "0.10.0-beta.14";
20
20
 
21
21
  // runtime/index.ts
22
22
  var EVENT = 1;
@@ -43,7 +43,7 @@ var SUSPENSE_JS = `{const i=new Map,o=e=>e.getAttribute("chunk-id"),l=(e,t)=>cus
43
43
  var COMPONENT_JS = `{const e=document,a=(t,s)=>t.getAttribute(s);customElements.define("m-component",class extends HTMLElement{static observedAttributes=["name","props"];#t;#s;#r;#h;#i;#e=new Map;#a=!0;async#l(){if(!this.#t){this.#n("");return}const t=this.#s||"{}",s=this.#t+t,i={"x-component":this.#t,"x-props":t,"x-flags":$FLAGS},n=new AbortController;if(this.#h?.abort(),this.#h=n,this.#e.has(s)){this.#n(this.#e.get(s));return}this.#r?.length&&this.#n(this.#r);const r=await fetch(location.href,{headers:i,signal:n.signal});if(!r.ok)throw this.#n(""),new Error("Failed to fetch component '"+this.#t+"'");const[h,o]=await r.json();this.#e.set(s,h),this.#n(h),o&&(e.body.appendChild(e.createElement("script")).textContent=o)}#n(t){const s=()=>typeof t=="string"?this.innerHTML=t:this.replaceChildren(...t);this.hasAttribute("vt")&&e.startViewTransition&&!this.#a?e.startViewTransition(s):s(),this.#a=!1}get name(){return this.#t??null}set name(t){t&&t!==this.#t&&(this.#t=t,this.#o())}get props(){return this.#s?JSON.parse(this.#s):void 0}set props(t){const s=typeof t=="string"?t:JSON.stringify(t);s&&s!==this.#s&&(this.#s=s,this.#o())}attributeChangedCallback(t,s,i){this.#t&&i&&(t==="name"?this.name=i:t==="props"&&(this.props=i))}connectedCallback(){setTimeout(()=>{if(!this.#r){const t=a(this,"props");this.#t=a(this,"name"),this.#s=t?.startsWith("base64,")?atob(t.slice(7)):void 0,this.#r=[...this.childNodes]}this.#l()})}disconnectedCallback(){this.#e.clear(),this.#h?.abort(),this.#h=void 0,this.#i&&clearTimeout(this.#i),this.#i=void 0}#o(){this.#i&&clearTimeout(this.#i),this.#i=setTimeout(()=>{this.#i=void 0,this.#l()},50)}refresh(){this.#t&&this.#e.delete(this.#t+(this.#s||"{}")),this.#o()}});}`;
44
44
  var ROUTER_JS = `{const o=window,r=document,n=location,d=e=>e.origin===n.origin&&l(e)===l(n),l=({pathname:e,search:t})=>e+t;customElements.define("m-router",class extends HTMLElement{#e;#i=new Map;#n=l(n);#t;#a=!0;#s;#r;async#c(e){this.#e?.abort(),this.#e=new AbortController;const t=await fetch(e,{headers:{"x-route":"true","x-flags":$FLAGS},signal:this.#e.signal});if(t.status===404)return null;if(!t.ok)throw this.replaceChildren(),new Error("Failed to fetch route: "+t.status+" "+t.statusText);const i=await t.json();if(!Array.isArray(i))throw new Error(i?.error?i.error:"Invalid response from server");return i}#o(e){const t=()=>typeof e=="string"?this.innerHTML=e:this.replaceChildren(...e);this.hasAttribute("vt")&&r.startViewTransition&&!this.#a?r.startViewTransition(t):t(),this.#a=!1}#l(){r.querySelectorAll("nav a").forEach(e=>{const{href:t,classList:i}=e,s=e.closest("nav")?.getAttribute("data-active-class")??"active";d(new URL(t))?i.add(s):i.remove(s)})}async#h(e,t){this.#n=l(e);let i,s=this.#i.get(this.#n);if(s!==void 0&&!t?.refresh&&!this.hasAttribute("no-cache"))this.#o(s);else{const h=await this.#c(e);typeof $signals<"u"&&($signals(0).url=e);let a,c;h?[a,i,c]=h:a=this.#t??[],c||this.#i.set(this.#n,a),this.#o(a)}history[t?.replace?"replaceState":"pushState"]({},"",e),this.#l(),window.scrollTo(0,0),i&&(r.body.appendChild(r.createElement("script")).textContent=i)}navigate(e,t){const i=new URL(e,n.href);if(i.origin!==n.origin||e.startsWith("#")){n.href=e;return}d(i)||this.#h(i,t)}connectedCallback(){if(o.$router)throw new Error("Only one <m-router> element is allowed on the page");o.$router=this,setTimeout(()=>{if(!this.#t)if(this.hasAttribute("fallback"))this.removeAttribute("fallback"),this.#t=[...this.childNodes];else{this.#t=[];for(const e of this.childNodes)if(e.nodeType===1&&e.tagName==="TEMPLATE"&&e.hasAttribute("m-fallback")){this.#t.push(...e.content.childNodes),e.remove();break}}this.#i.set(n.href,[...this.childNodes])}),this.#s=e=>{if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||!(e.target instanceof HTMLAnchorElement))return;const t=e.target.getAttribute("href");if(!t||t.startsWith("#"))return;const{download:i,href:s,rel:h,target:a}=e.target;i||h==="external"||a==="_blank"||!s.startsWith(n.origin)||(e.preventDefault(),this.navigate(s))},this.#r=()=>{l(n)!==this.#n&&this.#h(new URL(n.href))},o.addEventListener("popstate",this.#r),r.addEventListener("click",this.#s),setTimeout(()=>this.#l())}disconnectedCallback(){o.removeEventListener("popstate",this.#r),r.removeEventListener("click",this.#s),delete o.$router,this.#e?.abort(),this.#e=void 0,this.#i.clear(),this.#s=void 0,this.#r=void 0}});}`;
45
45
  var REDIRECT_JS = `{customElements.define("m-redirect",class extends HTMLElement{connectedCallback(){const e=this.getAttribute("to"),t=this.hasAttribute("replace");e&&($router?$router.navigate(e,{replace:t}):location.href=e)}});}`;
46
- var FORM_JS = `{const{document:c}=window,r=(n,e)=>n.getAttribute(e),y=(n,e="m-formslot")=>n.querySelector(e)??c.querySelector(e);customElements.define("m-invalid",class extends HTMLElement{connectedCallback(){const n=r(this,"for"),e=this.closest("form"),i=this.textContent;if(n&&e&&i)for(const d of n.split(",")){const l=e.elements.namedItem(d.trim());if(l){const t=()=>{l.removeEventListener("input",t),l.setCustomValidity("")};l.addEventListener("input",t),l.setCustomValidity(i),l.focus()}}this.remove()}}),window.$onRFS=async n=>{n.preventDefault();const e=n.target;if(!e.checkValidity())return;const i=r(e,"data-submitting-class")??"submitting",d=new FormData(e),l=[...e.elements];for(const t of l)t._disabled=t.disabled,t.disabled=!0;e.querySelectorAll("formslot").forEach(t=>t.innerHTML=""),e.classList.add(i);try{const t=await fetch(location.href,{method:"POST",headers:{"x-route-form":"true","x-flags":$FLAGS},body:d});if(t.ok){const[g,u]=await t.json(),f=new Map,p=c.createElement("template");p.innerHTML=g;const{content:a}=p;a.querySelectorAll("[formslot]").forEach(s=>{const o=r(s,"formslot");if(o){const m=y(e,'m-formslot[name="'+o+'"]');m&&(s.remove(),f.set(s,m))}});const E=y(e);if(E)f.set(a,E);else{const s=r(e,"mode");s==="replace"?e.replaceWith(a):s==="prepend"?e.prepend(a):e.append(a)}for(const[s,o]of f){const m=r(o,"scope"),b=r(o,"mode"),h=r(o,"onupdate");b==="insertbefore"?o.before(s):b==="insertafter"?o.after(s):o.replaceChildren(s),h&&$fmap.get(Number(h))?.call($signals?.(Number(m))??o,{type:"update",target:o})}setTimeout(()=>e.checkValidity()&&e.reset()),u&&(c.body.appendChild(c.createElement("script")).textContent=u+";document.currentScript.remove();")}}finally{e.classList.remove(i);for(const t of l)t.disabled=t._disabled,delete t._disabled}};}`;
46
+ var FORM_JS = `{const{document:d}=window,r=(l,e)=>l.getAttribute(e);customElements.define("m-invalid",class extends HTMLElement{connectedCallback(){const l=r(this,"for"),e=this.closest("form"),i=this.textContent;if(l&&e&&i)for(const f of l.split(",")){const n=e.elements.namedItem(f.trim());if(n){const t=()=>{n.removeEventListener("input",t),n.setCustomValidity("")};n.addEventListener("input",t),n.setCustomValidity(i),n.focus()}}this.remove()}}),window.$onRFS=async l=>{l.preventDefault();const e=l.target;if(!e.checkValidity())return;const i=r(e,"data-submitting-class")??"submitting",f=new FormData(e),n=[...e.elements];for(const t of n)t._disabled=t.disabled,t.disabled=!0;e.querySelectorAll("formslot").forEach(t=>t.innerHTML=""),e.classList.add(i);try{const t=await fetch(location.href,{method:"POST",headers:{"x-route-form":"true","x-flags":$FLAGS},body:f});if(t.ok){const[y,p]=await t.json(),u=new Map,E=d.createElement("template");E.innerHTML=y;const{content:a}=E;a.querySelectorAll("[formslot]").forEach(s=>{const o=r(s,"formslot");if(o){const m='m-formslot[name="'+o+'"]',c=e.querySelector(m)??d.querySelector(m);c&&(s.remove(),u.set(s,c))}});const b=e.querySelector("m-formslot:not([name])");if(b)u.set(a,b);else{const s=r(e,"mode");s==="replace"?e.replaceWith(a):s==="prepend"?e.prepend(a):e.append(a)}for(const[s,o]of u){const m=r(o,"scope"),c=r(o,"mode"),h=r(o,"onupdate");c==="insertbefore"?o.before(s):c==="insertafter"?o.after(s):o.replaceChildren(s),h&&$fmap.get(Number(h))?.call($signals?.(Number(m))??o,{type:"update",target:o})}setTimeout(()=>e.checkValidity()&&e.reset()),p&&(d.body.appendChild(d.createElement("script")).textContent=p+";document.currentScript.remove();")}}finally{e.classList.remove(i);for(const t of n)t.disabled=t._disabled,delete t._disabled}};}`;
47
47
  var RPC_JS = `{window.$RPC=(e,t)=>new Proxy(Object.create(null),{get(s,r){if(t.includes(r))return(...i)=>fetch(location.href,{method:"POST",body:JSON.stringify({fn:r,args:i}),headers:{"x-rpc":"true","x-rpc-id":e.toString()}}).then(async o=>{const{error:n,result:u}=await o.json();if(n)throw new Error(n);return u})}});}`;
48
48
 
49
49
  // runtime/utils.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-jsx",
3
- "version": "0.10.0-beta.13",
3
+ "version": "0.10.0-beta.14",
4
4
  "description": "`<html>` as a `Response` (Yet another JSX runtime for server-side rendering).",
5
5
  "type": "module",
6
6
  "module": "./index.mjs",