Comparing version 2.1.1 to 2.1.2
@@ -1,2 +0,2 @@ | ||
var ce=Object.defineProperty,ie=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var me=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var q=(r,s,i)=>s in r?ce(r,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[s]=i,R=(r,s)=>{for(var i in s||(s={}))me.call(s,i)&&q(r,i,s[i]);if(Y)for(var i of Y(s))fe.call(s,i)&&q(r,i,s[i]);return r},E=(r,s)=>ie(r,ue(s));export const Fragment=Symbol.for("FORGO_FRAGMENT");const Te="http://www.w3.org/1999/xhtml",Re="http://www.w3.org/1998/Math/MathML",ge="http://www.w3.org/2000/svg",V=1,Ee=2,L=3;export function createElement(r,s){var C;s=s!=null?s:{},s.children=arguments.length>3?S(Array.from(arguments).slice(2)):arguments.length===3?S(arguments[2]):void 0;const i=(C=s.key)!=null?C:void 0;return{type:r,props:s,key:i,__is_forgo_element__:!0}}export const h=createElement;function he(r,s){return i=>{if(!r.__forgo_deleted)return s(i)}}export function createForgoInstance(r){var J;const s=r;s.__internal=(J=s.__internal)!=null?J:{Text:s.window.Text,HTMLElement:s.window.HTMLElement};function i(n,e,o,t){return Array.isArray(n)?U(n,e,o,t):D(n)?Ne(n)?A(n,e,o,t):H(n)?O(n,e,o,t):Q(n,e,o,t):n==null?C(n,e,o,t):T(n,e,o,t)}function C(n,e,o,t){return{nodes:[]}}function T(n,e,o,t){var d;if(e.type==="detached"){const a=s.document.createTextNode($(n));return b(n,a,!0,o,void 0),{nodes:[a]}}else{const a=s.document.createTextNode($(n)),l=e.parentElement.childNodes;if(e.length){let c=l[e.currentNodeIndex];if(c.nodeType===L){c.replaceWith(a);const m=(d=getForgoState(c))==null?void 0:d.components;return b(n,a,!0,o,m),{nodes:[a]}}else{const m=l[e.currentNodeIndex];return e.parentElement.insertBefore(a,m),b(n,a,!0,o,void 0),{nodes:[a]}}}else{const c=e.parentElement.childNodes;if(c.length===0||e.currentNodeIndex===0)e.parentElement.prepend(a);else{const m=c[e.currentNodeIndex];e.parentElement.insertBefore(a,m)}return b(n,a,!0,o,void 0),{nodes:[a]}}}}function A(n,e,o,t){if(e.type==="detached")return l(void 0,null);{const c=e.parentElement.childNodes;if(e.length){const m=ee(n,c,e.currentNodeIndex,e.length);return m.found?a(m.index,c,e):l(e.parentElement,c[e.currentNodeIndex])}else return l(e.parentElement,c[e.currentNodeIndex])}function d(c){if(n.props.dangerouslySetInnerHTML)c.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{const m=n.props.children,p=S((Array.isArray(m)?m:[m]).filter(y=>y!=null));let u=0;for(const y of p){const{nodes:N}=i(y,{type:"search",parentElement:c,currentNodeIndex:u,length:c.childNodes.length-u},[],t);u+=N.length}const f=P(c.childNodes,u,c.childNodes.length);f.length&&(_(f),w(f,[]))}}function a(c,m,p){var N;const u=P(m,p.currentNodeIndex,c);_(u),w(u,o);const f=m[p.currentNodeIndex];d(f);const y=(N=getForgoState(f))==null?void 0:N.components;return b(n,f,!1,o,y),{nodes:[f]}}function l(c,m){const p=de(n,c);return c&&c.insertBefore(p,m),n.props.ref&&(n.props.ref.value=p),d(p),b(n,p,!0,o,void 0),{nodes:[p]}}}function Q(n,e,o,t){const d=o.length;if(e.type==="detached")return l();if(e.length){if(t)return l();{const m=e.parentElement.childNodes,p=ne(n,m,e.currentNodeIndex,e.length,o.length);return p.found?a(p.index,m,e):l()}}else return l();function a(m,p,u){const f=p[m],N=Z(f).components[d],F=P(p,u.currentNodeIndex,m);if(_(F),w(F,o.concat(N)),!N.component.shouldUpdate||N.component.shouldUpdate(n.props,N.props)){const g=E(R({},N),{props:n.props}),x=o.concat(g),k=N.args.element.node,se=g.component.render(n.props,g.args),le=g.component.error?g.component:void 0,pe=c(n.props,g.args,x,le,()=>{const ae={type:"search",currentNodeIndex:u.currentNodeIndex,length:g.nodes.length,parentElement:u.parentElement};return I(se,ae,x,g,t)});return g.component.afterRender&&g.component.afterRender(n.props,E(R({},g.args),{previousNode:k})),pe}else{let g=B(u.parentElement.childNodes,N.args.element.node);return{nodes:P(u.parentElement.childNodes,g,g+N.nodes.length)}}}function l(){const m={element:{componentIndex:d},update:F=>G(m.element,F)},p=n.type,u=p(n.props,{environment:s});ye(p,u);const f=u.error?u:void 0,y={key:n.key,ctor:p,component:u,props:n.props,args:m,nodes:[],isMounted:!1},N=o.concat(y);return c(n.props,m,N,f,()=>{const F=u.render(n.props,m),g=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:t?e.length:0,parentElement:e.parentElement},x=i(F,g,N,t);return y.nodes=x.nodes,x.nodes.length>1&&(y.args.element.node=x.nodes[0]),u.afterRender&&u.afterRender(n.props,m),x})}function c(m,p,u,f,y){try{return y()}catch(N){if(f&&f.error){const F=E(R({},p),{error:N}),g=f.error(m,F);return i(g,e,u,t)}else throw N}}}function I(n,e,o,t,d){const a=e.parentElement.childNodes.length,l=i(n,e,o,d),c=e.parentElement.childNodes.length,m=a+l.nodes.length-c,p=e.currentNodeIndex+l.nodes.length,u=P(e.parentElement.childNodes,p,p+t.nodes.length-m);return _(u),w(u,o),t.nodes=l.nodes,l.nodes.length>1&&(t.args.element.node=l.nodes[0]),l}function U(n,e,o,t){const d=S(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let a=[],l=e.currentNodeIndex,c=e.length;for(const m of d){const p=e.parentElement.childNodes.length,u=E(R({},e),{currentNodeIndex:l,length:c}),{nodes:f}=i(m,u,o,t);a=a.concat(f);const y=e.parentElement.childNodes.length,N=p+f.length-y;l+=f.length,c-=N}return{nodes:a}}}function O(n,e,o,t){return U(S(n),e,o,t)}function b(n,e,o,t,d){if(oe(n,e,o,t),d){const a=j(t,d);v(d,a),X(t,a)}else X(t,0)}function _(n){}function w(n,e){for(const o of n){const t=getForgoState(o);if(o.__forgo_deleted=!0,o.remove(),t){const d=t.components,a=j(e,d);v(t.components,a)}}}function j(n,e){let o=0;for(const t of n)if(e.length>o){if(e[o].component!==t.component)break;o++}else break;return o}function v(n,e){let o=!1;for(let t=e;t<n.length;t++){const d=n[t];d.component.unmount&&(o||d.nodes.every(a=>{if(a.isConnected){const l=Z(a);return!l.components[t]||l.components[t].component!==d.component}else return!0}))&&(d.component.unmount(d.props,d.args),o=!0)}}function X(n,e){for(let o=e;o<n.length;o++){const t=n[o];t.component.mount&&!t.isMounted&&(t.isMounted=!0,t.component.mount(t.props,t.args))}}function ee(n,e,o,t){for(let d=o;d<o+t;d++){const a=e[d];if(z(a)){const l=getForgoState(a);if(n.key){if((l==null?void 0:l.key)===n.key)return{found:!0,index:d}}else if(a.tagName.toLowerCase()===n.type&&(!l||!l.key))return{found:!0,index:d}}}return{found:!1}}function ne(n,e,o,t,d){for(let a=o;a<o+t;a++){const l=e[a],c=getForgoState(l);if(c&&c.components.length>d){if(n.key){if(c.components[d].key===n.key)return{found:!0,index:a}}else if(c.components[d].ctor===n.type)return{found:!0,index:a}}}return{found:!1}}function oe(n,e,o,t){var a;const d=[];for(const l of t)d.push(l.component.afterRender?l.args.element.node:void 0),l.args.element.node=e;if(D(n)){const l=getForgoState(e);if(l&&l.props)for(const p in l.props)p in n.props||p!=="children"&&p!=="xmlns"&&(e.nodeType===L||e instanceof s.__internal.HTMLElement&&p in e?delete e[p]:e.removeAttribute(p));else if(!o&&z(e)&&e.hasAttributes()){const p=Array.from(e.attributes);for(const u of p){const f=u.name;f in n.props||e.removeAttribute(f)}}const c=Object.entries(n.props);for(const[p,u]of c)if(((a=l==null?void 0:l.props)==null?void 0:a[p])!==u&&p!=="children"&&p!=="xmlns")if(e.nodeType===L)e[p]=u;else if(e instanceof s.__internal.HTMLElement)if(p==="style"){if(l===void 0||l.style===void 0||l.style!==n.props.style){const f=Ce(n.props.style);e.style.cssText!==f&&(e.style.cssText=f)}}else p==="onblur"?e[p]=he(e,u):p in e?e[p]=u:e.setAttribute(p,u);else typeof u=="string"?e.setAttribute(p,u):e[p]=u;const m={key:n.key,props:n.props,components:t};setForgoState(e,m)}else setForgoState(e,{components:t})}function te(n,e){let o=Fe(e)?s.document.querySelector(e):e;if(o)if(o.nodeType===V){const t=o.childNodes.length>0,d=i(n,{type:"search",currentNodeIndex:0,length:o.childNodes.length,parentElement:o},[],t);if(d.nodes.length<o.childNodes.length){const a=P(o.childNodes,d.nodes.length,o.childNodes.length);for(const l of a)l.remove()}return d}else throw new Error("The container argument to the mount() function should be an HTML element.");else throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`)}function re(n){const e=i(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function G(n,e){if(n&&n.node){const o=n.node.parentElement;if(o!==null){const t=getForgoState(n.node);if(t){const d=t.components[n.componentIndex],a=e!==void 0?e:d.props;if(!d.component.shouldUpdate||d.component.shouldUpdate(a,d.props)){const l=E(R({},d),{props:a}),c=t.components.slice(0,n.componentIndex),m=c.concat(l),p=d.args.element.node,u=d.component.render(a,d.args);let f=B(o.childNodes,n.node);const y={type:"search",currentNodeIndex:f,length:d.nodes.length,parentElement:o},N=I(u,y,m,l,!1);for(let F=0;F<c.length;F++){const g=c[F],x=g.nodes.findIndex(k=>k===d.nodes[0]);if(g.nodes=g.nodes.slice(0,x).concat(N.nodes).concat(g.nodes.slice(x+d.nodes.length)),g.nodes.length===0){v(c,F);break}else g.args.element.node=g.nodes[0]}return N.nodes.length===0&&v([l],0),d.component.afterRender&&d.component.afterRender(a,E(R({},d.args),{previousNode:p})),N}else{let l=B(o.childNodes,n.node);return{nodes:P(o.childNodes,l,l+d.nodes.length)}}}else throw new Error("Missing forgo state on node.")}else throw new Error("The rerender() function was called on a node without a parent element.")}else throw new Error("Missing node information in rerender() argument.")}function de(n,e){var t;const o=((t=n.props.xmlns)!=null?t:n.type==="svg")?ge:e&&e.namespaceURI;return n.props.is?o?s.document.createElementNS(o,n.type,{is:n.props.is}):s.document.createElement(n.type,{is:n.props.is}):o?s.document.createElementNS(o,n.type):s.document.createElement(n.type)}return{mount:te,render:re,rerender:G}}const W=globalThis||window;let M=createForgoInstance({window:W,document:W.document});export function setCustomEnv(r){M=createForgoInstance(r)}export function mount(r,s){return M.mount(r,s)}export function render(r){return M.render(r)}export function rerender(r,s){return M.rerender(r,s)}function S(r){function s(i,C=[]){const T=Array.isArray(i)?i:H(i)?Array.isArray(i.props.children)?i.props.children:i.props.children!==void 0&&i.props.children!==null?[i.props.children]:[]:[i];for(const A of T)Array.isArray(A)||H(A)?s(A,C):C.push(A);return C}return s(r,[])}function $(r){return r.toString()}function D(r){return r!=null&&r.__is_forgo_element__===!0}function Ne(r){return D(r)&&typeof r.type=="string"}function H(r){return r!=null&&r.type===Fragment}export function getForgoState(r){return r.__forgo}function Z(r){if(r.__forgo)return r.__forgo;throw new Error("Missing state in node.")}export function setForgoState(r,s){r.__forgo=s}function ye(r,s){if(!s.render)throw new Error(`${r.name||"Unnamed"} component constructor must return an object having a render() function.`)}function Fe(r){return typeof r=="string"}function z(r){return r.nodeType===V}function Ce(r){return typeof r=="string"?r:r==null?"":Object.keys(r).reduce((s,i)=>s+i.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+r[i]+";","")}function P(r,s,i){const C=[];for(let T=s;T<i;T++)C.push(r[T]);return C}function B(r,s){for(let i=0;i<r.length;i++)if(r[i]===s)return i;return-1}import{JSXTypes as K}from"./jsxTypes";export const JSX=K;(function(s){s.JSX=K})(createElement||(createElement={})); | ||
var ae=Object.defineProperty,pe=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var Y=(r,l,i)=>l in r?ae(r,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[l]=i,R=(r,l)=>{for(var i in l||(l={}))ie.call(l,i)&&Y(r,i,l[i]);if(W)for(var i of W(l))ue.call(l,i)&&Y(r,i,l[i]);return r},E=(r,l)=>pe(r,ce(l));export const Fragment=Symbol.for("FORGO_FRAGMENT");const Ce="http://www.w3.org/1999/xhtml",xe="http://www.w3.org/1998/Math/MathML",me="http://www.w3.org/2000/svg",q=1,Te=2,k=3;export function createElement(r,l){var C;l=l!=null?l:{},l.children=arguments.length>3?S(Array.from(arguments).slice(2)):arguments.length===3?S(arguments[2]):void 0;const i=(C=l.key)!=null?C:void 0;return{type:r,props:l,key:i,__is_forgo_element__:!0}}export const h=createElement;function fe(r,l){return i=>{if(!r.__forgo_deleted)return l(i)}}export function createForgoInstance(r){var J;const l=r;l.__internal=(J=l.__internal)!=null?J:{Text:l.window.Text,HTMLElement:l.window.HTMLElement};function i(n,e,o,t){return Array.isArray(n)?U(n,e,o,t):L(n)?ge(n)?A(n,e,o,t):D(n)?K(n,e,o,t):z(n,e,o,t):n==null?C(n,e,o,t):T(n,e,o,t)}function C(n,e,o,t){return{nodes:[]}}function T(n,e,o,t){var d;if(e.type==="detached"){const p=l.document.createTextNode($(n));return b(n,p,!0,o,void 0),{nodes:[p]}}else{const p=l.document.createTextNode($(n)),s=e.parentElement.childNodes;if(e.length){let c=s[e.currentNodeIndex];if(c.nodeType===k){c.replaceWith(p);const u=(d=getForgoState(c))==null?void 0:d.components;return b(n,p,!0,o,u),{nodes:[p]}}else{const u=s[e.currentNodeIndex];return e.parentElement.insertBefore(p,u),b(n,p,!0,o,void 0),{nodes:[p]}}}else{const c=e.parentElement.childNodes;if(c.length===0||e.currentNodeIndex===0)e.parentElement.prepend(p);else{const u=c[e.currentNodeIndex];e.parentElement.insertBefore(p,u)}return b(n,p,!0,o,void 0),{nodes:[p]}}}}function A(n,e,o,t){if(e.type==="detached")return s(void 0,null);{const c=e.parentElement.childNodes;if(e.length){const u=Q(n,c,e.currentNodeIndex,e.length);return u.found?p(u.index,c,e):s(e.parentElement,c[e.currentNodeIndex])}else return s(e.parentElement,c[e.currentNodeIndex])}function d(c){if(n.props.dangerouslySetInnerHTML)c.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{const u=n.props.children,a=S((Array.isArray(u)?u:[u]).filter(y=>y!=null));let m=0;for(const y of a){const{nodes:N}=i(y,{type:"search",parentElement:c,currentNodeIndex:m,length:c.childNodes.length-m},[],t);m+=N.length}const f=P(c.childNodes,m,c.childNodes.length);f.length&&_(f,[])}}function p(c,u,a){var N;const m=P(u,a.currentNodeIndex,c);_(m,o);const f=u[a.currentNodeIndex];d(f);const y=(N=getForgoState(f))==null?void 0:N.components;return b(n,f,!1,o,y),{nodes:[f]}}function s(c,u){const a=te(n,c);return c&&c.insertBefore(a,u),n.props.ref&&(n.props.ref.value=a),d(a),b(n,a,!0,o,void 0),{nodes:[a]}}}function z(n,e,o,t){const d=o.length;if(e.type==="detached")return s();if(e.length){if(t)return s();{const u=e.parentElement.childNodes,a=O(n,u,e.currentNodeIndex,e.length,o.length);return a.found?p(a.index,u,e):s()}}else return s();function p(u,a,m){const f=a[u],N=H(f).components[d],F=P(a,m.currentNodeIndex,u);if(_(F,o.concat(N)),!N.component.shouldUpdate||N.component.shouldUpdate(n.props,N.props)){const g=E(R({},N),{props:n.props}),x=g.component.render(n.props,g.args),w=o.concat(g),re=N.args.element.node,de=g.component.error?g.component:void 0,se=c(n.props,g.args,w,de,()=>{const le={type:"search",currentNodeIndex:m.currentNodeIndex,length:g.nodes.length,parentElement:m.parentElement};return I(x,le,w,g,t)});return g.component.afterRender&&g.component.afterRender(n.props,E(R({},g.args),{previousNode:re})),se}else{let g=B(m.parentElement.childNodes,N.args.element.node);return{nodes:P(m.parentElement.childNodes,g,g+N.nodes.length)}}}function s(){const u={element:{componentIndex:d},update:F=>G(u.element,F)},a=n.type,m=a(n.props,{environment:l});he(a,m);const f=m.error?m:void 0,y={key:n.key,ctor:a,component:m,props:n.props,args:u,nodes:[],isMounted:!1},N=o.concat(y);return c(n.props,u,N,f,()=>{const F=m.render(n.props,u),g=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:t?e.length:0,parentElement:e.parentElement},x=i(F,g,N,t);return y.nodes=x.nodes,x.nodes.length>1&&(y.args.element.node=x.nodes[0]),m.afterRender&&m.afterRender(n.props,u),x})}function c(u,a,m,f,y){try{return y()}catch(N){if(f&&f.error){const F=E(R({},a),{error:N}),g=f.error(u,F);return i(g,e,m,t)}else throw N}}}function I(n,e,o,t,d){const p=e.parentElement.childNodes.length,s=i(n,e,o,d),c=e.parentElement.childNodes.length,u=p+s.nodes.length-c,a=e.currentNodeIndex+s.nodes.length,m=P(e.parentElement.childNodes,a,a+t.nodes.length-u),f=s.nodes.length>0?o:[];return _(m,f),t.nodes=s.nodes,s.nodes.length>1&&(t.args.element.node=s.nodes[0]),s}function U(n,e,o,t){const d=S(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let p=[],s=e.currentNodeIndex,c=e.length;for(const u of d){const a=e.parentElement.childNodes.length,m=E(R({},e),{currentNodeIndex:s,length:c}),{nodes:f}=i(u,m,o,t);p=p.concat(f);const y=e.parentElement.childNodes.length,N=a+f.length-y;s+=f.length,c-=N}return{nodes:p}}}function K(n,e,o,t){return U(S(n),e,o,t)}function b(n,e,o,t,d){if(ee(n,e,o,t),d){const p=j(t,d);M(d,p),X(t,p)}else X(t,0)}function _(n,e){for(const o of n){const t=getForgoState(o);if(o.__forgo_deleted=!0,o.remove(),t){const d=t.components,p=j(e,d);M(t.components,p)}}}function j(n,e){let o=0;for(const t of n)if(e.length>o){if(e[o].component!==t.component)break;o++}else break;return o}function M(n,e){let o=!1;for(let t=e;t<n.length;t++){const d=n[t];d.component.unmount&&(o||d.nodes.every(p=>{if(p.isConnected){const s=H(p);return!s.components[t]||s.components[t].component!==d.component}else return!0}))&&(d.component.unmount(d.props,d.args),o=!0)}}function X(n,e){for(let o=e;o<n.length;o++){const t=n[o];t.component.mount&&!t.isMounted&&(t.isMounted=!0,t.component.mount(t.props,t.args))}}function Q(n,e,o,t){for(let d=o;d<o+t;d++){const p=e[d];if(Z(p)){const s=getForgoState(p);if(n.key){if((s==null?void 0:s.key)===n.key)return{found:!0,index:d}}else if(p.tagName.toLowerCase()===n.type&&(!s||!s.key))return{found:!0,index:d}}}return{found:!1}}function O(n,e,o,t,d){for(let p=o;p<o+t;p++){const s=e[p],c=getForgoState(s);if(c&&c.components.length>d){if(n.key){if(c.components[d].key===n.key)return{found:!0,index:p}}else if(c.components[d].ctor===n.type)return{found:!0,index:p}}}return{found:!1}}function ee(n,e,o,t){var p;const d=[];for(const s of t)d.push(s.component.afterRender?s.args.element.node:void 0),s.args.element.node=e;if(L(n)){const s=getForgoState(e);if(s&&s.props)for(const a in s.props)a in n.props||a!=="children"&&a!=="xmlns"&&(e.nodeType===k||e instanceof l.__internal.HTMLElement&&a in e?delete e[a]:e.removeAttribute(a));else if(!o&&Z(e)&&e.hasAttributes()){const a=Array.from(e.attributes);for(const m of a){const f=m.name;f in n.props||e.removeAttribute(f)}}const c=Object.entries(n.props);for(const[a,m]of c)if(((p=s==null?void 0:s.props)==null?void 0:p[a])!==m&&a!=="children"&&a!=="xmlns")if(e.nodeType===k)e[a]=m;else if(e instanceof l.__internal.HTMLElement)if(a==="style"){if(s===void 0||s.style===void 0||s.style!==n.props.style){const f=ye(n.props.style);e.style.cssText!==f&&(e.style.cssText=f)}}else a==="onblur"?e[a]=fe(e,m):a in e?e[a]=m:e.setAttribute(a,m);else typeof m=="string"?e.setAttribute(a,m):e[a]=m;const u={key:n.key,props:n.props,components:t};setForgoState(e,u)}else setForgoState(e,{components:t})}function ne(n,e){let o=Ne(e)?l.document.querySelector(e):e;if(o)if(o.nodeType===q){const t=o.childNodes.length>0,d=i(n,{type:"search",currentNodeIndex:0,length:o.childNodes.length,parentElement:o},[],t);if(d.nodes.length<o.childNodes.length){const p=P(o.childNodes,d.nodes.length,o.childNodes.length);for(const s of p)s.remove()}return d}else throw new Error("The container argument to the mount() function should be an HTML element.");else throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`)}function oe(n){const e=i(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function G(n,e){if(n&&n.node){const o=n.node.parentElement;if(o!==null){const t=H(n.node),d=t.components[n.componentIndex],p=e!==void 0?e:d.props;if(!d.component.shouldUpdate||d.component.shouldUpdate(p,d.props)){const s=E(R({},d),{props:p}),c=t.components.slice(0,n.componentIndex),u=c.concat(s),a=d.args.element.node,m=d.component.render(p,d.args);let f=B(o.childNodes,n.node);const y={type:"search",currentNodeIndex:f,length:d.nodes.length,parentElement:o},N=I(m,y,u,s,!1);for(let F=0;F<c.length;F++){const g=c[F],x=g.nodes.findIndex(w=>w===d.nodes[0]);if(g.nodes=g.nodes.slice(0,x).concat(N.nodes).concat(g.nodes.slice(x+d.nodes.length)),g.nodes.length===0){M(c,F);break}else g.args.element.node=g.nodes[0]}return d.component.afterRender&&d.component.afterRender(p,E(R({},d.args),{previousNode:a})),N}else{let s=B(o.childNodes,n.node);return{nodes:P(o.childNodes,s,s+d.nodes.length)}}}else throw new Error("The rerender() function was called on a detached node.")}else throw new Error("Missing node information in rerender() argument.")}function te(n,e){var t;const o=((t=n.props.xmlns)!=null?t:n.type==="svg")?me:e&&e.namespaceURI;return n.props.is?o?l.document.createElementNS(o,n.type,{is:n.props.is}):l.document.createElement(n.type,{is:n.props.is}):o?l.document.createElementNS(o,n.type):l.document.createElement(n.type)}return{mount:ne,render:oe,rerender:G}}const V=globalThis||window;let v=createForgoInstance({window:V,document:V.document});export function setCustomEnv(r){v=createForgoInstance(r)}export function mount(r,l){return v.mount(r,l)}export function render(r){return v.render(r)}export function rerender(r,l){return v.rerender(r,l)}function S(r){function l(i,C=[]){const T=Array.isArray(i)?i:D(i)?Array.isArray(i.props.children)?i.props.children:i.props.children!==void 0&&i.props.children!==null?[i.props.children]:[]:[i];for(const A of T)Array.isArray(A)||D(A)?l(A,C):C.push(A);return C}return l(r,[])}function $(r){return r.toString()}function L(r){return r!=null&&r.__is_forgo_element__===!0}function ge(r){return L(r)&&typeof r.type=="string"}function D(r){return r!=null&&r.type===Fragment}export function getForgoState(r){return r.__forgo}function H(r){if(r.__forgo)return r.__forgo;throw new Error("Missing forgo state on node.")}export function setForgoState(r,l){r.__forgo=l}function he(r,l){if(!l.render)throw new Error(`${r.name||"Unnamed"} component constructor must return an object having a render() function.`)}function Ne(r){return typeof r=="string"}function Z(r){return r.nodeType===q}function ye(r){return typeof r=="string"?r:r==null?"":Object.keys(r).reduce((l,i)=>l+i.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+r[i]+";","")}function P(r,l,i){const C=[];for(let T=l;T<i;T++)C.push(r[T]);return C}function B(r,l){for(let i=0;i<r.length;i++)if(r[i]===l)return i;return-1}export{}; | ||
//# sourceMappingURL=forgo.min.js.map |
@@ -143,3 +143,3 @@ export declare type ForgoRef<T> = { | ||
export declare function setForgoState(node: ChildNode, state: NodeAttachedState): void; | ||
import { JSXTypes } from "./jsxTypes"; | ||
import type { JSXTypes } from "./jsxTypes"; | ||
declare global { | ||
@@ -151,5 +151,2 @@ interface ChildNode { | ||
} | ||
export import JSX = JSXTypes; | ||
export declare namespace createElement { | ||
export import JSX = JSXTypes; | ||
} | ||
export { JSXTypes as JSX }; |
{ | ||
"name": "forgo", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"main": "./dist/index.js", | ||
@@ -13,24 +13,25 @@ "type": "module", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./jsx-dev-runtime": "./jsx-dev-runtime.js", | ||
"./jsx-runtime": "./jsx-runtime.js", | ||
"./": "./" | ||
".": { | ||
"import": "./dist/forgo.min.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@types/jsdom": "^16.2.13", | ||
"@types/mocha": "^8.2.3", | ||
"@types/jsdom": "^16.2.14", | ||
"@types/mocha": "^9.1.0", | ||
"@types/should": "^13.0.0", | ||
"esbuild": "^0.12.21", | ||
"jsdom": "^16.7.0", | ||
"mocha": "^9.0.3", | ||
"esbuild": "^0.14.12", | ||
"jsdom": "^19.0.0", | ||
"mocha": "^9.1.4", | ||
"rimraf": "^3.0.2", | ||
"should": "^13.2.3", | ||
"typescript": "^4.3.5" | ||
"typescript": "^4.5.5" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf ./dist", | ||
"build": "npm run clean && mkdir -p dist && npx tsc && npx esbuild src/index.ts --minify --sourcemap --target=es2015 --outfile=dist/forgo.min.js", | ||
"test": "npx mocha dist/test/test.js" | ||
"build": "npm run clean && mkdir -p dist && npx tsc --emitDeclarationOnly && npx esbuild src/index.ts --minify --sourcemap --target=es2015 --outfile=dist/forgo.min.js", | ||
"build-dev": "npx tsc", | ||
"test": "npx tsc && npx mocha dist/test/test.js" | ||
}, | ||
"license": "MIT" | ||
} |
235
src/index.ts
@@ -562,3 +562,2 @@ /* | ||
if (nodesToRemove.length) { | ||
removeNodes(nodesToRemove); | ||
unloadNodes(nodesToRemove, []); | ||
@@ -580,3 +579,2 @@ } | ||
); | ||
removeNodes(nodesToRemove); | ||
unloadNodes(nodesToRemove, pendingAttachStates); | ||
@@ -698,3 +696,2 @@ | ||
); | ||
removeNodes(nodesToRemove); | ||
unloadNodes(nodesToRemove, pendingAttachStates.concat(componentState)); | ||
@@ -716,2 +713,8 @@ | ||
// Get a new element by calling render on existing component. | ||
const newForgoNode = updatedComponentState.component.render( | ||
forgoElement.props, | ||
updatedComponentState.args | ||
); | ||
const statesToAttach = pendingAttachStates.concat( | ||
@@ -723,8 +726,2 @@ updatedComponentState | ||
// Get a new element by calling render on existing component. | ||
const newForgoNode = updatedComponentState.component.render( | ||
forgoElement.props, | ||
updatedComponentState.args | ||
); | ||
const boundary = updatedComponentState.component.error | ||
@@ -917,5 +914,8 @@ ? updatedComponentState.component | ||
); | ||
removeNodes(nodesToRemove); | ||
unloadNodes(nodesToRemove, statesToAttach); | ||
// If renderResult returned no nodes (ie, null or undefined), then all state will be discarded. | ||
const statesThatWillBeAttached = | ||
renderResult.nodes.length > 0 ? statesToAttach : []; | ||
unloadNodes(nodesToRemove, statesThatWillBeAttached); | ||
// In case we rendered an array, set the node to the first node. | ||
@@ -1027,13 +1027,2 @@ // We do this because args.element.node would be set to the last node otherwise. | ||
/* | ||
Remove node from the tree. | ||
Components mounted on it are not unloaded yet - since it may be reattached. | ||
*/ | ||
function removeNodes(nodes: ChildNode[]) { | ||
// for (const node of nodes) { | ||
// node.__forgo_deleted = true; | ||
// node.remove(); | ||
// } | ||
} | ||
/* | ||
@@ -1437,124 +1426,116 @@ Unmount components from nodes. | ||
if (parentElement !== null) { | ||
const state = getForgoState(element.node); | ||
if (state) { | ||
const originalComponentState = | ||
state.components[element.componentIndex]; | ||
const state = getExistingForgoState(element.node); | ||
const effectiveProps = | ||
props !== undefined ? props : originalComponentState.props; | ||
const originalComponentState = state.components[element.componentIndex]; | ||
if ( | ||
!originalComponentState.component.shouldUpdate || | ||
originalComponentState.component.shouldUpdate( | ||
effectiveProps, | ||
originalComponentState.props | ||
) | ||
) { | ||
const newComponentState = { | ||
...originalComponentState, | ||
props: effectiveProps, | ||
}; | ||
const effectiveProps = | ||
props !== undefined ? props : originalComponentState.props; | ||
const parentStates = state.components.slice( | ||
0, | ||
element.componentIndex | ||
); | ||
if ( | ||
!originalComponentState.component.shouldUpdate || | ||
originalComponentState.component.shouldUpdate( | ||
effectiveProps, | ||
originalComponentState.props | ||
) | ||
) { | ||
const newComponentState = { | ||
...originalComponentState, | ||
props: effectiveProps, | ||
}; | ||
const statesToAttach = parentStates.concat(newComponentState); | ||
const parentStates = state.components.slice( | ||
0, | ||
element.componentIndex | ||
); | ||
const previousNode = originalComponentState.args.element.node; | ||
const statesToAttach = parentStates.concat(newComponentState); | ||
const forgoNode = originalComponentState.component.render( | ||
effectiveProps, | ||
originalComponentState.args | ||
); | ||
const previousNode = originalComponentState.args.element.node; | ||
let nodeIndex = findNodeIndex( | ||
parentElement.childNodes, | ||
element.node | ||
); | ||
const forgoNode = originalComponentState.component.render( | ||
effectiveProps, | ||
originalComponentState.args | ||
); | ||
const insertionOptions: SearchableNodeInsertionOptions = { | ||
type: "search", | ||
currentNodeIndex: nodeIndex, | ||
length: originalComponentState.nodes.length, | ||
parentElement, | ||
}; | ||
let nodeIndex = findNodeIndex(parentElement.childNodes, element.node); | ||
const renderResult = renderComponentAndRemoveStaleNodes( | ||
forgoNode, | ||
insertionOptions, | ||
statesToAttach, | ||
newComponentState, | ||
false | ||
); | ||
const insertionOptions: SearchableNodeInsertionOptions = { | ||
type: "search", | ||
currentNodeIndex: nodeIndex, | ||
length: originalComponentState.nodes.length, | ||
parentElement, | ||
}; | ||
// We have to propagate node changes up the tree. | ||
for (let i = 0; i < parentStates.length; i++) { | ||
const parentState = parentStates[i]; | ||
const renderResult = renderComponentAndRemoveStaleNodes( | ||
forgoNode, | ||
insertionOptions, | ||
statesToAttach, | ||
newComponentState, | ||
false | ||
); | ||
const indexOfOriginalRootNode = parentState.nodes.findIndex( | ||
(x) => x === originalComponentState.nodes[0] | ||
); | ||
// We have to propagate node changes up the tree. | ||
for (let i = 0; i < parentStates.length; i++) { | ||
const parentState = parentStates[i]; | ||
// Let's recreate the node list. | ||
parentState.nodes = parentState.nodes | ||
// 1. all the nodes before first node associated with rendered component. | ||
.slice(0, indexOfOriginalRootNode) | ||
// 2. newly created nodes. | ||
.concat(renderResult.nodes) | ||
// 3. nodes after last node associated with rendered component. | ||
.concat( | ||
parentState.nodes.slice( | ||
indexOfOriginalRootNode + | ||
originalComponentState.nodes.length | ||
) | ||
); | ||
const indexOfOriginalRootNode = parentState.nodes.findIndex( | ||
(x) => x === originalComponentState.nodes[0] | ||
); | ||
// If there are no nodes, call unmount on it (and child states) | ||
if (parentState.nodes.length === 0) { | ||
unmountComponents(parentStates, i); | ||
break; | ||
} else { | ||
// The root node might have changed, so fix it up anyway. | ||
parentState.args.element.node = parentState.nodes[0]; | ||
} | ||
} | ||
// Let's recreate the node list. | ||
parentState.nodes = parentState.nodes | ||
// 1. all the nodes before first node associated with rendered component. | ||
.slice(0, indexOfOriginalRootNode) | ||
// 2. newly created nodes. | ||
.concat(renderResult.nodes) | ||
// 3. nodes after last node associated with rendered component. | ||
.concat( | ||
parentState.nodes.slice( | ||
indexOfOriginalRootNode + originalComponentState.nodes.length | ||
) | ||
); | ||
// Unmount rendered component itself if all nodes are gone. | ||
if (renderResult.nodes.length === 0) { | ||
unmountComponents([newComponentState], 0); | ||
// If there are no nodes, call unmount on it (and child states) | ||
if (parentState.nodes.length === 0) { | ||
unmountComponents(parentStates, i); | ||
break; | ||
} else { | ||
// The root node might have changed, so fix it up anyway. | ||
parentState.args.element.node = parentState.nodes[0]; | ||
} | ||
} | ||
// Run afterRender() if defined. | ||
if (originalComponentState.component.afterRender) { | ||
originalComponentState.component.afterRender(effectiveProps, { | ||
...originalComponentState.args, | ||
previousNode, | ||
}); | ||
} | ||
// Unmount rendered component itself if all nodes are gone. | ||
// if (renderResult.nodes.length === 0) { | ||
// unmountComponents([newComponentState], 0); | ||
// } | ||
return renderResult; | ||
// Run afterRender() if defined. | ||
if (originalComponentState.component.afterRender) { | ||
originalComponentState.component.afterRender(effectiveProps, { | ||
...originalComponentState.args, | ||
previousNode, | ||
}); | ||
} | ||
// shouldUpdate() returned false | ||
else { | ||
let indexOfNode = findNodeIndex( | ||
parentElement.childNodes, | ||
element.node | ||
); | ||
return { | ||
nodes: sliceNodes( | ||
parentElement.childNodes, | ||
indexOfNode, | ||
indexOfNode + originalComponentState.nodes.length | ||
), | ||
}; | ||
} | ||
} else { | ||
throw new Error(`Missing forgo state on node.`); | ||
return renderResult; | ||
} | ||
// shouldUpdate() returned false | ||
else { | ||
let indexOfNode = findNodeIndex( | ||
parentElement.childNodes, | ||
element.node | ||
); | ||
return { | ||
nodes: sliceNodes( | ||
parentElement.childNodes, | ||
indexOfNode, | ||
indexOfNode + originalComponentState.nodes.length | ||
), | ||
}; | ||
} | ||
} else { | ||
throw new Error( | ||
`The rerender() function was called on a node without a parent element.` | ||
`The rerender() function was called on a detached node.` | ||
); | ||
@@ -1702,3 +1683,3 @@ } | ||
} else { | ||
throw new Error("Missing state in node."); | ||
throw new Error("Missing forgo state on node."); | ||
} | ||
@@ -1787,3 +1768,3 @@ } | ||
/* JSX Types */ | ||
import { JSXTypes } from "./jsxTypes"; | ||
import type { JSXTypes } from "./jsxTypes"; | ||
@@ -1797,6 +1778,2 @@ declare global { | ||
export import JSX = JSXTypes; | ||
export namespace createElement { | ||
export import JSX = JSXTypes; | ||
} | ||
export { JSXTypes as JSX }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
212970
12
3320