@unsetsoft/ryunixjs 1.1.6-canary.49 → 1.1.6-canary.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Ryunix.js +24 -20
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/dist/Ryunix.js
CHANGED
|
@@ -612,10 +612,10 @@
|
|
|
612
612
|
function reconcileChildren(wipFiber, elements) {
|
|
613
613
|
let index = 0;
|
|
614
614
|
let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
|
|
615
|
-
let newFiber = null;
|
|
616
615
|
let prevSibling = null;
|
|
617
616
|
const oldFibersByKey = new Map();
|
|
618
617
|
|
|
618
|
+
// Mapea los antiguos `fibers` por clave
|
|
619
619
|
while (oldFiber) {
|
|
620
620
|
const key = oldFiber.props.key || index;
|
|
621
621
|
oldFibersByKey.set(key, oldFiber);
|
|
@@ -623,19 +623,25 @@
|
|
|
623
623
|
index++;
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
-
|
|
627
|
-
|
|
626
|
+
index = 0;
|
|
627
|
+
oldFiber = wipFiber.alternate && wipFiber.alternate.child; // Reinicia oldFiber
|
|
628
|
+
while (index < elements.length || oldFiber) {
|
|
629
|
+
const element = elements[index];
|
|
630
|
+
let newFiber = null;
|
|
628
631
|
|
|
629
|
-
const
|
|
632
|
+
const key = element ? element.props.key || index : null;
|
|
633
|
+
const oldFiberByKey = oldFibersByKey.get(key);
|
|
634
|
+
const sameType =
|
|
635
|
+
oldFiberByKey && element && element.type === oldFiberByKey.type;
|
|
630
636
|
|
|
631
637
|
if (sameType) {
|
|
632
638
|
// Actualiza el nodo si es del mismo tipo
|
|
633
639
|
newFiber = {
|
|
634
|
-
type:
|
|
640
|
+
type: oldFiberByKey.type,
|
|
635
641
|
props: element.props,
|
|
636
|
-
dom:
|
|
642
|
+
dom: oldFiberByKey.dom,
|
|
637
643
|
parent: wipFiber,
|
|
638
|
-
alternate:
|
|
644
|
+
alternate: oldFiberByKey,
|
|
639
645
|
key,
|
|
640
646
|
effectTag: 'UPDATE',
|
|
641
647
|
};
|
|
@@ -652,10 +658,10 @@
|
|
|
652
658
|
};
|
|
653
659
|
}
|
|
654
660
|
|
|
655
|
-
if (
|
|
661
|
+
if (oldFiberByKey && !sameType) {
|
|
656
662
|
// Marca el nodo viejo para eliminación si ya no es del mismo tipo
|
|
657
|
-
|
|
658
|
-
vars.deletions.push(
|
|
663
|
+
oldFiberByKey.effectTag = 'DELETION';
|
|
664
|
+
vars.deletions.push(oldFiberByKey);
|
|
659
665
|
}
|
|
660
666
|
|
|
661
667
|
// Solo avanza `oldFiber` si es el mismo tipo o ya no hay un nuevo elemento
|
|
@@ -671,18 +677,16 @@
|
|
|
671
677
|
}
|
|
672
678
|
|
|
673
679
|
prevSibling = newFiber;
|
|
674
|
-
|
|
675
680
|
index++;
|
|
676
|
-
});
|
|
677
|
-
// Manejo de eliminaciones de antiguos fibers que no existen en los nuevos elementos
|
|
678
|
-
if (oldFibersByKey) {
|
|
679
|
-
oldFibersByKey.forEach((oldFiber, key) => {
|
|
680
|
-
if (!elements.some((element) => (element.props.key || index) === key)) {
|
|
681
|
-
oldFiber.effectTag = 'DELETION';
|
|
682
|
-
vars.deletions.push(oldFiber);
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
681
|
}
|
|
682
|
+
|
|
683
|
+
// Elimina cualquier fiber sobrante en oldFibersByKey que no tenga un match en elements
|
|
684
|
+
oldFibersByKey.forEach((oldFiber, key) => {
|
|
685
|
+
if (!elements.some((element) => (element.props.key || index) === key)) {
|
|
686
|
+
oldFiber.effectTag = 'DELETION';
|
|
687
|
+
vars.deletions.push(oldFiber);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
686
690
|
}
|
|
687
691
|
|
|
688
692
|
var Reconciler = /*#__PURE__*/Object.freeze({
|
package/dist/Ryunix.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,t){"use strict";let o={containerRoot:{},nextUnitOfWork:{},currentRoot:{},wipRoot:{},deletions:[],wipFiber:{},hookIndex:0};const n=/[A-Z]/g,r=Object.freeze({TEXT_ELEMENT:Symbol("text.element"),RYUNIX_ELEMENT:Symbol("ryunix.element"),RYUNIX_EFFECT:Symbol("ryunix.effect"),RYUNIX_MEMO:Symbol("ryunix.memo"),RYUNIX_URL_QUERY:Symbol("ryunix.urlQuery"),RYUNIX_REF:Symbol("ryunix.ref"),RYUNIX_STORE:Symbol("ryunix.store"),RYUNIX_REDUCE:Symbol("ryunix.reduce")}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean",string:"string"}),s=Object.freeze({PLACEMENT:"PLACEMENT",UPDATE:"UPDATE",DELETION:"DELETION"});function l(e,t){return t=t||[],null==e||"boolean"==typeof e||(Array.isArray(e)?e.some((e=>{l(e,t)})):t.push(e)),t}function a(e,t,...o){return o=l(o,[]),{type:e,props:{...t,children:o.map((e=>typeof e===i.object?e:p(e))),key:t&&t.key?t.key:(n=r.RYUNIX_ELEMENT.toString(),`${n}-${Math.random().toString(36).substring(2,9)}`)}};var n}const p=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}});function u(e,t){o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.deletions=[],o.nextUnitOfWork=o.wipRoot}const c=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={state:t?t.state:e,queue:t?[...t.queue]:[]};n.queue.forEach((e=>{n.state=typeof e===i.function?e(n.state):e})),n.queue=[];return o.wipFiber&&o.wipFiber.hooks&&(o.wipFiber.hooks.push(n),o.hookIndex++),[n.state,e=>{n.queue.push(e),o.wipRoot={dom:o.currentRoot.dom,props:{...o.currentRoot.props},alternate:o.currentRoot},o.nextUnitOfWork=o.wipRoot,o.deletions=[]}]},d=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_EFFECT,deps:n};i&&t.isEqual(i.deps,s.deps)||e(),o.wipFiber.hooks&&(o.wipFiber.hooks.push(s),o.hookIndex++)},f=(e,n)=>{const i=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],s={type:r.RYUNIX_MEMO,value:null,deps:n};return i&&t.isEqual(i.deps,s.deps)?s.value=i.value:s.value=e(),o.wipFiber.hooks&&(o.wipFiber.hooks.push(s),o.hookIndex++),s.value},h=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},m=e=>e.startsWith("on"),y=e=>e!==i.children&&!m(e),b=(e,t)=>o=>e[o]!==t[o];function E(e){const t=e.type===r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return w(t,{},e.props),t}function w(e,t,o){var n;Object.keys(t).filter(m).filter((e=>!(e in o)||b(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(y).filter((n=o,e=>!(e in n))).forEach((t=>{e[t]=""})),Object.keys(o).filter(y).filter(b(t,o)).forEach((t=>{e[t]=o[t]})),Object.keys(o).filter(m).filter(b(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))}var k=Object.freeze({__proto__:null,DomStyle:(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")},createDom:E,updateDom:w});function R(){o.deletions.forEach(F),o.wipRoot&&o.wipRoot.child&&(F(o.wipRoot.child),o.currentRoot=o.wipRoot),o.wipRoot=void 0}function F(e){if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===s.PLACEMENT&&null!=e.dom)o.appendChild(e.dom);else if(e.effectTag===s.UPDATE&&null!=e.dom)w(e.dom,e.alternate.props,e.props);else if(e.effectTag===s.DELETION)return void _(o,e);F(e.child),F(e.sibling)}function _(e,t){t&&t.dom?e.removeChild(t.dom):t&&t.child&&_(e,t.child)}var T=Object.freeze({__proto__:null,commitDeletion:_,commitRoot:R,commitWork:F});function x(e,t){let n=0,r=e.alternate&&e.alternate.child,i=null;const s=new Map;for(;r;){const e=r.props.key||n;s.set(e,r),r=r.sibling,n++}for(n=0,r=e.alternate&&e.alternate.child;n<t.length||r;){const l=t[n];let a=null;const p=l?l.props.key||n:null,u=s.get(p),c=u&&l&&l.type===u.type;c?a={type:u.type,props:l.props,dom:u.dom,parent:e,alternate:u,key:p,effectTag:"UPDATE"}:l&&(a={type:l.type,props:l.props,dom:null,parent:e,alternate:null,key:p,effectTag:"PLACEMENT"}),u&&!c&&(u.effectTag="DELETION",o.deletions.push(u)),r&&(r=r.sibling),0===n?e.child=a:i&&(i.sibling=a),i=a,n++}s.forEach(((e,r)=>{t.some((e=>(e.props.key||n)===r))||(e.effectTag="DELETION",o.deletions.push(e))}))}var g=Object.freeze({__proto__:null,reconcileChildren:x});const N=e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];let t=e.type(e.props),n=[];n=Array.isArray(t)?[...t]:[t],x(e,n)};function v(e){e.dom||(e.dom=E(e)),x(e,e.props.children)}var I=Object.freeze({__proto__:null,updateFunctionComponent:N,updateHostComponent:v});function O(e){let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=U(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&R(),window.requestIdleCallback(O)}function U(e){if(e.type instanceof Function?N(e):v(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}}requestIdleCallback(O);var L={createElement:a,render:u,init:(e,t="__ryunix")=>{u(e,document.getElementById(t))},Fragment:e=>e.children,Dom:k,Workers:Object.freeze({__proto__:null,performUnitOfWork:U,workLoop:O}),Reconciler:g,Components:I,Commits:T};window.Ryunix=L,e.default=L,e.useCallback=(e,t)=>f((()=>e),t),e.useEffect=d,e.useMemo=f,e.useQuery=h,e.useRef=e=>{const t=o.wipFiber.alternate&&o.wipFiber.alternate.hooks&&o.wipFiber.alternate.hooks[o.hookIndex],n={type:r.RYUNIX_REF,value:t?t.value:{current:e}};return o.wipFiber.hooks&&(o.wipFiber.hooks.push(n),o.hookIndex++),n.value},e.useRouter=e=>{const[t,o]=c(window.location.pathname),n=(e,t)=>{const o=t.split("?")[0],r=e.find((e=>e.NotFound)),i=r?{route:{component:r.NotFound},params:{}}:{route:{component:null},params:{}};for(const r of e){if(r.subRoutes){const e=n(r.subRoutes,t);if(e)return e}if("*"===r.path)return i;if(!r.path||"string"!=typeof r.path){console.warn("Invalid route detected:",r),console.info("if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }");continue}const e=[],s=new RegExp(`^${r.path.replace(/:\w+/g,(t=>(e.push(t.substring(1)),"([^/]+)")))}$`),l=o.match(s);if(l){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=l[o+1],e)),{})}}}return i},r=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};d((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const l=n(e,t)||{};return{Children:()=>{const e=h(),{route:t}=l;return t&&t.component&&typeof t.component===i.function?t.component({params:l.params||{},query:e}):(console.error("Component not found for current path or the component is not a valid function:",l),null)},NavLink:({to:e,...t})=>a("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}},e.useStore=c,Object.defineProperty(e,"__esModule",{value:!0})}));
|