mono-jsx 0.3.3 → 0.3.4

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/jsx-runtime.mjs CHANGED
@@ -7,7 +7,7 @@ var $computed = Symbol.for("mono.computed");
7
7
 
8
8
  // runtime/index.ts
9
9
  var STATE_JS = `const m=new Map,u=e=>m.get(e)??m.set(e,b(e)).get(e),f=(e,t)=>e.getAttribute(t),d=(e,t)=>e.hasAttribute(t),b=e=>{const t=Object.create(null),r=new Map,n=(i,c)=>{let a=c;Object.defineProperty(t,i,{get:()=>a,set:o=>{if(o!==a){const l=r.get(i);l&&queueMicrotask(()=>l.forEach(h=>h())),a=o}}})},s=(i,c)=>{let a=r.get(i);a||(a=[],r.set(i,a)),a.push(c)};return e>0&&Object.defineProperty(t,"app",{get:()=>u(0).store,enumerable:!1,configurable:!1}),{store:t,define:n,watch:s}},g=(e,t,r)=>{if(t==="toggle"){let n;return()=>{if(!n){const s=e.firstElementChild;s&&s.tagName==="TEMPLATE"&&d(s,"m-slot")?(n=s.content.childNodes,e.innerHTML=""):n=e.childNodes}r()?e.append(...n):e.innerHTML=""}}if(t==="switch"){let n=f(e,"match"),s,i,c=o=>s.get(o)??s.set(o,[]).get(o),a;return()=>{if(!s){s=new Map,i=[];for(const o of e.childNodes)if(o.nodeType===1&&o.tagName==="TEMPLATE"&&d(o,"m-slot")){for(const l of o.content.childNodes)l.nodeType===1&&d(l,"slot")?c(f(l,"slot")).push(l):i.push(l);o.remove()}else n?c(n).push(o):i.push(o)}a=r(),e.innerHTML="",e.append(...s.has(a)?s.get(a):i)}}if(t&&t.length>2&&t.startsWith("[")&&t.endsWith("]")){let n=t.slice(1,-1),s=e.parentElement;return s.tagName==="M-GROUP"&&(s=s.previousElementSibling),()=>{const i=r();i===!1?s.removeAttribute(n):(n==="class"||n==="style")&&i&&typeof i=="object"?s.setAttribute(n,n==="class"?$cx(i):$styleToCSS(i)):s.setAttribute(n,i===!0?"":""+i)}}return()=>e.textContent=""+r()},p=e=>{const t=e.indexOf(":");if(t>0)return[Number(e.slice(0,t)),e.slice(t+1)];throw new Error("Invalid state key")};customElements.define("m-state",class extends HTMLElement{connectedCallback(){const e=this,t=f(e,"key");if(t){const r=u(Number(f(e,"fc")));r.watch(t,g(e,f(e,"mode"),()=>r.store[t]));return}}}),Object.assign(window,{$state:e=>e!==void 0?u(e).store:void 0,$defineState:(e,t)=>{const[r,n]=p(e);u(r).define(n,t)},$defineComputed:(e,t,r)=>{const n=document.querySelector("m-state[computed='"+e+"']");if(n){const s=u(Number(f(n,"fc"))).store,i=g(n,f(n,"mode"),t.bind(s));for(const c of r){const[a,o]=p(c);u(a).watch(o,i)}}}});`;
