@unsetsoft/ryunixjs 1.1.4-nightly.7 → 1.1.4-nightly.9
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 +1 -1
- package/package.json +1 -1
- package/src/lib/commits.js +17 -0
- package/src/lib/createElement.js +19 -31
- package/src/lib/hooks.js +8 -0
- package/src/lib/index.js +2 -0
- package/src/main.js +1 -0
package/dist/Ryunix.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,o){"use strict";const t={containerRoot:void 0,nextUnitOfWork:void 0,currentRoot:void 0,wipRoot:void 0,deletions:void 0,wipFiber:void 0,hookIndex:void 0},
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("lodash")):"function"==typeof define&&define.amd?define(["exports","lodash"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).Ryunix={},e.lodash)}(this,(function(e,o){"use strict";const t={containerRoot:void 0,nextUnitOfWork:void 0,currentRoot:void 0,wipRoot:void 0,deletions:void 0,wipFiber:void 0,hookIndex:void 0},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")}),i=Object.freeze({object:"object",function:"function",style:"ryunix-style",className:"ryunix-class",children:"children",boolean:"boolean"}),s=Object.freeze({style:"style",className:"className"}),a=Object.freeze({PLACEMENT:Symbol(),UPDATE:Symbol(),DELETION:Symbol()}),l=e=>e.children,c=(e,o)=>(o=o||[],null==e||typeof e==i.boolean||(Array.isArray(e)?e.some((e=>{c(e,o)})):o.push(e)),o),p=(e,o,...t)=>{t=c(t,[]);const n=o&&o.key?o.key:`${r.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2,9)}`;return typeof e===i.object&&e.load?{type:"div",props:{...o,key:n,children:[]},asyncLoad:e.load}:{type:e,props:{...o,key:n,children:t.map((e=>typeof e===i.object?e:u(e)))}}},u=e=>({type:r.TEXT_ELEMENT,props:{nodeValue:e,children:[]}}),d=(e,o)=>{t.wipRoot={dom:t.containerRoot||o,props:{children:[e]},alternate:t.currentRoot},t.deletions=[],t.nextUnitOfWork=t.wipRoot},f=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],n={state:o?o.state:e,queue:o?[...o.queue]:[]};n.queue.forEach((e=>{n.state=typeof e===i.function?e(n.state):e})),n.queue=[];return t.wipFiber&&t.wipFiber.hooks&&(t.wipFiber.hooks.push(n),t.hookIndex++),[n.state,e=>{n.queue.push(e),t.wipRoot={dom:t.currentRoot.dom,props:t.currentRoot.props,alternate:t.currentRoot},t.nextUnitOfWork=t.wipRoot,t.deletions=[]}]},m=(e,n)=>{const i=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],s={type:r.RYUNIX_EFFECT,deps:n};i&&o.isEqual(i.deps,s.deps)||e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(s),t.hookIndex++)},h=(e,n)=>{const i=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],s={type:r.RYUNIX_MEMO,value:null,deps:n};return i&&o.isEqual(i.deps,s.deps)?s.value=i.value:s.value=e(),t.wipFiber.hooks&&(t.wipFiber.hooks.push(s),t.hookIndex++),s.value},y=()=>{const e=new URLSearchParams(window.location.search),o={};for(let[t,n]of e.entries())o[t]=n;return o},b=e=>e.startsWith("on"),E=e=>e!==i.children&&!b(e),w=(e,o)=>t=>e[t]!==o[t],k=e=>o=>!(o 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 o=e.type==r.TEXT_ELEMENT?document.createTextNode(""):document.createElement(e.type);return v(o,{},e.props),o},v=(e,o,t)=>{Object.keys(o).filter(b).filter((e=>k(t)(e)||w(o,t)(e))).forEach((t=>{const n=t.toLowerCase().substring(2);e.removeEventListener(n,o[t])})),Object.keys(o).filter(E).filter(k(t)).forEach((o=>{e[o]=""})),Object.keys(t).filter(E).filter(w(o,t)).forEach((n=>{if(n===i.style)_(e,t["ryunix-style"]);else if(n===s.style)_(e,t.style);else if(n===i.className){if(""===t["ryunix-class"])throw new Error("data-class cannot be empty.");o["ryunix-class"]&&e.classList.remove(...o["ryunix-class"].split(/\s+/)),e.classList.add(...t["ryunix-class"].split(/\s+/))}else if(n===s.className){if(""===t.className)throw new Error("className cannot be empty.");o.className&&e.classList.remove(...o.className.split(/\s+/)),e.classList.add(...t.className.split(/\s+/))}else e[n]=t[n]})),Object.keys(t).filter(b).filter(w(o,t)).forEach((o=>{const n=o.toLowerCase().substring(2);e.addEventListener(n,t[o])}))},_=(e,o)=>{e.style=Object.keys(o).reduce(((e,t)=>e+=`${t.replace(n,(function(e){return"-"+e.toLowerCase()}))}: ${o[t]};`),"")};var N=Object.freeze({__proto__:null,DomStyle:_,createDom:F,updateDom:v});const T=()=>{t.deletions.forEach(g),t.wipRoot&&t.wipRoot.child&&(g(t.wipRoot.child),t.currentRoot=t.wipRoot),t.wipRoot=void 0},g=e=>{if(!e)return;if(e.props&&e.asyncLoad)return void e.asyncLoad().then((o=>{e.type=o,e.asyncLoad=null,t.wipRoot={dom:t.currentRoot.dom,props:t.currentRoot.props,alternate:t.currentRoot},t.nextUnitOfWork=t.wipRoot,t.deletions=[]}));let o=e.parent;for(;!o.dom;)o=o.parent;const n=o.dom;if(e.effectTag===a.PLACEMENT&&(null!=e.dom&&n.appendChild(e.dom),x(e)),e.effectTag===a.UPDATE&&(R(e),null!=e.dom&&v(e.dom,e.alternate.props,e.props),x(e)),e.effectTag===a.DELETION)return L(e,n),void R(e);g(e.child),g(e.sibling)},L=(e,o)=>{e.dom?o.removeChild(e.dom):L(e.child,o)};var O=Object.freeze({__proto__:null,commitDeletion:L,commitRoot:T,commitWork:g});const I=(e,o)=>{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<o.length;){const r=o[n],l=r.props.key||r.type,c=s.get(l);let p;c&&r&&r.type===c.type?(p={type:c.type,props:r.props,dom:c.dom,parent:e,alternate:c,effectTag:a.UPDATE},s.delete(l)):r&&(p={type:r.type,props:r.props,dom:void 0,parent:e,alternate:void 0,effectTag:a.PLACEMENT}),s.forEach((e=>{e.effectTag=a.DELETION,t.deletions.push(e)})),0===n?e.child=p:i&&(i.sibling=p),i=p,n++}};var U=Object.freeze({__proto__:null,reconcileChildren:I});const C=e=>{t.wipFiber=e,t.hookIndex=0,t.wipFiber.hooks=[];const o=e.type(e.props);let n=[];n=Array.isArray(o)?[...o]:[o],I(e,n)},j=e=>{e.dom||(e.dom=F(e)),I(e,e.props.children)};var M=Object.freeze({__proto__:null,updateFunctionComponent:C,updateHostComponent:j});const S=e=>{let o=!1;for(;t.nextUnitOfWork&&!o;)t.nextUnitOfWork=D(t.nextUnitOfWork),o=e.timeRemaining()<1;!t.nextUnitOfWork&&t.wipRoot&&T(),requestIdleCallback(S)};requestIdleCallback(S);const D=e=>{if(e.type instanceof Function?C(e):j(e),e.child)return e.child;let o=e;for(;o;){if(o.sibling)return o.sibling;o=o.parent}};var W={createElement:p,render:d,init:(e,o="__ryunix")=>{t.containerRoot=document.getElementById(o),d(e,t.containerRoot)},Fragment:l,Dom:N,Workers:Object.freeze({__proto__:null,performUnitOfWork:D,workLoop:S}),Reconciler:U,Components:M,Commits:O};window.Ryunix=W,e.Fragment=l,e.default=W,e.useCallback=(e,o)=>h((()=>e),o),e.useEffect=m,e.useMemo=h,e.useOnDemand=e=>({load:()=>e().then((e=>e.default||e))}),e.useQuery=y,e.useRef=e=>{const o=t.wipFiber.alternate&&t.wipFiber.alternate.hooks&&t.wipFiber.alternate.hooks[t.hookIndex],n={type:r.RYUNIX_REF,value:o?o.value:{current:e}};return t.wipFiber.hooks&&(t.wipFiber.hooks.push(n),t.hookIndex++),n.value},e.useRouter=e=>{const[o,t]=f(window.location.pathname),n=e=>{window.history.pushState({},"",e),r(e)},r=e=>{t(e.split("?")[0])};m((()=>{const e=()=>r(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)}),[]);const i=((e,o)=>{const t=o.split("?")[0];for(const{path:o,component:n}of e){if(!o)continue;const e=[],r=new RegExp(`^${o.replace(/:\w+/g,(o=>(e.push(o.substring(1)),"([^/]+)")))}$`),i=t.match(r);if(i){return{route:{component:n},params:e.reduce(((e,o,t)=>(e[o]=i[t+1],e)),{})}}}const n=e.find((e=>e.NotFound));return n?{route:{component:n.NotFound},params:{}}:{route:{component:null},params:{}}})(e,o);return{Children:()=>{const e=y();return i.route.component?i.route.component({params:i.params,query:e}):null},NavLink:({to:e,...o})=>p("a",{href:e,onClick:o=>{o.preventDefault(),n(e)},...o},o.children),navigate:n}},e.useStore=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
package/src/lib/commits.js
CHANGED
|
@@ -24,6 +24,23 @@ const commitRoot = () => {
|
|
|
24
24
|
const commitWork = (fiber) => {
|
|
25
25
|
if (!fiber) return
|
|
26
26
|
|
|
27
|
+
// # TODO: TEST
|
|
28
|
+
if (fiber.props && fiber.asyncLoad) {
|
|
29
|
+
fiber.asyncLoad().then((loadedComponent) => {
|
|
30
|
+
fiber.type = loadedComponent
|
|
31
|
+
fiber.asyncLoad = null
|
|
32
|
+
|
|
33
|
+
vars.wipRoot = {
|
|
34
|
+
dom: vars.currentRoot.dom,
|
|
35
|
+
props: vars.currentRoot.props,
|
|
36
|
+
alternate: vars.currentRoot,
|
|
37
|
+
}
|
|
38
|
+
vars.nextUnitOfWork = vars.wipRoot
|
|
39
|
+
vars.deletions = []
|
|
40
|
+
})
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
27
44
|
let domParentFiber = fiber.parent
|
|
28
45
|
while (!domParentFiber.dom) {
|
|
29
46
|
domParentFiber = domParentFiber.parent
|
package/src/lib/createElement.js
CHANGED
|
@@ -45,47 +45,35 @@ const cloneElement = (element, props) => {
|
|
|
45
45
|
* that is an array of any child elements passed in the `...children` argument
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
|
-
const createElement = (type, props
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const key = props.key
|
|
48
|
+
const createElement = (type, props, ...children) => {
|
|
49
|
+
children = childArray(children, [])
|
|
50
|
+
const key =
|
|
51
|
+
props && props.key
|
|
53
52
|
? props.key
|
|
54
53
|
: `${RYUNIX_TYPES.Ryunix_ELEMENT.toString()}-${Math.random().toString(36).substring(2, 9)}`
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
`Invalid element type: ${type}. Expected a string (for HTML elements) or a function (for components).`,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
55
|
+
// # TODO: TEST
|
|
56
|
+
if (typeof type === STRINGS.object && type.load) {
|
|
62
57
|
return {
|
|
63
|
-
type,
|
|
58
|
+
type: 'div',
|
|
64
59
|
props: {
|
|
65
60
|
...props,
|
|
66
61
|
key,
|
|
67
|
-
children:
|
|
68
|
-
typeof child === STRINGS.object ? child : createTextElement(child),
|
|
69
|
-
),
|
|
62
|
+
children: [],
|
|
70
63
|
},
|
|
64
|
+
asyncLoad: type.load,
|
|
71
65
|
}
|
|
72
|
-
}
|
|
73
|
-
console.error('Error rendering element:', error)
|
|
66
|
+
}
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
createTextElement(
|
|
85
|
-
`An error occurred while rendering this component. [ERROR] ${error.message}`,
|
|
86
|
-
),
|
|
87
|
-
],
|
|
88
|
-
})
|
|
68
|
+
return {
|
|
69
|
+
type,
|
|
70
|
+
props: {
|
|
71
|
+
...props,
|
|
72
|
+
key,
|
|
73
|
+
children: children.map((child) =>
|
|
74
|
+
typeof child === STRINGS.object ? child : createTextElement(child),
|
|
75
|
+
),
|
|
76
|
+
},
|
|
89
77
|
}
|
|
90
78
|
}
|
|
91
79
|
|
package/src/lib/hooks.js
CHANGED
|
@@ -277,6 +277,13 @@ const useRouter = (routes) => {
|
|
|
277
277
|
return { Children, NavLink, navigate }
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
// # TODO: TEST
|
|
281
|
+
const useOnDemand = (importFunc) => {
|
|
282
|
+
return {
|
|
283
|
+
load: () => importFunc().then((module) => module.default || module),
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
280
287
|
export {
|
|
281
288
|
useStore,
|
|
282
289
|
useEffect,
|
|
@@ -285,4 +292,5 @@ export {
|
|
|
285
292
|
useMemo,
|
|
286
293
|
useCallback,
|
|
287
294
|
useRouter,
|
|
295
|
+
useOnDemand,
|
|
288
296
|
}
|
package/src/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useMemo,
|
|
9
9
|
useCallback,
|
|
10
10
|
useRouter,
|
|
11
|
+
useOnDemand,
|
|
11
12
|
} from './hooks'
|
|
12
13
|
import * as Dom from './dom'
|
|
13
14
|
import * as Workers from './workers'
|
|
@@ -24,6 +25,7 @@ export {
|
|
|
24
25
|
useCallback,
|
|
25
26
|
useRouter,
|
|
26
27
|
Fragment,
|
|
28
|
+
useOnDemand,
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export default {
|