jaxs 0.3.1 → 0.4.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/dist/jaxs.d.ts +634 -0
- package/dist/jaxs.js +793 -1054
- package/dist/jaxs.umd.cjs +1 -0
- package/package.json +41 -30
- package/.env +0 -1
- package/README.md +0 -15
- package/bun.lockb +0 -0
- package/bundle.ts +0 -5
- package/bunfig.toml +0 -0
- package/cypress/e2e/add-remove-nested-children.cy.js +0 -39
- package/cypress/e2e/add-remove-root-children.cy.js +0 -37
- package/cypress/e2e/svg-renders.cy.js +0 -10
- package/cypress/jaxs-apps/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/add-remove-nested-children.jsx +0 -85
- package/cypress/jaxs-apps/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/add-remove-root-children.jsx +0 -54
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js +0 -1022
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +0 -1665
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js +0 -1011
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/dist/svg.04290504.js +0 -644
- package/cypress/jaxs-apps/dist/svg.04290504.js.map +0 -1
- package/cypress/jaxs-apps/dist/svg.html +0 -11
- package/cypress/jaxs-apps/svg.html +0 -11
- package/cypress/jaxs-apps/svg.jsx +0 -15
- package/cypress/support/commands.js +0 -25
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -10
- package/src/app.ts +0 -64
- package/src/debugging.js +0 -5
- package/src/jaxs.ts +0 -7
- package/src/jsx.js +0 -27
- package/src/messageBus.ts +0 -70
- package/src/navigation/findHref.js +0 -10
- package/src/navigation/routeState.js +0 -15
- package/src/navigation/setupHistory.js +0 -38
- package/src/navigation/setupNavigation.js +0 -25
- package/src/navigation.ts +0 -2
- package/src/rendering/change/compile.ts +0 -1
- package/src/rendering/change/instructions/attributes.ts +0 -81
- package/src/rendering/change/instructions/children.ts +0 -127
- package/src/rendering/change/instructions/element.ts +0 -49
- package/src/rendering/change/instructions/events.ts +0 -51
- package/src/rendering/change/instructions/generate.ts +0 -122
- package/src/rendering/change/instructions/idMap.js +0 -55
- package/src/rendering/change/instructions/node.ts +0 -55
- package/src/rendering/change/instructions/text.ts +0 -10
- package/src/rendering/change.ts +0 -139
- package/src/rendering/dom/attributesAndEvents.ts +0 -33
- package/src/rendering/dom/create.ts +0 -68
- package/src/rendering/dom/svg.ts +0 -18
- package/src/rendering/templates/bound.js +0 -56
- package/src/rendering/templates/children.ts +0 -99
- package/src/rendering/templates/root.ts +0 -55
- package/src/rendering/templates/tag.ts +0 -92
- package/src/rendering/templates/text.ts +0 -17
- package/src/state/equality.js +0 -36
- package/src/state/stores.js +0 -63
- package/src/state/testingTypes.js +0 -6
- package/src/state.js +0 -89
- package/src/types.ts +0 -152
- package/src/views/conditionals.jsx +0 -18
- package/src/views/link.jsx +0 -5
- package/src/views.js +0 -7
- package/tsconfig.json +0 -26
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.jaxs={}))})(this,function(m){"use strict";const b=(e,t)=>t.createElement(e),nt=(e,t)=>{for(const s in t){if(s==="__self")continue;const n=t[s].toString();s==="value"?e.value=n:e.setAttribute(s,n)}},rt=(e,t,s)=>{const n={};for(const r in t){const o=t[r],c=h=>s(o,h);e.addEventListener(r,c),n[r]={domEvent:r,busEvent:o,listener:c}}e.eventMaps=n},ot=(e,t,s,n)=>{const r=b(e,n.document);return nt(r,t),rt(r,s,n.publish),r},w="http://www.w3.org/2000/svg",it=e=>e==="svg",at=(e,t,s)=>{const n=s.createElementNS(w,e);for(const r in t)r==="__self"||r==="xmlns"||n.setAttributeNS(null,r,t[r].toString());return n},ct=e=>e.namespaceURI===w,ut=(e,t)=>t.createTextNode(e);class ht{constructor(t){this.value=t.toString(),this.isSvg=!1}render(t){const s=ut(this.value,t.document);return s.__jsx="TextNode",[s]}}const lt=e=>typeof e=="string"||typeof e=="number",dt=e=>new ht(e),pt=e=>lt(e)?dt(e):e,mt=e=>t=>(t&&(t.isSvg=t.isSvg||e),t),bt=(e,t)=>ft(e).map(pt).flat().map(mt(t)),ft=e=>Array.isArray(e)?e.flat():e?[e]:[],N=(e,t={})=>e||t.children||[],vt=(e,t="")=>{const s={},n={};for(const r in e){const o=e[r];if(r.match(/^on.+/i)){const c=r.slice(2).toLowerCase();n[c]=o?o.toString():""}else{if(o===!1)continue;r==="__source"?s.__source=e.__source:s[r]=gt(r,o,t)}}return{attributes:s,events:n}},gt=(e,t,s="")=>t==null?s:t.toString(),yt=(e,t)=>{const s=e||{},n=N(t,s);return s.children=s.children||n,s},j=(e,t,s=[])=>e.reduce(Et(t),s).flat(),Et=e=>(t,s)=>s?Array.isArray(s)?j(s,e,t):(s.render(e).forEach(n=>t.push(n)),t):t;class k{constructor(t,s=!1){this.collection=bt(t,s),this.isSvg=s}render(t,s){this.parentElement=s;const n=this.generateDom(t);return this.attachToParent(n),n}generateDom(t){return j(this.collection,t)}attachToParent(t){if(this.parentElement===void 0)return;const s=this.parentElement;t.forEach(n=>s.appendChild(n))}}class At{constructor(t,s){this.type=t,this.attributes=s}generate(){return this.attributes.key||this.sourceKey()||this.createKeyFromAttributes()}sourceKey(){if(this.attributes.__source){const{fileName:t,lineNumber:s,columnNumber:n}=this.attributes.__source;return`${t}:${s}:${n}`}}createKeyFromAttributes(){const t=this.attributes.id?`#${this.attributes.id}`:"",s=this.attributes.type?`[type=${this.attributes.type}]`:"",n=this.attributes.name?`[name=${this.attributes.name}]`:"";return`${this.type}${t}${s}${n}`}}class St{constructor(t,s,n=[],r=!1){this.type=t;const{events:o,attributes:c}=vt(s);this.events=o,this.attributes=c,this.isSvg=r||it(this.type),this.children=new k(n,this.isSvg)}render(t){const s=this.generateDom(t);return s?(this.children.render(t,s),[s]):[]}generateDom(t){return this.isSvg?this.generateSvgDom(t):this.generateHtmlDom(t)}generateHtmlDom(t){const s=ot(this.type,this.attributes,this.events,t);return s.__jsx=this.jsxKey(),s}generateSvgDom(t){const s=at(this.type,this.attributes,t.document);return s.__jsx=this.jsxKey(),s}jsxKey(){return new At(this.type,this.attributes).generate()}}const O=(e,t,...s)=>typeof e=="string"?new St(e,t,s):e(yt(t,s));O.fragment=(e,t)=>{const s=N(t,e);return new k(s)};class xt{constructor(t,s,n){this.template=t,this.selector=s,this.renderKit=n,this.dom=[]}renderAndAttach(t){this.parentElement=this.getParentElement(),this.dom=this.render({...t,parent:this.parentElement}),this.parentElement&&this.attach()}render(t){return this.template.render(t)}attach(){this.parentElement&&(this.parentElement.innerHTML=""),this.dom.forEach(t=>{this.parentElement&&this.parentElement.appendChild(t)})}getParentElement(){return this.renderKit.document.querySelector(this.selector)}}const _t=(e,t,s)=>{const n=new xt(e,t,s);return n.renderAndAttach(s),n},$="go-to-href",f="navigation:location-change",M="navigation:route-change",wt=Object.freeze(Object.defineProperty({__proto__:null,linkNavigationEvent:$,locationChangeEvent:f,routeChangeEvent:M},Symbol.toStringTag,{value:"Module"})),T=e=>{e.createRecord("route",{host:"",path:"",query:{}})},F=e=>{const t=e.closest("[href]");return t&&t.getAttribute("href")||""},D=(e,{publish:t,window:s})=>{s.history.pushState(null,"",e),t(f,null)},z=(e,t)=>{if(!e||!e.target)return;e.preventDefault();const s=F(e.target);D(s,t)},L=e=>e.replace(/^\?/,"").split("&").reduce((t,s)=>{if(!s)return t;const n=s.split("=");return t[n[0]]=n[1],t},{}),P=(e,t)=>{const{state:s,publish:n,window:r}=t,{host:o,pathname:c,search:h}=r.location,i=c,d=L(h),u={host:o,path:i,query:d};s.store("route").update(u),n(M,u)},U=e=>{const{subscribe:t}=e;t($,z)},B=e=>{const{publish:t,subscribe:s,state:n,window:r}=e;T(n),r.addEventListener("popstate",()=>t(f,null)),s(f,P)},K=e=>{setTimeout(()=>e.publish(f,null),0)},V=e=>{B(e),U(e),K(e)},Nt=Object.freeze(Object.defineProperty({__proto__:null,publishLocation:K,startNavigation:V,subscribeToHistoryChange:B,subscribeToNavigation:U},Symbol.toStringTag,{value:"Module"}));class R{constructor({window:t,document:s,publish:n,subscribe:r,bus:o,state:c,renderKit:h}){this.window=t,this.document=s,this.publish=n,this.subscribe=r,this.bus=o,this.state=c,this.renderKit=h,this.roots=[]}render(t,s){const n=_t(t,s,this.renderKit);return this.roots.push(n),n}startNavigation(){V(this)}}const jt=Object.freeze(Object.defineProperty({__proto__:null,App:R},Symbol.toStringTag,{value:"Module"}));class J{constructor(){this.lookup={}}add(t,s,n){this.ensureArrayFor(t);const r={listener:s,index:n,matcher:t};return this.lookup[t].push(r),()=>this.remove(r)}remove(t){this.lookup[t.matcher]&&(this.lookup[t.matcher]=this.lookup[t.matcher].reduce((s,n)=>(n!==t&&s.push(n),s),[]))}matches(t){return this.lookup[t]||[]}ensureArrayFor(t){this.lookup[t]||(this.lookup[t]=[])}}class q{constructor(){this.lookup=[]}add(t,s,n){const r={listener:s,index:n,matcher:t};return this.lookup.push(r),()=>this.remove(r)}remove(t){this.lookup=this.lookup.reduce((s,n)=>(n!==t&&s.push(n),s),[])}matches(t){return this.lookup.filter(s=>s.matcher.test(t))}}class H{constructor(){this.exactSubscriptions=new J,this.fuzzySubscriptions=new q,this.currentIndex=0}subscribe(t,s){let n;return typeof t=="string"?n=this.exactSubscriptions.add(t,s,this.currentIndex):n=this.fuzzySubscriptions.add(t,s,this.currentIndex),this.currentIndex+=1,n}publish(t,s){[...this.exactSubscriptions.matches(t),...this.fuzzySubscriptions.matches(t)].sort((r,o)=>r.index-o.index).forEach(r=>{r.listener(s,this.listenerOptions(t))})}addListenerOptions(t){this.options=t}listenerOptions(t){return{eventName:t,...this.options,publish:this.publish.bind(this)}}}const I=()=>{const e=new H;return{bus:e,publish:(n,r)=>e.publish(n,r),subscribe:(n,r)=>e.subscribe(n,r)}},kt=Object.freeze(Object.defineProperty({__proto__:null,ExactSubscriptions:J,FuzzySubscriptions:q,JaxsBus:H,createBus:I},Symbol.toStringTag,{value:"Module"})),g=e=>Array.isArray(e),y=e=>e!==null&&!g(e)&&typeof e=="object",Ot=(e,t)=>e===t,$t=(e,t)=>Object.keys(e).length===Object.keys(t).length,Mt=(e,t)=>!(y(e)&&y(t))||!$t(e,t)?!1:Object.keys(e).every(s=>{const n=e[s],r=t[s];return E(n,r)}),Tt=(e,t)=>!(g(e)&&g(t))||e.length!==t.length?!1:e.every((s,n)=>{const r=t[n];return E(s,r)}),E=(e,t)=>y(e)?Mt(e,t):g(e)?Tt(e,t):Ot(e,t);class v{constructor(t){this.store=t}update(t){this.store.update(t)}reset(){this.store.update(this.store.initialState)}get value(){return this.store.value}addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}addUpdaterFunctions(t){for(const s in t)this.addUpdaterFunction(s,t[s])}}class A extends v{push(t){const s=[...this.value,t];this.update(s)}pop(){const t=[...this.value],s=t.pop();return this.update(t),s}unshift(t){const s=[t,...this.value];this.update(s)}shift(){const t=[...this.value],s=t.shift();return this.update(t),s}addSorter(t,s){this[t]=()=>{this.sortBy(s)}}sortBy(t){const s=[...this.value];s.sort(t),this.update(s)}insertAt(t,s){const n=[...this.value];n.splice(t,0,s),this.update(n)}}class S{constructor(t){this.name=t.name,this.parent=t.parent,this._value=t.value,this.initialState=structuredClone(t.value),this.updater=new v(this)}get value(){return this._value}set value(t){throw new Error("Cannot set value directly. Use an updater!")}update(t){if(typeof t=="function"){const s=this.getUpdatedValue(t);this.updateValue(s)}else this.updateValue(t)}updateValue(t){E(this._value,t)||(this._value=t,this.parent.notify(this.name))}getUpdatedValue(t){return t(this.value)}addUpdaters(t){this.updater.addUpdaterFunctions(t)}addUpdater(t,s){this.updater.addUpdaterFunction(t,s)}addSorter(t,s){this.updater instanceof A&&this.updater.addSorter(t,s)}}class Q extends v{toggle(){const t=!this.value;this.update(t)}setTrue(){this.update(!0)}setFalse(){this.update(!1)}}class W extends v{updateAttribute(t,s){const n={...this.value};n[t]=s,this.update(n)}}const x="state";class G{constructor(t){this.publisher=t,this.stores={},this.eventNamePrefix=x,this.notifications=new Set,this.inTransaction=!1}create(t,s){const n=new S({name:t,parent:this,value:s});return this.stores[t]=n,n}createBoolean(t,s){const n=this.create(t,s);return n.updater=new Q(n),n}createRecord(t,s){const n=this.create(t,s);return n.updater=new W(n),n}createList(t,s){const n=this.create(t,s);return n.updater=new A(n),n}store(t){return this.stores[t]||new S({name:t,parent:this,value:void 0})}get(t){return this.store(t).value}getAll(t){return t.reduce((s,n)=>(s[n]=this.get(n),s),{})}notify(t){this.inTransaction?this.notifications.add(t):this.publish(t)}update(t,s){this.store(t).update(s)}transaction(t){this.inTransaction=!0,t(this.stores),this.inTransaction=!1,this.publishAll()}publishAll(){this.notifications.forEach(t=>{this.publish(t)}),this.notifications.clear()}publish(t){this.publisher(this.event(t),{state:this,store:this.store(t)})}event(t){return`${this.eventNamePrefix}:${t}`}}const X=e=>new G(e),Ft=Object.freeze(Object.defineProperty({__proto__:null,BooleanUpdater:Q,JaxsState:G,JaxsStore:S,JaxsStoreUpdater:v,ListUpdater:A,ObjectUpdater:W,createState:X,eventName:x},Symbol.toStringTag,{value:"Module"}));class Dt{constructor(t){this.setupDomEnvironment(t)}setup(){return this.setupBus(),this.setupState(),this.addBusOptions(),this.setRenderKit(),new R({window:this.window,document:this.document,publish:this.publish,subscribe:this.subscribe,bus:this.bus,state:this.state,renderKit:this.renderKit})}setupDomEnvironment(t){t.window?(this.window=t.window,this.document=this.window.document):t.document?(this.window=t.document.defaultView,this.document=t.document):(this.window=window,this.document=document)}setupBus(){const{publish:t,subscribe:s,bus:n}=I();this.publish=t,this.subscribe=s,this.bus=n}setupState(){this.state=X(this.publish)}addBusOptions(){this.bus.addListenerOptions({state:this.state,document:this.document,window:this.window})}setRenderKit(){this.renderKit={publish:this.publish,subscribe:this.subscribe,state:this.state,document:this.document,window:this.window}}}const zt=(e={})=>{const s=new Dt(e).setup();return s.startNavigation(),s};var a=(e=>(e[e.removeNode=0]="removeNode",e[e.insertNode=1]="insertNode",e[e.replaceNode=2]="replaceNode",e[e.removeAttribute=3]="removeAttribute",e[e.addAttribute=4]="addAttribute",e[e.updateAttribute=5]="updateAttribute",e[e.removeEvent=6]="removeEvent",e[e.addEvent=7]="addEvent",e[e.updateEvent=8]="updateEvent",e[e.changeValue=9]="changeValue",e[e.changeText=10]="changeText",e))(a||{});const Lt=Object.freeze(Object.defineProperty({__proto__:null,ChangeInstructionTypes:a},Symbol.toStringTag,{value:"Module"})),Pt=(e,t)=>({source:e,target:t,type:a.changeText,data:{}}),Ut=(e,t)=>({source:e,target:t,type:a.replaceNode,data:{}}),Bt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeAttribute}),Kt=(e,t,s)=>({source:e,target:t,data:s,type:a.addAttribute}),Vt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateAttribute}),Rt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeEvent}),Jt=(e,t,s)=>({source:e,target:t,data:s,type:a.addEvent}),qt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateEvent}),Y=e=>({source:e,target:e,type:a.removeNode,data:{}}),_=(e,t)=>({target:e,source:e,type:a.insertNode,data:t}),Ht=(e,t,s)=>({source:e,target:t,type:a.changeValue,data:s}),It=(e,t)=>e.type>t.type?1:e.type<t.type?-1:0,Z={index:-1};class Qt{constructor(){this.map={}}populate(t){t.forEach((s,n)=>{const r=s.__jsx;r&&(this.map[r]=this.map[r]||[],this.map[r].push({element:s,index:n}))})}pullMatch(t){const s=t&&t.__jsx;return!s||!(this.map[s]&&this.map[s].length)?Z:this.map[s].shift()}clear(t){const s=t&&t.__jsx;if(!(s&&this.map[s]&&this.map[s].length))return;const n=this.map[s];this.map[s]=n.reduce((r,o)=>(o.element!==t&&r.push(o),r),[])}check(t){const s=t&&t.__jsx;return s&&this.map[s]?this.map[s].length>0:!1}remaining(){return Object.values(this.map).flat()}}const C=e=>{const t=new Qt;return t.populate(e),t},tt=(e,t,s=!1)=>{const n=[],r=e.attributes,o=r.length,c=t.attributes,h=c.length;let i,d,u;for(i=0;i<o;i++){u=null;const l=r.item(i);if(l){for(d=0;d<h;d++){const p=c.item(d);if(p&&l.name==p.name){u=p;break}}u?l.value!==u.value&&n.push(Vt(e,t,{name:l.name,value:u.value,isSvg:s})):n.push(Bt(e,t,{name:l.name,isSvg:s}))}}for(i=0;i<h;i++){u=null;const l=c.item(i);if(l){for(d=0;d<o;d++){const p=r.item(d);if(p&&p.name==l.name){u=p;break}}u||n.push(Kt(e,t,{name:l.name,value:l.value,isSvg:s}))}}return n},Wt=(e,t)=>{const s=[],n=e.eventMaps,r=t.eventMaps,o=Object.keys(n),c=Object.keys(r);return o.forEach(h=>{const i=n[h],d=r[h];d?d.busEvent!==i.busEvent&&s.push(qt(e,t,{name:h,targetValue:d.listener,sourceValue:i.listener})):s.push(Rt(e,t,{name:i.domEvent,value:i.listener}))}),c.forEach(h=>{const i=n[h],d=r[h];i||s.push(Jt(e,t,{name:d.domEvent,value:d.listener}))}),s},Gt=e=>e.tagName!=="INPUT",Xt=(e,t)=>e.value===t.value,Yt=(e,t)=>{if(Gt(e)||Xt(e,t))return[];const s=e,n=t;return[Ht(s,n,{name:"value",value:n.value})]},Zt=(e,t)=>{const s=tt(e,t),n=Wt(e,t),r=Yt(e,t);return s.concat(n).concat(r)},Ct=(e,t)=>tt(e,t,!0),te=(e,t)=>e.textContent!==t.textContent?[Pt(e,t)]:[],ee=(e,t,s)=>{let n=[];if(e.nodeType===1&&ct(e)){const r=e,o=t,c=Ct(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else if(e.nodeType===1){const r=e,o=t,c=Zt(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else e.nodeType===3&&(n=te(e,t));return n},et=(e,t,s)=>{const n=[],r=se(e,t),o=C(e),c=C(t),h=[];let i=0;for(;i<r;i++){const u=e[i],l=t[i];if(l&&c.check(l)){const p=o.pullMatch(l);c.clear(l),p.element?(p.index!==i&&n.push(_(p.element,{parent:s,index:i})),h.push({source:p.element,target:l})):u?c.check(u)?n.push(_(l,{parent:s,index:i})):(o.clear(u),n.push(Ut(u,l))):n.push(_(l,{parent:s,index:i}))}else u&&o.pullMatch(u).element&&n.push(Y(u))}o.remaining().forEach(({element:u})=>{n.push(Y(u))});const d=h.reduce((u,{source:l,target:p})=>u.concat(ee(l,p,et)),[]);return n.concat(d).sort(It)},se=(e,t)=>{const s=e.length,n=t.length;return s>n?s:n},ne=(e,t,s)=>{et(e,t,s).forEach(r=>{re(r)})},re=e=>{(fe[e.type]||oe)(e)},oe=e=>{},ie=e=>{const{source:t,target:s}=e;t.nodeValue=s.textContent},ae=e=>{const{source:t}=e;t.remove()},ce=e=>{const{target:t,data:s}=e,{parent:n,index:r}=s,o=n.childNodes[r];o?o&&o!==t&&n.insertBefore(t,o):n.appendChild(t)},ue=e=>{const{source:t,target:s}=e;t.replaceWith(s)},he=e=>{const{source:t,data:s}=e,{name:n,isSvg:r}=s;r?t.removeAttributeNS(null,n):t.removeAttribute(n)},st=e=>{const{source:t,data:s}=e,{name:n,value:r,isSvg:o}=s;o?t.setAttributeNS(null,n,r):t.setAttribute(n,r)},le=e=>{st(e)},de=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.removeEventListener(n,r)},pe=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.addEventListener(n,r)},me=e=>{const t=e.data,s=e.source,{name:n,sourceValue:r,targetValue:o}=t;s.removeEventListener(n,r),s.addEventListener(n,o)},be=e=>{const t=e.data,s=e.source,{value:n}=t;s.value=n},fe={[a.changeText]:ie,[a.removeNode]:ae,[a.insertNode]:ce,[a.replaceNode]:ue,[a.removeAttribute]:he,[a.addAttribute]:st,[a.updateAttribute]:le,[a.removeEvent]:de,[a.addEvent]:pe,[a.updateEvent]:me,[a.changeValue]:be};class ve{constructor({Template:t,subscriptions:s,attributes:n,viewModel:r}){this.Template=t,this.viewModel=r,this.attributes=n,this.subscriptions=s,this.dom=[],this.parentElement=null}render(t){return this.parentElement=t.parent,this.renderKit=t,this.subscribeForRerender(),this.dom=this.generateDom(t),this.dom}generateDom(t){const s={...this.attributes,...this.viewModel(t.state.getAll(this.subscriptions))},n=this.Template(s);return n?n.render(t):[]}rerender(){if(!this.parentElement&&this.dom[0]){const s=this.dom[0].parentElement;this.parentElement=s}const t=this.generateDom(this.renderKit);ne(this.dom,t,this.parentElement),this.parentElement&&(this.dom=Array.from(this.parentElement.childNodes))}subscribeForRerender(){const{subscribe:t}=this.renderKit;this.subscriptions.forEach(s=>{t(this.eventName(s),()=>this.rerender())})}eventName(t){return`${x}:${t}`}}const ge=e=>e,ye=({Template:e,viewModel:t,subscriptions:s})=>(s=s||[],t=t||ge,n=>new ve({Template:e,viewModel:t,subscriptions:s,attributes:n})),Ee=Object.freeze(Object.defineProperty({__proto__:null,createRouteState:T,events:wt,extractQueryParams:L,findHref:F,navigate:D,onLinkClick:z,onLocationChange:P,start:Nt},Symbol.toStringTag,{value:"Module"}));m.JaxsTypes=Lt,m.appBuilding=jt,m.bind=ye,m.createApp=zt,m.jsx=O,m.messageBus=kt,m.navigation=Ee,m.state=Ft,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jaxs",
|
|
3
|
-
"version": "0.3.1",
|
|
4
3
|
"description": "Modular J/TSX application framework",
|
|
5
|
-
"
|
|
4
|
+
"private": false,
|
|
5
|
+
"version": "0.4.0",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"devDependencies": {
|
|
8
|
-
"@types/bun": "latest",
|
|
9
|
-
"@types/jsdom": "^21.1.6",
|
|
10
|
-
"concurrently": "^8.2.2",
|
|
11
|
-
"cypress": "^13.6.2",
|
|
12
|
-
"jsdom": "^23.2.0",
|
|
13
|
-
"npm": "^10.3.0",
|
|
14
|
-
"parcel": "^2.11.0",
|
|
15
|
-
"standard": "^17.1.0"
|
|
16
|
-
},
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"typescript": "^5.0.0"
|
|
19
|
-
},
|
|
20
7
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"build": "
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
8
|
+
"build": "vite build && npm run build:types",
|
|
9
|
+
"build:types": "tsc --declaration --emitDeclarationOnly lib/jaxs.ts --outfile dist/jaxs.d.ts",
|
|
10
|
+
"test": "npm run lint; vitest run",
|
|
11
|
+
"e2e:server": "vite dev --config ./cypress/apps/vite.config.js",
|
|
12
|
+
"e2e": "cypress open",
|
|
13
|
+
"e2e:ci": "cypress run",
|
|
14
|
+
"lint": "prettier . --write"
|
|
26
15
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/jaxs.umd.cjs",
|
|
20
|
+
"module": "./dist/jaxs.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/jaxs.js",
|
|
24
|
+
"require": "./dist/jaxs.umd.cjs"
|
|
34
25
|
}
|
|
35
26
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
27
|
+
"directories": {
|
|
28
|
+
"lib": "lib"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/baccigalupi/jaxs.git"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"client-side rendering",
|
|
36
|
+
"JSX",
|
|
37
|
+
"TSX"
|
|
38
|
+
],
|
|
39
|
+
"author": "Kane Baccigalupi",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/jsdom": "^21.1.7",
|
|
43
|
+
"cypress": "^13.14.2",
|
|
44
|
+
"jsdom": "^24.1.1",
|
|
45
|
+
"prettier": "^3.3.3",
|
|
46
|
+
"typescript": "^5.5.4",
|
|
47
|
+
"vite": "^5.4.1",
|
|
48
|
+
"vitest": "^2.0.5"
|
|
38
49
|
}
|
|
39
|
-
}
|
|
50
|
+
}
|
package/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
DEBUG=false
|
package/README.md
DELETED
package/bun.lockb
DELETED
|
Binary file
|
package/bundle.ts
DELETED
package/bunfig.toml
DELETED
|
File without changes
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
describe('Add and remove child nodes with state', () => {
|
|
2
|
-
beforeEach(() => {
|
|
3
|
-
cy.visit('http://localhost:1234/add-remove-nested-children.html')
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
it('it toggles conditional children correctly', () => {
|
|
7
|
-
cy.get('.validation-error').should('not.exist')
|
|
8
|
-
|
|
9
|
-
cy.get('input[name=email]').type('hello?')
|
|
10
|
-
cy.get('.validation-error').should('not.exist')
|
|
11
|
-
|
|
12
|
-
cy.get('input[name=email]').blur()
|
|
13
|
-
cy.get('.validation-error').contains('Email unknown')
|
|
14
|
-
/* change instructions for blur
|
|
15
|
-
{source: input#email, target: input#email, type: removeNode, data: {…}}
|
|
16
|
-
{target: p.validation-error, source: p.validation-error, type: addNode, data: {…}}
|
|
17
|
-
{target: input#email, source: input#email, type: addNode, data: {…}}
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
cy.get('input[name=email]').focus()
|
|
21
|
-
cy.get('input[name=email]').should('exist')
|
|
22
|
-
cy.get('.validation-error').should('not.exist')
|
|
23
|
-
/* On focus
|
|
24
|
-
{source: p.validation-error, target: p.validation-error, type: removeNode, data: {…}}
|
|
25
|
-
{target: input#email, source: input#email, type: addNode, data: {…}}
|
|
26
|
-
{source: input#email, target: input#email, type: removeNode, data: {…}} // trigger blur?
|
|
27
|
-
*/
|
|
28
|
-
/*
|
|
29
|
-
change triggered on blur:
|
|
30
|
-
{source: input#email, target: input#email, type: removeNode, data: {…}}
|
|
31
|
-
{target: p.validation-error, source: p.validation-error, type: addNode, data: {…}}
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
cy.get('input[name=email]').clear()
|
|
35
|
-
cy.get('input[name=email]').type('kane@example.com')
|
|
36
|
-
cy.get('input[name=email]').blur()
|
|
37
|
-
cy.get('.validation-error').should('not.exist')
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
describe('Add and remove child nodes with state', () => {
|
|
2
|
-
beforeEach(() => {
|
|
3
|
-
cy.visit('http://localhost:1234/add-remove-root-children.html')
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
it('if/else conditional with nested children and toggling conditions', () => {
|
|
7
|
-
cy.get('.member-content').should('not.exist')
|
|
8
|
-
cy.get('.guest-content').contains('that is fine')
|
|
9
|
-
cy.get('form').should.exist
|
|
10
|
-
cy.get('input[type=submit]').should.exist
|
|
11
|
-
|
|
12
|
-
cy.get('a.exclusive-link').click()
|
|
13
|
-
|
|
14
|
-
cy.get('h1.member-content').contains('Oh great crickets!')
|
|
15
|
-
cy.get('p.member-content').contains('Sing me a tale')
|
|
16
|
-
cy.get('.guest-content').should('not.exist')
|
|
17
|
-
|
|
18
|
-
cy.go('back')
|
|
19
|
-
|
|
20
|
-
cy.get('.member-content').should('not.exist')
|
|
21
|
-
cy.get('.guest-content').contains('that is fine')
|
|
22
|
-
cy.get('form').should.exist
|
|
23
|
-
cy.get('input[type=submit]').should.exist
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('show/hide at the root level', () => {
|
|
27
|
-
cy.get('a.exclusive-link').contains('Go to')
|
|
28
|
-
|
|
29
|
-
cy.get('a.exclusive-link').click()
|
|
30
|
-
|
|
31
|
-
cy.get('a.exclusive-link').should('not.exist')
|
|
32
|
-
|
|
33
|
-
cy.go('back')
|
|
34
|
-
|
|
35
|
-
cy.get('a.exclusive-link').contains('Go to')
|
|
36
|
-
})
|
|
37
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
describe('SVG rendering', () => {
|
|
2
|
-
beforeEach(() => {
|
|
3
|
-
cy.visit('http://localhost:1234/svg.html')
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
it('has the correct size because it is correctly setup as svg', () => {
|
|
7
|
-
cy.get('svg').invoke('outerWidth').should('be.eq', 24)
|
|
8
|
-
cy.get('svg').invoke('outerHeight').should('be.eq', 24)
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8"/>
|
|
5
|
-
<title>Jaxs integration test</title>
|
|
6
|
-
<script type="module" src="./add-remove-nested-children.jsx"></script>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<article id="app">
|
|
10
|
-
</article>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { bind, createApp, jsx } from '../../dist/jaxs.js'
|
|
2
|
-
import { views } from '../../src/views.js'
|
|
3
|
-
const { If } = views
|
|
4
|
-
|
|
5
|
-
const app = createApp()
|
|
6
|
-
|
|
7
|
-
app.state.create('form', {
|
|
8
|
-
email: '',
|
|
9
|
-
emailValidation: '',
|
|
10
|
-
emailInvalid: false
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export const onInput = (event, { state }) => {
|
|
14
|
-
const { form } = state
|
|
15
|
-
const { name, value } = event.target
|
|
16
|
-
state.form.update({
|
|
17
|
-
...form,
|
|
18
|
-
[name]: value
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const onFocus = (event, { state }) => {
|
|
23
|
-
const { form } = state
|
|
24
|
-
const { name } = event.target
|
|
25
|
-
state.form.update({
|
|
26
|
-
...form,
|
|
27
|
-
[`${name}Validation`]: ''
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const onBlur = (event, { state }) => {
|
|
32
|
-
const { form } = state
|
|
33
|
-
const { name, value } = event.target
|
|
34
|
-
|
|
35
|
-
if (value !== 'kane@example.com') {
|
|
36
|
-
state.form.update({
|
|
37
|
-
...form,
|
|
38
|
-
[`${name}Validation`]: 'Email unknown'
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const FormTemplate = ({ email, emailValidation, emailInvalid }) => {
|
|
44
|
-
return (
|
|
45
|
-
<form>
|
|
46
|
-
<div>
|
|
47
|
-
<p>
|
|
48
|
-
<label for='email'>Email</label>
|
|
49
|
-
</p>
|
|
50
|
-
<If condition={emailInvalid}>
|
|
51
|
-
<p class='validation-error'>{emailValidation}</p>
|
|
52
|
-
</If>
|
|
53
|
-
<input
|
|
54
|
-
id='email'
|
|
55
|
-
name='email'
|
|
56
|
-
value={email}
|
|
57
|
-
onInput='onInput'
|
|
58
|
-
onBlur='onBlur'
|
|
59
|
-
onFocus='onFocus'
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
<input type='submit' value="Let's go!" class='button-primary mt-6' />
|
|
64
|
-
</form>
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const viewModel = ({ form }) => {
|
|
69
|
-
return {
|
|
70
|
-
...form,
|
|
71
|
-
emailInvalid: !!form.emailValidation
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const Form = bind({
|
|
76
|
-
Template: FormTemplate,
|
|
77
|
-
viewModel,
|
|
78
|
-
subscriptions: ['form']
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
app.subscribe('onInput', onInput)
|
|
82
|
-
app.subscribe('onFocus', onFocus)
|
|
83
|
-
app.subscribe('onBlur', onBlur)
|
|
84
|
-
|
|
85
|
-
app.render(<Form />, '#app')
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8"/>
|
|
5
|
-
<title>Jaxs integration test</title>
|
|
6
|
-
<script type="module" src="./add-remove-root-children.jsx"></script>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<header style="background-color: yellowgreen; border: 1px solid blue; padding: 10px;">
|
|
10
|
-
<div>Hello!</div>
|
|
11
|
-
<div id="profile-area" style="width: 25%"></div>
|
|
12
|
-
</header>
|
|
13
|
-
<article id="main-content"></article>
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { bind, createApp, jsx } from '../../dist/jaxs.js'
|
|
2
|
-
import { views } from '../../src/views.js'
|
|
3
|
-
const { If, Unless } = views
|
|
4
|
-
|
|
5
|
-
const app = createApp()
|
|
6
|
-
|
|
7
|
-
export const MainContentTemplate = ({ inMembers }) => {
|
|
8
|
-
return (
|
|
9
|
-
<>
|
|
10
|
-
<Unless condition={inMembers}>
|
|
11
|
-
<form>
|
|
12
|
-
<p class='guest-content'>
|
|
13
|
-
You are a guest, and I guess that is fine.
|
|
14
|
-
</p>
|
|
15
|
-
<input type='submit' value='Agree! or something' />
|
|
16
|
-
</form>
|
|
17
|
-
</Unless>
|
|
18
|
-
<If condition={inMembers}>
|
|
19
|
-
<h1 class='member-content'>Oh great crickets!</h1>
|
|
20
|
-
<p class='member-content'>Sing me a tale of private content.</p>
|
|
21
|
-
</If>
|
|
22
|
-
</>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
const ProfileAreaTemplate = ({ inMembers }) => {
|
|
26
|
-
return (
|
|
27
|
-
<Unless condition={inMembers}>
|
|
28
|
-
<a href='/members' onClick='goToHref' class='exclusive-link'>
|
|
29
|
-
Go to members area
|
|
30
|
-
</a>
|
|
31
|
-
</Unless>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const viewModel = ({ route }) => {
|
|
36
|
-
return {
|
|
37
|
-
inMembers: route && route.path && route.path.match(/members/)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const MainContent = bind({
|
|
42
|
-
Template: MainContentTemplate,
|
|
43
|
-
viewModel,
|
|
44
|
-
subscriptions: ['route']
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const ProfileArea = bind({
|
|
48
|
-
Template: ProfileAreaTemplate,
|
|
49
|
-
viewModel,
|
|
50
|
-
subscriptions: ['route']
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
app.render(<MainContent />, '#main-content')
|
|
54
|
-
app.render(<ProfileArea />, '#profile-area')
|