@unsetsoft/ryunixjs 1.1.6-canary.3 → 1.1.6-canary.7
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 +183 -142
- package/dist/Ryunix.min.js +1 -1
- package/package.json +1 -1
package/dist/Ryunix.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ryunix = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Ryunix = {}, global.lodash));
|
|
5
|
+
})(this, (function (exports, lodash) { 'use strict';
|
|
6
6
|
|
|
7
7
|
let vars = {
|
|
8
8
|
containerRoot: {},
|
|
@@ -37,37 +37,31 @@
|
|
|
37
37
|
string: 'string',
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
const OLD_STRINGS = Object.freeze({
|
|
41
|
+
style: 'style',
|
|
42
|
+
className: 'className',
|
|
43
|
+
});
|
|
44
|
+
|
|
40
45
|
const EFFECT_TAGS = Object.freeze({
|
|
41
46
|
PLACEMENT: Symbol('ryunix.reconciler.status.placement').toString(),
|
|
42
47
|
UPDATE: Symbol('ryunix.reconciler.status.update').toString(),
|
|
43
48
|
DELETION: Symbol('ryunix.reconciler.status.deletion').toString(),
|
|
44
49
|
});
|
|
45
50
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
for (let i = 0; i < arr1.length; i++) {
|
|
49
|
-
if (arr1[i] !== arr2[i]) return false
|
|
50
|
-
}
|
|
51
|
-
return true
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const resolveProps = (props) => {
|
|
55
|
-
const resolvedProps = {};
|
|
56
|
-
for (const key in props) {
|
|
57
|
-
resolvedProps[key] =
|
|
58
|
-
typeof props[key] === STRINGS.function ? props[key]() : props[key];
|
|
59
|
-
}
|
|
60
|
-
return resolvedProps
|
|
51
|
+
const generateHash = (prefix) => {
|
|
52
|
+
return `${prefix}-${Math.random().toString(36).substring(2, 9)}`
|
|
61
53
|
};
|
|
62
54
|
|
|
63
55
|
const Fragment = (props) => {
|
|
64
56
|
return props.children
|
|
65
57
|
};
|
|
66
58
|
|
|
67
|
-
const childArray = (children, out
|
|
68
|
-
|
|
69
|
-
if (Array.isArray(children)) {
|
|
70
|
-
children.
|
|
59
|
+
const childArray = (children, out) => {
|
|
60
|
+
out = out || [];
|
|
61
|
+
if (children == undefined || typeof children == STRINGS.boolean) ; else if (Array.isArray(children)) {
|
|
62
|
+
children.some((child) => {
|
|
63
|
+
childArray(child, out);
|
|
64
|
+
});
|
|
71
65
|
} else {
|
|
72
66
|
out.push(children);
|
|
73
67
|
}
|
|
@@ -92,18 +86,18 @@
|
|
|
92
86
|
*/
|
|
93
87
|
|
|
94
88
|
const createElement = (type, props, ...children) => {
|
|
95
|
-
|
|
96
|
-
resolvedProps.children = childArray(children, []);
|
|
89
|
+
children = childArray(children, []);
|
|
97
90
|
const key =
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
props && props.key
|
|
92
|
+
? generateHash(props.key)
|
|
93
|
+
: generateHash(RYUNIX_TYPES.Ryunix_ELEMENT.toString());
|
|
100
94
|
|
|
101
95
|
return {
|
|
102
96
|
type,
|
|
103
97
|
props: {
|
|
104
|
-
...
|
|
98
|
+
...props,
|
|
105
99
|
key,
|
|
106
|
-
children:
|
|
100
|
+
children: children.map((child) =>
|
|
107
101
|
typeof child === STRINGS.object ? child : createTextElement(child),
|
|
108
102
|
),
|
|
109
103
|
},
|
|
@@ -170,36 +164,40 @@
|
|
|
170
164
|
* `setState` function that can be used to update the state.
|
|
171
165
|
*/
|
|
172
166
|
const useStore = (initial) => {
|
|
173
|
-
const oldHook =
|
|
167
|
+
const oldHook =
|
|
168
|
+
vars.wipFiber.alternate &&
|
|
169
|
+
vars.wipFiber.alternate.hooks &&
|
|
170
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
174
171
|
const hook = {
|
|
175
172
|
state: oldHook ? oldHook.state : initial,
|
|
176
173
|
queue: oldHook ? [...oldHook.queue] : [],
|
|
177
174
|
};
|
|
178
175
|
|
|
179
176
|
hook.queue.forEach((action) => {
|
|
180
|
-
|
|
177
|
+
hook.state =
|
|
181
178
|
typeof action === STRINGS.function ? action(hook.state) : action;
|
|
182
|
-
if (newState !== hook.state) {
|
|
183
|
-
hook.state = newState;
|
|
184
|
-
}
|
|
185
179
|
});
|
|
186
180
|
|
|
181
|
+
hook.queue = [];
|
|
182
|
+
|
|
187
183
|
const setState = (action) => {
|
|
188
184
|
hook.queue.push(action);
|
|
189
185
|
|
|
190
|
-
|
|
191
|
-
vars.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
vars.wipRoot = {
|
|
187
|
+
dom: vars.currentRoot.dom,
|
|
188
|
+
props: {
|
|
189
|
+
...vars.currentRoot.props,
|
|
190
|
+
},
|
|
191
|
+
alternate: vars.currentRoot,
|
|
192
|
+
};
|
|
193
|
+
vars.nextUnitOfWork = vars.wipRoot;
|
|
194
|
+
vars.deletions = [];
|
|
199
195
|
};
|
|
200
196
|
|
|
201
|
-
vars.wipFiber.hooks
|
|
202
|
-
|
|
197
|
+
if (vars.wipFiber && vars.wipFiber.hooks) {
|
|
198
|
+
vars.wipFiber.hooks.push(hook);
|
|
199
|
+
vars.hookIndex++;
|
|
200
|
+
}
|
|
203
201
|
|
|
204
202
|
return [hook.state, setState]
|
|
205
203
|
};
|
|
@@ -215,53 +213,77 @@
|
|
|
215
213
|
*/
|
|
216
214
|
|
|
217
215
|
const useEffect = (callback, deps) => {
|
|
218
|
-
const oldHook =
|
|
216
|
+
const oldHook =
|
|
217
|
+
vars.wipFiber.alternate &&
|
|
218
|
+
vars.wipFiber.alternate.hooks &&
|
|
219
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
220
|
+
|
|
219
221
|
const hook = {
|
|
220
222
|
type: RYUNIX_TYPES.RYUNIX_EFFECT,
|
|
221
223
|
deps,
|
|
222
|
-
cleanup: oldHook?.cleanup,
|
|
223
224
|
};
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
if (!oldHook) {
|
|
227
|
+
// invoke callback if this is the first time
|
|
228
|
+
callback();
|
|
229
|
+
} else {
|
|
230
|
+
if (!lodash.isEqual(oldHook.deps, hook.deps)) {
|
|
231
|
+
callback();
|
|
232
|
+
}
|
|
229
233
|
}
|
|
230
234
|
|
|
231
|
-
if (
|
|
232
|
-
|
|
235
|
+
if (vars.wipFiber.hooks) {
|
|
236
|
+
vars.wipFiber.hooks.push(hook);
|
|
237
|
+
vars.hookIndex++;
|
|
233
238
|
}
|
|
234
|
-
|
|
235
|
-
vars.wipFiber.hooks.push(hook);
|
|
236
|
-
vars.hookIndex++;
|
|
237
239
|
};
|
|
238
240
|
|
|
239
241
|
const useRef = (initial) => {
|
|
240
|
-
const oldHook =
|
|
242
|
+
const oldHook =
|
|
243
|
+
vars.wipFiber.alternate &&
|
|
244
|
+
vars.wipFiber.alternate.hooks &&
|
|
245
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
246
|
+
|
|
241
247
|
const hook = {
|
|
242
248
|
type: RYUNIX_TYPES.RYUNIX_REF,
|
|
243
249
|
value: oldHook ? oldHook.value : { current: initial },
|
|
244
250
|
};
|
|
245
251
|
|
|
246
|
-
vars.wipFiber.hooks
|
|
247
|
-
|
|
252
|
+
if (vars.wipFiber.hooks) {
|
|
253
|
+
vars.wipFiber.hooks.push(hook);
|
|
254
|
+
vars.hookIndex++;
|
|
255
|
+
}
|
|
256
|
+
|
|
248
257
|
return hook.value
|
|
249
258
|
};
|
|
250
259
|
|
|
251
|
-
const useMemo = (
|
|
252
|
-
const oldHook =
|
|
260
|
+
const useMemo = (comp, deps) => {
|
|
261
|
+
const oldHook =
|
|
262
|
+
vars.wipFiber.alternate &&
|
|
263
|
+
vars.wipFiber.alternate.hooks &&
|
|
264
|
+
vars.wipFiber.alternate.hooks[vars.hookIndex];
|
|
265
|
+
|
|
253
266
|
const hook = {
|
|
254
267
|
type: RYUNIX_TYPES.RYUNIX_MEMO,
|
|
255
|
-
value:
|
|
268
|
+
value: null,
|
|
256
269
|
deps,
|
|
257
270
|
};
|
|
258
271
|
|
|
259
|
-
if (
|
|
260
|
-
hook.
|
|
272
|
+
if (oldHook) {
|
|
273
|
+
if (lodash.isEqual(oldHook.deps, hook.deps)) {
|
|
274
|
+
hook.value = oldHook.value;
|
|
275
|
+
} else {
|
|
276
|
+
hook.value = comp();
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
hook.value = comp();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (vars.wipFiber.hooks) {
|
|
283
|
+
vars.wipFiber.hooks.push(hook);
|
|
284
|
+
vars.hookIndex++;
|
|
261
285
|
}
|
|
262
286
|
|
|
263
|
-
vars.wipFiber.hooks.push(hook);
|
|
264
|
-
vars.hookIndex++;
|
|
265
287
|
return hook.value
|
|
266
288
|
};
|
|
267
289
|
|
|
@@ -341,51 +363,51 @@
|
|
|
341
363
|
const useRouter = (routes) => {
|
|
342
364
|
const [location, setLocation] = useStore(window.location.pathname);
|
|
343
365
|
|
|
344
|
-
const routeCache = new Map();
|
|
345
|
-
|
|
346
366
|
const findRoute = (routes, path) => {
|
|
347
|
-
if (routeCache.has(path)) return routeCache.get(path)
|
|
348
|
-
|
|
349
367
|
const pathname = path.split('?')[0];
|
|
350
|
-
|
|
368
|
+
|
|
369
|
+
const notFoundRoute = routes.find((route) => route.NotFound);
|
|
351
370
|
const notFound = notFoundRoute
|
|
352
371
|
? { route: { component: notFoundRoute.NotFound }, params: {} }
|
|
353
372
|
: { route: { component: null }, params: {} };
|
|
354
373
|
|
|
355
374
|
for (const route of routes) {
|
|
356
375
|
if (route.subRoutes) {
|
|
357
|
-
const
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
376
|
+
const childRoute = findRoute(route.subRoutes, path);
|
|
377
|
+
if (childRoute) return childRoute
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (route.path === '*') {
|
|
381
|
+
return notFound
|
|
362
382
|
}
|
|
363
383
|
|
|
364
384
|
if (!route.path || typeof route.path !== 'string') {
|
|
365
385
|
console.warn('Invalid route detected:', route);
|
|
386
|
+
console.info(
|
|
387
|
+
"if you are using { NotFound: NotFound } please add { path: '*', NotFound: NotFound }",
|
|
388
|
+
);
|
|
366
389
|
continue
|
|
367
390
|
}
|
|
368
391
|
|
|
369
392
|
const keys = [];
|
|
370
|
-
const pattern =
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
393
|
+
const pattern = new RegExp(
|
|
394
|
+
`^${route.path.replace(/:\w+/g, (match) => {
|
|
395
|
+
keys.push(match.substring(1));
|
|
396
|
+
return '([^/]+)'
|
|
397
|
+
})}$`,
|
|
398
|
+
);
|
|
374
399
|
|
|
375
|
-
const match = pathname.match(
|
|
400
|
+
const match = pathname.match(pattern);
|
|
376
401
|
if (match) {
|
|
377
402
|
const params = keys.reduce((acc, key, index) => {
|
|
378
403
|
acc[key] = match[index + 1];
|
|
379
404
|
return acc
|
|
380
405
|
}, {});
|
|
381
406
|
|
|
382
|
-
|
|
383
|
-
routeCache.set(path, routeData);
|
|
384
|
-
return routeData
|
|
407
|
+
return { route, params }
|
|
385
408
|
}
|
|
386
409
|
}
|
|
387
410
|
|
|
388
|
-
routeCache.set(path, notFound);
|
|
389
411
|
return notFound
|
|
390
412
|
};
|
|
391
413
|
|
|
@@ -458,12 +480,13 @@
|
|
|
458
480
|
* "cancelEffects" is likely intended
|
|
459
481
|
*/
|
|
460
482
|
const cancelEffects = (fiber) => {
|
|
461
|
-
if (
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
483
|
+
if (fiber.hooks) {
|
|
484
|
+
fiber.hooks
|
|
485
|
+
.filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.cancel)
|
|
486
|
+
.forEach((effectHook) => {
|
|
487
|
+
effectHook.cancel();
|
|
488
|
+
});
|
|
489
|
+
}
|
|
467
490
|
};
|
|
468
491
|
|
|
469
492
|
/**
|
|
@@ -474,12 +497,13 @@
|
|
|
474
497
|
* contains information about a component and its children, as
|
|
475
498
|
*/
|
|
476
499
|
const runEffects = (fiber) => {
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
500
|
+
if (fiber.hooks) {
|
|
501
|
+
fiber.hooks
|
|
502
|
+
.filter((hook) => hook.tag === RYUNIX_TYPES.RYUNIX_EFFECT && hook.effect)
|
|
503
|
+
.forEach((effectHook) => {
|
|
504
|
+
effectHook.cancel = effectHook.effect();
|
|
505
|
+
});
|
|
506
|
+
}
|
|
483
507
|
};
|
|
484
508
|
|
|
485
509
|
/**
|
|
@@ -494,14 +518,15 @@
|
|
|
494
518
|
*/
|
|
495
519
|
const createDom = (fiber) => {
|
|
496
520
|
const dom =
|
|
497
|
-
fiber.type
|
|
498
|
-
? document.createTextNode(
|
|
521
|
+
fiber.type == RYUNIX_TYPES.TEXT_ELEMENT
|
|
522
|
+
? document.createTextNode('')
|
|
499
523
|
: document.createElement(fiber.type);
|
|
500
524
|
|
|
501
525
|
updateDom(dom, {}, fiber.props);
|
|
502
526
|
|
|
503
527
|
return dom
|
|
504
528
|
};
|
|
529
|
+
|
|
505
530
|
/**
|
|
506
531
|
* The function updates the DOM by removing old event listeners and properties, and adding new ones
|
|
507
532
|
* based on the previous and next props.
|
|
@@ -518,14 +543,6 @@
|
|
|
518
543
|
dom.removeEventListener(eventType, prevProps[name]);
|
|
519
544
|
});
|
|
520
545
|
|
|
521
|
-
Object.keys(nextProps)
|
|
522
|
-
.filter(isEvent)
|
|
523
|
-
.filter(isNew(prevProps, nextProps))
|
|
524
|
-
.forEach((name) => {
|
|
525
|
-
const eventType = name.toLowerCase().substring(2);
|
|
526
|
-
dom.addEventListener(eventType, nextProps[name]);
|
|
527
|
-
});
|
|
528
|
-
|
|
529
546
|
Object.keys(prevProps)
|
|
530
547
|
.filter(isProperty)
|
|
531
548
|
.filter(isGone(nextProps))
|
|
@@ -538,24 +555,47 @@
|
|
|
538
555
|
.filter(isNew(prevProps, nextProps))
|
|
539
556
|
.forEach((name) => {
|
|
540
557
|
if (name === STRINGS.style) {
|
|
541
|
-
DomStyle(dom, nextProps[
|
|
558
|
+
DomStyle(dom, nextProps['ryunix-style']);
|
|
559
|
+
} else if (name === OLD_STRINGS.style) {
|
|
560
|
+
DomStyle(dom, nextProps.style);
|
|
542
561
|
} else if (name === STRINGS.className) {
|
|
543
|
-
if (nextProps[
|
|
544
|
-
|
|
562
|
+
if (nextProps['ryunix-class'] === '') {
|
|
563
|
+
throw new Error('data-class cannot be empty.')
|
|
545
564
|
}
|
|
565
|
+
|
|
566
|
+
prevProps['ryunix-class'] &&
|
|
567
|
+
dom.classList.remove(...prevProps['ryunix-class'].split(/\s+/));
|
|
568
|
+
dom.classList.add(...nextProps['ryunix-class'].split(/\s+/));
|
|
569
|
+
} else if (name === OLD_STRINGS.className) {
|
|
570
|
+
if (nextProps.className === '') {
|
|
571
|
+
throw new Error('className cannot be empty.')
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
prevProps.className &&
|
|
575
|
+
dom.classList.remove(...prevProps.className.split(/\s+/));
|
|
576
|
+
dom.classList.add(...nextProps.className.split(/\s+/));
|
|
546
577
|
} else {
|
|
547
578
|
dom[name] = nextProps[name];
|
|
548
579
|
}
|
|
549
580
|
});
|
|
581
|
+
|
|
582
|
+
Object.keys(nextProps)
|
|
583
|
+
.filter(isEvent)
|
|
584
|
+
.filter(isNew(prevProps, nextProps))
|
|
585
|
+
.forEach((name) => {
|
|
586
|
+
const eventType = name.toLowerCase().substring(2);
|
|
587
|
+
dom.addEventListener(eventType, nextProps[name]);
|
|
588
|
+
});
|
|
550
589
|
};
|
|
551
590
|
|
|
552
591
|
const DomStyle = (dom, style) => {
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
592
|
+
dom.style = Object.keys(style).reduce((acc, styleName) => {
|
|
593
|
+
const key = styleName.replace(reg, function (v) {
|
|
594
|
+
return '-' + v.toLowerCase()
|
|
595
|
+
});
|
|
596
|
+
acc += `${key}: ${style[styleName]};`;
|
|
597
|
+
return acc
|
|
598
|
+
}, '');
|
|
559
599
|
};
|
|
560
600
|
|
|
561
601
|
var Dom = /*#__PURE__*/Object.freeze({
|
|
@@ -574,7 +614,7 @@
|
|
|
574
614
|
commitWork(vars.wipRoot.child);
|
|
575
615
|
vars.currentRoot = vars.wipRoot;
|
|
576
616
|
}
|
|
577
|
-
vars.wipRoot =
|
|
617
|
+
vars.wipRoot = undefined;
|
|
578
618
|
};
|
|
579
619
|
|
|
580
620
|
/**
|
|
@@ -588,15 +628,15 @@
|
|
|
588
628
|
if (!fiber) return
|
|
589
629
|
|
|
590
630
|
let domParentFiber = fiber.parent;
|
|
591
|
-
while (
|
|
631
|
+
while (!domParentFiber.dom) {
|
|
592
632
|
domParentFiber = domParentFiber.parent;
|
|
593
633
|
}
|
|
594
|
-
const domParent = domParentFiber
|
|
634
|
+
const domParent = domParentFiber.dom;
|
|
595
635
|
|
|
596
|
-
if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom) {
|
|
636
|
+
if (fiber.effectTag === EFFECT_TAGS.PLACEMENT && fiber.dom != null) {
|
|
597
637
|
domParent.appendChild(fiber.dom);
|
|
598
638
|
runEffects(fiber);
|
|
599
|
-
} else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom) {
|
|
639
|
+
} else if (fiber.effectTag === EFFECT_TAGS.UPDATE && fiber.dom != null) {
|
|
600
640
|
cancelEffects(fiber);
|
|
601
641
|
updateDom(fiber.dom, fiber.alternate.props, fiber.props);
|
|
602
642
|
runEffects(fiber);
|
|
@@ -606,6 +646,7 @@
|
|
|
606
646
|
return
|
|
607
647
|
}
|
|
608
648
|
|
|
649
|
+
// Recorre los "fibers" hijos y hermanos
|
|
609
650
|
commitWork(fiber.child);
|
|
610
651
|
commitWork(fiber.sibling);
|
|
611
652
|
};
|
|
@@ -620,12 +661,9 @@
|
|
|
620
661
|
const commitDeletion = (fiber, domParent) => {
|
|
621
662
|
if (fiber.dom) {
|
|
622
663
|
domParent.removeChild(fiber.dom);
|
|
623
|
-
} else
|
|
664
|
+
} else {
|
|
624
665
|
commitDeletion(fiber.child, domParent);
|
|
625
666
|
}
|
|
626
|
-
if (fiber.sibling) {
|
|
627
|
-
commitDeletion(fiber.sibling, domParent);
|
|
628
|
-
}
|
|
629
667
|
};
|
|
630
668
|
|
|
631
669
|
var Commits = /*#__PURE__*/Object.freeze({
|
|
@@ -644,16 +682,15 @@
|
|
|
644
682
|
* @param elements - an array of elements representing the new children to be rendered in the current
|
|
645
683
|
* fiber's subtree
|
|
646
684
|
*/
|
|
647
|
-
|
|
648
685
|
const reconcileChildren = (wipFiber, elements) => {
|
|
649
686
|
let index = 0;
|
|
687
|
+
let oldFiber = wipFiber.alternate && wipFiber.alternate.child;
|
|
650
688
|
let prevSibling = null;
|
|
651
|
-
const oldFibersMap = new Map();
|
|
652
689
|
|
|
653
|
-
|
|
690
|
+
const oldFibersMap = new Map();
|
|
654
691
|
while (oldFiber) {
|
|
655
|
-
const
|
|
656
|
-
oldFibersMap.set(
|
|
692
|
+
const oldKey = oldFiber.props.key || oldFiber.type;
|
|
693
|
+
oldFibersMap.set(oldKey, oldFiber);
|
|
657
694
|
oldFiber = oldFiber.sibling;
|
|
658
695
|
}
|
|
659
696
|
|
|
@@ -665,12 +702,13 @@
|
|
|
665
702
|
let newFiber;
|
|
666
703
|
const sameType = oldFiber && element && element.type === oldFiber.type;
|
|
667
704
|
|
|
668
|
-
if (sameType
|
|
669
|
-
newFiber = oldFiber;
|
|
670
|
-
} else if (sameType) {
|
|
705
|
+
if (sameType) {
|
|
671
706
|
newFiber = {
|
|
672
|
-
|
|
707
|
+
type: oldFiber.type,
|
|
673
708
|
props: element.props,
|
|
709
|
+
dom: oldFiber.dom,
|
|
710
|
+
parent: wipFiber,
|
|
711
|
+
alternate: oldFiber,
|
|
674
712
|
effectTag: EFFECT_TAGS.UPDATE,
|
|
675
713
|
};
|
|
676
714
|
oldFibersMap.delete(key);
|
|
@@ -678,8 +716,10 @@
|
|
|
678
716
|
newFiber = {
|
|
679
717
|
type: element.type,
|
|
680
718
|
props: element.props,
|
|
681
|
-
|
|
719
|
+
dom: undefined,
|
|
682
720
|
parent: wipFiber,
|
|
721
|
+
alternate: undefined,
|
|
722
|
+
effectTag: EFFECT_TAGS.PLACEMENT,
|
|
683
723
|
};
|
|
684
724
|
}
|
|
685
725
|
|
|
@@ -717,7 +757,9 @@
|
|
|
717
757
|
vars.wipFiber.hooks = [];
|
|
718
758
|
|
|
719
759
|
const children = fiber.type(fiber.props);
|
|
720
|
-
|
|
760
|
+
let childArr = Array.isArray(children) ? children : [children];
|
|
761
|
+
|
|
762
|
+
reconcileChildren(fiber, childArr);
|
|
721
763
|
};
|
|
722
764
|
|
|
723
765
|
/**
|
|
@@ -758,9 +800,7 @@
|
|
|
758
800
|
commitRoot();
|
|
759
801
|
}
|
|
760
802
|
|
|
761
|
-
|
|
762
|
-
requestIdleCallback(workLoop);
|
|
763
|
-
}
|
|
803
|
+
requestIdleCallback(workLoop);
|
|
764
804
|
};
|
|
765
805
|
|
|
766
806
|
requestIdleCallback(workLoop);
|
|
@@ -784,9 +824,9 @@
|
|
|
784
824
|
} else {
|
|
785
825
|
updateHostComponent(fiber);
|
|
786
826
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
827
|
+
if (fiber.child) {
|
|
828
|
+
return fiber.child
|
|
829
|
+
}
|
|
790
830
|
let nextFiber = fiber;
|
|
791
831
|
while (nextFiber) {
|
|
792
832
|
if (nextFiber.sibling) {
|
|
@@ -794,6 +834,7 @@
|
|
|
794
834
|
}
|
|
795
835
|
nextFiber = nextFiber.parent;
|
|
796
836
|
}
|
|
837
|
+
return undefined
|
|
797
838
|
};
|
|
798
839
|
|
|
799
840
|
var Workers = /*#__PURE__*/Object.freeze({
|
package/dist/Ryunix.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={})}(this,(function(e){"use strict";let
|
|
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({style:"style",className:"className"}),a=Object.freeze({PLACEMENT:Symbol("ryunix.reconciler.status.placement").toString(),UPDATE:Symbol("ryunix.reconciler.status.update").toString(),DELETION:Symbol("ryunix.reconciler.status.deletion").toString()}),l=e=>`${e}-${Math.random().toString(36).substring(2,9)}`,c=(e,t)=>(t=t||[],null==e||typeof e==i.boolean||(Array.isArray(e)?e.some((e=>{c(e,t)})):t.push(e)),t),p=(e,t,...o)=>{o=c(o,[]);const n=t&&t.key?l(t.key):l(r.Ryunix_ELEMENT.toString());return{type:e,props:{...t,key:n,children:o.map((e=>typeof e===i.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),d=(e,t)=>{o.wipRoot={dom:t,props:{children:[e]},alternate:o.currentRoot},o.deletions=[],o.nextUnitOfWork=o.wipRoot},f=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=[]}]},m=(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++)},h=(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},y=()=>{const e=new URLSearchParams(window.location.search),t={};for(let[o,n]of e.entries())t[o]=n;return t},b=e=>e.startsWith("on"),E=e=>e!==i.children&&!b(e),w=(e,t)=>o=>e[o]!==t[o],k=e=>t=>!(t in e),R=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.cancel)).forEach((e=>{e.cancel()}))},x=e=>{e.hooks&&e.hooks.filter((e=>e.tag===r.RYUNIX_EFFECT&&e.effect)).forEach((e=>{e.cancel=e.effect()}))},F=e=>{const t=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return _(t,{},e.props),t},_=(e,t,o)=>{Object.keys(t).filter(b).filter((e=>k(o)(e)||w(t,o)(e))).forEach((o=>{const n=o.toLowerCase().substring(2);e.removeEventListener(n,t[o])})),Object.keys(t).filter(E).filter(k(o)).forEach((t=>{e[t]=""})),Object.keys(o).filter(E).filter(w(t,o)).forEach((n=>{if(n===i.style)N(e,o["ryunix-style"]);else if(n===s.style)N(e,o.style);else if(n===i.className){if(""===o["ryunix-class"])throw new Error("data-class cannot be empty.");t["ryunix-class"]&&e.classList.remove(...t["ryunix-class"].split(/\s+/)),e.classList.add(...o["ryunix-class"].split(/\s+/))}else if(n===s.className){if(""===o.className)throw new Error("className cannot be empty.");t.className&&e.classList.remove(...t.className.split(/\s+/)),e.classList.add(...o.className.split(/\s+/))}else e[n]=o[n]})),Object.keys(o).filter(b).filter(w(t,o)).forEach((t=>{const n=t.toLowerCase().substring(2);e.addEventListener(n,o[t])}))},N=(e,t)=>{e.style=Object.keys(t).reduce(((e,o)=>e+=`${o.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${t[o]};`),"")};var g=Object.freeze({__proto__:null,DomStyle:N,createDom:F,updateDom:_});const T=()=>{o.deletions.forEach(v),o.wipRoot&&o.wipRoot.child&&(v(o.wipRoot.child),o.currentRoot=o.wipRoot),o.wipRoot=void 0},v=e=>{if(!e)return;let t=e.parent;for(;!t.dom;)t=t.parent;const o=t.dom;if(e.effectTag===a.PLACEMENT&&null!=e.dom)o.appendChild(e.dom),x(e);else if(e.effectTag===a.UPDATE&&null!=e.dom)R(e),_(e.dom,e.alternate.props,e.props),x(e);else if(e.effectTag===a.DELETION)return O(e,o),void R(e);v(e.child),v(e.sibling)},O=(e,t)=>{e.dom?t.removeChild(e.dom):O(e.child,t)};var I=Object.freeze({__proto__:null,commitDeletion:O,commitRoot:T,commitWork:v});const L=(e,t)=>{let n=0,r=e.alternate&&e.alternate.child,i=null;const s=new Map;for(;r;){const e=r.props.key||r.type;s.set(e,r),r=r.sibling}for(;n<t.length;){const o=t[n],r=o.props.key||o.type,l=s.get(r);let c;l&&o&&o.type===l.type?(c={type:l.type,props:o.props,dom:l.dom,parent:e,alternate:l,effectTag:a.UPDATE},s.delete(r)):o&&(c={type:o.type,props:o.props,dom:void 0,parent:e,alternate:void 0,effectTag:a.PLACEMENT}),0===n?e.child=c:i&&(i.sibling=c),i=c,n++}s.forEach((e=>{e.effectTag=a.DELETION,o.deletions.push(e)}))};var U=Object.freeze({__proto__:null,reconcileChildren:L});const C=e=>{o.wipFiber=e,o.hookIndex=0,o.wipFiber.hooks=[];const t=e.type(e.props);let n=Array.isArray(t)?t:[t];L(e,n)},S=e=>{e.dom||(e.dom=F(e)),L(e,e.props.children)};var j=Object.freeze({__proto__:null,updateFunctionComponent:C,updateHostComponent:S});const M=e=>{let t=!1;for(;o.nextUnitOfWork&&!t;)o.nextUnitOfWork=X(o.nextUnitOfWork),t=e.timeRemaining()<1;!o.nextUnitOfWork&&o.wipRoot&&T(),requestIdleCallback(M)};requestIdleCallback(M);const X=e=>{if(e.type instanceof Function?C(e):S(e),e.child)return e.child;let t=e;for(;t;){if(t.sibling)return t.sibling;t=t.parent}};var D={createElement:p,render:d,init:(e,t="__ryunix")=>{o.containerRoot=document.getElementById(t),d(e,o.containerRoot)},Fragment:e=>e.children,Dom:g,Workers:Object.freeze({__proto__:null,performUnitOfWork:X,workLoop:M}),Reconciler:U,Components:j,Commits:I};window.Ryunix=D,e.default=D,e.useCallback=(e,t)=>h((()=>e),t),e.useEffect=m,e.useMemo=h,e.useQuery=y,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]=f(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)),"([^/]+)")))}$`),a=o.match(s);if(a){return{route:r,params:e.reduce(((e,t,o)=>(e[t]=a[o+1],e)),{})}}}return i},r=e=>{window.history.pushState({},"",e),s(e)},s=e=>{const t=e.split("?")[0];o(t)};m((()=>{const e=()=>s(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const a=n(e,t)||{};return{Children:()=>{const e=y(),{route:t}=a;return t&&t.component&&typeof t.component===i.function?t.component({params:a.params||{},query:e}):(console.error("Component not found for current path or the component is not a valid function:",a),null)},NavLink:({to:e,...t})=>p("a",{href:e,onClick:t=>{t.preventDefault(),r(e)},...t},t.children),navigate:r}},e.useStore=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|