mosaic 1.0.3 → 1.0.4
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/LICENSE +21 -0
- package/README.md +63 -8
- package/cjs/attribute.js +90 -0
- package/cjs/constants.js +15 -0
- package/cjs/context.js +66 -0
- package/cjs/define.js +152 -0
- package/cjs/formControl.js +42 -0
- package/cjs/helpers.js +140 -0
- package/cjs/index.js +9 -0
- package/cjs/list.js +109 -0
- package/cjs/mergeSlots.js +37 -0
- package/cjs/proxy.js +42 -0
- package/cjs/render.js +395 -0
- package/cjs/token.js +63 -0
- package/cjs/update.js +128 -0
- package/dist/mosaic.js +1142 -0
- package/dist/mosaic.min.js +1 -0
- package/package.json +42 -25
- package/src/attribute.js +84 -0
- package/src/constants.js +5 -0
- package/src/context.js +60 -0
- package/src/define.js +158 -0
- package/src/formControl.js +36 -0
- package/src/helpers.js +123 -0
- package/src/index.js +1 -0
- package/src/list.js +100 -0
- package/src/mergeSlots.js +31 -0
- package/src/proxy.js +36 -0
- package/src/render.js +397 -0
- package/src/token.js +55 -0
- package/src/update.js +122 -0
- package/SCRATCH.md +0 -31
- package/cli.js +0 -17
- package/conf.json +0 -0
- package/docs/assets/css/main.css +0 -2638
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/index.html +0 -111
- package/docs/modules.html +0 -131
- package/example/components/x-drawer.html +0 -41
- package/example/mosaic/templates/mocha/index.html +0 -39
- package/example/mosaic/tests.d.ts +0 -13
- package/example/mosaic/tests.js +0 -28
- package/example/mosaic/website.d.ts +0 -31
- package/example/mosaic/website.js +0 -64
- package/example/mosaic.config.d.ts +0 -7
- package/example/mosaic.config.js +0 -8
- package/example/package-lock.json +0 -899
- package/example/package.json +0 -20
- package/example/pages/index.html +0 -12
- package/example/test/x-drawer.d.ts +0 -0
- package/example/test/x-drawer.js +0 -94
- package/index.d.ts +0 -85
- package/index.js +0 -125
- package/index.wdocs.js +0 -37
- package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Light-webfont.eot +0 -0
- package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Light-webfont.woff +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/out/global.html +0 -912
- package/out/index.html +0 -65
- package/out/index.js.html +0 -239
- package/out/scripts/linenumber.js +0 -25
- package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/out/scripts/prettify/lang-css.js +0 -2
- package/out/scripts/prettify/prettify.js +0 -28
- package/out/styles/jsdoc-default.css +0 -358
- package/out/styles/prettify-jsdoc.css +0 -111
- package/out/styles/prettify-tomorrow.css +0 -132
- package/tsconfig.json +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e=[])=>e[e.length-1],t=e=>e.nodeType===e.TEXT_NODE&&""===e.nodeValue.trim(),r=(e,n,i=!0)=>{if(e){if(!t(e)){let t=n(e);if(!1===t)return;if(t?.nodeName)return r(t,n,i)}i&&r(e.firstChild,n,i),r(e.nextSibling,n,i)}},n=(t,r)=>{let[i,a]=((t,r)=>{let i=((e="")=>e.split(/(\[[^\]]+\])/).filter((e=>e)).reduce(((e,t)=>e+("["===t.charAt(0)?"."+t.replace(/\./g,":"):t)),""))(t).split(".").map((e=>{if("["===e.charAt(0)){let t=e.slice(1,-1).replace(/:/g,".");return n(t,r)}return e}));return[i.slice(0,-1).reduce(((e,t)=>e&&e[t]),r)||r,e(i)]})(t,r),l=i?.[a];return"function"==typeof l?l.bind(i):l},i=e=>{if("string"==typeof e){let t=document.createElement("template");return t.innerHTML=e.trim(),t.content}return"TEMPLATE"===e.nodeName?e.cloneNode(!0).content:"defs"===e.nodeName?e.firstElementChild.cloneNode(!0):void 0},a=e=>null===e||"object"!=typeof e,l=e=>e.replace(/[\w]([A-Z])/g,(function(e){return e[0]+"-"+e[1].toLowerCase()})),c=(e,t,r)=>{t=l(t),"boolean"==typeof r&&(t.startsWith("aria-")?r=""+r:r&&(r="")),"string"==typeof r||"number"==typeof r?e.setAttribute(t,r):e.removeAttribute(t)},s=(e,t)=>{let r=e.replace(/[\w]-([\w])/g,(function(e){return e[0]+e[2].toUpperCase()}));return""===t&&(t=!0),e.startsWith("aria-")&&("true"===t&&(t=!0),"false"===t&&(t=!1)),{name:r,value:t}};const o=e=>{let t=0;return r(e.content?.firstChild||e.firstChild,(()=>t++),!1),t},u=e=>t(e.nextSibling)?u(e.nextSibling):e.nextSibling;const d=(e,t,r,n)=>{let i=e.getAttribute("length")||0,a=((e,t)=>{let r=o(e),n=[];if(t)for(;t--;){let t=document.createDocumentFragment(),i=r;for(;i--;)t.appendChild(u(e));n.push(t)}return n})(e,i),l=e;t.forEach(((e,t)=>{let i=-1===e?n(r[t][1],r[t][0]):a[e],c=(s=i).nodeType===s.DOCUMENT_FRAGMENT_NODE&&s.lastChild||s;var s;l.after(i),l=c})),e.setAttribute("length",t.length)},p=e=>e.trim().split(/({{[^{}]+}})/).filter((e=>e)).map((e=>{let t=e.match(/{{([^{}]+)}}/);if(!t)return{type:1,value:e,negated:!1};let r="!"===(e=t[1].trim()).charAt(0);return r&&(e=e.slice(1)),{type:2,value:e,negated:r}})),h=(e,t)=>t.reduce(((t,r)=>{let i,{type:a,value:l,negated:c}=r;if(1===a&&(i=l),2===a&&(i=n(l,e)),3===a){let t=r.args.map((t=>n(t,e)));i=n(r.method,e)?.(...t)}return c&&(i=!i),t||0===t?t+i:i}),""),f=e=>e.replace(/[\w]([A-Z])/g,(function(e){return e[0]+"-"+e[1].toLowerCase()})),m=e=>{let t=typeof e;return"string"===t?e.split(";").reduce(((e,t)=>{const[r,n]=t.split(":").map((e=>e.trim()));return r&&(e[r]=n),e}),{}):"object"===t?e:{}},b=(e,t,r)=>{if("style"===t)r=(e=>Object.entries(e).map((([e,t])=>`${e}: ${t};`)).join(" "))((l={...m(e.getAttribute("style")),...m(r)},Object.keys(l).reduce(((e,t)=>(e[f(t)]=l[t],e)),{})));else if("class"===t)switch(i=r,Object.prototype.toString.call(i).match(/\s(.+[^\]])/)[1]){case"Array":r=r.join(" ");break;case"Object":r=Object.keys(r).reduce(((e,t)=>(r[t]&&e.push(t),e)),[]).join(" ")}else if(!a(r))return e[(n=t,n.replace(/[\w]-([\w])/g,(function(e){return e[0]+e[2].toUpperCase()})))]=r;var n,i,l;t=f(t),"boolean"==typeof r&&(t.startsWith("aria-")?r=""+r:r&&(r=""));let c=e.getAttribute(t);r!==c&&("string"==typeof r||"number"==typeof r?e.setAttribute(t,r):e.removeAttribute(t))},y=(e=[])=>{let t=e;return{get:()=>t,push:e=>t.push(e),wrap:e=>t.reduce(((e,t)=>new Proxy(e,(({path:e,identifier:t,key:r,index:i,i:l,k:c})=>({get(a,s){let o=n(e,a);if(s===t)for(let e in o){let t=o[e];if(r){if(t[r]===c)return t}else if(e==l)return t}if(s===i)for(let e in o){let t=o[e];if(r){if(t[r]===c)return e}else if(e==l)return e}let u=r?o.find((e=>e[r]===c)):o[l];return u?.hasOwnProperty?.(s)?u[s]:Reflect.get(...arguments)},set(t,i,s){let o=n(e,t),u=r?o.find((e=>e[r]===c)):o[l];return u&&!a(u)?(u[i]=s,!0):Reflect.set(...arguments)}}))(t))),e)}},g=(t,{getState:a,dispatch:l},c,s,f)=>{const m={1:({value:e,node:t,context:r},{getState:n})=>({handler:()=>{let i=r?r.wrap(n()):n(),a=t.textContent,l=h(i,p(e));a!==l&&(t.textContent=l)}}),2:({value:e,node:t,name:r,context:i},{getState:a})=>({handler:()=>{let l=i?i.wrap(a()):a(),c=h(l,p(e));if(b(t,r,c),"OPTION"===t.nodeName){let e=t.parentNode.getAttribute("name"),r=n(e,l);t.selected=r===c}}}),3:({node:e,path:t,context:r},{getState:i,dispatch:a})=>(e.addEventListener("input",(()=>{let n="checkbox"===e.getAttribute("type")?e.checked:e.value;if(n.trim?.().length&&!isNaN(n)&&(n=+n),r){let e=r.wrap(i());e[t]=n,a({type:"MERGE",payload:e})}else a({type:"SET",payload:{name:t,value:n,context:r}})})),{handler:()=>{let a=r?r.wrap(i()):i();((e,t)=>{if("SELECT"===e.nodeName)return void Array.from(e.querySelectorAll("option")).forEach((e=>{e.selected=t.includes(e.value)}));let r;switch(e.getAttribute("type")){case"checkbox":if(r=t,e.checked===r)break;r?e.setAttribute("checked",""):e.removeAttribute("checked");break;case"radio":if(r=t===e.getAttribute("value"),e.checked===r)break;e.checked=r,r?e.setAttribute("checked",""):e.removeAttribute("checked");break;default:if(e.value===t)break;e.setAttribute("value",e.value=t||"")}})(e,n(t,a))}}),4:({node:e,eventType:t,actionType:r,context:n},{dispatch:i,getState:a})=>(e.addEventListener(t,(t=>{let l=r.startsWith("$"),c={type:r,event:t};l||(c.context=n?n.wrap(a()):a()),i(c),l&&e.dispatchEvent(new CustomEvent(r,{detail:c,bubbles:!0}))})),{handler:()=>{}}),5:({node:t,context:a,map:l,path:c,identifier:s,index:p,key:h,blockIndex:f,hydrate:m,pickupNode:b},{getState:g})=>{let E;t.$t=f-1;const A=(e,t,n,i)=>{r(e,k((e=>{if(e===i)return!1}),T(l,m,y((a?.get()||[]).concat({path:c,identifier:s,key:h,index:p,i:t,k:n}))),(e=>e.$t=f)))};const v=(e,r)=>{let n=e[h],a=i(t);var l;return A((l=a).nodeType===l.DOCUMENT_FRAGMENT_NODE&&l.firstChild||l,r,n),a};if(m){let r=n(c,g()),i=(e=>{let t=e.getAttribute("length"),r=o(e),n=[],i=e;if(t)for(;t--;){let e=[],t=r;for(;t--;)i=u(i),e.push(i);n.push(e)}return n})(t);i.forEach(((t,n)=>{let i=r[n]?.[h];A(t[0],n,i,e(t).nextSibling)})),b=e(e(i)).nextSibling}return{handler:()=>{let e=a?a.wrap(g()):g();const r=Object.entries(n(c,e)||[]),i=((e,t=[],r=[])=>{let n=r.map((([r,n])=>e?t.findIndex((([t,r])=>r[e]===n[e])):r in t?r:-1));if(t.length!==r.length||!n.every(((e,t)=>e===t)))return n})(h,E,r);i&&d(t,i,r,v),E=r.slice(0)},pickupNode:b}}},{bind:g,update:E}=(()=>{const e=(()=>{let e=new Set;return{publish:t=>{for(let t of e)t();t?.()},subscribe(t){e.add(t)}}})();return{bind(t){let r=m[t.type](t,{getState:a,dispatch:l});return e.subscribe(r.handler),r},update:t=>e.publish(t)}})();let A=0;const v=e=>{let t=0,n={};return r(e,(e=>{let r,i=[];switch(e.nodeType){case e.TEXT_NODE:{let t=e.textContent;t.match(/({{[^{}]+}})/)&&i.push({type:1,value:t});break}case e.ELEMENT_NODE:{let t=function(e){let t=e.getAttribute("each"),r=t?.match(/(.+)\s+in\s+(.+)/);if(!r)return t?{path:t.trim(),key:e.getAttribute("key")}:r;let[n,i,a]=r,l=i.match(/\(([^\)]+)\)/),[c,s]=(l?l[1].split(","):[i]).map((e=>e.trim()));return{path:a.trim(),identifier:s||c,index:s?c:s,key:e.getAttribute("key")}}(e);if(t){let n,a=e.namespaceURI;if(a.endsWith("/svg")){e.removeAttribute("each");let t=document.createElementNS(a,"defs");t.innerHTML=e.outerHTML,e.parentNode.replaceChild(t,e),n=v((e=t).firstChild)}else{if("TEMPLATE"!==e.nodeName){e.removeAttribute("each");let t=document.createElement("template");t.innerHTML=e.outerHTML,e.parentNode.replaceChild(t,e),e=t}n=v(e.content.firstChild)}r=e.nextSibling,i.push({type:5,map:n,blockIndex:A++,...t,pickupNode:r});break}let n=e.attributes,a=n.length;for(;a--;){let{name:t,value:r}=n[a];if(":name"!==t||!r||"INPUT"!==e.nodeName&&"SELECT"!==e.nodeName&&"TEXTAREA"!==e.nodeName){if(t.startsWith(":on")){e.removeAttribute(t);let n=t.split(":on")[1];i.push({type:4,eventType:n,actionType:r})}else if(t.startsWith(":")){let n=t.slice(1),a=r||n;a.includes("{{")||(a=`{{${a}}}`),i.push({type:2,name:n,value:a}),e.removeAttribute(t)}}else i.push({type:3,path:r}),e.removeAttribute(t),e.setAttribute("name",r)}}}return i.length&&(n[t]=i),t++,r})),n},k=(...e)=>(...t)=>{for(let r of e){if(!1===r(...t))return!1}},T=(e,t=0,r)=>{let n=0;return i=>{let a;return n in e&&(e[n].forEach((e=>{let n=g({...e,node:i,context:r,hydrate:t});a=n.pickupNode})),i.$i=n),n++,a}};let N=i(c),S=v(N);return t.hasAttribute?.("mosaic-hydrate")?r(t,T(S,1)):(r(N,T(S)),f?.(N),t.prepend(N),E(),t.setAttribute?.("mosaic-hydrate",1)),(e=>{let t=!1,r=!1;return()=>{t?r=!0:(t=!0,e(),requestAnimationFrame((()=>{r&&e(),t=!1})))}})((()=>E(s)))},E=e=>{let t=document.createDocumentFragment();for(;e.firstChild;)t.appendChild(e.firstChild);return t};function A(e){return e.querySelector('script[type="application/mosaic"]')}function v(e,t){(A(e)||function(e){let t=document.createElement("script");return t.setAttribute("type","application/mosaic"),e.append(t),t}(e)).innerText=JSON.stringify(t)}const k=(e,t,r)=>customElements.define(e,class extends HTMLElement{async connectedCallback(){if(!this.initialised){let n=t(this);n instanceof Promise&&(n=await n);let{update:i,middleware:o,derivations:u,subscribe:d,shadow:p,initialState:h={}}=n;this.connectedCallback=n.connectedCallback,this.disconnectedCallback=n.disconnectedCallback;const{dispatch:f,getState:m,onUpdate:b,flush:y}=function({update:e={},middleware:t=[],derivations:r={},initialState:n={}},i){let a,l=[],c=()=>{};function s(e){a={...e};for(let t in r)a[t]=r[t](e)}function o(){return{...a}}function u(e){l.push(e)}function d(r){const{type:n}=r;if("SET"===n||"MERGE"===n)s(function(e,t){switch(t.type){case"SET":{const{name:r,value:n}=t.payload;return{...e,[r]:n}}case"MERGE":return{...e,...t.payload}}}(o(),r));else if(t.length){let i=t.slice(),a=t=>{if(i.length){let e=i.shift();t.type in e?e[t.type](t,a,{getState:o,dispatch:d,afterNextRender:u}):a(t)}else t.type in e&&s(e[t.type](o(),t))},l=i.shift();n in l?l[n](r,a,{getState:o,dispatch:d,afterNextRender:u}):a(r)}else n in e&&s(e[n](o(),r));c()}s(n);for(let t in e)t.startsWith("$")&&i.addEventListener(t,(({detail:e})=>d(e)));return{dispatch:d,getState:o,onUpdate:function(e){c=e},flush:function(){l.forEach((e=>e())),l=[]}}}(n,this);f({type:"MERGE",payload:(e=this,JSON.parse(A(e)?.innerText||"{}"))}),h=m();let k,T=Object.keys(h).filter((e=>"$"===e.charAt(0))),N=T.map((e=>e.slice(1))).map(l),S=this.setAttribute;this.setAttribute=(e,t)=>{if(N.includes(e)){let{name:r,value:n}=s(e,t);f({type:"SET",payload:{name:"$"+r,value:n}})}S.apply(this,[e,t])},N.forEach((e=>{let t,r=s(e).name;t=this.hasAttribute(e)?this.getAttribute(e):this[r]||h["$"+r],Object.defineProperty(this,r,{get:()=>m()["$"+r],set(e){f({type:"SET",payload:{name:"$"+r,value:e}}),a(e)&&c(this,r,e)}}),this[r]=t})),p?this.attachShadow({mode:p}):k=e=>((e,t)=>{t.querySelectorAll("slot[name]").forEach((t=>{let r=t.attributes.name.value,n=e.querySelector(`[slot="${r}"]`);n?(n.removeAttribute("slot"),t.parentNode.replaceChild(n,t)):t.parentNode.replaceChild(E(t),t)}));let r=t.querySelector("slot:not([name])");r&&r.parentNode.replaceChild(E(e.innerHTML.trim()?e:r),r)})(this,e),b(g(this.shadowRoot||this,{getState:m,dispatch:f},r,(()=>{v(this,m()),T.forEach((e=>{let t=m()[e];a(t)&&c(this,e.slice(1),t)})),d?.(m()),y()}),k)),this.initialised=!0}var e;this.connectedCallback?.()}disconnectedCallback(){this.disconnectedCallback?.()}});export{k as define};
|
package/package.json
CHANGED
|
@@ -1,36 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosaic",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "The Web UI Framework",
|
|
5
|
+
"main": "dist/mosaic.min.js",
|
|
6
|
+
"browser": "dist/mosaic.min.js",
|
|
7
|
+
"unpkg": "dist/mosaic.min.js",
|
|
8
|
+
"module": "src/index.js",
|
|
9
|
+
"types": "types/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"dist",
|
|
13
|
+
"cjs"
|
|
14
|
+
],
|
|
15
|
+
"directories": {
|
|
16
|
+
"test": "test"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "mocha-express --coverage",
|
|
20
|
+
"test:watch": "mocha-express --watch",
|
|
21
|
+
"build": "rm -rf dist && rollup -c && npm run size",
|
|
22
|
+
"size": "gzip -c9 ./dist/mosaic.min.js | wc -c",
|
|
23
|
+
"coveralls": "cat ./coverage/lcov-report/lcov.info | coveralls",
|
|
24
|
+
"prepublishOnly": "npm t && npm run build",
|
|
25
|
+
"release": "npm t && standard-version"
|
|
26
|
+
},
|
|
7
27
|
"repository": {
|
|
8
28
|
"type": "git",
|
|
9
29
|
"url": "git+https://github.com/defx/mosaic.git"
|
|
10
30
|
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
|
|
13
|
-
|
|
31
|
+
"keywords": [
|
|
32
|
+
"simple",
|
|
33
|
+
"declarative",
|
|
34
|
+
"dom",
|
|
35
|
+
"ui",
|
|
36
|
+
"user interface",
|
|
37
|
+
"web components",
|
|
38
|
+
"framework"
|
|
39
|
+
],
|
|
40
|
+
"author": "Matt Donkin",
|
|
41
|
+
"license": "MIT",
|
|
14
42
|
"bugs": {
|
|
15
43
|
"url": "https://github.com/defx/mosaic/issues"
|
|
16
44
|
},
|
|
17
|
-
"homepage": "https://github.com/defx/mosaic
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"express": "^
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"glob-promise": "^3.4.0",
|
|
25
|
-
"lodash.debounce": "^4.0.8",
|
|
26
|
-
"path": "^0.12.7",
|
|
27
|
-
"ws": "^7.4.2"
|
|
28
|
-
},
|
|
29
|
-
"bin": {
|
|
30
|
-
"mosaic": "cli.js"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
45
|
+
"homepage": "https://github.com/defx/mosaic",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"coveralls": "^3.1.0",
|
|
48
|
+
"mocha-express": "^0.1.2",
|
|
49
|
+
"rollup": "^2.26.4",
|
|
50
|
+
"rollup-plugin-terser": "^7.0.1",
|
|
51
|
+
"standard-version": "^9.1.1"
|
|
35
52
|
}
|
|
36
53
|
}
|
package/src/attribute.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isPrimitive, typeOf } from "./helpers.js"
|
|
2
|
+
|
|
3
|
+
const pascalToKebab = (string) =>
|
|
4
|
+
string.replace(/[\w]([A-Z])/g, function (m) {
|
|
5
|
+
return m[0] + "-" + m[1].toLowerCase()
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
const kebabToPascal = (string) =>
|
|
9
|
+
string.replace(/[\w]-([\w])/g, function (m) {
|
|
10
|
+
return m[0] + m[2].toUpperCase()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const parseStyles = (value) => {
|
|
14
|
+
let type = typeof value
|
|
15
|
+
|
|
16
|
+
if (type === "string")
|
|
17
|
+
return value.split(";").reduce((o, value) => {
|
|
18
|
+
const [k, v] = value.split(":").map((v) => v.trim())
|
|
19
|
+
if (k) o[k] = v
|
|
20
|
+
return o
|
|
21
|
+
}, {})
|
|
22
|
+
|
|
23
|
+
if (type === "object") return value
|
|
24
|
+
|
|
25
|
+
return {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const joinStyles = (value) =>
|
|
29
|
+
Object.entries(value)
|
|
30
|
+
.map(([k, v]) => `${k}: ${v};`)
|
|
31
|
+
.join(" ")
|
|
32
|
+
|
|
33
|
+
const convertStyles = (o) =>
|
|
34
|
+
Object.keys(o).reduce((a, k) => {
|
|
35
|
+
a[pascalToKebab(k)] = o[k]
|
|
36
|
+
return a
|
|
37
|
+
}, {})
|
|
38
|
+
|
|
39
|
+
export const applyAttribute = (node, name, value) => {
|
|
40
|
+
if (name === "style") {
|
|
41
|
+
value = joinStyles(
|
|
42
|
+
convertStyles({
|
|
43
|
+
...parseStyles(node.getAttribute("style")),
|
|
44
|
+
...parseStyles(value),
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
} else if (name === "class") {
|
|
48
|
+
switch (typeOf(value)) {
|
|
49
|
+
case "Array":
|
|
50
|
+
value = value.join(" ")
|
|
51
|
+
break
|
|
52
|
+
case "Object":
|
|
53
|
+
value = Object.keys(value)
|
|
54
|
+
.reduce((a, k) => {
|
|
55
|
+
if (value[k]) a.push(k)
|
|
56
|
+
return a
|
|
57
|
+
}, [])
|
|
58
|
+
.join(" ")
|
|
59
|
+
break
|
|
60
|
+
}
|
|
61
|
+
} else if (!isPrimitive(value)) {
|
|
62
|
+
return (node[kebabToPascal(name)] = value)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
name = pascalToKebab(name)
|
|
66
|
+
|
|
67
|
+
if (typeof value === "boolean") {
|
|
68
|
+
if (name.startsWith("aria-")) {
|
|
69
|
+
value = "" + value
|
|
70
|
+
} else if (value) {
|
|
71
|
+
value = ""
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let current = node.getAttribute(name)
|
|
76
|
+
|
|
77
|
+
if (value === current) return
|
|
78
|
+
|
|
79
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
80
|
+
node.setAttribute(name, value)
|
|
81
|
+
} else {
|
|
82
|
+
node.removeAttribute(name)
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/constants.js
ADDED
package/src/context.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getValueAtPath, isPrimitive } from "./helpers.js"
|
|
2
|
+
|
|
3
|
+
const handler = ({ path, identifier, key, index, i, k }) => ({
|
|
4
|
+
get(target, property) {
|
|
5
|
+
let x = getValueAtPath(path, target)
|
|
6
|
+
|
|
7
|
+
// x === the collection
|
|
8
|
+
|
|
9
|
+
if (property === identifier) {
|
|
10
|
+
for (let n in x) {
|
|
11
|
+
let v = x[n]
|
|
12
|
+
if (key) {
|
|
13
|
+
if (v[key] === k) return v
|
|
14
|
+
} else {
|
|
15
|
+
if (n == i) return v
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (property === index) {
|
|
21
|
+
for (let n in x) {
|
|
22
|
+
let v = x[n]
|
|
23
|
+
if (key) {
|
|
24
|
+
if (v[key] === k) return n
|
|
25
|
+
} else {
|
|
26
|
+
if (n == i) return n
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let t = key ? x.find((v) => v[key] === k) : x[i]
|
|
32
|
+
if (t?.hasOwnProperty?.(property)) return t[property]
|
|
33
|
+
|
|
34
|
+
return Reflect.get(...arguments)
|
|
35
|
+
},
|
|
36
|
+
set(target, property, value) {
|
|
37
|
+
let x = getValueAtPath(path, target)
|
|
38
|
+
let t = key ? x.find((v) => v[key] === k) : x[i]
|
|
39
|
+
if (t && !isPrimitive(t)) {
|
|
40
|
+
t[property] = value
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return Reflect.set(...arguments)
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export const createContext = (v = []) => {
|
|
49
|
+
let context = v
|
|
50
|
+
return {
|
|
51
|
+
get: () => context,
|
|
52
|
+
push: (v) => context.push(v),
|
|
53
|
+
wrap: (state) => {
|
|
54
|
+
return context.reduce(
|
|
55
|
+
(target, ctx) => new Proxy(target, handler(ctx)),
|
|
56
|
+
state
|
|
57
|
+
)
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/define.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { configure } from "./update.js"
|
|
2
|
+
import { render } from "./render.js"
|
|
3
|
+
import { mergeSlots } from "./mergeSlots.js"
|
|
4
|
+
import {
|
|
5
|
+
applyAttribute,
|
|
6
|
+
attributeToProp,
|
|
7
|
+
isPrimitive,
|
|
8
|
+
pascalToKebab,
|
|
9
|
+
} from "./helpers.js"
|
|
10
|
+
|
|
11
|
+
function getDataScript(node) {
|
|
12
|
+
return node.querySelector(`script[type="application/mosaic"]`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function createDataScript(node) {
|
|
16
|
+
let ds = document.createElement("script")
|
|
17
|
+
ds.setAttribute("type", "application/mosaic")
|
|
18
|
+
node.append(ds)
|
|
19
|
+
return ds
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function serialise(node, state) {
|
|
23
|
+
let ds = getDataScript(node) || createDataScript(node)
|
|
24
|
+
|
|
25
|
+
ds.innerText = JSON.stringify(state)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function deserialise(node) {
|
|
29
|
+
return JSON.parse(getDataScript(node)?.innerText || "{}")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let count = 0
|
|
33
|
+
|
|
34
|
+
function nextId() {
|
|
35
|
+
return count++
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const define = (name, factory, template) =>
|
|
39
|
+
customElements.define(
|
|
40
|
+
name,
|
|
41
|
+
class extends HTMLElement {
|
|
42
|
+
async connectedCallback() {
|
|
43
|
+
if (!this.initialised) {
|
|
44
|
+
let config = factory(this)
|
|
45
|
+
const slice = `name.${nextId()}`
|
|
46
|
+
|
|
47
|
+
if (config instanceof Promise) config = await config
|
|
48
|
+
|
|
49
|
+
let {
|
|
50
|
+
update,
|
|
51
|
+
middleware,
|
|
52
|
+
derivations,
|
|
53
|
+
subscribe,
|
|
54
|
+
shadow,
|
|
55
|
+
initialState = {},
|
|
56
|
+
} = config
|
|
57
|
+
|
|
58
|
+
this.connectedCallback = config.connectedCallback
|
|
59
|
+
this.disconnectedCallback = config.disconnectedCallback
|
|
60
|
+
|
|
61
|
+
const { dispatch, getState, onUpdate, flush } = configure(
|
|
62
|
+
config,
|
|
63
|
+
this
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
dispatch({
|
|
67
|
+
type: "MERGE",
|
|
68
|
+
payload: deserialise(this),
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
initialState = getState()
|
|
72
|
+
|
|
73
|
+
let observedProps = Object.keys(initialState).filter(
|
|
74
|
+
(v) => v.charAt(0) === "$"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
let observedAttributes = observedProps
|
|
78
|
+
.map((v) => v.slice(1))
|
|
79
|
+
.map(pascalToKebab)
|
|
80
|
+
|
|
81
|
+
let sa = this.setAttribute
|
|
82
|
+
this.setAttribute = (k, v) => {
|
|
83
|
+
if (observedAttributes.includes(k)) {
|
|
84
|
+
let { name, value } = attributeToProp(k, v)
|
|
85
|
+
dispatch({
|
|
86
|
+
type: "SET",
|
|
87
|
+
payload: { name: "$" + name, value },
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
sa.apply(this, [k, v])
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
observedAttributes.forEach((name) => {
|
|
94
|
+
let property = attributeToProp(name).name
|
|
95
|
+
|
|
96
|
+
let value
|
|
97
|
+
|
|
98
|
+
if (this.hasAttribute(name)) {
|
|
99
|
+
value = this.getAttribute(name)
|
|
100
|
+
} else {
|
|
101
|
+
value = this[property] || initialState["$" + property]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Object.defineProperty(this, property, {
|
|
105
|
+
get() {
|
|
106
|
+
return getState()["$" + property]
|
|
107
|
+
},
|
|
108
|
+
set(v) {
|
|
109
|
+
dispatch({
|
|
110
|
+
type: "SET",
|
|
111
|
+
payload: { name: "$" + property, value: v },
|
|
112
|
+
})
|
|
113
|
+
if (isPrimitive(v)) {
|
|
114
|
+
applyAttribute(this, property, v)
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
this[property] = value
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
let beforeMountCallback
|
|
123
|
+
|
|
124
|
+
if (shadow) {
|
|
125
|
+
this.attachShadow({
|
|
126
|
+
mode: shadow,
|
|
127
|
+
})
|
|
128
|
+
} else {
|
|
129
|
+
beforeMountCallback = (frag) => mergeSlots(this, frag)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onUpdate(
|
|
133
|
+
render(
|
|
134
|
+
this.shadowRoot || this,
|
|
135
|
+
{ getState, dispatch },
|
|
136
|
+
template,
|
|
137
|
+
() => {
|
|
138
|
+
serialise(this, getState())
|
|
139
|
+
|
|
140
|
+
observedProps.forEach((k) => {
|
|
141
|
+
let v = getState()[k]
|
|
142
|
+
if (isPrimitive(v)) applyAttribute(this, k.slice(1), v)
|
|
143
|
+
})
|
|
144
|
+
subscribe?.(getState())
|
|
145
|
+
flush()
|
|
146
|
+
},
|
|
147
|
+
beforeMountCallback
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
this.initialised = true
|
|
151
|
+
}
|
|
152
|
+
this.connectedCallback?.()
|
|
153
|
+
}
|
|
154
|
+
disconnectedCallback() {
|
|
155
|
+
this.disconnectedCallback?.()
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const updateFormControl = (node, value) => {
|
|
2
|
+
if (node.nodeName === "SELECT") {
|
|
3
|
+
Array.from(node.querySelectorAll("option")).forEach((option) => {
|
|
4
|
+
option.selected = value.includes(option.value)
|
|
5
|
+
})
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let checked
|
|
10
|
+
|
|
11
|
+
switch (node.getAttribute("type")) {
|
|
12
|
+
case "checkbox":
|
|
13
|
+
checked = value
|
|
14
|
+
if (node.checked === checked) break
|
|
15
|
+
if (checked) {
|
|
16
|
+
node.setAttribute("checked", "")
|
|
17
|
+
} else {
|
|
18
|
+
node.removeAttribute("checked")
|
|
19
|
+
}
|
|
20
|
+
break
|
|
21
|
+
case "radio":
|
|
22
|
+
checked = value === node.getAttribute("value")
|
|
23
|
+
if (node.checked === checked) break
|
|
24
|
+
node.checked = checked
|
|
25
|
+
if (checked) {
|
|
26
|
+
node.setAttribute("checked", "")
|
|
27
|
+
} else {
|
|
28
|
+
node.removeAttribute("checked")
|
|
29
|
+
}
|
|
30
|
+
break
|
|
31
|
+
default:
|
|
32
|
+
if (node.value === value) break
|
|
33
|
+
node.setAttribute("value", (node.value = value || ""))
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/helpers.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const last = (v = []) => v[v.length - 1]
|
|
2
|
+
|
|
3
|
+
export const isWhitespace = (node) => {
|
|
4
|
+
return node.nodeType === node.TEXT_NODE && node.nodeValue.trim() === ""
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const walk = (node, callback, deep = true) => {
|
|
8
|
+
if (!node) return
|
|
9
|
+
if (!isWhitespace(node)) {
|
|
10
|
+
let v = callback(node)
|
|
11
|
+
if (v === false) return
|
|
12
|
+
if (v?.nodeName) return walk(v, callback, deep)
|
|
13
|
+
}
|
|
14
|
+
if (deep) walk(node.firstChild, callback, deep)
|
|
15
|
+
walk(node.nextSibling, callback, deep)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const transformBrackets = (str = "") => {
|
|
19
|
+
let parts = str.split(/(\[[^\]]+\])/).filter((v) => v)
|
|
20
|
+
return parts.reduce((a, part) => {
|
|
21
|
+
let v = part.charAt(0) === "[" ? "." + part.replace(/\./g, ":") : part
|
|
22
|
+
return a + v
|
|
23
|
+
}, "")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getTarget = (path, target) => {
|
|
27
|
+
let parts = transformBrackets(path)
|
|
28
|
+
.split(".")
|
|
29
|
+
.map((k) => {
|
|
30
|
+
if (k.charAt(0) === "[") {
|
|
31
|
+
let p = k.slice(1, -1).replace(/:/g, ".")
|
|
32
|
+
return getValueAtPath(p, target)
|
|
33
|
+
} else {
|
|
34
|
+
return k
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
let t =
|
|
39
|
+
parts.slice(0, -1).reduce((o, k) => {
|
|
40
|
+
return o && o[k]
|
|
41
|
+
}, target) || target
|
|
42
|
+
return [t, last(parts)]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const getValueAtPath = (path, target) => {
|
|
46
|
+
let [a, b] = getTarget(path, target)
|
|
47
|
+
let v = a?.[b]
|
|
48
|
+
if (typeof v === "function") return v.bind(a)
|
|
49
|
+
return v
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const fragmentFromTemplate = (v) => {
|
|
53
|
+
if (typeof v === "string") {
|
|
54
|
+
let tpl = document.createElement("template")
|
|
55
|
+
tpl.innerHTML = v.trim()
|
|
56
|
+
return tpl.content
|
|
57
|
+
}
|
|
58
|
+
if (v.nodeName === "TEMPLATE") return v.cloneNode(true).content
|
|
59
|
+
if (v.nodeName === "defs") return v.firstElementChild.cloneNode(true)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const debounce = (fn) => {
|
|
63
|
+
let wait = false
|
|
64
|
+
let invoke = false
|
|
65
|
+
return () => {
|
|
66
|
+
if (wait) {
|
|
67
|
+
invoke = true
|
|
68
|
+
} else {
|
|
69
|
+
wait = true
|
|
70
|
+
fn()
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
if (invoke) fn()
|
|
73
|
+
wait = false
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const isPrimitive = (v) => v === null || typeof v !== "object"
|
|
80
|
+
|
|
81
|
+
export const typeOf = (v) =>
|
|
82
|
+
Object.prototype.toString.call(v).match(/\s(.+[^\]])/)[1]
|
|
83
|
+
|
|
84
|
+
export const pascalToKebab = (string) =>
|
|
85
|
+
string.replace(/[\w]([A-Z])/g, function (m) {
|
|
86
|
+
return m[0] + "-" + m[1].toLowerCase()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
export const kebabToPascal = (string) =>
|
|
90
|
+
string.replace(/[\w]-([\w])/g, function (m) {
|
|
91
|
+
return m[0] + m[2].toUpperCase()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
export const applyAttribute = (node, name, value) => {
|
|
95
|
+
name = pascalToKebab(name)
|
|
96
|
+
|
|
97
|
+
if (typeof value === "boolean") {
|
|
98
|
+
if (name.startsWith("aria-")) {
|
|
99
|
+
value = "" + value
|
|
100
|
+
} else if (value) {
|
|
101
|
+
value = ""
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
106
|
+
node.setAttribute(name, value)
|
|
107
|
+
} else {
|
|
108
|
+
node.removeAttribute(name)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const attributeToProp = (k, v) => {
|
|
113
|
+
let name = kebabToPascal(k)
|
|
114
|
+
if (v === "") v = true
|
|
115
|
+
if (k.startsWith("aria-")) {
|
|
116
|
+
if (v === "true") v = true
|
|
117
|
+
if (v === "false") v = false
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
name,
|
|
121
|
+
value: v,
|
|
122
|
+
}
|
|
123
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { define } from "./define.js"
|
package/src/list.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isWhitespace, walk } from "./helpers.js"
|
|
2
|
+
|
|
3
|
+
export function parseEach(node) {
|
|
4
|
+
let each = node.getAttribute("each")
|
|
5
|
+
let m = each?.match(/(.+)\s+in\s+(.+)/)
|
|
6
|
+
if (!m) {
|
|
7
|
+
if (!each) return m
|
|
8
|
+
return {
|
|
9
|
+
path: each.trim(),
|
|
10
|
+
key: node.getAttribute("key"),
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
let [_, left, right] = m
|
|
14
|
+
let parts = left.match(/\(([^\)]+)\)/)
|
|
15
|
+
let [a, b] = (parts ? parts[1].split(",") : [left]).map((v) => v.trim())
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
path: right.trim(),
|
|
19
|
+
identifier: b ? b : a,
|
|
20
|
+
index: b ? a : b,
|
|
21
|
+
key: node.getAttribute("key"),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const getBlockSize = (template) => {
|
|
26
|
+
let i = 0
|
|
27
|
+
walk(template.content?.firstChild || template.firstChild, () => i++, false)
|
|
28
|
+
return i
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const nextNonWhitespaceSibling = (node) => {
|
|
32
|
+
return isWhitespace(node.nextSibling)
|
|
33
|
+
? nextNonWhitespaceSibling(node.nextSibling)
|
|
34
|
+
: node.nextSibling
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getBlockFragments = (template, numBlocks) => {
|
|
38
|
+
let blockSize = getBlockSize(template)
|
|
39
|
+
|
|
40
|
+
let r = []
|
|
41
|
+
if (numBlocks) {
|
|
42
|
+
while (numBlocks--) {
|
|
43
|
+
let f = document.createDocumentFragment()
|
|
44
|
+
let n = blockSize
|
|
45
|
+
while (n--) {
|
|
46
|
+
f.appendChild(nextNonWhitespaceSibling(template))
|
|
47
|
+
}
|
|
48
|
+
r.push(f)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return r
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const getBlocks = (template) => {
|
|
55
|
+
let numBlocks = template.getAttribute("length")
|
|
56
|
+
let blockSize = getBlockSize(template)
|
|
57
|
+
let r = []
|
|
58
|
+
let node = template
|
|
59
|
+
if (numBlocks) {
|
|
60
|
+
while (numBlocks--) {
|
|
61
|
+
let f = []
|
|
62
|
+
let n = blockSize
|
|
63
|
+
while (n--) {
|
|
64
|
+
node = nextNonWhitespaceSibling(node)
|
|
65
|
+
f.push(node)
|
|
66
|
+
}
|
|
67
|
+
r.push(f)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return r
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const compareKeyedLists = (key, a = [], b = []) => {
|
|
74
|
+
let delta = b.map(([k, item]) =>
|
|
75
|
+
!key ? (k in a ? k : -1) : a.findIndex(([_, v]) => v[key] === item[key])
|
|
76
|
+
)
|
|
77
|
+
if (a.length !== b.length || !delta.every((a, b) => a === b)) return delta
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function lastChild(v) {
|
|
81
|
+
return (v.nodeType === v.DOCUMENT_FRAGMENT_NODE && v.lastChild) || v
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const updateList = (template, delta, entries, createListItem) => {
|
|
85
|
+
let n = template.getAttribute("length") || 0
|
|
86
|
+
let blocks = getBlockFragments(template, n)
|
|
87
|
+
let t = template
|
|
88
|
+
|
|
89
|
+
delta.forEach((i, newIndex) => {
|
|
90
|
+
let frag =
|
|
91
|
+
i === -1
|
|
92
|
+
? createListItem(entries[newIndex][1], entries[newIndex][0])
|
|
93
|
+
: blocks[i]
|
|
94
|
+
let x = lastChild(frag)
|
|
95
|
+
t.after(frag)
|
|
96
|
+
t = x
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
template.setAttribute("length", delta.length)
|
|
100
|
+
}
|