mono-jsx 0.6.10 → 0.6.11
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 +15 -7
- package/package.json +1 -1
- package/types/html.d.ts +24 -16
- package/types/jsx-runtime.d.ts +1 -1
package/jsx-runtime.mjs
CHANGED
|
@@ -12,7 +12,7 @@ var ROUTER = 512;
|
|
|
12
12
|
var EVENT_JS = `{var w=window;w.$emit=(e,f,s)=>f.call(w.$signals?.(s)??e.target,e.type==="mount"?e.target:e);w.$onsubmit=(e,f,s)=>{e.preventDefault();f.call(w.$signals?.(s)??e.target,new FormData(e.target),e)};}`;
|
|
13
13
|
var CX_JS = `{var n=e=>typeof e=="string"?e:typeof e=="object"&&e!==null?Array.isArray(e)?e.map(n).filter(Boolean).join(" "):Object.entries(e).filter(([,t])=>!!t).map(([t])=>t).join(" "):"";window.$cx=n;}`;
|
|
14
14
|
var STYLE_JS = `{var a=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;var l=e=>typeof e=="string";var u=e=>e.replace(/[a-z][A-Z]/g,r=>r.charAt(0)+"-"+r.charAt(1).toLowerCase());var p=e=>{let r=[],t=[],n=new g;for(let[o,s]of Object.entries(e))switch(o.charCodeAt(0)){case 58:t.push(null,o+"{"+c(s)+"}");break;case 64:t.push(o+"{",null,"{"+c(s)+"}}");break;case 38:t.push(null,o.slice(1)+"{"+c(s)+"}");break;default:r.push([o,s])}return r.length>0&&(n.inline=c(r)),t.length>0&&(n.css=t),n},f=(e,r)=>{let{inline:t,css:n}=p(r);if(n){let o="data-css-",s="["+o+(Date.now()+Math.random()).toString(36).replace(".","")+"]";document.head.appendChild(document.createElement("style")).textContent=(t?s+"{"+t+"}":"")+n.map(i=>i===null?s:i).join(""),e.getAttributeNames().forEach(i=>i.startsWith(o)&&e.removeAttribute(i)),e.setAttribute(s.slice(1,-1),"")}else t&&e.setAttribute("style",t)},c=e=>{if(typeof e=="object"&&e!==null){let r="";for(let[t,n]of Array.isArray(e)?e:Object.entries(e))if(l(n)||typeof n=="number"){let o=u(t),s=typeof n=="number"?a.test(t)?""+n:n+"px":""+n;r+=(r?";":"")+o+":"+(o==="content"?JSON.stringify(s):s)}return r}return""},g=(()=>{function e(){}return e.prototype=Object.freeze(Object.create(null)),e})();window.$applyStyle=f;}`;
|
|
15
|
-
var RENDER_ATTR_JS = `{var s=(l,n,r)=>{let
|
|
15
|
+
var RENDER_ATTR_JS = `{var s=(l,n,r)=>{let e=l.parentElement;return e.tagName==="M-GROUP"&&(e=e.previousElementSibling),()=>{let t=r();n==="value"?e.value=String(t):n==="checked"?e.checked=!!t:typeof t=="boolean"?e.toggleAttribute(n,t):t==null?e.removeAttribute(n):typeof t=="object"?n==="class"?e.setAttribute(n,$cx(t)):n==="style"?$applyStyle(e,t):e.setAttribute(n,JSON.stringify(t)):e.setAttribute(n,String(t))}};window.$renderAttr=s;}`;
|
|
16
16
|
var RENDER_TOGGLE_JS = `{var r=(n,l)=>{let e;return()=>{if(!e){let t=n.firstElementChild;t&&t.tagName==="TEMPLATE"&&t.hasAttribute("m-slot")?e=[...t.content.childNodes]:e=[...n.childNodes]}n.replaceChildren(...l()?e:[])}};window.$renderToggle=r;}`;
|
|
17
17
|
var RENDER_SWITCH_JS = `{var u=(r,d)=>{let s,i=r.getAttribute("value"),t,l,o=e=>t.get(e)??t.set(e,[]).get(e);return()=>{if(!t){t=new Map,l=[];for(let e of r.childNodes)if(e.nodeType===1&&e.tagName==="TEMPLATE"&&e.hasAttribute("m-slot")){for(let n of e.content.childNodes)n.nodeType===1&&n.hasAttribute("slot")?o(n.getAttribute("slot")).push(n):l.push(n);e.remove()}else i?o(i).push(e):l.push(e)}s=""+d(),r.replaceChildren(...t.has(s)?t.get(s):l)}};window.$renderSwitch=u;}`;
|
|
18
18
|
var SIGNALS_JS = `{let m;const h=window,b=new Map,k=new Map,l=n=>k.get(n)??k.set(n,M(n)).get(n),y=()=>Object.create(null),f=(n,e)=>n.getAttribute(e),M=n=>{const e=y(),t=(r,c)=>{e[r]=c},s=new Map,a=(r,c)=>{let o=s.get(r);return o||(o=new Set,s.set(r,o)),o.add(c),()=>{o.delete(c),o.size===0&&s.delete(r)}},i=new Proxy(y(),{get:(r,c)=>document.querySelector("[data-ref='"+n+":"+c+"']")});return new Proxy(e,{get:(r,c,o)=>{switch(c){case"$init":return t;case"$watch":return a;case"app":return l(0);case"refs":return i;default:return m?.(n,c),Reflect.get(r,c,o)}},set:(r,c,o,d)=>{if(o!==Reflect.get(r,c,d)){const u=s.get(c);return u&&queueMicrotask(()=>u.forEach(g=>g())),Reflect.set(r,c,o,d)}return!1}})},$=(n,e,t)=>{switch(e){case"toggle":return $renderToggle(n,t);case"switch":return $renderSwitch(n,t);case"html":return()=>n.innerHTML=""+t()}return e&&e.length>2&&e.startsWith("[")&&e.endsWith("]")?$renderAttr(n,e.slice(1,-1),t):()=>n.textContent=""+t()},E=n=>{const e=n.indexOf(":");return e>0?[Number(n.slice(0,e)),n.slice(e+1)]:null},p=async n=>{const e=n();return e!==void 0?e:(await new Promise(t=>setTimeout(t,0)),p(n))},S=n=>{typeof n=="function"&&n()},v=(n,e)=>customElements.define(n,class extends HTMLElement{disposes=[];connectedCallback(){e(this)}disconnectedCallback(){this.disposes.forEach(t=>t()),this.disposes.length=0}});v("m-signal",n=>{const e=Number(f(n,"scope")),t=l(e),s=f(n,"key");if(s)n.disposes.push(t.$watch(s,$(n,f(n,"mode"),()=>t[s])));else{const a=Number(f(n,"computed"));p(()=>b.get(e*1e9+a)).then(([i,r])=>{const c=$(n,f(n,"mode"),i.bind(t));r.forEach(o=>{const[d,u]=E(o);n.disposes.push(l(d).$watch(u,c))})})}}),v("m-effect",n=>{const{disposes:e}=n,t=Number(f(n,"scope")),s=Number(f(n,"n")),a=new Array(s);e.push(()=>{a.forEach(S),a.length=0});for(let i=0;i<s;i++){const r="$ME_"+t+"_"+i;p(()=>h[r]).then(c=>{const o=[],d=l(t),u=()=>{S(a[i]),a[i]=c.call(d)};m=(g,w)=>o.push([g,w]),u(),m=void 0;for(const[g,w]of o)e.push(l(g).$watch(w,u))},()=>{})}}),h.$MS=(n,e)=>{const[t,s]=E(n);l(t).$init(s,e)},h.$MC=(n,e,t,s)=>{b.set(n*1e9+e,[t,s])},h.$patch=(n,...e)=>{for(const[t,...s]of e){const a=s.pop();let i=n;for(const r of s)i=i[r];i[a]=t}return n},h.$signals=n=>n!==void 0?l(n):void 0;}`;
|
|
@@ -135,7 +135,7 @@ var $signal = Symbol.for("mono.signal");
|
|
|
135
135
|
var $vnode = Symbol.for("jsx.vnode");
|
|
136
136
|
|
|
137
137
|
// version.ts
|
|
138
|
-
var VERSION = "0.6.
|
|
138
|
+
var VERSION = "0.6.10";
|
|
139
139
|
|
|
140
140
|
// render.ts
|
|
141
141
|
var cdn = "https://raw.esm.sh";
|
|
@@ -651,7 +651,7 @@ async function renderNode(rc, node, stripSlotProp) {
|
|
|
651
651
|
if (propName === "children") {
|
|
652
652
|
continue;
|
|
653
653
|
}
|
|
654
|
-
const [attr, addonHtml, signalValue] = renderAttr(rc, propName, propValue, stripSlotProp);
|
|
654
|
+
const [attr, addonHtml, signalValue, binding] = renderAttr(rc, propName, propValue, stripSlotProp);
|
|
655
655
|
if (addonHtml) {
|
|
656
656
|
write(addonHtml);
|
|
657
657
|
}
|
|
@@ -659,7 +659,7 @@ async function renderNode(rc, node, stripSlotProp) {
|
|
|
659
659
|
const write2 = (chunk) => {
|
|
660
660
|
attrModifiers += chunk;
|
|
661
661
|
};
|
|
662
|
-
renderSignal({ ...rc, write: write2 }, signalValue, [
|
|
662
|
+
renderSignal({ ...rc, write: write2 }, signalValue, [binding ? propName.slice(1) : propName]);
|
|
663
663
|
rc.flags.runtime |= RENDER_ATTR;
|
|
664
664
|
}
|
|
665
665
|
buffer += attr;
|
|
@@ -702,6 +702,7 @@ function renderAttr(rc, attrName, attrValue, stripSlotProp) {
|
|
|
702
702
|
let attr = "";
|
|
703
703
|
let addonHtml = "";
|
|
704
704
|
let signalValue;
|
|
705
|
+
let binding = false;
|
|
705
706
|
let scopeId = rc.fcCtx?.scopeId;
|
|
706
707
|
if (isObject(attrValue)) {
|
|
707
708
|
let signal;
|
|
@@ -793,16 +794,23 @@ function renderAttr(rc, attrName, attrValue, stripSlotProp) {
|
|
|
793
794
|
attr = " slot=" + toAttrStringLit(attrValue);
|
|
794
795
|
}
|
|
795
796
|
break;
|
|
797
|
+
case "$checked":
|
|
796
798
|
case "$value":
|
|
797
|
-
|
|
799
|
+
if (!(attrValue === false || attrValue === null || attrValue === void 0)) {
|
|
800
|
+
attr = " " + attrName.slice(1);
|
|
801
|
+
if (attrValue !== true) {
|
|
802
|
+
attr += "=" + toAttrStringLit(String(attrValue));
|
|
803
|
+
}
|
|
804
|
+
}
|
|
798
805
|
if (signalValue) {
|
|
799
806
|
const { key } = signalValue[$signal];
|
|
800
807
|
if (isString(key)) {
|
|
801
808
|
const fn = () => {
|
|
802
809
|
};
|
|
803
|
-
fn.str = "e=>this[" + toAttrStringLit(key) + "]=e.target.
|
|
810
|
+
fn.str = "e=>this[" + toAttrStringLit(key) + "]=e.target." + attrName.slice(1);
|
|
804
811
|
attr += ' oninput="$emit(event,$MF_' + (scopeId ?? 0) + "_" + rc.mfs.gen(fn, scopeId) + toStr(scopeId, (i) => "," + i) + ')"';
|
|
805
812
|
}
|
|
813
|
+
binding = true;
|
|
806
814
|
}
|
|
807
815
|
break;
|
|
808
816
|
default:
|
|
@@ -816,7 +824,7 @@ function renderAttr(rc, attrName, attrValue, stripSlotProp) {
|
|
|
816
824
|
}
|
|
817
825
|
}
|
|
818
826
|
}
|
|
819
|
-
return [attr, addonHtml, signalValue];
|
|
827
|
+
return [attr, addonHtml, signalValue, binding];
|
|
820
828
|
}
|
|
821
829
|
async function renderFC(rc, fc, props, eager) {
|
|
822
830
|
const { write } = rc;
|
package/package.json
CHANGED
package/types/html.d.ts
CHANGED
|
@@ -44,7 +44,9 @@ export namespace HTML {
|
|
|
44
44
|
|
|
45
45
|
/** Global HTML attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes */
|
|
46
46
|
interface GlobalAttributes<T extends EventTarget> extends EventAttributes<T>, Aria.Attributes, Mono.BaseAttributes, JSX.HtmlTag {
|
|
47
|
-
|
|
47
|
+
/** @mono-jsx
|
|
48
|
+
* A reference to the element.
|
|
49
|
+
*/
|
|
48
50
|
ref?: HTMLElement | ((el: T) => unknown);
|
|
49
51
|
/** Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS). */
|
|
50
52
|
id?: string;
|
|
@@ -122,7 +124,8 @@ export namespace HTML {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
interface NavAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
125
|
-
/** @mono-jsx
|
|
127
|
+
/** @mono-jsx
|
|
128
|
+
* This attribute is used to specify the class name for the active link. */
|
|
126
129
|
"data-active-class"?: string;
|
|
127
130
|
}
|
|
128
131
|
|
|
@@ -185,7 +188,7 @@ export namespace HTML {
|
|
|
185
188
|
src?: string;
|
|
186
189
|
step?: number | string;
|
|
187
190
|
type?: InputType;
|
|
188
|
-
value?: string | number
|
|
191
|
+
value?: string | number;
|
|
189
192
|
width?: number | string;
|
|
190
193
|
/**
|
|
191
194
|
* Turns a <button> or <input> element into a popover control button; takes the ID of the popover element to control as its value.
|
|
@@ -202,10 +205,15 @@ export namespace HTML {
|
|
|
202
205
|
*/
|
|
203
206
|
onSearch?: EventHandler<Event, T>;
|
|
204
207
|
/**
|
|
205
|
-
* @mono-jsx
|
|
206
|
-
*
|
|
208
|
+
* @mono-jsx
|
|
209
|
+
* Two-way binding prop that automatically creates checked and oninput attributes for signal binding
|
|
207
210
|
*/
|
|
208
|
-
$
|
|
211
|
+
$checked?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* @mono-jsx
|
|
214
|
+
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
215
|
+
*/
|
|
216
|
+
$value?: string | number;
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
interface OptionAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -223,12 +231,12 @@ export namespace HTML {
|
|
|
223
231
|
name?: string;
|
|
224
232
|
required?: boolean;
|
|
225
233
|
size?: number;
|
|
226
|
-
value?: string | number
|
|
234
|
+
value?: string | number;
|
|
227
235
|
/**
|
|
228
|
-
* @mono-jsx
|
|
229
|
-
*
|
|
236
|
+
* @mono-jsx
|
|
237
|
+
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
230
238
|
*/
|
|
231
|
-
$value?: string | number
|
|
239
|
+
$value?: string | number;
|
|
232
240
|
}
|
|
233
241
|
|
|
234
242
|
interface TextareaAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -248,8 +256,8 @@ export namespace HTML {
|
|
|
248
256
|
wrap?: string;
|
|
249
257
|
onChange?: EventHandler<Event, T>;
|
|
250
258
|
/**
|
|
251
|
-
* @mono-jsx
|
|
252
|
-
*
|
|
259
|
+
* @mono-jsx
|
|
260
|
+
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
253
261
|
*/
|
|
254
262
|
$value?: string;
|
|
255
263
|
}
|
|
@@ -319,7 +327,7 @@ export namespace HTML {
|
|
|
319
327
|
}
|
|
320
328
|
|
|
321
329
|
interface DataAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
322
|
-
value?: string |
|
|
330
|
+
value?: string | number;
|
|
323
331
|
}
|
|
324
332
|
|
|
325
333
|
interface DetailsAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -379,7 +387,7 @@ export namespace HTML {
|
|
|
379
387
|
}
|
|
380
388
|
|
|
381
389
|
interface LiAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
382
|
-
value?: string |
|
|
390
|
+
value?: string | number;
|
|
383
391
|
}
|
|
384
392
|
|
|
385
393
|
interface LinkAttributes<T extends EventTarget> extends GlobalAttributes<T>, LoaderElementAttributes<T> {
|
|
@@ -456,7 +464,7 @@ export namespace HTML {
|
|
|
456
464
|
max?: number | string;
|
|
457
465
|
min?: number | string;
|
|
458
466
|
optimum?: number;
|
|
459
|
-
value?: string |
|
|
467
|
+
value?: string | number;
|
|
460
468
|
}
|
|
461
469
|
|
|
462
470
|
interface QuoteAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -494,7 +502,7 @@ export namespace HTML {
|
|
|
494
502
|
|
|
495
503
|
interface ProgressAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
496
504
|
max?: number | string;
|
|
497
|
-
value?: string |
|
|
505
|
+
value?: string | number;
|
|
498
506
|
}
|
|
499
507
|
|
|
500
508
|
interface SlotAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
package/types/jsx-runtime.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { FC, VNode } from "./jsx.d.ts";
|
|
|
2
2
|
|
|
3
3
|
export const html: JSX.Raw;
|
|
4
4
|
export const JSX: typeof globalThis.JSX;
|
|
5
|
-
export const Fragment: (props:
|
|
5
|
+
export const Fragment: (props: {}) => VNode;
|
|
6
6
|
export const jsx: (tag: string | FC, props: Record<string, unknown>, key?: string | number) => VNode;
|
|
7
7
|
|
|
8
8
|
export { html as css, html as js, jsx as jsxDEV, jsx as jsxs };
|