OSDN Git Service

Update app/devtools and add it to app drawer [0.2.1]
[kit/kit.git] / system.js
index d80372f..1711208 100644 (file)
--- a/system.js
+++ b/system.js
@@ -510,6 +510,7 @@ async function launch( str, args, dir ) {
         }
         catch(error){
             Notification.push( "System Error", error, "system" );
+            System.launchLock = false;
         }
     }
 }
@@ -740,20 +741,15 @@ const System = new function() {
     this.noop = () => {}
 
     this.launchLock = false;
-    
-    this.waitLaunchUnlock = (callback) => {
-        setTimeout(()=>{
-            if(this.ajaxLock){
-                this.waitLaunchUnlock(callback);
-            }else{
-                return callback();
-            }
-        }, 100)
-    }
 
     this.ajaxWait = () =>{
         return new Promise(resolve =>{
-             System.waitLaunchUnlock(resolve);
+            let interval = setInterval(()=>{
+                if(this.launchLock === false) {
+                    clearInterval(interval);
+                    resolve();
+                }
+            }, 100)
         });
     }
 
@@ -1051,10 +1047,12 @@ const System = new function() {
             try{
                 $.getJSON( _path + '/define.json', appData ).fail( () => {
                     Notification.push('kitアプリをロードできません。', `${_path}を展開できませんでした。`, 'system');
+                    System.launchLock = false;
                 } );
             }
             catch(error){
                 Notification.push( "System Error", error, "system" );
+                System.launchLock = false;
             }
         }
     }
@@ -1444,12 +1442,22 @@ class App {
         if( _value !== undefined ) {
             S.dom(_pid, `[kit\\:bind=${_name}]`).val( _value );
             S.dom(_pid, `[kit\\:observe=${_name}]`).text( _value );
+            S.dom(_pid, `template[kit\\:for=${_name}] + kit-for`).text('');
+            if (typeof _value == 'object'){
+                for(let elem of S.qs(_pid, `template[kit\\:for=${_name}] + kit-for`)){
+                    let _rep = App.d[_pid][`__kaf_node_id_${elem.getAttribute('kaf-node-id')}`], _result = '';
+                    for(let i in _value) {
+                        _result += _rep.replace(/{{\s*key\s*}}/g, i).replace(/{{\s*value\s*}}/g, _value[i]);
+                    }
+                    elem.innerHTML = _result;
+                }
+            }
             if( _value ) S.dom(_pid, `[kit\\:if=${_name}]`).show();
             else S.dom(_pid, `[kit\\:if=${_name}]`).hide();
             return App.d[_pid][_name] = _value;
         }
         else if( _name ) return App.d[_pid][_name];
-        else return App.d[_pid];
+        else return Object.fromEntries( Object.entries(App.d[_pid] || {}).filter(d => d[0].indexOf("__") != 0) );
     }
 
     static event( _pid, _name, _event ) {
@@ -1480,11 +1488,13 @@ class App {
             "[kit-value]",
             "[kit-color]",
             "[kit\\:if]",
-            "[kit-if]"
+            "[kit-if]",
+            "[kit\\:for]"
         ]
         const PID = _pid;
         const DATA = App.data(_pid);
         const ARGS = System.args[_pid];
+        let _kaf_node_id = 0;
         for( let i of S.qs(_pid, ...attrs) ){
             if( i.hasAttribute("kit-ref") ){
                 $(i).on("click", () => App.load(_pid, i.getAttribute("kit-ref")) );
@@ -1548,6 +1558,15 @@ class App {
                 }
                 else $(i).hide();
             }
+            if( i.hasAttribute("kit:for") ){
+                if ('content' in document.createElement('template')) {
+                    i.setAttribute('kaf-node-id', _kaf_node_id);
+                    App.d[_pid][`__kaf_node_id_${_kaf_node_id}`] = i.innerHTML;
+                    i.insertAdjacentHTML('afterend', `<kit-for kaf-node-id="${_kaf_node_id}"></kit-for>`);
+                }
+                else i.style.display = 'none';
+            }
+            _kaf_node_id ++;
         }
     }