10
- var SUSPENSE_JS = `const n={},o=e=>e.getAttribute("chunk-id");c("m-portal",e=>{n[o(e)]=e}),c("m-chunk",e=>{const t=o(e),s=n[t];s&&setTimeout(()=>{s.replaceWith(...e.firstChild.content.childNodes),delete n[t],e.remove()})});function c(e,t){customElements.define(e,class extends HTMLElement{connectedCallback(){t(this)}})}`;
10
+ var SUSPENSE_JS = `const n={},o=e=>e.getAttribute("chunk-id");c("m-portal",e=>{n[o(e)]=e}),c("m-chunk",e=>{setTimeout(()=>{const t=o(e),s=n[t];s&&(s.replaceWith(...e.firstChild.content.childNodes),e.remove(),delete n[t])})});function c(e,t){customElements.define(e,class extends HTMLElement{connectedCallback(){t(this)}})}`;
11
11
  var UTILS_JS = {
12
12
  /** cx.js (225 bytes) */
13
13
  cx: `var n=e=>typeof e=="string",o=e=>typeof e=="object"&&e!==null;function t(e){return n(e)?e:o(e)?Array.isArray(e)?e.map(t).filter(Boolean).join(" "):Object.entries(e).filter(([,r])=>!!r).map(([r])=>r).join(" "):""}window.$cx=t;`,
@@ -358,20 +358,27 @@ async function renderNode(rc, node, stripSlotProp) {
358
358
  }
359
359
  if (typeof tag === "function") {
360
360
  const fcIndex = ++rc.status.fcIndex;
361
- const { rendering, placeholder, catch: catchFC, ...fcProps } = props ?? /* @__PURE__ */ Object.create(null);
361
+ const { children, rendering, placeholder, catch: catchFC } = props;
362
362
  try {
363
- const v = tag.call(createThis(fcIndex, rc.appState, rc.context, rc.request), fcProps);
364
- const { children } = fcProps;
363
+ const v = tag.call(createThis(fcIndex, rc.appState, rc.context, rc.request), props);
365
364
  const fcSlots = children !== void 0 ? Array.isArray(children) ? isVNode(children) ? [children] : children : [children] : void 0;
365
+ const eager = (rendering ?? tag.rendering) === "eager";
366
366
  if (v instanceof Promise) {
367
- if ((rendering ?? tag.rendering) === "eager") {
367
+ if (eager) {
368
368
  await renderNode({ ...rc, fcIndex, fcSlots }, await v);
369
369
  } else {
370
370
  const chunkIdAttr = 'chunk-id="' + (rc.status.chunkIndex++).toString(36) + '"';
371
371
  rc.suspenses.push(v.then(async (node2) => {
372
- write("<m-chunk " + chunkIdAttr + "><template>");
373
- await renderNode({ ...rc, fcIndex, fcSlots }, node2);
374
- write("</template></m-chunk>");
372
+ let buf = "<m-chunk " + chunkIdAttr + "><template>";
373
+ await renderNode({
374
+ ...rc,
375
+ fcIndex,
376
+ fcSlots,
377
+ write: (chunk) => {
378
+ buf += chunk;
379
+ }
380
+ }, node2);
381
+ return buf + "</template></m-chunk>";
375
382
  }));
376
383
  write("<m-portal " + chunkIdAttr + ">");
377
384
  if (placeholder) {
@@ -380,7 +387,7 @@ async function renderNode(rc, node, stripSlotProp) {
380
387
  write("</m-portal>");
381
388
  }
382
389
  } else if (isObject(v) && Symbol.asyncIterator in v) {
383
- if ((rendering ?? tag.rendering) === "eager") {
390
+ if (eager) {
384
391
  for await (const c of v) {
385
392
  await renderNode({ ...rc, fcIndex, fcSlots }, c);
386
393
  }
@@ -672,7 +679,7 @@ function render(node, renderOptions = {}) {
672
679
  write("<script>/* app.js (generated by mono-jsx) */" + js + "<\/script>");
673
680
  }
674
681
  if (suspenses.length > 0) {
675
- await Promise.all(suspenses.splice(0, suspenses.length));
682
+ await Promise.all(suspenses.splice(0, suspenses.length).map((suspense) => suspense.then(write)));
676
683
  await finalize();
677
684
  }
678
685
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-jsx",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "`<html>` as a `Response`.",
5
5
  "type": "module",
6
6
  "module": "./index.mjs",
package/types/css.d.ts CHANGED
@@ -6107,7 +6107,8 @@ export interface StandardShorthandProperties<TLength = (string & {}) | 0, TTime
6107
6107
  }
6108
6108
 
6109
6109
  export interface StandardProperties<TLength = (string & {}) | 0, TTime = string & {}>
6110
- extends StandardLonghandProperties<TLength, TTime>, StandardShorthandProperties<TLength, TTime> {}
6110
+ extends StandardLonghandProperties<TLength, TTime>, StandardShorthandProperties<TLength, TTime>
6111
+ {}
6111
6112
 
6112
6113
  export interface VendorLonghandProperties<TLength = (string & {}) | 0, TTime = string & {}> {
6113
6114
  /**
@@ -8018,7 +8019,8 @@ export interface VendorShorthandProperties<TLength = (string & {}) | 0, TTime =
8018
8019
  }
8019
8020
 
8020
8021
  export interface VendorProperties<TLength = (string & {}) | 0, TTime = string & {}>
8021
- extends VendorLonghandProperties<TLength, TTime>, VendorShorthandProperties<TLength, TTime> {}
8022
+ extends VendorLonghandProperties<TLength, TTime>, VendorShorthandProperties<TLength, TTime>
8023
+ {}
8022
8024
 
8023
8025
  export interface ObsoleteProperties<TLength = (string & {}) | 0, TTime = string & {}> {
8024
8026
  /**
@@ -9143,7 +9145,8 @@ export interface Properties<TLength = (string & {}) | 0, TTime = string & {}>
9143
9145
  StandardProperties<TLength, TTime>,
9144
9146
  VendorProperties<TLength, TTime>,
9145
9147
  ObsoleteProperties<TLength, TTime>,
9146
- SvgProperties<TLength, TTime> {}
9148
+ SvgProperties<TLength, TTime>
9149
+ {}
9147
9150
 
9148
9151
  export type AtRules =
9149
9152
  | "@charset"
package/types/mono.d.ts CHANGED
@@ -66,7 +66,7 @@ export interface CSSProperties extends BaseCSSProperties, AtRuleCSSProperties, P
66
66
  [key: `&${" " | "." | "["}${string}`]: CSSProperties;
67
67
  }
68
68
 
69
- export type ChildType = JSX.Element | JSX.Element[] | string | number | bigint | boolean | null;
69
+ export type ChildType = JSX.Element | (JSX.Element | string | null)[] | string | number | bigint | boolean | null;
70
70
 
71
71
  export interface BaseAttributes {
72
72
  children?: ChildType | ChildType[];
@@ -76,16 +76,16 @@ export interface BaseAttributes {
76
76
 
77
77
  export interface AsyncComponentAttributes {
78
78
  /**
79
- * Error handler.
79
+ * Try to catch errors in the component.
80
80
  */
81
81
  catch?: (err: any) => JSX.Element;
82
82
  /**
83
- * Loading spinner.
83
+ * The loading spinner for the async component.
84
84
  */
85
- placeholder?: JSX.Element | string;
85
+ placeholder?: JSX.Element;
86
86
  /**
87
87
  * Rendering mode
88
- * - `eager`: render immediately
88
+ * - `eager`: render async component eagerly
89
89
  */
90
90
  rendering?: "eager";
91
91
  }