hydroxide-dom
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -90,6 +90,6 @@ 'use strict'; | ||
// create context for conditional element | ||
const prevContext = hydroxide.globalInfo.context; | ||
hydroxide.globalInfo.context = contexts[i] = { isConnected: true }; | ||
const prevContext = hydroxide.coreInfo.context; | ||
hydroxide.coreInfo.context = contexts[i] = { isConnected: true }; | ||
elements[i] = branches[i][1](); | ||
hydroxide.globalInfo.context = prevContext; | ||
hydroxide.coreInfo.context = prevContext; | ||
add(contexts[i], elements[i]); | ||
@@ -112,3 +112,3 @@ } | ||
// don't detect states beyond this point | ||
hydroxide.globalInfo.detectorEnabled = false; | ||
hydroxide.coreInfo.detectorEnabled = false; | ||
// if no context should be rendered, and there is a rendered context, disconnect it | ||
@@ -226,4 +226,4 @@ if (contextIndex === -1) { | ||
const elContext = { isConnected: true }; | ||
const parentContext = hydroxide.globalInfo.context; | ||
hydroxide.globalInfo.context = elContext; | ||
const parentContext = hydroxide.coreInfo.context; | ||
hydroxide.coreInfo.context = elContext; | ||
const reactiveValue = hydroxide.reactive(value); | ||
@@ -234,3 +234,3 @@ const element = listInfo.props.children(reactiveValue); | ||
} | ||
hydroxide.globalInfo.context = parentContext; | ||
hydroxide.coreInfo.context = parentContext; | ||
return { | ||
@@ -584,3 +584,3 @@ el: element, | ||
const listInfo = { | ||
context: hydroxide.globalInfo.context, | ||
context: hydroxide.coreInfo.context, | ||
props: listProps, | ||
@@ -671,3 +671,3 @@ parent: parent, | ||
const text = document.createTextNode(initValue + ''); | ||
hydroxide.globalInfo.context; | ||
hydroxide.coreInfo.context; | ||
function update() { | ||
@@ -747,3 +747,3 @@ const value = expr(); | ||
// root context | ||
hydroxide.globalInfo.context = { isConnected: true }; | ||
hydroxide.coreInfo.context = { isConnected: true }; | ||
// call component | ||
@@ -755,4 +755,4 @@ let el; | ||
catch (error) { | ||
if (hydroxide.globalInfo.context.onError) { | ||
hydroxide.globalInfo.context.onError.forEach((handleError) => handleError(error)); | ||
if (hydroxide.coreInfo.context.onError) { | ||
hydroxide.coreInfo.context.onError.forEach((handleError) => handleError(error)); | ||
} | ||
@@ -767,4 +767,4 @@ else { | ||
// run onConnect callbacks | ||
if (hydroxide.globalInfo.context.onConnect) { | ||
hydroxide.globalInfo.context.onConnect.forEach((cb) => cb()); | ||
if (hydroxide.coreInfo.context.onConnect) { | ||
hydroxide.coreInfo.context.onConnect.forEach((cb) => cb()); | ||
} | ||
@@ -776,3 +776,3 @@ // save the component tree for dev | ||
} | ||
hydroxide.globalInfo.context = null; | ||
hydroxide.coreInfo.context = null; | ||
} | ||
@@ -779,0 +779,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { List, detect, effect, CONNECTION_PHASE, globalInfo, reactive, invalidate, subscribe, LIST_PHASE, RENDER_PHASE } from 'hydroxide'; | ||
import { List, detect, effect, CONNECTION_PHASE, coreInfo, reactive, invalidate, subscribe, LIST_PHASE, RENDER_PHASE } from 'hydroxide'; | ||
@@ -86,6 +86,6 @@ const devInfo = { | ||
// create context for conditional element | ||
const prevContext = globalInfo.context; | ||
globalInfo.context = contexts[i] = { isConnected: true }; | ||
const prevContext = coreInfo.context; | ||
coreInfo.context = contexts[i] = { isConnected: true }; | ||
elements[i] = branches[i][1](); | ||
globalInfo.context = prevContext; | ||
coreInfo.context = prevContext; | ||
add(contexts[i], elements[i]); | ||
@@ -108,3 +108,3 @@ } | ||
// don't detect states beyond this point | ||
globalInfo.detectorEnabled = false; | ||
coreInfo.detectorEnabled = false; | ||
// if no context should be rendered, and there is a rendered context, disconnect it | ||
@@ -222,4 +222,4 @@ if (contextIndex === -1) { | ||
const elContext = { isConnected: true }; | ||
const parentContext = globalInfo.context; | ||
globalInfo.context = elContext; | ||
const parentContext = coreInfo.context; | ||
coreInfo.context = elContext; | ||
const reactiveValue = reactive(value); | ||
@@ -230,3 +230,3 @@ const element = listInfo.props.children(reactiveValue); | ||
} | ||
globalInfo.context = parentContext; | ||
coreInfo.context = parentContext; | ||
return { | ||
@@ -580,3 +580,3 @@ el: element, | ||
const listInfo = { | ||
context: globalInfo.context, | ||
context: coreInfo.context, | ||
props: listProps, | ||
@@ -667,3 +667,3 @@ parent: parent, | ||
const text = document.createTextNode(initValue + ''); | ||
globalInfo.context; | ||
coreInfo.context; | ||
function update() { | ||
@@ -743,3 +743,3 @@ const value = expr(); | ||
// root context | ||
globalInfo.context = { isConnected: true }; | ||
coreInfo.context = { isConnected: true }; | ||
// call component | ||
@@ -751,4 +751,4 @@ let el; | ||
catch (error) { | ||
if (globalInfo.context.onError) { | ||
globalInfo.context.onError.forEach((handleError) => handleError(error)); | ||
if (coreInfo.context.onError) { | ||
coreInfo.context.onError.forEach((handleError) => handleError(error)); | ||
} | ||
@@ -763,4 +763,4 @@ else { | ||
// run onConnect callbacks | ||
if (globalInfo.context.onConnect) { | ||
globalInfo.context.onConnect.forEach((cb) => cb()); | ||
if (coreInfo.context.onConnect) { | ||
coreInfo.context.onConnect.forEach((cb) => cb()); | ||
} | ||
@@ -772,5 +772,5 @@ // save the component tree for dev | ||
} | ||
globalInfo.context = null; | ||
coreInfo.context = null; | ||
} | ||
export { branch, component, delegateEvents, insert, render, setAttribute, svg, template }; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("hydroxide");function t(t,n){const o=t(n||{});if(n&&t!==e.List){const[t]=e.detect((()=>{for(const e in n)n[e]}));t.size&&t.forEach((e=>{e.mutable=!1}))}return o}const n=new Set;function o(e){const t=`$$${e.type}`;let n=e.composedPath&&e.composedPath()[0]||e.target;for(e.target!==n&&Object.defineProperty(e,"target",{configurable:!0,value:n}),Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>n||document});null!==n;){const o=n[t];if(o&&!n.disabled&&(Array.isArray(o)?o[0](o[1],e):o(e),e.cancelBubble))return;n=n.host&&n.host!==n&&n.host instanceof Node?n.host:n.parentNode}}function c(t,n){const o={isConnected:!0},c=e.globalInfo.context;e.globalInfo.context=o;const r=e.reactive(t),s=n.props.children(r);return o.onConnect&&o.onConnect.forEach((e=>e())),e.globalInfo.context=c,{el:s,value:r,context:o}}function r(e,t,n){const o=n.list.length;if(e===o||0===o)return function(e,t){const n=t.list.length;for(let o=0;o<e.length;o++){const r=c(e[o],t);t.parent.appendChild(r.el),t.list[n+o]=r}}(t,n);const r=new Array(t.length),s=n.list[e].el;for(let e=0;e<t.length;e++){const o=c(t[e],n);n.parent.insertBefore(o.el,s),r[e]=o}n.list.splice(e,0,...r)}function s(e,t,n){if(t!==n.list.length){for(let o=e;o<e+t;o++){const e=n.list[o];e.context.onDisconnect&&e.context.onDisconnect.forEach((e=>e())),e.el.remove()}n.list.splice(e,t)}else l(n)}function l(e){const t=e.list.length;for(let n=0;n<t;n++){const t=e.list[n].context;t.onDisconnect&&t.onDisconnect.forEach((e=>e()))}e.list=[],e.parent.textContent=""}const i=document.createComment("");function a(e,t,n){n.list.length;const o=n.list[e].el,c=n.list[t].el,r=n.list[e];n.list[e]=n.list[t],n.list[t]=r,c.replaceWith(i),o.replaceWith(c),i.replaceWith(o)}function f(e){const t=e.currentValue,n=function(e,t){const n=[];if(0===e.length)return n.push({indexes:[0,t.length-1],insertAt:0}),n;if(0===t.length)return n.push({clear:!0}),n;let o,c=e.length-1,r=t.length-1,s=0,l=0,i=0;for(;s<=c||l<=r;){if(s>c){n.push({insertAt:l,indexes:l===r?[l]:[l,r]});break}if(l>r){s<=c&&(n.push({removeAt:s-i,count:c-s+1}),i++);break}if(e[s]===t[l])s++,l++;else if(e[c]===t[r])c--,r--;else if(e[s]===t[r]&&t[l]===e[c])n.push({swap:[s,c]}),s++,l++,c--,r--;else if(s+1<=c&&e[s]===t[l+1]&&e[s+1]===t[l])n.push({swap:[s,s+1]}),s+=2,l+=2;else if(s+1<=c&&e[c]===t[r-1]&&e[c-1]===t[r])n.push({swap:[c,c-1]}),c-=2,r-=2;else{if(!o){o=new Map;for(let e=l;e<=r;e++)o.set(t[e],e)}if(o.has(e[s])){const t=o.get(e[s]);if(l<=t&&t<=r){let a=1;for(let n=s+1;n<=c&&n<=r&&o.get(e[n])===t+a;n++)a++;if(t-l<a){const e=t-1;n.push({indexes:l===e?[l]:[l,e],insertAt:l}),l=t}else n.push({replace:[s-i,l]}),l++,s++}else s++}else{const e=n[n.length-1];n.length>0&&"removeAt"in e&&e.removeAt+e.count===s?e.count++:n.push({removeAt:s-i,count:1}),i++,s++}}}return n}(e.prevValue,t);for(let o=0;o<n.length;o++){const c=n[o];if("removeAt"in c)s(c.removeAt,c.count,e);else if("insertAt"in c){const[n,o=n]=c.indexes,s=[];for(let e=n;e<=o;e++)s.push(t[e]);r(c.insertAt,s,e)}else if("swap"in c){const[t,n]=c.swap;a(t,n,e)}else if("replace"in c){const[t,n]=c.replace,o=e.list[t].value,r=e.currentValue[n];o.set(r)}else"clear"in c&&l(e)}}function u(t,n){const o=t.parentElement;t.remove();const c={context:e.globalInfo.context,props:n,parent:o,prevValue:[],currentValue:[],list:[]},[i,u]=e.detect((()=>n.each));if(c.prevValue=u,r(0,u,c),0===i.size)return;let h,p=!0;if(1===i.size){h=i.values().next().value;p=h()!==u,p&&(h.mutable=!1)}if(p){function d(){c.currentValue=n.each,f(c),c.prevValue=c.currentValue}e.subscribe(h,d,e.CONNECTION_PHASE)}else{const b=(t,o,i)=>{switch(c.currentValue=n.each,t){case"insert":r(o,i,c);break;case"remove":s(o,i,c);break;case"swap":a(o,i,c);break;case"clear":l(c);break;case"set":!function(t,n,o){if(t&&t.length>1){const c=o.list[t[0]].value;if(c.mutable){let o=c.value;const r=t.length-1;for(let e=1;e<r;e++)o=o[t[e]];o[r]=n,e.invalidate(c)}else c.$(t.slice(1)).set(n)}else f(o)}(o,i,c)}c.prevValue=c.currentValue};e.subscribe(h,b,e.LIST_PHASE)}}function h(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstChild}exports.branch=function(...t){let n,o,c;const r=[],s=[];function l(e,t){o?(o.onDisconnect&&o.onDisconnect.forEach((e=>e())),c.replaceWith(t)):n.replaceWith(t),o=e,c=t,e.onConnect&&e.onConnect.forEach((e=>e()))}function i(){let i=-1;for(let e=0;e<t.length;e++)if(t[e][0]()){i=e;break}e.globalInfo.detectorEnabled=!1,-1===i?o&&c&&(o.onDisconnect&&o.onDisconnect.forEach((e=>e())),c.replaceWith(n),o=void 0,c=void 0):function(n){if(!o||o!==r[n])if(r[n])l(r[n],s[n]);else{const o=e.globalInfo.context;e.globalInfo.context=r[n]={isConnected:!0},s[n]=t[n][1](),e.globalInfo.context=o,l(r[n],s[n])}}(i)}return{$$branch:t=>{n=t,e.effect(i,e.CONNECTION_PHASE)}}},exports.component=t,exports.delegateEvents=function(e){for(let t=0,c=e.length;t<c;t++){const c=e[t];n.has(c)||(n.add(c),document.addEventListener(c,o))}},exports.insert=function t(n,o){if(o instanceof Node)n.replaceWith(o);else if("function"==typeof o){const[c,r]=e.detect(o);if(c.size){const s=document.createTextNode(r+"");function l(){const e=o();s.textContent=e}e.globalInfo.context,s.textContent=r,c.forEach((t=>{e.subscribe(t,l,e.RENDER_PHASE)})),n.replaceWith(s)}else"object"==typeof r?t(n,r):n.replaceWith(r+"")}else if(Array.isArray(o))o.forEach((t=>{if("function"==typeof t){const[o,c]=e.detect(t);if(c instanceof Node)n.before(c);else if(o.size){const r=document.createTextNode(c+"");function s(){r.textContent=t()}o.forEach((t=>{e.subscribe(t,s,e.RENDER_PHASE)}))}}else n.before(t)})),n.remove();else{if(o&&o.$$list)return u(n,o.$$list);if(o&&o.$$branch)return o.$$branch(n);{const i=document.createTextNode(o+"");n.replaceWith(i)}}},exports.render=function(n,o){let c;e.globalInfo.context={isConnected:!0};try{c=t(n)}catch(t){if(!e.globalInfo.context.onError)throw t;e.globalInfo.context.onError.forEach((e=>e(t)))}o.appendChild(c),e.globalInfo.context.onConnect&&e.globalInfo.context.onConnect.forEach((e=>e())),e.globalInfo.context=null},exports.setAttribute=function(e,t,n){n?e.setAttribute(t,n):e.removeAttribute(t)},exports.svg=function(e){return h(`<svg>${e}</svg>`).firstChild},exports.template=h; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("hydroxide");function t(t,n){const o=t(n||{});if(n&&t!==e.List){const[t]=e.detect((()=>{for(const e in n)n[e]}));t.size&&t.forEach((e=>{e.mutable=!1}))}return o}const n=new Set;function o(e){const t=`$$${e.type}`;let n=e.composedPath&&e.composedPath()[0]||e.target;for(e.target!==n&&Object.defineProperty(e,"target",{configurable:!0,value:n}),Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>n||document});null!==n;){const o=n[t];if(o&&!n.disabled&&(Array.isArray(o)?o[0](o[1],e):o(e),e.cancelBubble))return;n=n.host&&n.host!==n&&n.host instanceof Node?n.host:n.parentNode}}function c(t,n){const o={isConnected:!0},c=e.coreInfo.context;e.coreInfo.context=o;const r=e.reactive(t),s=n.props.children(r);return o.onConnect&&o.onConnect.forEach((e=>e())),e.coreInfo.context=c,{el:s,value:r,context:o}}function r(e,t,n){const o=n.list.length;if(e===o||0===o)return function(e,t){const n=t.list.length;for(let o=0;o<e.length;o++){const r=c(e[o],t);t.parent.appendChild(r.el),t.list[n+o]=r}}(t,n);const r=new Array(t.length),s=n.list[e].el;for(let e=0;e<t.length;e++){const o=c(t[e],n);n.parent.insertBefore(o.el,s),r[e]=o}n.list.splice(e,0,...r)}function s(e,t,n){if(t!==n.list.length){for(let o=e;o<e+t;o++){const e=n.list[o];e.context.onDisconnect&&e.context.onDisconnect.forEach((e=>e())),e.el.remove()}n.list.splice(e,t)}else i(n)}function i(e){const t=e.list.length;for(let n=0;n<t;n++){const t=e.list[n].context;t.onDisconnect&&t.onDisconnect.forEach((e=>e()))}e.list=[],e.parent.textContent=""}const l=document.createComment("");function f(e,t,n){n.list.length;const o=n.list[e].el,c=n.list[t].el,r=n.list[e];n.list[e]=n.list[t],n.list[t]=r,c.replaceWith(l),o.replaceWith(c),l.replaceWith(o)}function a(e){const t=e.currentValue,n=function(e,t){const n=[];if(0===e.length)return n.push({indexes:[0,t.length-1],insertAt:0}),n;if(0===t.length)return n.push({clear:!0}),n;let o,c=e.length-1,r=t.length-1,s=0,i=0,l=0;for(;s<=c||i<=r;){if(s>c){n.push({insertAt:i,indexes:i===r?[i]:[i,r]});break}if(i>r){s<=c&&(n.push({removeAt:s-l,count:c-s+1}),l++);break}if(e[s]===t[i])s++,i++;else if(e[c]===t[r])c--,r--;else if(e[s]===t[r]&&t[i]===e[c])n.push({swap:[s,c]}),s++,i++,c--,r--;else if(s+1<=c&&e[s]===t[i+1]&&e[s+1]===t[i])n.push({swap:[s,s+1]}),s+=2,i+=2;else if(s+1<=c&&e[c]===t[r-1]&&e[c-1]===t[r])n.push({swap:[c,c-1]}),c-=2,r-=2;else{if(!o){o=new Map;for(let e=i;e<=r;e++)o.set(t[e],e)}if(o.has(e[s])){const t=o.get(e[s]);if(i<=t&&t<=r){let f=1;for(let n=s+1;n<=c&&n<=r&&o.get(e[n])===t+f;n++)f++;if(t-i<f){const e=t-1;n.push({indexes:i===e?[i]:[i,e],insertAt:i}),i=t}else n.push({replace:[s-l,i]}),i++,s++}else s++}else{const e=n[n.length-1];n.length>0&&"removeAt"in e&&e.removeAt+e.count===s?e.count++:n.push({removeAt:s-l,count:1}),l++,s++}}}return n}(e.prevValue,t);for(let o=0;o<n.length;o++){const c=n[o];if("removeAt"in c)s(c.removeAt,c.count,e);else if("insertAt"in c){const[n,o=n]=c.indexes,s=[];for(let e=n;e<=o;e++)s.push(t[e]);r(c.insertAt,s,e)}else if("swap"in c){const[t,n]=c.swap;f(t,n,e)}else if("replace"in c){const[t,n]=c.replace,o=e.list[t].value,r=e.currentValue[n];o.set(r)}else"clear"in c&&i(e)}}function u(t,n){const o=t.parentElement;t.remove();const c={context:e.coreInfo.context,props:n,parent:o,prevValue:[],currentValue:[],list:[]},[l,u]=e.detect((()=>n.each));if(c.prevValue=u,r(0,u,c),0===l.size)return;let h,p=!0;if(1===l.size){h=l.values().next().value;p=h()!==u,p&&(h.mutable=!1)}if(p){function d(){c.currentValue=n.each,a(c),c.prevValue=c.currentValue}e.subscribe(h,d,e.CONNECTION_PHASE)}else{const x=(t,o,l)=>{switch(c.currentValue=n.each,t){case"insert":r(o,l,c);break;case"remove":s(o,l,c);break;case"swap":f(o,l,c);break;case"clear":i(c);break;case"set":!function(t,n,o){if(t&&t.length>1){const c=o.list[t[0]].value;if(c.mutable){let o=c.value;const r=t.length-1;for(let e=1;e<r;e++)o=o[t[e]];o[r]=n,e.invalidate(c)}else c.$(t.slice(1)).set(n)}else a(o)}(o,l,c)}c.prevValue=c.currentValue};e.subscribe(h,x,e.LIST_PHASE)}}function h(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstChild}exports.branch=function(...t){let n,o,c;const r=[],s=[];function i(e,t){o?(o.onDisconnect&&o.onDisconnect.forEach((e=>e())),c.replaceWith(t)):n.replaceWith(t),o=e,c=t,e.onConnect&&e.onConnect.forEach((e=>e()))}function l(){let l=-1;for(let e=0;e<t.length;e++)if(t[e][0]()){l=e;break}e.coreInfo.detectorEnabled=!1,-1===l?o&&c&&(o.onDisconnect&&o.onDisconnect.forEach((e=>e())),c.replaceWith(n),o=void 0,c=void 0):function(n){if(!o||o!==r[n])if(r[n])i(r[n],s[n]);else{const o=e.coreInfo.context;e.coreInfo.context=r[n]={isConnected:!0},s[n]=t[n][1](),e.coreInfo.context=o,i(r[n],s[n])}}(l)}return{$$branch:t=>{n=t,e.effect(l,e.CONNECTION_PHASE)}}},exports.component=t,exports.delegateEvents=function(e){for(let t=0,c=e.length;t<c;t++){const c=e[t];n.has(c)||(n.add(c),document.addEventListener(c,o))}},exports.insert=function t(n,o){if(o instanceof Node)n.replaceWith(o);else if("function"==typeof o){const[c,r]=e.detect(o);if(c.size){const s=document.createTextNode(r+"");function i(){const e=o();s.textContent=e}e.coreInfo.context,s.textContent=r,c.forEach((t=>{e.subscribe(t,i,e.RENDER_PHASE)})),n.replaceWith(s)}else"object"==typeof r?t(n,r):n.replaceWith(r+"")}else if(Array.isArray(o))o.forEach((t=>{if("function"==typeof t){const[o,c]=e.detect(t);if(c instanceof Node)n.before(c);else if(o.size){const r=document.createTextNode(c+"");function s(){r.textContent=t()}o.forEach((t=>{e.subscribe(t,s,e.RENDER_PHASE)}))}}else n.before(t)})),n.remove();else{if(o&&o.$$list)return u(n,o.$$list);if(o&&o.$$branch)return o.$$branch(n);{const l=document.createTextNode(o+"");n.replaceWith(l)}}},exports.render=function(n,o){let c;e.coreInfo.context={isConnected:!0};try{c=t(n)}catch(t){if(!e.coreInfo.context.onError)throw t;e.coreInfo.context.onError.forEach((e=>e(t)))}o.appendChild(c),e.coreInfo.context.onConnect&&e.coreInfo.context.onConnect.forEach((e=>e())),e.coreInfo.context=null},exports.setAttribute=function(e,t,n){n?e.setAttribute(t,n):e.removeAttribute(t)},exports.svg=function(e){return h(`<svg>${e}</svg>`).firstChild},exports.template=h; |
@@ -1,1 +0,1 @@ | ||
import{List as e,detect as t,effect as n,CONNECTION_PHASE as o,globalInfo as c,reactive as r,invalidate as s,subscribe as i,LIST_PHASE as l,RENDER_PHASE as a}from"hydroxide";function f(n,o){const c=n(o||{});if(o&&n!==e){const[e]=t((()=>{for(const e in o)o[e]}));e.size&&e.forEach((e=>{e.mutable=!1}))}return c}function u(...e){let t,r,s;const i=[],l=[];function a(e,n){r?(r.onDisconnect&&r.onDisconnect.forEach((e=>e())),s.replaceWith(n)):t.replaceWith(n),r=e,s=n,e.onConnect&&e.onConnect.forEach((e=>e()))}function f(){let n=-1;for(let t=0;t<e.length;t++)if(e[t][0]()){n=t;break}c.detectorEnabled=!1,-1===n?r&&s&&(r.onDisconnect&&r.onDisconnect.forEach((e=>e())),s.replaceWith(t),r=void 0,s=void 0):function(t){if(!r||r!==i[t])if(i[t])a(i[t],l[t]);else{const n=c.context;c.context=i[t]={isConnected:!0},l[t]=e[t][1](),c.context=n,a(i[t],l[t])}}(n)}return{$$branch:e=>{t=e,n(f,o)}}}const h=new Set;function p(e){for(let t=0,n=e.length;t<n;t++){const n=e[t];h.has(n)||(h.add(n),document.addEventListener(n,d))}}function d(e){const t=`$$${e.type}`;let n=e.composedPath&&e.composedPath()[0]||e.target;for(e.target!==n&&Object.defineProperty(e,"target",{configurable:!0,value:n}),Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>n||document});null!==n;){const o=n[t];if(o&&!n.disabled&&(Array.isArray(o)?o[0](o[1],e):o(e),e.cancelBubble))return;n=n.host&&n.host!==n&&n.host instanceof Node?n.host:n.parentNode}}function x(e,t){const n={isConnected:!0},o=c.context;c.context=n;const s=r(e),i=t.props.children(s);return n.onConnect&&n.onConnect.forEach((e=>e())),c.context=o,{el:i,value:s,context:n}}function g(e,t,n){const o=n.list.length;if(e===o||0===o)return function(e,t){const n=t.list.length;for(let o=0;o<e.length;o++){const c=x(e[o],t);t.parent.appendChild(c.el),t.list[n+o]=c}}(t,n);const c=new Array(t.length),r=n.list[e].el;for(let e=0;e<t.length;e++){const o=x(t[e],n);n.parent.insertBefore(o.el,r),c[e]=o}n.list.splice(e,0,...c)}function m(e,t,n){if(t!==n.list.length){for(let o=e;o<e+t;o++){const e=n.list[o];e.context.onDisconnect&&e.context.onDisconnect.forEach((e=>e())),e.el.remove()}n.list.splice(e,t)}else v(n)}function v(e){const t=e.list.length;for(let n=0;n<t;n++){const t=e.list[n].context;t.onDisconnect&&t.onDisconnect.forEach((e=>e()))}e.list=[],e.parent.textContent=""}const b=document.createComment("");function A(e,t,n){n.list.length;const o=n.list[e].el,c=n.list[t].el,r=n.list[e];n.list[e]=n.list[t],n.list[t]=r,c.replaceWith(b),o.replaceWith(c),b.replaceWith(o)}function C(e){const t=e.currentValue,n=function(e,t){const n=[];if(0===e.length)return n.push({indexes:[0,t.length-1],insertAt:0}),n;if(0===t.length)return n.push({clear:!0}),n;let o,c=e.length-1,r=t.length-1,s=0,i=0,l=0;for(;s<=c||i<=r;){if(s>c){n.push({insertAt:i,indexes:i===r?[i]:[i,r]});break}if(i>r){s<=c&&(n.push({removeAt:s-l,count:c-s+1}),l++);break}if(e[s]===t[i])s++,i++;else if(e[c]===t[r])c--,r--;else if(e[s]===t[r]&&t[i]===e[c])n.push({swap:[s,c]}),s++,i++,c--,r--;else if(s+1<=c&&e[s]===t[i+1]&&e[s+1]===t[i])n.push({swap:[s,s+1]}),s+=2,i+=2;else if(s+1<=c&&e[c]===t[r-1]&&e[c-1]===t[r])n.push({swap:[c,c-1]}),c-=2,r-=2;else{if(!o){o=new Map;for(let e=i;e<=r;e++)o.set(t[e],e)}if(o.has(e[s])){const t=o.get(e[s]);if(i<=t&&t<=r){let a=1;for(let n=s+1;n<=c&&n<=r&&o.get(e[n])===t+a;n++)a++;if(t-i<a){const e=t-1;n.push({indexes:i===e?[i]:[i,e],insertAt:i}),i=t}else n.push({replace:[s-l,i]}),i++,s++}else s++}else{const e=n[n.length-1];n.length>0&&"removeAt"in e&&e.removeAt+e.count===s?e.count++:n.push({removeAt:s-l,count:1}),l++,s++}}}return n}(e.prevValue,t);for(let o=0;o<n.length;o++){const c=n[o];if("removeAt"in c)m(c.removeAt,c.count,e);else if("insertAt"in c){const[n,o=n]=c.indexes,r=[];for(let e=n;e<=o;e++)r.push(t[e]);g(c.insertAt,r,e)}else if("swap"in c){const[t,n]=c.swap;A(t,n,e)}else if("replace"in c){const[t,n]=c.replace,o=e.list[t].value,r=e.currentValue[n];o.set(r)}else"clear"in c&&v(e)}}function E(e,n){const r=e.parentElement;e.remove();const a={context:c.context,props:n,parent:r,prevValue:[],currentValue:[],list:[]},[f,u]=t((()=>n.each));if(a.prevValue=u,g(0,u,a),0===f.size)return;let h,p=!0;if(1===f.size){h=f.values().next().value;p=h()!==u,p&&(h.mutable=!1)}if(p){i(h,(function(){a.currentValue=n.each,C(a),a.prevValue=a.currentValue}),o)}else{const e=(e,t,o)=>{switch(a.currentValue=n.each,e){case"insert":g(t,o,a);break;case"remove":m(t,o,a);break;case"swap":A(t,o,a);break;case"clear":v(a);break;case"set":!function(e,t,n){if(e&&e.length>1){const o=n.list[e[0]].value;if(o.mutable){let n=o.value;const c=e.length-1;for(let t=1;t<c;t++)n=n[e[t]];n[c]=t,s(o)}else o.$(e.slice(1)).set(t)}else C(n)}(t,o,a)}a.prevValue=a.currentValue};i(h,e,l)}}function $(e,n){if(n instanceof Node)e.replaceWith(n);else if("function"==typeof n){const[r,s]=t(n);if(r.size){const l=document.createTextNode(s+"");function o(){const e=n();l.textContent=e}c.context,l.textContent=s,r.forEach((e=>{i(e,o,a)})),e.replaceWith(l)}else"object"==typeof s?$(e,s):e.replaceWith(s+"")}else if(Array.isArray(n))n.forEach((n=>{if("function"==typeof n){const[c,r]=t(n);if(r instanceof Node)e.before(r);else if(c.size){const s=document.createTextNode(r+"");function o(){s.textContent=n()}c.forEach((e=>{i(e,o,a)}))}}else e.before(n)})),e.remove();else{if(n&&n.$$list)return E(e,n.$$list);if(n&&n.$$branch)return n.$$branch(e);{const f=document.createTextNode(n+"");e.replaceWith(f)}}}function y(e,t,n){n?e.setAttribute(t,n):e.removeAttribute(t)}function V(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstChild}function w(e){return V(`<svg>${e}</svg>`).firstChild}function W(e,t){let n;c.context={isConnected:!0};try{n=f(e)}catch(e){if(!c.context.onError)throw e;c.context.onError.forEach((t=>t(e)))}t.appendChild(n),c.context.onConnect&&c.context.onConnect.forEach((e=>e())),c.context=null}export{u as branch,f as component,p as delegateEvents,$ as insert,W as render,y as setAttribute,w as svg,V as template}; | ||
import{List as e,detect as t,effect as n,CONNECTION_PHASE as o,coreInfo as c,reactive as r,invalidate as s,subscribe as i,LIST_PHASE as l,RENDER_PHASE as a}from"hydroxide";function f(n,o){const c=n(o||{});if(o&&n!==e){const[e]=t((()=>{for(const e in o)o[e]}));e.size&&e.forEach((e=>{e.mutable=!1}))}return c}function u(...e){let t,r,s;const i=[],l=[];function a(e,n){r?(r.onDisconnect&&r.onDisconnect.forEach((e=>e())),s.replaceWith(n)):t.replaceWith(n),r=e,s=n,e.onConnect&&e.onConnect.forEach((e=>e()))}function f(){let n=-1;for(let t=0;t<e.length;t++)if(e[t][0]()){n=t;break}c.detectorEnabled=!1,-1===n?r&&s&&(r.onDisconnect&&r.onDisconnect.forEach((e=>e())),s.replaceWith(t),r=void 0,s=void 0):function(t){if(!r||r!==i[t])if(i[t])a(i[t],l[t]);else{const n=c.context;c.context=i[t]={isConnected:!0},l[t]=e[t][1](),c.context=n,a(i[t],l[t])}}(n)}return{$$branch:e=>{t=e,n(f,o)}}}const h=new Set;function p(e){for(let t=0,n=e.length;t<n;t++){const n=e[t];h.has(n)||(h.add(n),document.addEventListener(n,d))}}function d(e){const t=`$$${e.type}`;let n=e.composedPath&&e.composedPath()[0]||e.target;for(e.target!==n&&Object.defineProperty(e,"target",{configurable:!0,value:n}),Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>n||document});null!==n;){const o=n[t];if(o&&!n.disabled&&(Array.isArray(o)?o[0](o[1],e):o(e),e.cancelBubble))return;n=n.host&&n.host!==n&&n.host instanceof Node?n.host:n.parentNode}}function x(e,t){const n={isConnected:!0},o=c.context;c.context=n;const s=r(e),i=t.props.children(s);return n.onConnect&&n.onConnect.forEach((e=>e())),c.context=o,{el:i,value:s,context:n}}function g(e,t,n){const o=n.list.length;if(e===o||0===o)return function(e,t){const n=t.list.length;for(let o=0;o<e.length;o++){const c=x(e[o],t);t.parent.appendChild(c.el),t.list[n+o]=c}}(t,n);const c=new Array(t.length),r=n.list[e].el;for(let e=0;e<t.length;e++){const o=x(t[e],n);n.parent.insertBefore(o.el,r),c[e]=o}n.list.splice(e,0,...c)}function m(e,t,n){if(t!==n.list.length){for(let o=e;o<e+t;o++){const e=n.list[o];e.context.onDisconnect&&e.context.onDisconnect.forEach((e=>e())),e.el.remove()}n.list.splice(e,t)}else v(n)}function v(e){const t=e.list.length;for(let n=0;n<t;n++){const t=e.list[n].context;t.onDisconnect&&t.onDisconnect.forEach((e=>e()))}e.list=[],e.parent.textContent=""}const b=document.createComment("");function A(e,t,n){n.list.length;const o=n.list[e].el,c=n.list[t].el,r=n.list[e];n.list[e]=n.list[t],n.list[t]=r,c.replaceWith(b),o.replaceWith(c),b.replaceWith(o)}function C(e){const t=e.currentValue,n=function(e,t){const n=[];if(0===e.length)return n.push({indexes:[0,t.length-1],insertAt:0}),n;if(0===t.length)return n.push({clear:!0}),n;let o,c=e.length-1,r=t.length-1,s=0,i=0,l=0;for(;s<=c||i<=r;){if(s>c){n.push({insertAt:i,indexes:i===r?[i]:[i,r]});break}if(i>r){s<=c&&(n.push({removeAt:s-l,count:c-s+1}),l++);break}if(e[s]===t[i])s++,i++;else if(e[c]===t[r])c--,r--;else if(e[s]===t[r]&&t[i]===e[c])n.push({swap:[s,c]}),s++,i++,c--,r--;else if(s+1<=c&&e[s]===t[i+1]&&e[s+1]===t[i])n.push({swap:[s,s+1]}),s+=2,i+=2;else if(s+1<=c&&e[c]===t[r-1]&&e[c-1]===t[r])n.push({swap:[c,c-1]}),c-=2,r-=2;else{if(!o){o=new Map;for(let e=i;e<=r;e++)o.set(t[e],e)}if(o.has(e[s])){const t=o.get(e[s]);if(i<=t&&t<=r){let a=1;for(let n=s+1;n<=c&&n<=r&&o.get(e[n])===t+a;n++)a++;if(t-i<a){const e=t-1;n.push({indexes:i===e?[i]:[i,e],insertAt:i}),i=t}else n.push({replace:[s-l,i]}),i++,s++}else s++}else{const e=n[n.length-1];n.length>0&&"removeAt"in e&&e.removeAt+e.count===s?e.count++:n.push({removeAt:s-l,count:1}),l++,s++}}}return n}(e.prevValue,t);for(let o=0;o<n.length;o++){const c=n[o];if("removeAt"in c)m(c.removeAt,c.count,e);else if("insertAt"in c){const[n,o=n]=c.indexes,r=[];for(let e=n;e<=o;e++)r.push(t[e]);g(c.insertAt,r,e)}else if("swap"in c){const[t,n]=c.swap;A(t,n,e)}else if("replace"in c){const[t,n]=c.replace,o=e.list[t].value,r=e.currentValue[n];o.set(r)}else"clear"in c&&v(e)}}function E(e,n){const r=e.parentElement;e.remove();const a={context:c.context,props:n,parent:r,prevValue:[],currentValue:[],list:[]},[f,u]=t((()=>n.each));if(a.prevValue=u,g(0,u,a),0===f.size)return;let h,p=!0;if(1===f.size){h=f.values().next().value;p=h()!==u,p&&(h.mutable=!1)}if(p){i(h,(function(){a.currentValue=n.each,C(a),a.prevValue=a.currentValue}),o)}else{const e=(e,t,o)=>{switch(a.currentValue=n.each,e){case"insert":g(t,o,a);break;case"remove":m(t,o,a);break;case"swap":A(t,o,a);break;case"clear":v(a);break;case"set":!function(e,t,n){if(e&&e.length>1){const o=n.list[e[0]].value;if(o.mutable){let n=o.value;const c=e.length-1;for(let t=1;t<c;t++)n=n[e[t]];n[c]=t,s(o)}else o.$(e.slice(1)).set(t)}else C(n)}(t,o,a)}a.prevValue=a.currentValue};i(h,e,l)}}function $(e,n){if(n instanceof Node)e.replaceWith(n);else if("function"==typeof n){const[r,s]=t(n);if(r.size){const l=document.createTextNode(s+"");function o(){const e=n();l.textContent=e}c.context,l.textContent=s,r.forEach((e=>{i(e,o,a)})),e.replaceWith(l)}else"object"==typeof s?$(e,s):e.replaceWith(s+"")}else if(Array.isArray(n))n.forEach((n=>{if("function"==typeof n){const[c,r]=t(n);if(r instanceof Node)e.before(r);else if(c.size){const s=document.createTextNode(r+"");function o(){s.textContent=n()}c.forEach((e=>{i(e,o,a)}))}}else e.before(n)})),e.remove();else{if(n&&n.$$list)return E(e,n.$$list);if(n&&n.$$branch)return n.$$branch(e);{const f=document.createTextNode(n+"");e.replaceWith(f)}}}function y(e,t,n){n?e.setAttribute(t,n):e.removeAttribute(t)}function V(e){const t=document.createElement("template");return t.innerHTML=e,t.content.firstChild}function w(e){return V(`<svg>${e}</svg>`).firstChild}function W(e,t){let n;c.context={isConnected:!0};try{n=f(e)}catch(e){if(!c.context.onError)throw e;c.context.onError.forEach((t=>t(e)))}t.appendChild(n),c.context.onConnect&&c.context.onConnect.forEach((e=>e())),c.context=null}export{u as branch,f as component,p as delegateEvents,$ as insert,W as render,y as setAttribute,w as svg,V as template}; |
{ | ||
"name": "hydroxide-dom", | ||
"description": "Client side renderer for Hydroxide Framework", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"author": "Manan Tank", | ||
@@ -35,8 +35,10 @@ "license": "MIT", | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"build": "rollup -c", | ||
"ts-check": "tsc --noEmit --project tsconfig.json", | ||
"test": "jest" | ||
"test": "jest", | ||
"prepublishOnly": "npm run clean && npm run build" | ||
}, | ||
"dependencies": { | ||
"hydroxide": "^0.1.1", | ||
"hydroxide": "^0.3.0", | ||
"hydroxide-jsx": "^0.2.0" | ||
@@ -56,2 +58,3 @@ }, | ||
"jest": "^27.4.5", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.76.0", | ||
@@ -58,0 +61,0 @@ "rollup-plugin-terser": "^7.0.2", |
@@ -1,2 +0,2 @@ | ||
import { CONNECTION_PHASE, Context, effect, globalInfo } from 'hydroxide' | ||
import { CONNECTION_PHASE, Context, effect, coreInfo } from 'hydroxide' | ||
import { Branch } from '../types' | ||
@@ -41,6 +41,6 @@ | ||
// create context for conditional element | ||
const prevContext = globalInfo.context | ||
globalInfo.context = contexts[i] = { isConnected: true } as Context | ||
const prevContext = coreInfo.context | ||
coreInfo.context = contexts[i] = { isConnected: true } as Context | ||
elements[i] = branches[i][1]() | ||
globalInfo.context = prevContext | ||
coreInfo.context = prevContext | ||
add(contexts[i], elements[i]) | ||
@@ -67,3 +67,3 @@ } | ||
// don't detect states beyond this point | ||
globalInfo.detectorEnabled = false | ||
coreInfo.detectorEnabled = false | ||
@@ -70,0 +70,0 @@ // if no context should be rendered, and there is a rendered context, disconnect it |
@@ -1,2 +0,2 @@ | ||
import { detect, globalInfo, RENDER_PHASE, subscribe } from 'hydroxide' | ||
import { detect, coreInfo, RENDER_PHASE, subscribe } from 'hydroxide' | ||
import { objectStringifiedCheck, unwrappedListCheck } from '../dev/check' | ||
@@ -27,3 +27,3 @@ import { $list } from './list/renderList' | ||
const text = document.createTextNode(initValue + '') | ||
const context = globalInfo.context | ||
const context = coreInfo.context | ||
@@ -30,0 +30,0 @@ function update() { |
@@ -1,2 +0,2 @@ | ||
import { Context, globalInfo, reactive } from 'hydroxide' | ||
import { Context, coreInfo, reactive } from 'hydroxide' | ||
import { ListInfo, ListItem } from '../../types' | ||
@@ -7,4 +7,4 @@ | ||
const parentContext = globalInfo.context | ||
globalInfo.context = elContext | ||
const parentContext = coreInfo.context | ||
coreInfo.context = elContext | ||
@@ -18,3 +18,3 @@ const reactiveValue = reactive(value) | ||
globalInfo.context = parentContext | ||
coreInfo.context = parentContext | ||
@@ -21,0 +21,0 @@ return { |
import { | ||
CONNECTION_PHASE, | ||
detect, | ||
globalInfo, | ||
coreInfo, | ||
ListProps, | ||
@@ -29,3 +29,3 @@ LIST_PHASE, | ||
const listInfo: ListInfo<T> = { | ||
context: globalInfo.context, | ||
context: coreInfo.context, | ||
props: listProps, | ||
@@ -32,0 +32,0 @@ parent: parent!, |
@@ -1,2 +0,2 @@ | ||
import { globalInfo } from 'hydroxide' | ||
import { coreInfo } from 'hydroxide' | ||
import { devInfo } from './dev/info' | ||
@@ -23,3 +23,3 @@ import { component } from './hydrate/component' | ||
// root context | ||
globalInfo.context = { isConnected: true } | ||
coreInfo.context = { isConnected: true } | ||
@@ -31,4 +31,4 @@ // call component | ||
} catch (error) { | ||
if (globalInfo.context.onError) { | ||
globalInfo.context.onError.forEach((handleError) => handleError(error)) | ||
if (coreInfo.context.onError) { | ||
coreInfo.context.onError.forEach((handleError) => handleError(error)) | ||
} else { | ||
@@ -44,4 +44,4 @@ throw error | ||
// run onConnect callbacks | ||
if (globalInfo.context.onConnect) { | ||
globalInfo.context.onConnect.forEach((cb) => cb()) | ||
if (coreInfo.context.onConnect) { | ||
coreInfo.context.onConnect.forEach((cb) => cb()) | ||
} | ||
@@ -55,3 +55,3 @@ | ||
globalInfo.context = null | ||
coreInfo.context = null | ||
} |
113396
14
+ Added@babel/compat-data@7.26.8(transitive)
+ Added@babel/core@7.26.8(transitive)
+ Added@babel/generator@7.26.8(transitive)
+ Added@babel/parser@7.26.8(transitive)
+ Added@babel/template@7.26.8(transitive)
+ Added@babel/traverse@7.26.8(transitive)
+ Added@babel/types@7.26.8(transitive)
+ Added@types/gensync@1.0.4(transitive)
+ Addedcaniuse-lite@1.0.30001699(transitive)
+ Addedelectron-to-chromium@1.5.97(transitive)
+ Addedhydroxide@0.3.0(transitive)
- Removed@babel/compat-data@7.26.5(transitive)
- Removed@babel/core@7.26.7(transitive)
- Removed@babel/generator@7.26.5(transitive)
- Removed@babel/parser@7.26.7(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.26.7(transitive)
- Removed@babel/types@7.26.7(transitive)
- Removedcaniuse-lite@1.0.30001698(transitive)
- Removedelectron-to-chromium@1.5.96(transitive)
- Removedhydroxide@0.1.1(transitive)
Updatedhydroxide@^0.3.0