Comparing version 4.0.4 to 4.0.5
@@ -1,2 +0,2 @@ | ||
var ce=Object.defineProperty,be=Object.defineProperties;var ye=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var J=(t,r,l)=>r in t?ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[r]=l,_=(t,r)=>{for(var l in r||(r={}))fe.call(r,l)&&J(t,l,r[l]);if($)for(var l of $(r))Ee.call(r,l)&&J(t,l,r[l]);return t},H=(t,r)=>be(t,ye(r));var A={};var he=["ref","dangerouslySetInnerHTML"],Te=Symbol.for("FORGO_FRAGMENT"),ve="http://www.w3.org/2000/svg";var W=1,G=3,U=8,C={mount(t,r){t.__internal.eventListeners.mount.forEach(l=>l(r,t))},remount(t,r){t.__internal.eventListeners.remount.forEach(l=>l(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(l=>l(r,t))},shouldUpdate(t,r,l){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(h=>h(r,l,t)).some(Boolean)},afterRender(t,r,l){t.__internal.eventListeners.afterRender.forEach(h=>h(r,l,t))}},R=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],remount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1}}}update(r){return xe(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}remount(r){this.__internal.eventListeners.remount.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 L(t,r,...l){var T;r=r!=null?r:{},r.children=l.length>1?w(Array.from(l)):l.length===1?w(l[0]):void 0;let h=(T=r.key)!=null?T:void 0;return{type:t,props:r,key:h,__is_forgo_element__:!0}}var we=L;function Ne(t,r){return l=>{if(t.__forgo===void 0||t.__forgo.deleted===!1)return r(l)}}function te(t){var Y;let r=t;r.__internal=(Y=r.__internal)!=null?Y:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function l(e,n,i,u){return Array.isArray(e)||z(e)?oe(w(e),n,i,u):q(e)?Ce(e)?T(e,n,i,u):re(e,n,i,u):h(e,n,i)}function h(e,n,i){var b;let u;k(e)?u=r.document.createComment("null component render"):u=r.document.createTextNode(Pe(e));let m;if(n.type==="search"){let g=n.parentElement.childNodes;if(n.length){let d=g[n.currentNodeIndex];if(d.nodeType===G||d.nodeType===U)d.replaceWith(u),m=(b=N(d))==null?void 0:b.components;else{let o=g[n.currentNodeIndex];n.parentElement.insertBefore(u,o!=null?o:null)}}else if(g.length===0||n.currentNodeIndex===0)n.parentElement.prepend(u);else{let d=g[n.currentNodeIndex];n.parentElement.insertBefore(u,d!=null?d:null)}}return K(e,u,!0,i),{nodes:[u]}}function T(e,n,i,u){if(n.type==="detached")return g(void 0,void 0);{let d=n.parentElement.childNodes;return se(e,n,i)?b(n):g(n.parentElement,n.currentNodeIndex)}function m(d){if(e.props.dangerouslySetInnerHTML)d.innerHTML=e.props.dangerouslySetInnerHTML.__html;else{let o=N(d);x(o);let s=w([e.props.children]).filter(y=>!k(y)),p=0;for(let y of s){let{nodes:c}=l(y,{type:"search",parentElement:d,currentNodeIndex:p,length:d.childNodes.length-p},[],u);p+=c.length}j(d.childNodes,p,d.childNodes.length),D(d),X(o)}}function b(d){let o=d.parentElement.childNodes,s=N(d.parentElement),p=o[d.currentNodeIndex];return i.forEach((y,c)=>{var a;if(y.key!==void 0){let E=S(y.key,c),f=(a=s.lookups.newlyAddedKeyedComponentNodes.get(E))!=null?a:[];f.push(p),s.lookups.newlyAddedKeyedComponentNodes.set(E,f)}}),e.key!==void 0&&s.lookups.newlyAddedKeyedElementNodes.set(e.key,p),K(e,p,!1,i),m(p),{nodes:[p]}}function g(d,o){let s=ue(e,d);e.props.ref&&(e.props.ref.value=s);let p=o!==void 0?d.childNodes[o]:null;if(d){let y=N(d);i.forEach((c,a)=>{if(c.key!==void 0){let E=S(c.key,a);y.lookups.newlyAddedKeyedComponentNodes.set(E,[s])}}),e.key!==void 0&&y.lookups.newlyAddedKeyedElementNodes.set(e.key,s)}return d&&d.insertBefore(s,p!=null?p:null),K(e,s,!0,i),m(s),{nodes:[s]}}}function x(e){e.lookups.renderCount++}function X(e){e.lookups.renderCount--,e.lookups.renderCount===0&&(e.lookups.keyedComponentNodes=e.lookups.newlyAddedKeyedComponentNodes,e.lookups.keyedElementNodes=e.lookups.newlyAddedKeyedElementNodes,e.lookups.newlyAddedKeyedComponentNodes=new Map,e.lookups.newlyAddedKeyedElementNodes=new Map,e.lookups.deletedKeyedComponentNodes=new Map,e.lookups.deletedKeyedElementNodes=new Map,e.lookups.deletedUnkeyedNodes=[])}function re(e,n,i,u){let m=i.length;if(n.type!=="detached"&&!u){let o=n.parentElement.childNodes;if(de(e,n,i.length))return b(o,n)}return g();function b(o,s){let p=o[s.currentNodeIndex],c=N(p).components[m];if(C.shouldUpdate(c.component,e.props,c.props)){let a=H(_({},c),{props:e.props}),E=a.component.__internal.registeredMethods.render(e.props,a.component),f=i.length,v=i.concat(a),P=c.component.__internal.element.node,F=a.component.__internal.registeredMethods.error?a.component:void 0,ge=d(e.props,v,F,()=>{let me={type:"search",currentNodeIndex:s.currentNodeIndex,length:a.nodes.length,parentElement:s.parentElement};return V(E,me,v,f,a.nodes.length,u)});return C.afterRender(a.component,e.props,P),ge}else{let a=B(s.parentElement.childNodes,c.component.__internal.element.node);return{nodes:I(s.parentElement.childNodes,a,a+c.nodes.length)}}}function g(){let o=e.type,s=Fe(o,o(e.props),r.window.FORGO_NO_LEGACY_WARN!==!0);s.__internal.element.componentIndex=m;let p=s.__internal.registeredMethods.error?s:void 0,y={key:e.key,ctor:o,component:s,props:e.props,nodes:[],isMounted:!1},c=i.length,a=i.concat(y);return d(e.props,a,p,()=>{let E=s.__internal.registeredMethods.render(e.props,s),f=n.type==="detached"?n:{type:"search",currentNodeIndex:n.currentNodeIndex,length:u?n.length:0,parentElement:n.parentElement},v=l(E,f,a,u),F=N(v.nodes[0]).components[c];return F.nodes=v.nodes,F.component.__internal.element.node=v.nodes[0],C.mount(y.component,e.props),C.afterRender(s,e.props,void 0),v})}function d(o,s,p,y){try{return y()}catch(c){if(p!=null&&p.__internal.registeredMethods.error){let a=p.__internal.registeredMethods.error(o,c,p);return l(a,n,s,u)}else throw c}}}function V(e,n,i,u,m,b){let g=n.parentElement.childNodes.length,d=i.slice(-1)[0],o=d.component.__internal.element.node,s=l(e,n,i,b),p=d.component.__internal.element.node;o!==p&&C.remount(d.component,d.props);let y=n.parentElement.childNodes.length,c=g+s.nodes.length-y,a=n.currentNodeIndex+s.nodes.length;if(j(n.parentElement.childNodes,a,a+m-c),s.nodes.length){let f=N(s.nodes[0]).components[u];f.nodes=s.nodes,f.component.__internal.element.node=s.nodes[0]}return s}function oe(e,n,i,u){let m=w(e);if(n.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let b={nodes:[]},g=n.currentNodeIndex,d=n.length,o=N(n.parentElement);x(o);for(let s of m){let p=n.parentElement.childNodes.length,y=H(_({},n),{currentNodeIndex:g,length:d}),c=l(s,y,i,u);b.nodes.push(...c.nodes);let a=n.parentElement.childNodes.length,E=p+c.nodes.length-a;g+=c.nodes.length,d-=E}return X(o),b}}function j(e,n,i){let u=[],m=I(e,n,i);if(m.length){let b=m[0].parentElement,g=N(b);for(let d of m){let o=N(d);d.remove(),o.components.forEach((s,p)=>{var y;if(s.key!==void 0){let c=S(s.key,p),a=g.lookups.keyedComponentNodes.get(c);if(a!==void 0){let f=a.filter(v=>v!==d);f.length?g.lookups.keyedComponentNodes.set(c,f):g.lookups.keyedComponentNodes.delete(c)}let E=(y=g.lookups.deletedKeyedComponentNodes.get(c))!=null?y:[];E.push(d),g.lookups.deletedKeyedComponentNodes.set(c,E)}}),o.key!==void 0?(g.lookups.keyedComponentNodes.delete(o.key),g.lookups.deletedKeyedComponentNodes.set(o.key,[d])):g.lookups.deletedUnkeyedNodes.push({node:d}),u.push(d)}}return u}function D(e){function n(u){let m=N(u);m.deleted=!0;for(let b of m.components)b.component.__internal.element.node===u&&(b.component.__internal.unmounted||C.unmount(b.component,b.props))}let i=N(e);for(let u of i.lookups.deletedKeyedComponentNodes.values())for(let m of u)m.isConnected&&n(m);for(let{node:u}of i.lookups.deletedUnkeyedNodes)n(u);i.lookups.deletedKeyedComponentNodes.clear(),i.lookups.deletedUnkeyedNodes=[]}function se(e,n,i){function u(g,d,o){if(O(g)){let s=N(g);return g.tagName.toLowerCase()===d.type&&s.components.every((p,y)=>o[y]!==void 0&&o[y].component===p.component)}else return!1}function m(g,d,o){let{parentElement:s,currentNodeIndex:p}=d,y=N(s),c=y.lookups.keyedElementNodes.get(g.key);if(c!==void 0)if(u(c,g,o)){let a=s.childNodes[p];return c!==a&&s.insertBefore(c,a!=null?a:null),!0}else return y.lookups.keyedComponentNodes.delete(g.key),!1;else{let a=y.lookups.deletedKeyedElementNodes.get(g.key);if(a!==void 0){let E=s.childNodes;if(y.lookups.deletedKeyedComponentNodes.delete(g.key),u(a,g,o)){let f=E[p];return a!==f&&s.insertBefore(a,f!=null?f:null),!0}}return!1}}function b(g,d,o){var a;let{parentElement:s,currentNodeIndex:p,length:y}=d,c=s.childNodes;for(let E=p;E<p+y;E++){let f=c[E];if(O(f)){let v=N(f);if(f.tagName.toLowerCase()===g.type&&v.key===void 0&&u(f,g,o)){let P=(a=s.childNodes[p])!=null?a:null;return f!==P&&s.insertBefore(f,P),!0}}}return!1}return ne(e)?m(e,n,i):b(e,n,i)}function de(e,n,i){function u(b,g,d){let{parentElement:o,currentNodeIndex:s}=g,p=S(b.key,d),y=N(o),c=y.lookups.keyedComponentNodes.get(p);if(c!==void 0){let a=o.childNodes[s];for(let E of c)E!==a&&o.insertBefore(E,a!=null?a:null);return!0}else{let a=y.lookups.deletedKeyedComponentNodes.get(p);if(a!==void 0){y.lookups.deletedKeyedComponentNodes.delete(p);for(let E of a){let f=o.childNodes[s];E!==f&&o.insertBefore(E,f!=null?f:null)}return!0}}return!1}function m(b,g,d){var c;let{parentElement:o,currentNodeIndex:s,length:p}=g,y=o.childNodes;for(let a=s;a<s+p;a++){let E=y[a],f=N(E);if(f!==void 0&&f.components.length>d&&f.components[d].ctor===b.type){let v=(c=o.childNodes[s])!=null?c:null;return E!==v&&o.insertBefore(E,v),!0}}return!1}return ne(e)?u(e,n,i):m(e,n,i)}function K(e,n,i,u){var m;if(u.length>0&&(u[u.length-1].component.__internal.element.node=n),q(e)){let b=N(n);if(b!==void 0&&b.props)for(let o in b.props)o in e.props||o!=="children"&&o!=="xmlns"&&(n.nodeType===G||n.nodeType===U||n instanceof r.__internal.HTMLElement&&o in n?delete n[o]:n.removeAttribute(o));else if(!i&&O(n)&&n.hasAttributes()){let o=Array.from(n.attributes);for(let s of o){let p=s.name;p in e.props||n.removeAttribute(p)}}let g=Object.entries(e.props);for(let[o,s]of g)if(!he.includes(o)&&((m=b==null?void 0:b.props)==null?void 0:m[o])!==s&&o!=="children"&&o!=="xmlns")if(n.nodeType===G||n.nodeType===U)n[o]=s;else if(n instanceof r.__internal.HTMLElement)if(o==="style"){if(b===void 0||b.style===void 0||b.style!==e.props.style){let p=_e(e.props.style);n.style.cssText!==p&&(n.style.cssText=p)}}else o==="onblur"?n[o]=Ne(n,s):o in n?n[o]=s:n.setAttribute(o,s);else typeof s=="string"?n.setAttribute(o,s):n[o]=s;let d=H(_({},b),{key:e.key,props:e.props,components:u});Q(n,d)}else Q(n,{components:u,lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,keyedElementNodes:new Map,renderCount:0}})}function ie(e,n){let i=ee(n)?r.document.querySelector(n):n;if(i==null)throw new Error(`The mount() function was called on a non-element (${typeof n=="string"?n:n==null?void 0:n.tagName}).`);if(i.nodeType!==W)throw new Error("The container argument to the mount() function should be an HTML element.");let u=i.childNodes.length>0,m=l(e,{type:"search",currentNodeIndex:0,length:i.childNodes.length,parentElement:i},[],u);if(m.nodes.length<i.childNodes.length){let b=I(i.childNodes,m.nodes.length,i.childNodes.length);for(let g of b)g.remove()}return m}function ae(e){let n=ee(e)?r.document.querySelector(e):e;if(n===null)throw new Error(`The unmount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(n.nodeType!==W)throw new Error("The container argument to the unmount() function should be an HTML element.");j(n.childNodes,0,n.childNodes.length),D(n)}function le(e){let n=l(e,{type:"detached"},[],!1);return{node:n.nodes[0],nodes:n.nodes}}function pe(e,n){if(!(e!=null&&e.node))throw new Error("Missing node information in rerender() argument.");let i=e.node.parentElement;if(k(i))return{nodes:[]};{let u=N(e.node),m=u.components[e.componentIndex],b=n!=null?n:m.props;if(!C.shouldUpdate(m.component,b,m.props)){let f=B(i.childNodes,e.node);return{nodes:I(i.childNodes,f,f+m.nodes.length)}}let g=H(_({},m),{props:b}),d=u.components.slice(0,e.componentIndex),o=d.length,s=d.concat(g),p=m.component.__internal.element.node,y=m.component.__internal.registeredMethods.render(b,m.component),c=B(i.childNodes,e.node),a={type:"search",currentNodeIndex:c,length:m.nodes.length,parentElement:i},E=V(y,a,s,o,m.nodes.length,!1);for(let f=0;f<d.length;f++){let v=d[f],P=v.nodes.findIndex(F=>F===m.nodes[0]);v.nodes=v.nodes.slice(0,P).concat(E.nodes).concat(v.nodes.slice(P+m.nodes.length)),v.nodes.length>0&&(v.component.__internal.element.node=v.nodes[0])}return D(i),C.afterRender(m.component,b,p),E}}function ue(e,n){let i=k(e.props.xmlns)?e.type==="svg"?ve:n!==void 0?n.namespaceURI:null:e.props.xmlns;return e.props.is!==void 0?i!==null?r.document.createElementNS(i,e.type,{is:e.props.is}):r.document.createElement(e.type,{is:e.props.is}):i!==null?r.document.createElementNS(i,e.type):r.document.createElement(e.type)}return{mount:ie,unmount:ae,render:le,rerender:pe}}var Z=globalThis!==void 0?globalThis:window,M=te({window:Z,document:Z.document});function Re(t){M=te(t)}function Me(t,r){return M.mount(t,r)}function Ae(t){return M.unmount(t)}function Se(t){return M.render(t)}function xe(t,r){return M.rerender(t,r)}function w(t){function r(l,h=[]){let T=Array.isArray(l)?l:z(l)?Array.isArray(l.props.children)?l.props.children:k(l.props.children)?[]:[l.props.children]:[l];for(let x of T)Array.isArray(x)||z(x)?r(x,h):h.push(x);return h}return r(t,[])}function Pe(t){return t.toString()}function q(t){return!k(t)&&t.__is_forgo_element__===!0}function Ce(t){return q(t)&&typeof t.type=="string"}function z(t){return!k(t)&&t.type===Te}function N(t){return t.__forgo===void 0&&(t.__forgo={components:[],lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,keyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,renderCount:0}}),t.__forgo}function Q(t,r){t.__forgo=r}var ke=t=>{let r=T=>({get element(){return T.__internal.element},update(x){return T.update(x)}}),l={render(T,x){return t.render(T,r(x))}};t.error&&(l.error=(T,x)=>t.error(T,Object.assign(r(h),{error:x})));let h=new R(_({},l));return t.mount&&h.mount(T=>{t.mount(T,r(h))}),t.remount&&h.remount(T=>{t.remount(T,r(h))}),t.unmount&&h.unmount(T=>{t.unmount(T,r(h))}),t.afterRender&&h.afterRender((T,x)=>{t.afterRender(T,Object.assign(r(h),{previousNode:x}))}),t.shouldUpdate&&h.shouldUpdate((T,x)=>t.shouldUpdate(T,x)),h};function S(t,r){return`$Component${r}_${t}`}function Fe(t,r,l){if(!(r instanceof R)&&Reflect.has(r,"render"))return l&&(console.warn("Legacy component syntax is deprecated since v3.2.0 and will be removed in v5.0. The affected component was found here:"),console.warn(new Error().stack)),ke(r);if(!(r instanceof R))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function k(t){return t==null}function ee(t){return typeof t=="string"}function O(t){return t.nodeType===W}function _e(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,l)=>r+l.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[l]+";","")}function ne(t){return t.key!==void 0}function I(t,r,l){return Array.from(t).slice(r,l)}function B(t,r){return r?Array.from(t).indexOf(r):-1}(r=>r.JSX=A)(L||(L={}));export{R as Component,Te as Fragment,A as JSX,L as createElement,te as createForgoInstance,N as getForgoState,we as h,ke as legacyComponentSyntaxCompat,Me as mount,Se as render,xe as rerender,Re as setCustomEnv,Q as setForgoState,Ae as unmount}; | ||
var ce=Object.defineProperty,be=Object.defineProperties;var ye=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var J=(t,r,a)=>r in t?ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[r]=a,_=(t,r)=>{for(var a in r||(r={}))fe.call(r,a)&&J(t,a,r[a]);if($)for(var a of $(r))Ee.call(r,a)&&J(t,a,r[a]);return t},H=(t,r)=>be(t,ye(r));var A={};var he=["ref","dangerouslySetInnerHTML"],Te=Symbol.for("FORGO_FRAGMENT"),ve="http://www.w3.org/2000/svg";var W=1,K=3,G=8,C={mount(t,r){t.__internal.eventListeners.mount.forEach(a=>a(r,t))},remount(t,r){t.__internal.eventListeners.remount.forEach(a=>a(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(a=>a(r,t))},shouldUpdate(t,r,a){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(h=>h(r,a,t)).some(Boolean)},afterRender(t,r,a){t.__internal.eventListeners.afterRender.forEach(h=>h(r,a,t))}},M=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],remount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1}}}update(r){return xe(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}remount(r){this.__internal.eventListeners.remount.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,...a){var T;r=r!=null?r:{},r.children=a.length>1?w(Array.from(a)):a.length===1?w(a[0]):void 0;let h=(T=r.key)!=null?T:void 0;return{type:t,props:r,key:h,__is_forgo_element__:!0}}var we=I;function Ne(t,r){return a=>{if(t.__forgo===void 0||t.__forgo.deleted===!1)return r(a)}}function te(t){var Y;let r=t;r.__internal=(Y=r.__internal)!=null?Y:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function a(n,e,i,u){return Array.isArray(n)||z(n)?oe(w(n),e,i,u):q(n)?Ce(n)?T(n,e,i,u):re(n,e,i,u):h(n,e,i)}function h(n,e,i){var g;let u;k(n)?u=r.document.createComment("null component render"):u=r.document.createTextNode(Pe(n));let c;if(e.type==="search"){let b=e.parentElement.childNodes;if(e.length){let d=b[e.currentNodeIndex];if(d.nodeType===K||d.nodeType===G)d.replaceWith(u),c=(g=N(d))==null?void 0:g.components;else{let o=b[e.currentNodeIndex];e.parentElement.insertBefore(u,o!=null?o:null)}}else if(b.length===0||e.currentNodeIndex===0)e.parentElement.prepend(u);else{let d=b[e.currentNodeIndex];e.parentElement.insertBefore(u,d!=null?d:null)}}return D(n,u,!0,i),{nodes:[u]}}function T(n,e,i,u){if(e.type==="detached")return b(void 0,void 0);{let d=e.parentElement.childNodes;return se(n,e,i)?g(e):b(e.parentElement,e.currentNodeIndex)}function c(d){if(n.props.dangerouslySetInnerHTML)d.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{let o=N(d);x(o);let s=w([n.props.children]).filter(y=>!k(y)),p=0;for(let y of s){let{nodes:m}=a(y,{type:"search",parentElement:d,currentNodeIndex:p,length:d.childNodes.length-p},[],u);p+=m.length}L(d.childNodes,p,d.childNodes.length),j(d),X(o)}}function g(d){let o=d.parentElement.childNodes,s=N(d.parentElement),p=o[d.currentNodeIndex];return i.forEach((y,m)=>{var l;if(y.key!==void 0){let E=S(y.key,m),f=(l=s.lookups.newlyAddedKeyedComponentNodes.get(E))!=null?l:[];f.push(p),s.lookups.newlyAddedKeyedComponentNodes.set(E,f)}}),n.key!==void 0&&s.lookups.newlyAddedKeyedElementNodes.set(n.key,p),D(n,p,!1,i),c(p),{nodes:[p]}}function b(d,o){let s=ue(n,d);n.props.ref&&(n.props.ref.value=s);let p=o!==void 0?d.childNodes[o]:null;if(d){let y=N(d);i.forEach((m,l)=>{if(m.key!==void 0){let E=S(m.key,l);y.lookups.newlyAddedKeyedComponentNodes.set(E,[s])}}),n.key!==void 0&&y.lookups.newlyAddedKeyedElementNodes.set(n.key,s)}return d&&d.insertBefore(s,p!=null?p:null),D(n,s,!0,i),c(s),{nodes:[s]}}}function x(n){n.lookups.renderCount++}function X(n){n.lookups.renderCount--,n.lookups.renderCount===0&&(n.lookups.keyedComponentNodes=n.lookups.newlyAddedKeyedComponentNodes,n.lookups.keyedElementNodes=n.lookups.newlyAddedKeyedElementNodes,n.lookups.newlyAddedKeyedComponentNodes=new Map,n.lookups.newlyAddedKeyedElementNodes=new Map,n.lookups.deletedKeyedComponentNodes=new Map,n.lookups.deletedKeyedElementNodes=new Map,n.lookups.deletedUnkeyedNodes=[])}function re(n,e,i,u){let c=i.length;if(e.type!=="detached"&&!u){let o=e.parentElement.childNodes;if(de(n,e,i.length))return g(o,e)}return b();function g(o,s){let p=o[s.currentNodeIndex],m=N(p).components[c];if(C.shouldUpdate(m.component,n.props,m.props)){let l=H(_({},m),{props:n.props}),E=l.component.__internal.registeredMethods.render(n.props,l.component),f=i.length,v=i.concat(l),P=m.component.__internal.element.node,F=l.component.__internal.registeredMethods.error?l.component:void 0,ge=d(n.props,v,F,()=>{let me={type:"search",currentNodeIndex:s.currentNodeIndex,length:l.nodes.length,parentElement:s.parentElement};return V(E,me,v,f,l.nodes.length,u)});return C.afterRender(l.component,n.props,P),ge}else{let l=B(s.parentElement.childNodes,m.component.__internal.element.node,s.currentNodeIndex);return{nodes:O(s.parentElement.childNodes,l,l+m.nodes.length)}}}function b(){let o=n.type,s=Fe(o,o(n.props),r.window.FORGO_NO_LEGACY_WARN!==!0);s.__internal.element.componentIndex=c;let p=s.__internal.registeredMethods.error?s:void 0,y={key:n.key,ctor:o,component:s,props:n.props,nodes:[],isMounted:!1},m=i.length,l=i.concat(y);return d(n.props,l,p,()=>{let E=s.__internal.registeredMethods.render(n.props,s),f=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:u?e.length:0,parentElement:e.parentElement},v=a(E,f,l,u),F=N(v.nodes[0]).components[m];return F.nodes=v.nodes,F.component.__internal.element.node=v.nodes[0],C.mount(y.component,n.props),C.afterRender(s,n.props,void 0),v})}function d(o,s,p,y){try{return y()}catch(m){if(p!=null&&p.__internal.registeredMethods.error){let l=p.__internal.registeredMethods.error(o,m,p);return a(l,e,s,u)}else throw m}}}function V(n,e,i,u,c,g){let b=e.parentElement.childNodes.length,d=i.slice(-1)[0],o=d.component.__internal.element.node,s=a(n,e,i,g),p=d.component.__internal.element.node;o!==p&&C.remount(d.component,d.props);let y=e.parentElement.childNodes.length,m=b+s.nodes.length-y,l=e.currentNodeIndex+s.nodes.length;if(L(e.parentElement.childNodes,l,l+c-m),s.nodes.length){let f=N(s.nodes[0]).components[u];f.nodes=s.nodes,f.component.__internal.element.node=s.nodes[0]}return s}function oe(n,e,i,u){let c=w(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let g={nodes:[]},b=e.currentNodeIndex,d=e.length,o=N(e.parentElement);x(o);for(let s of c){let p=e.parentElement.childNodes.length,y=H(_({},e),{currentNodeIndex:b,length:d}),m=a(s,y,i,u);g.nodes.push(...m.nodes);let l=e.parentElement.childNodes.length,E=p+m.nodes.length-l;b+=m.nodes.length,d-=E}return X(o),g}}function L(n,e,i){let u=[];if(i>e){let c=n[e].parentElement,g=N(c);for(let b=e;b<i;b++){let d=n[e],o=N(d);d.remove(),o.components.forEach((s,p)=>{var y;if(s.key!==void 0){let m=S(s.key,p),l=g.lookups.keyedComponentNodes.get(m);if(l!==void 0){let f=l.filter(v=>v!==d);f.length?g.lookups.keyedComponentNodes.set(m,f):g.lookups.keyedComponentNodes.delete(m)}let E=(y=g.lookups.deletedKeyedComponentNodes.get(m))!=null?y:[];E.push(d),g.lookups.deletedKeyedComponentNodes.set(m,E)}}),o.key!==void 0?(g.lookups.keyedComponentNodes.delete(o.key),g.lookups.deletedKeyedComponentNodes.set(o.key,[d])):g.lookups.deletedUnkeyedNodes.push({node:d}),u.push(d)}}return u}function j(n){function e(u){let c=N(u);c.deleted=!0;for(let g of c.components)g.component.__internal.element.node===u&&(g.component.__internal.unmounted||C.unmount(g.component,g.props))}let i=N(n);for(let u of i.lookups.deletedKeyedComponentNodes.values())for(let c of u)c.isConnected&&e(c);for(let{node:u}of i.lookups.deletedUnkeyedNodes)e(u);i.lookups.deletedKeyedComponentNodes.clear(),i.lookups.deletedUnkeyedNodes=[]}function se(n,e,i){function u(b,d,o){if(U(b)){let s=N(b);return b.tagName.toLowerCase()===d.type&&s.components.every((p,y)=>o[y]!==void 0&&o[y].component===p.component)}else return!1}function c(b,d,o){let{parentElement:s,currentNodeIndex:p}=d,y=N(s),m=y.lookups.keyedElementNodes.get(b.key);if(m!==void 0)if(u(m,b,o)){let l=s.childNodes[p];return m!==l&&s.insertBefore(m,l!=null?l:null),!0}else return y.lookups.keyedComponentNodes.delete(b.key),!1;else{let l=y.lookups.deletedKeyedElementNodes.get(b.key);if(l!==void 0){let E=s.childNodes;if(y.lookups.deletedKeyedComponentNodes.delete(b.key),u(l,b,o)){let f=E[p];return l!==f&&s.insertBefore(l,f!=null?f:null),!0}}return!1}}function g(b,d,o){var l;let{parentElement:s,currentNodeIndex:p,length:y}=d,m=s.childNodes;for(let E=p;E<p+y;E++){let f=m[E];if(U(f)){let v=N(f);if(f.tagName.toLowerCase()===b.type&&v.key===void 0&&u(f,b,o)){let P=(l=s.childNodes[p])!=null?l:null;return f!==P&&s.insertBefore(f,P),!0}}}return!1}return ne(n)?c(n,e,i):g(n,e,i)}function de(n,e,i){function u(g,b,d){let{parentElement:o,currentNodeIndex:s}=b,p=S(g.key,d),y=N(o),m=y.lookups.keyedComponentNodes.get(p);if(m!==void 0){let l=o.childNodes[s];for(let E of m)E!==l&&o.insertBefore(E,l!=null?l:null);return!0}else{let l=y.lookups.deletedKeyedComponentNodes.get(p);if(l!==void 0){y.lookups.deletedKeyedComponentNodes.delete(p);for(let E of l){let f=o.childNodes[s];E!==f&&o.insertBefore(E,f!=null?f:null)}return!0}}return!1}function c(g,b,d){var m;let{parentElement:o,currentNodeIndex:s,length:p}=b,y=o.childNodes;for(let l=s;l<s+p;l++){let E=y[l],f=N(E);if(f!==void 0&&f.components.length>d&&f.components[d].ctor===g.type){let v=(m=o.childNodes[s])!=null?m:null;return E!==v&&o.insertBefore(E,v),!0}}return!1}return ne(n)?u(n,e,i):c(n,e,i)}function D(n,e,i,u){var c;if(u.length>0&&(u[u.length-1].component.__internal.element.node=e),q(n)){let g=N(e);if(g!==void 0&&g.props)for(let o in g.props)o in n.props||o!=="children"&&o!=="xmlns"&&(e.nodeType===K||e.nodeType===G||e instanceof r.__internal.HTMLElement&&o in e?delete e[o]:e.removeAttribute(o));else if(!i&&U(e)&&e.hasAttributes()){let o=Array.from(e.attributes);for(let s of o){let p=s.name;p in n.props||e.removeAttribute(p)}}let b=Object.entries(n.props);for(let[o,s]of b)if(!he.includes(o)&&((c=g==null?void 0:g.props)==null?void 0:c[o])!==s&&o!=="children"&&o!=="xmlns")if(e.nodeType===K||e.nodeType===G)e[o]=s;else if(e instanceof r.__internal.HTMLElement)if(o==="style"){if(g===void 0||g.style===void 0||g.style!==n.props.style){let p=_e(n.props.style);e.style.cssText!==p&&(e.style.cssText=p)}}else o==="onblur"?e[o]=Ne(e,s):o in e?e[o]=s:e.setAttribute(o,s);else typeof s=="string"?e.setAttribute(o,s):e[o]=s;let d=H(_({},g),{key:n.key,props:n.props,components:u});Q(e,d)}else Q(e,{components:u,lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,keyedElementNodes:new Map,renderCount:0}})}function ie(n,e){let i=ee(e)?r.document.querySelector(e):e;if(i==null)throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(i.nodeType!==W)throw new Error("The container argument to the mount() function should be an HTML element.");let u=i.childNodes.length>0,c=a(n,{type:"search",currentNodeIndex:0,length:i.childNodes.length,parentElement:i},[],u);if(c.nodes.length<i.childNodes.length){let g=O(i.childNodes,c.nodes.length,i.childNodes.length);for(let b of g)b.remove()}return c}function ae(n){let e=ee(n)?r.document.querySelector(n):n;if(e===null)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.");L(e.childNodes,0,e.childNodes.length),j(e)}function le(n){let e=a(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function pe(n,e){if(!(n!=null&&n.node))throw new Error("Missing node information in rerender() argument.");let i=n.node.parentElement;if(k(i))return{nodes:[]};{let u=N(n.node),c=u.components[n.componentIndex],g=e!=null?e:c.props;if(!C.shouldUpdate(c.component,g,c.props)){let f=B(i.childNodes,n.node,0);return{nodes:O(i.childNodes,f,f+c.nodes.length)}}let b=H(_({},c),{props:g}),d=u.components.slice(0,n.componentIndex),o=d.length,s=d.concat(b),p=c.component.__internal.element.node,y=c.component.__internal.registeredMethods.render(g,c.component),m=B(i.childNodes,n.node,0),l={type:"search",currentNodeIndex:m,length:c.nodes.length,parentElement:i},E=V(y,l,s,o,c.nodes.length,!1);for(let f=0;f<d.length;f++){let v=d[f],P=v.nodes.findIndex(F=>F===c.nodes[0]);v.nodes=v.nodes.slice(0,P).concat(E.nodes).concat(v.nodes.slice(P+c.nodes.length)),v.nodes.length>0&&(v.component.__internal.element.node=v.nodes[0])}return j(i),C.afterRender(c.component,g,p),E}}function ue(n,e){let i=k(n.props.xmlns)?n.type==="svg"?ve:e!==void 0?e.namespaceURI:null:n.props.xmlns;return n.props.is!==void 0?i!==null?r.document.createElementNS(i,n.type,{is:n.props.is}):r.document.createElement(n.type,{is:n.props.is}):i!==null?r.document.createElementNS(i,n.type):r.document.createElement(n.type)}return{mount:ie,unmount:ae,render:le,rerender:pe}}var Z=globalThis!==void 0?globalThis:window,R=te({window:Z,document:Z.document});function Me(t){R=te(t)}function Re(t,r){return R.mount(t,r)}function Ae(t){return R.unmount(t)}function Se(t){return R.render(t)}function xe(t,r){return R.rerender(t,r)}function w(t){function r(a,h=[]){let T=Array.isArray(a)?a:z(a)?Array.isArray(a.props.children)?a.props.children:k(a.props.children)?[]:[a.props.children]:[a];for(let x of T)Array.isArray(x)||z(x)?r(x,h):h.push(x);return h}return r(t,[])}function Pe(t){return t.toString()}function q(t){return!k(t)&&t.__is_forgo_element__===!0}function Ce(t){return q(t)&&typeof t.type=="string"}function z(t){return!k(t)&&t.type===Te}function N(t){return t.__forgo===void 0&&(t.__forgo={components:[],lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,keyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,renderCount:0}}),t.__forgo}function Q(t,r){t.__forgo=r}var ke=t=>{let r=T=>({get element(){return T.__internal.element},update(x){return T.update(x)}}),a={render(T,x){return t.render(T,r(x))}};t.error&&(a.error=(T,x)=>t.error(T,Object.assign(r(h),{error:x})));let h=new M(_({},a));return t.mount&&h.mount(T=>{t.mount(T,r(h))}),t.remount&&h.remount(T=>{t.remount(T,r(h))}),t.unmount&&h.unmount(T=>{t.unmount(T,r(h))}),t.afterRender&&h.afterRender((T,x)=>{t.afterRender(T,Object.assign(r(h),{previousNode:x}))}),t.shouldUpdate&&h.shouldUpdate((T,x)=>t.shouldUpdate(T,x)),h};function S(t,r){return`$Component${r}_${t}`}function Fe(t,r,a){if(!(r instanceof M)&&Reflect.has(r,"render"))return a&&(console.warn("Legacy component syntax is deprecated since v3.2.0 and will be removed in v5.0. The affected component was found here:"),console.warn(new Error().stack)),ke(r);if(!(r instanceof M))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function k(t){return t==null}function ee(t){return typeof t=="string"}function U(t){return t.nodeType===W}function _e(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,a)=>r+a.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[a]+";","")}function ne(t){return t.key!==void 0}function O(t,r,a){let h=[];for(let T=r;T<a;T++)h.push(t[T]);return h}function B(t,r,a){if(r===void 0)return-1;for(let h=a;h<t.length;h++)if(t[h]===r)return h;return-1}(r=>r.JSX=A)(I||(I={}));export{M as Component,Te as Fragment,A as JSX,I as createElement,te as createForgoInstance,N as getForgoState,we as h,ke as legacyComponentSyntaxCompat,Re as mount,Se as render,xe as rerender,Me as setCustomEnv,Q as setForgoState,Ae as unmount}; | ||
//# sourceMappingURL=forgo.min.js.map |
@@ -372,3 +372,3 @@ // Since we'll set any attribute the user passes us, we need to be sure not to | ||
else { | ||
const indexOfNode = findNodeIndex(insertionOptions.parentElement.childNodes, componentState.component.__internal.element.node); | ||
const indexOfNode = findNodeIndex(insertionOptions.parentElement.childNodes, componentState.component.__internal.element.node, insertionOptions.currentNodeIndex); | ||
return { | ||
@@ -511,7 +511,7 @@ nodes: sliceNodes(insertionOptions.parentElement.childNodes, indexOfNode, indexOfNode + componentState.nodes.length), | ||
const removedNodes = []; | ||
const nodesToRemove = sliceNodes(nodes, from, to); | ||
if (nodesToRemove.length) { | ||
const parentElement = nodesToRemove[0].parentElement; | ||
if (to > from) { | ||
const parentElement = nodes[from].parentElement; | ||
const parentState = getForgoState(parentElement); | ||
for (const node of nodesToRemove) { | ||
for (let i = from; i < to; i++) { | ||
const node = nodes[from]; | ||
const state = getForgoState(node); | ||
@@ -926,3 +926,3 @@ // Remove the node from DOM | ||
if (!lifecycleEmitters.shouldUpdate(originalComponentState.component, effectiveProps, originalComponentState.props)) { | ||
const indexOfNode = findNodeIndex(parentElement.childNodes, element.node); | ||
const indexOfNode = findNodeIndex(parentElement.childNodes, element.node, 0); | ||
return { | ||
@@ -938,3 +938,3 @@ nodes: sliceNodes(parentElement.childNodes, indexOfNode, indexOfNode + originalComponentState.nodes.length), | ||
const forgoNode = originalComponentState.component.__internal.registeredMethods.render(effectiveProps, originalComponentState.component); | ||
const nodeIndex = findNodeIndex(parentElement.childNodes, element.node); | ||
const nodeIndex = findNodeIndex(parentElement.childNodes, element.node, 0); | ||
const insertionOptions = { | ||
@@ -1219,3 +1219,7 @@ type: "search", | ||
function sliceNodes(nodes, from, to) { | ||
return Array.from(nodes).slice(from, to); | ||
const result = []; | ||
for (let i = from; i < to; i++) { | ||
result.push(nodes[i]); | ||
} | ||
return result; | ||
} | ||
@@ -1226,6 +1230,11 @@ /** | ||
*/ | ||
function findNodeIndex(nodes, element) { | ||
if (!element) | ||
function findNodeIndex(nodes, element, startSearchFrom) { | ||
if (element === undefined) | ||
return -1; | ||
return Array.from(nodes).indexOf(element); | ||
for (let i = startSearchFrom; i < nodes.length; i++) { | ||
if (nodes[i] === element) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
@@ -1232,0 +1241,0 @@ /* JSX Types */ |
{ | ||
"name": "forgo", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"main": "./dist/forgo.min.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
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
392460
4894