Comparing version 3.2.1 to 3.2.2
@@ -0,7 +1,11 @@ | ||
# 3.2.2 | ||
- Fix #76: Add support for TypeScript 4.8 | ||
# 3.2.1 | ||
- Feature #73: Add a function to unmount a component tree from outside the Forgo | ||
- Fix #50: Components that returned a fragment saw their `mount` lifecycle | ||
method called after the first child element had been created instead of after | ||
the render had completed. | ||
- Fix a bug where calling `component.update()` during a mount lifecycle handler | ||
- Fix #70: Calling `component.update()` during a mount lifecycle handler | ||
resulted in the component recursively mounting ad infinitum. | ||
@@ -8,0 +12,0 @@ - Fix #75: ESLint plugin `eslint-plugin-import` could not resolve imports of Forgo |
@@ -1,2 +0,2 @@ | ||
var ce=Object.defineProperty,fe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var he=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var $=(t,r,p)=>r in t?ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):t[r]=p,F=(t,r)=>{for(var p in r||(r={}))he.call(r,p)&&$(t,p,r[p]);if(J)for(var p of J(r))Te.call(r,p)&&$(t,p,r[p]);return t},k=(t,r)=>fe(t,be(r));var A={};var ye=["ref","dangerouslySetInnerHTML"],ve=Symbol.for("FORGO_FRAGMENT");var Ee="http://www.w3.org/2000/svg",W=1,O=3,z=8,N={mount(t,r){t.__internal.eventListeners.mount.forEach(p=>p(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(p=>p(r,t))},shouldUpdate(t,r,p){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(b=>b(r,p,t)).some(Boolean)},afterRender(t,r,p){t.__internal.eventListeners.afterRender.forEach(b=>b(r,p,t))}},w=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1}}}update(r){return Ne(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}unmount(r){this.__internal.eventListeners.unmount.push(r)}shouldUpdate(r){this.__internal.eventListeners.shouldUpdate.push(r)}afterRender(r){this.__internal.eventListeners.afterRender.push(r)}};function I(t,r){var b;r=r!=null?r:{},r.children=arguments.length>3?_(Array.from(arguments).slice(2)):arguments.length===3?_(arguments[2]):void 0;let p=(b=r.key)!=null?b:void 0;return{type:t,props:r,key:p,__is_forgo_element__:!0}}var Ae=I;function xe(t,r){return p=>{var b;if(!((b=t.__forgo)!=null&&b.deleted))return r(p)}}function te(t){var K;let r=t;r.__internal=(K=r.__internal)!=null?K:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function p(n,e,o,l){if(Array.isArray(n)||V(n))return re(_(n),e,o,l);if(X(n)){if(Pe(n))return y(n,e,o,l);{let d=v(n,e,o,l);return d.pendingMounts.forEach(g=>g()),d.pendingMounts.length=0,d}}else return b(n,e,o)}function b(n,e,o){var g;let l;n==null?l=r.document.createComment("null component render"):l=r.document.createTextNode(Ce(n));let d;if(e.type==="search"){let m=e.parentElement.childNodes;if(e.length){let s=m[e.currentNodeIndex];if(s.nodeType===O||s.nodeType===z)s.replaceWith(l),d=(g=x(s))==null?void 0:g.components;else{let i=m[e.currentNodeIndex];e.parentElement.insertBefore(l,i)}}else if(m.length===0||e.currentNodeIndex===0)e.parentElement.prepend(l);else{let s=m[e.currentNodeIndex];e.parentElement.insertBefore(l,s)}}return U(n,l,!0,o),R(o,d),{nodes:[l],pendingMounts:[()=>G(o,d)]}}function y(n,e,o,l){if(e.type==="detached")return m(void 0,null);{let s=e.parentElement.childNodes;if(e.length){let i=oe(n,e.parentElement,e.currentNodeIndex,e.length);if(i.found)return g(i.index,s,e)}return m(e.parentElement,s[e.currentNodeIndex])}function d(s){if(n.props.dangerouslySetInnerHTML)s.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{let i=_([n.props.children]).filter(c=>c!=null),a=Array.from(s.childNodes).findIndex(c=>x(c)),u=a===-1?0:a;for(let c of i){let{nodes:f}=p(c,{type:"search",parentElement:s,currentNodeIndex:u,length:s.childNodes.length-u},[],l);if(f.length){for(;s.childNodes[u]!==f[f.length-1];)u+=1;for(u+=1;u<s.childNodes.length&&!x(s.childNodes[u]);)u+=1}}C(s.childNodes,u,s.childNodes.length)}}function g(s,i,a){var f;C(i,a.currentNodeIndex,s);let u=i[a.currentNodeIndex],c=(f=x(u))==null?void 0:f.components;return U(n,u,!1,o),d(u),L(u,o),R(o,c),{nodes:[u],pendingMounts:[()=>G(o,c)]}}function m(s,i){let a=ge(n,s);return s&&s.insertBefore(a,i),n.props.ref&&(n.props.ref.value=a),U(n,a,!0,o),d(a),R(o,void 0),{nodes:[a],pendingMounts:[()=>G(o,void 0)]}}}function v(n,e,o,l){let d=o.length;if(e.type!=="detached"&&e.length&&!l){let i=e.parentElement.childNodes,a=se(n,e.parentElement,e.currentNodeIndex,e.length,o.length);if(a.found)return g(a.index,i,e)}return m();function g(i,a,u){let c=a[i],h=j(c).components[d];if(C(a,u.currentNodeIndex,i),N.shouldUpdate(h.component,n.props,h.props)){let T=k(F({},h),{props:n.props}),E=T.component.__internal.registeredMethods.render(n.props,T.component),P=o.concat(T),B=h.component.__internal.element.node,ue=T.component.__internal.registeredMethods.error?T.component:void 0,pe=s(n.props,P,ue,()=>{let me={type:"search",currentNodeIndex:u.currentNodeIndex,length:T.nodes.length,parentElement:u.parentElement};return Y(E,me,P,T,l)});return N.afterRender(T.component,n.props,B),pe}else{let T=q(u.parentElement.childNodes,h.component.__internal.element.node);return{nodes:S(u.parentElement.childNodes,T,T+h.nodes.length),pendingMounts:[]}}}function m(){let i=n.type,a=He(i,i(n.props),r.window.FORGO_NO_LEGACY_WARN!==!0);a.__internal.element.componentIndex=d;let u=a.__internal.registeredMethods.error?a:void 0,c={key:n.key,ctor:i,component:a,props:n.props,nodes:[],isMounted:!1},f=o.concat(c);return s(n.props,f,u,()=>{let h=a.__internal.registeredMethods.render(n.props,a),T=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:l?e.length:0,parentElement:e.parentElement},E=p(h,T,f,l);return c.nodes=E.nodes,c.component.__internal.element.node=E.nodes[0],N.afterRender(a,n.props,void 0),E})}function s(i,a,u,c){try{return c()}catch(f){if(u!=null&&u.__internal.registeredMethods.error){let h=u.__internal.registeredMethods.error(i,f,u);return p(h,e,a,l)}else throw f}}}function Y(n,e,o,l,d){let g=e.parentElement.childNodes.length,m=p(n,e,o,d),s=e.parentElement.childNodes.length,i=g+m.nodes.length-s,a=e.currentNodeIndex+m.nodes.length,u=C(e.parentElement.childNodes,a,a+l.nodes.length-i),c=m.nodes.length>0?o:[];for(let f of u){let h=x(f);if(h){let T=D(c,h.components);h.components=h.components.slice(T)}}return l.nodes=m.nodes,l.component.__internal.element.node=m.nodes[0],m}function re(n,e,o,l){let d=_(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let g={nodes:[],pendingMounts:[]},m=e.currentNodeIndex,s=e.length;for(let i of d){let a=e.parentElement.childNodes.length,u=k(F({},e),{currentNodeIndex:m,length:s}),c=p(i,u,o,l);g.nodes.push(...c.nodes),g.pendingMounts.push(...c.pendingMounts);let f=e.parentElement.childNodes.length,h=a+c.nodes.length-f;m+=c.nodes.length,s-=h}return g}}function C(n,e,o){let l=[],d=S(n,e,o);if(d.length){let g=d[0].parentElement,m=M(g);for(let s of d)!x(s)||(s.remove(),l.push(s),m.push({node:s}))}return l}function L(n,e){let o=M(n);for(let{node:l}of o){let d=x(l);if(d){d.deleted=!0;let g=d.components;R(e,g)}}Fe(n)}function D(n,e){let o=0;for(let l of n)if(e.length>o){if(e[o].component!==l.component)break;o++}else break;return o}function R(n,e){if(!e)return;let o=!1,l=D(n,e);for(let d=l;d<e.length;d++){let g=e[d],m=g.component;(o||g.nodes.every(s=>{if(s.isConnected){let i=j(s);return!i.components[d]||i.components[d].component!==g.component}else return!0}))&&(m.__internal.unmounted||(m.__internal.unmounted=!0,N.unmount(m,g.props)),o=!0)}}function G(n,e){let o=e?D(n,e):0;for(let l=o;l<n.length;l++){let d=n[l];d.isMounted||(d.isMounted=!0,N.mount(d.component,d.props))}}function oe(n,e,o,l){let d=e.childNodes;for(let g=o;g<o+l;g++){let m=d[g];if(ne(m)){let s=x(m);if(!s)continue;if(n.key!==void 0&&(s==null?void 0:s.key)===n.key)return{found:!0,index:g};if(m.tagName.toLowerCase()===n.type&&!(s!=null&&s.key))return{found:!0,index:g}}}if(n.key!==void 0){let g=M(e);for(let m=0;m<g.length;m++){let{node:s}=g[m],i=x(s);if((i==null?void 0:i.key)===n.key){g.splice(m,1);let a=d[o];return a?e.insertBefore(s,a):e.appendChild(s),{found:!0,index:o}}}}return{found:!1}}function se(n,e,o,l,d){let g=e.childNodes;for(let s=o;s<o+l;s++){let i=g[s],a=x(i);if(a&&a.components.length>d){if(n.key!==void 0){if(a.components[d].ctor===n.type&&a.components[d].key===n.key)return{found:!0,index:s}}else if(a.components[d].ctor===n.type)return{found:!0,index:s}}}function m(s,i,a){let u=x(s);return!!(u&&u.components.length>a&&u.components[a].ctor===i.type&&u.components[a].key===i.key)}if(n.key!==void 0){let s=M(e);for(let i=0;i<s.length;i++){let{node:a}=s[i];if(m(a,n,d)){let u=[a];for(let f=i+1;f<s.length;f++){let{node:h}=s[f];m(h,n,d)&&u.push(h)}s.splice(i,u.length);let c=g[o];if(c)for(let f of u)e.insertBefore(f,c);else for(let f of u)e.appendChild(f);return{found:!0,index:o}}}}return{found:!1}}function U(n,e,o,l){var d;if(l.length>0&&(l[l.length-1].component.__internal.element.node=e),X(n)){let g=x(e);if(g&&g.props)for(let i in g.props)i in n.props||i!=="children"&&i!=="xmlns"&&(e.nodeType===O||e.nodeType===z||e instanceof r.__internal.HTMLElement&&i in e?delete e[i]:e.removeAttribute(i));else if(!o&&ne(e)&&e.hasAttributes()){let i=Array.from(e.attributes);for(let a of i){let u=a.name;u in n.props||e.removeAttribute(u)}}let m=Object.entries(n.props);for(let[i,a]of m)if(!ye.includes(i)&&((d=g==null?void 0:g.props)==null?void 0:d[i])!==a&&i!=="children"&&i!=="xmlns")if(e.nodeType===O||e.nodeType===z)e[i]=a;else if(e instanceof r.__internal.HTMLElement)if(i==="style"){if(g===void 0||g.style===void 0||g.style!==n.props.style){let u=Re(n.props.style);e.style.cssText!==u&&(e.style.cssText=u)}}else i==="onblur"?e[i]=xe(e,a):i in e?e[i]=a:e.setAttribute(i,a);else typeof a=="string"?e.setAttribute(i,a):e[i]=a;let s={key:n.key,props:n.props,components:l};Q(e,s)}else Q(e,{components:l})}function ie(n,e){let o=ee(e)?r.document.querySelector(e):e;if(!o)throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(o.nodeType!==W)throw new Error("The container argument to the mount() function should be an HTML element.");let l=o.childNodes.length>0,d=p(n,{type:"search",currentNodeIndex:0,length:o.childNodes.length,parentElement:o},[],l);if(d.nodes.length<o.childNodes.length){let g=S(o.childNodes,d.nodes.length,o.childNodes.length);for(let m of g)m.remove()}return d}function de(n){let e=ee(n)?r.document.querySelector(n):n;if(!e)throw new Error(`The unmount() function was called on a non-element (${typeof n=="string"?n:n==null?void 0:n.tagName}).`);if(e.nodeType!==W)throw new Error("The container argument to the unmount() function should be an HTML element.");C(e.childNodes,0,e.childNodes.length),L(e,[])}function ae(n){let e=p(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function le(n,e){if(!(n!=null&&n.node))throw new Error("Missing node information in rerender() argument.");let o=n.node.parentElement;if(o!==null){let l=j(n.node),d=l.components[n.componentIndex],g=e!=null?e:d.props;if(!N.shouldUpdate(d.component,g,d.props)){let T=q(o.childNodes,n.node);return{nodes:S(o.childNodes,T,T+d.nodes.length),pendingMounts:[]}}let m=k(F({},d),{props:g}),s=l.components.slice(0,n.componentIndex),i=s.concat(m),a=d.component.__internal.element.node,u=d.component.__internal.registeredMethods.render(g,d.component),c=q(o.childNodes,n.node),f={type:"search",currentNodeIndex:c,length:d.nodes.length,parentElement:o},h=Y(u,f,i,m,!1);for(let T=0;T<s.length;T++){let E=s[T],P=E.nodes.findIndex(B=>B===d.nodes[0]);E.nodes=E.nodes.slice(0,P).concat(h.nodes).concat(E.nodes.slice(P+d.nodes.length)),E.nodes.length>0&&(E.component.__internal.element.node=E.nodes[0])}return L(o,h.nodes.length>0?i:[]),N.afterRender(d.component,g,a),h}else return{nodes:[],pendingMounts:[]}}function ge(n,e){var l;let o=((l=n.props.xmlns)!=null?l:n.type==="svg")?Ee:e&&e.namespaceURI;return n.props.is?o?r.document.createElementNS(o,n.type,{is:n.props.is}):r.document.createElement(n.type,{is:n.props.is}):o?r.document.createElementNS(o,n.type):r.document.createElement(n.type)}return{mount:ie,unmount:de,render:ae,rerender:le}}var Z=globalThis||window,H=te({window:Z,document:Z.document});function Me(t){H=te(t)}function Se(t,r){return H.mount(t,r)}function we(t){return H.unmount(t)}function Ie(t){return H.render(t)}function Ne(t,r){return H.rerender(t,r)}function _(t){function r(p,b=[]){let y=Array.isArray(p)?p:V(p)?Array.isArray(p.props.children)?p.props.children:p.props.children!==void 0&&p.props.children!==null?[p.props.children]:[]:[p];for(let v of y)Array.isArray(v)||V(v)?r(v,b):b.push(v);return b}return r(t,[])}function Ce(t){return t.toString()}function X(t){return t!=null&&t.__is_forgo_element__===!0}function Pe(t){return X(t)&&typeof t.type=="string"}function V(t){return t!=null&&t.type===ve}function x(t){return t.__forgo}function j(t){if(t.__forgo)return t.__forgo;throw new Error("Missing forgo state on node.")}function Q(t,r){t.__forgo=r}function M(t){return t.__forgo_deletedNodes||(t.__forgo_deletedNodes=[]),t.__forgo_deletedNodes}function Fe(t){t.__forgo_deletedNodes&&(t.__forgo_deletedNodes=[])}var _e=t=>{let r=y=>({get element(){return y.__internal.element},update(v){return y.update(v)}}),p={render(y,v){return t.render(y,r(v))}};t.error&&(p.error=(y,v)=>t.error(y,Object.assign(r(b),{error:v})));let b=new w(F({},p));return t.mount&&b.mount(y=>{t.mount(y,r(b))}),t.unmount&&b.unmount(y=>{t.unmount(y,r(b))}),t.afterRender&&b.afterRender((y,v)=>{t.afterRender(y,Object.assign(r(b),{previousNode:v}))}),t.shouldUpdate&&b.shouldUpdate((y,v)=>t.shouldUpdate(y,v)),b};function He(t,r,p){if(!(r instanceof w)&&Reflect.has(r,"render"))return p&&(console.warn("Legacy component syntax is deprecated in v3.2.0 and will be removed in v4.0. The affected component was found here:"),console.warn(new Error().stack)),_e(r);if(!(r instanceof w))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function ee(t){return typeof t=="string"}function ne(t){return t.nodeType===W}function Re(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,p)=>r+p.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[p]+";","")}function S(t,r,p){return Array.from(t).slice(r,p)}function q(t,r){return r?Array.from(t).indexOf(r):-1}(r=>r.JSX=A)(I||(I={}));export{w as Component,ve as Fragment,A as JSX,I as createElement,te as createForgoInstance,x as getForgoState,Ae as h,_e as legacyComponentSyntaxCompat,Se as mount,Ie as render,Ne as rerender,Me as setCustomEnv,Q as setForgoState,we as unmount}; | ||
var ce=Object.defineProperty,fe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var he=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var $=(t,r,p)=>r in t?ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):t[r]=p,F=(t,r)=>{for(var p in r||(r={}))he.call(r,p)&&$(t,p,r[p]);if(J)for(var p of J(r))Te.call(r,p)&&$(t,p,r[p]);return t},k=(t,r)=>fe(t,be(r));var A={};var ye=["ref","dangerouslySetInnerHTML"],Ee=Symbol.for("FORGO_FRAGMENT");var ve="http://www.w3.org/2000/svg",W=1,O=3,z=8,N={mount(t,r){t.__internal.eventListeners.mount.forEach(p=>p(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(p=>p(r,t))},shouldUpdate(t,r,p){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(b=>b(r,p,t)).some(Boolean)},afterRender(t,r,p){t.__internal.eventListeners.afterRender.forEach(b=>b(r,p,t))}},w=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1}}}update(r){return Ne(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}unmount(r){this.__internal.eventListeners.unmount.push(r)}shouldUpdate(r){this.__internal.eventListeners.shouldUpdate.push(r)}afterRender(r){this.__internal.eventListeners.afterRender.push(r)}};function I(t,r){var b;r=r!=null?r:{},r.children=arguments.length>3?_(Array.from(arguments).slice(2)):arguments.length===3?_(arguments[2]):void 0;let p=(b=r.key)!=null?b:void 0;return{type:t,props:r,key:p,__is_forgo_element__:!0}}var Ae=I;function xe(t,r){return p=>{var b;if(!((b=t.__forgo)!=null&&b.deleted))return r(p)}}function te(t){var K;let r=t;r.__internal=(K=r.__internal)!=null?K:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function p(n,e,o,l){if(Array.isArray(n)||V(n))return re(_(n),e,o,l);if(X(n)){if(Ce(n))return y(n,e,o,l);{let d=E(n,e,o,l);return d.pendingMounts.forEach(g=>g()),d.pendingMounts.length=0,d}}else return b(n,e,o)}function b(n,e,o){var g;let l;n==null?l=r.document.createComment("null component render"):l=r.document.createTextNode(Pe(n));let d;if(e.type==="search"){let m=e.parentElement.childNodes;if(e.length){let s=m[e.currentNodeIndex];if(s.nodeType===O||s.nodeType===z)s.replaceWith(l),d=(g=x(s))==null?void 0:g.components;else{let i=m[e.currentNodeIndex];e.parentElement.insertBefore(l,i)}}else if(m.length===0||e.currentNodeIndex===0)e.parentElement.prepend(l);else{let s=m[e.currentNodeIndex];e.parentElement.insertBefore(l,s)}}return U(n,l,!0,o),R(o,d),{nodes:[l],pendingMounts:[()=>G(o,d)]}}function y(n,e,o,l){if(e.type==="detached")return m(void 0,null);{let s=e.parentElement.childNodes;if(e.length){let i=oe(n,e.parentElement,e.currentNodeIndex,e.length);if(i.found)return g(i.index,s,e)}return m(e.parentElement,s[e.currentNodeIndex])}function d(s){if(n.props.dangerouslySetInnerHTML)s.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{let i=_([n.props.children]).filter(c=>c!=null),a=Array.from(s.childNodes).findIndex(c=>x(c)),u=a===-1?0:a;for(let c of i){let{nodes:f}=p(c,{type:"search",parentElement:s,currentNodeIndex:u,length:s.childNodes.length-u},[],l);if(f.length){for(;s.childNodes[u]!==f[f.length-1];)u+=1;for(u+=1;u<s.childNodes.length&&!x(s.childNodes[u]);)u+=1}}P(s.childNodes,u,s.childNodes.length)}}function g(s,i,a){var f;P(i,a.currentNodeIndex,s);let u=i[a.currentNodeIndex],c=(f=x(u))==null?void 0:f.components;return U(n,u,!1,o),d(u),L(u,o),R(o,c),{nodes:[u],pendingMounts:[()=>G(o,c)]}}function m(s,i){let a=ge(n,s);return s&&s.insertBefore(a,i),n.props.ref&&(n.props.ref.value=a),U(n,a,!0,o),d(a),R(o,void 0),{nodes:[a],pendingMounts:[()=>G(o,void 0)]}}}function E(n,e,o,l){let d=o.length;if(e.type!=="detached"&&e.length&&!l){let i=e.parentElement.childNodes,a=se(n,e.parentElement,e.currentNodeIndex,e.length,o.length);if(a.found)return g(a.index,i,e)}return m();function g(i,a,u){let c=a[i],h=j(c).components[d];if(P(a,u.currentNodeIndex,i),N.shouldUpdate(h.component,n.props,h.props)){let T=k(F({},h),{props:n.props}),v=T.component.__internal.registeredMethods.render(n.props,T.component),C=o.concat(T),B=h.component.__internal.element.node,ue=T.component.__internal.registeredMethods.error?T.component:void 0,pe=s(n.props,C,ue,()=>{let me={type:"search",currentNodeIndex:u.currentNodeIndex,length:T.nodes.length,parentElement:u.parentElement};return Y(v,me,C,T,l)});return N.afterRender(T.component,n.props,B),pe}else{let T=q(u.parentElement.childNodes,h.component.__internal.element.node);return{nodes:S(u.parentElement.childNodes,T,T+h.nodes.length),pendingMounts:[]}}}function m(){let i=n.type,a=He(i,i(n.props),r.window.FORGO_NO_LEGACY_WARN!==!0);a.__internal.element.componentIndex=d;let u=a.__internal.registeredMethods.error?a:void 0,c={key:n.key,ctor:i,component:a,props:n.props,nodes:[],isMounted:!1},f=o.concat(c);return s(n.props,f,u,()=>{let h=a.__internal.registeredMethods.render(n.props,a),T=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:l?e.length:0,parentElement:e.parentElement},v=p(h,T,f,l);return c.nodes=v.nodes,c.component.__internal.element.node=v.nodes[0],N.afterRender(a,n.props,void 0),v})}function s(i,a,u,c){try{return c()}catch(f){if(u!=null&&u.__internal.registeredMethods.error){let h=u.__internal.registeredMethods.error(i,f,u);return p(h,e,a,l)}else throw f}}}function Y(n,e,o,l,d){let g=e.parentElement.childNodes.length,m=p(n,e,o,d),s=e.parentElement.childNodes.length,i=g+m.nodes.length-s,a=e.currentNodeIndex+m.nodes.length,u=P(e.parentElement.childNodes,a,a+l.nodes.length-i),c=m.nodes.length>0?o:[];for(let f of u){let h=x(f);if(h){let T=D(c,h.components);h.components=h.components.slice(T)}}return l.nodes=m.nodes,l.component.__internal.element.node=m.nodes[0],m}function re(n,e,o,l){let d=_(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let g={nodes:[],pendingMounts:[]},m=e.currentNodeIndex,s=e.length;for(let i of d){let a=e.parentElement.childNodes.length,u=k(F({},e),{currentNodeIndex:m,length:s}),c=p(i,u,o,l);g.nodes.push(...c.nodes),g.pendingMounts.push(...c.pendingMounts);let f=e.parentElement.childNodes.length,h=a+c.nodes.length-f;m+=c.nodes.length,s-=h}return g}}function P(n,e,o){let l=[],d=S(n,e,o);if(d.length){let g=d[0].parentElement,m=M(g);for(let s of d)!x(s)||(s.remove(),l.push(s),m.push({node:s}))}return l}function L(n,e){let o=M(n);for(let{node:l}of o){let d=x(l);if(d){d.deleted=!0;let g=d.components;R(e,g)}}Fe(n)}function D(n,e){let o=0;for(let l of n)if(e.length>o){if(e[o].component!==l.component)break;o++}else break;return o}function R(n,e){if(!e)return;let o=!1,l=D(n,e);for(let d=l;d<e.length;d++){let g=e[d],m=g.component;(o||g.nodes.every(s=>{if(s.isConnected){let i=j(s);return!i.components[d]||i.components[d].component!==g.component}else return!0}))&&(m.__internal.unmounted||(m.__internal.unmounted=!0,N.unmount(m,g.props)),o=!0)}}function G(n,e){let o=e?D(n,e):0;for(let l=o;l<n.length;l++){let d=n[l];d.isMounted||(d.isMounted=!0,N.mount(d.component,d.props))}}function oe(n,e,o,l){let d=e.childNodes;for(let g=o;g<o+l;g++){let m=d[g];if(ne(m)){let s=x(m);if(!s)continue;if(n.key!==void 0&&(s==null?void 0:s.key)===n.key)return{found:!0,index:g};if(m.tagName.toLowerCase()===n.type&&!(s!=null&&s.key))return{found:!0,index:g}}}if(n.key!==void 0){let g=M(e);for(let m=0;m<g.length;m++){let{node:s}=g[m],i=x(s);if((i==null?void 0:i.key)===n.key){g.splice(m,1);let a=d[o];return a?e.insertBefore(s,a):e.appendChild(s),{found:!0,index:o}}}}return{found:!1}}function se(n,e,o,l,d){let g=e.childNodes;for(let s=o;s<o+l;s++){let i=g[s],a=x(i);if(a&&a.components.length>d){if(n.key!==void 0){if(a.components[d].ctor===n.type&&a.components[d].key===n.key)return{found:!0,index:s}}else if(a.components[d].ctor===n.type)return{found:!0,index:s}}}function m(s,i,a){let u=x(s);return!!(u&&u.components.length>a&&u.components[a].ctor===i.type&&u.components[a].key===i.key)}if(n.key!==void 0){let s=M(e);for(let i=0;i<s.length;i++){let{node:a}=s[i];if(m(a,n,d)){let u=[a];for(let f=i+1;f<s.length;f++){let{node:h}=s[f];m(h,n,d)&&u.push(h)}s.splice(i,u.length);let c=g[o];if(c)for(let f of u)e.insertBefore(f,c);else for(let f of u)e.appendChild(f);return{found:!0,index:o}}}}return{found:!1}}function U(n,e,o,l){var d;if(l.length>0&&(l[l.length-1].component.__internal.element.node=e),X(n)){let g=x(e);if(g&&g.props)for(let i in g.props)i in n.props||i!=="children"&&i!=="xmlns"&&(e.nodeType===O||e.nodeType===z||e instanceof r.__internal.HTMLElement&&i in e?delete e[i]:e.removeAttribute(i));else if(!o&&ne(e)&&e.hasAttributes()){let i=Array.from(e.attributes);for(let a of i){let u=a.name;u in n.props||e.removeAttribute(u)}}let m=Object.entries(n.props);for(let[i,a]of m)if(!ye.includes(i)&&((d=g==null?void 0:g.props)==null?void 0:d[i])!==a&&i!=="children"&&i!=="xmlns")if(e.nodeType===O||e.nodeType===z)e[i]=a;else if(e instanceof r.__internal.HTMLElement)if(i==="style"){if(g===void 0||g.style===void 0||g.style!==n.props.style){let u=Re(n.props.style);e.style.cssText!==u&&(e.style.cssText=u)}}else i==="onblur"?e[i]=xe(e,a):i in e?e[i]=a:e.setAttribute(i,a);else typeof a=="string"?e.setAttribute(i,a):e[i]=a;let s={key:n.key,props:n.props,components:l};Q(e,s)}else Q(e,{components:l})}function ie(n,e){let o=ee(e)?r.document.querySelector(e):e;if(!o)throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(o.nodeType!==W)throw new Error("The container argument to the mount() function should be an HTML element.");let l=o.childNodes.length>0,d=p(n,{type:"search",currentNodeIndex:0,length:o.childNodes.length,parentElement:o},[],l);if(d.nodes.length<o.childNodes.length){let g=S(o.childNodes,d.nodes.length,o.childNodes.length);for(let m of g)m.remove()}return d}function de(n){let e=ee(n)?r.document.querySelector(n):n;if(!e)throw new Error(`The unmount() function was called on a non-element (${typeof n=="string"?n:n==null?void 0:n.tagName}).`);if(e.nodeType!==W)throw new Error("The container argument to the unmount() function should be an HTML element.");P(e.childNodes,0,e.childNodes.length),L(e,[])}function ae(n){let e=p(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function le(n,e){if(!(n!=null&&n.node))throw new Error("Missing node information in rerender() argument.");let o=n.node.parentElement;if(o!==null){let l=j(n.node),d=l.components[n.componentIndex],g=e!=null?e:d.props;if(!N.shouldUpdate(d.component,g,d.props)){let T=q(o.childNodes,n.node);return{nodes:S(o.childNodes,T,T+d.nodes.length),pendingMounts:[]}}let m=k(F({},d),{props:g}),s=l.components.slice(0,n.componentIndex),i=s.concat(m),a=d.component.__internal.element.node,u=d.component.__internal.registeredMethods.render(g,d.component),c=q(o.childNodes,n.node),f={type:"search",currentNodeIndex:c,length:d.nodes.length,parentElement:o},h=Y(u,f,i,m,!1);for(let T=0;T<s.length;T++){let v=s[T],C=v.nodes.findIndex(B=>B===d.nodes[0]);v.nodes=v.nodes.slice(0,C).concat(h.nodes).concat(v.nodes.slice(C+d.nodes.length)),v.nodes.length>0&&(v.component.__internal.element.node=v.nodes[0])}return L(o,h.nodes.length>0?i:[]),N.afterRender(d.component,g,a),h}else return{nodes:[],pendingMounts:[]}}function ge(n,e){var l;let o=((l=n.props.xmlns)!=null?l:n.type==="svg")?ve:e&&e.namespaceURI;return n.props.is?o?r.document.createElementNS(o,n.type,{is:n.props.is}):r.document.createElement(n.type,{is:n.props.is}):o?r.document.createElementNS(o,n.type):r.document.createElement(n.type)}return{mount:ie,unmount:de,render:ae,rerender:le}}var Z=globalThis||window,H=te({window:Z,document:Z.document});function Me(t){H=te(t)}function Se(t,r){return H.mount(t,r)}function we(t){return H.unmount(t)}function Ie(t){return H.render(t)}function Ne(t,r){return H.rerender(t,r)}function _(t){function r(p,b=[]){let y=Array.isArray(p)?p:V(p)?Array.isArray(p.props.children)?p.props.children:p.props.children!==void 0&&p.props.children!==null?[p.props.children]:[]:[p];for(let E of y)Array.isArray(E)||V(E)?r(E,b):b.push(E);return b}return r(t,[])}function Pe(t){return t.toString()}function X(t){return t!=null&&t.__is_forgo_element__===!0}function Ce(t){return X(t)&&typeof t.type=="string"}function V(t){return t!=null&&t.type===Ee}function x(t){return t.__forgo}function j(t){if(t.__forgo)return t.__forgo;throw new Error("Missing forgo state on node.")}function Q(t,r){t.__forgo=r}function M(t){return t.__forgo_deletedNodes||(t.__forgo_deletedNodes=[]),t.__forgo_deletedNodes}function Fe(t){t.__forgo_deletedNodes&&(t.__forgo_deletedNodes=[])}var _e=t=>{let r=y=>({get element(){return y.__internal.element},update(E){return y.update(E)}}),p={render(y,E){return t.render(y,r(E))}};t.error&&(p.error=(y,E)=>t.error(y,Object.assign(r(b),{error:E})));let b=new w(F({},p));return t.mount&&b.mount(y=>{t.mount(y,r(b))}),t.unmount&&b.unmount(y=>{t.unmount(y,r(b))}),t.afterRender&&b.afterRender((y,E)=>{t.afterRender(y,Object.assign(r(b),{previousNode:E}))}),t.shouldUpdate&&b.shouldUpdate((y,E)=>t.shouldUpdate(y,E)),b};function He(t,r,p){if(!(r instanceof w)&&Reflect.has(r,"render"))return p&&(console.warn("Legacy component syntax is deprecated in v3.2.0 and will be removed in v4.0. The affected component was found here:"),console.warn(new Error().stack)),_e(r);if(!(r instanceof w))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function ee(t){return typeof t=="string"}function ne(t){return t.nodeType===W}function Re(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,p)=>r+p.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[p]+";","")}function S(t,r,p){return Array.from(t).slice(r,p)}function q(t,r){return r?Array.from(t).indexOf(r):-1}(r=>r.JSX=A)(I||(I={}));export{w as Component,Ee as Fragment,A as JSX,I as createElement,te as createForgoInstance,x as getForgoState,Ae as h,_e as legacyComponentSyntaxCompat,Se as mount,Ie as render,Ne as rerender,Me as setCustomEnv,Q as setForgoState,we as unmount}; | ||
//# sourceMappingURL=forgo.min.js.map |
@@ -39,3 +39,3 @@ export declare type ForgoRef<T> = { | ||
}; | ||
export declare type ForgoElement<TProps> = ForgoDOMElement<TProps> | ForgoComponentElement<TProps>; | ||
export declare type ForgoElement<TProps extends ForgoDOMElementProps> = ForgoDOMElement<TProps> | ForgoComponentElement<TProps>; | ||
export declare type ForgoNonEmptyPrimitiveNode = string | number | boolean | object | BigInt | null | undefined; | ||
@@ -48,3 +48,3 @@ export declare type ForgoPrimitiveNode = ForgoNonEmptyPrimitiveNode | null | undefined; | ||
export declare type ForgoNode = ForgoPrimitiveNode | ForgoElement<any> | ForgoFragment; | ||
export declare type NodeAttachedComponentState<TProps> = { | ||
export declare type NodeAttachedComponentState<TProps extends {}> = { | ||
key?: any; | ||
@@ -157,3 +157,3 @@ ctor: ForgoNewComponentCtor<TProps> | ForgoComponentCtor<TProps>; | ||
*/ | ||
interface ComponentEventListeners<Props> extends ComponentEventListenerBase { | ||
interface ComponentEventListeners<Props extends {}> extends ComponentEventListenerBase { | ||
mount: Array<(props: Props & ForgoComponentProps, component: Component<Props>) => void>; | ||
@@ -164,3 +164,3 @@ unmount: Array<(props: Props & ForgoComponentProps, component: Component<Props>) => void>; | ||
} | ||
interface ComponentInternal<Props> { | ||
interface ComponentInternal<Props extends {}> { | ||
unmounted: boolean; | ||
@@ -172,6 +172,6 @@ registeredMethods: ForgoComponentMethods<Props>; | ||
declare const lifecycleEmitters: { | ||
mount<Props>(component: Component<Props>, props: Props): void; | ||
unmount<Props_1>(component: Component<Props_1>, props: Props_1): void; | ||
shouldUpdate<Props_2>(component: Component<Props_2>, newProps: Props_2, oldProps: Props_2): boolean; | ||
afterRender<Props_3>(component: Component<Props_3>, props: Props_3, previousNode: ChildNode | undefined): void; | ||
mount<Props extends {}>(component: Component<Props>, props: Props): void; | ||
unmount<Props_1 extends {}>(component: Component<Props_1>, props: Props_1): void; | ||
shouldUpdate<Props_2 extends {}>(component: Component<Props_2>, newProps: Props_2, oldProps: Props_2): boolean; | ||
afterRender<Props_3 extends {}>(component: Component<Props_3>, props: Props_3, previousNode: ChildNode | undefined): void; | ||
}; | ||
@@ -264,3 +264,3 @@ /** | ||
}; | ||
export declare const legacyComponentSyntaxCompat: <Props>(legacyComponent: ForgoComponent<Props>) => Component<Props>; | ||
export declare const legacyComponentSyntaxCompat: <Props extends {}>(legacyComponent: ForgoComponent<Props>) => Component<Props>; | ||
export * as JSX from "./jsxTypes.js"; | ||
@@ -267,0 +267,0 @@ import * as JSXTypes from "./jsxTypes.js"; |
{ | ||
"name": "forgo", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"main": "./dist/forgo.min.js", | ||
@@ -14,13 +14,13 @@ "type": "module", | ||
"devDependencies": { | ||
"@types/jsdom": "^16.2.14", | ||
"@types/mocha": "^9.1.0", | ||
"@types/jsdom": "^20.0.0", | ||
"@types/mocha": "^9.1.1", | ||
"@types/should": "^13.0.0", | ||
"@types/source-map-support": "^0.5.4", | ||
"esbuild": "^0.14.25", | ||
"jsdom": "^19.0.0", | ||
"mocha": "^9.2.1", | ||
"@types/source-map-support": "^0.5.6", | ||
"esbuild": "^0.15.5", | ||
"jsdom": "^20.0.0", | ||
"mocha": "^10.0.0", | ||
"rimraf": "^3.0.2", | ||
"should": "^13.2.3", | ||
"source-map-support": "^0.5.21", | ||
"typescript": "^4.6.2" | ||
"typescript": "^4.8.2" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
282740
3592