From 7bd3dbcf54060f491efcf0a39e75ab21211d2dba Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 4 Apr 2021 00:21:16 +0000 Subject: [PATCH] fix: update socket to socket-lient and crud to crud client" --- dist/CoCreate-api.min.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 dist/CoCreate-api.min.js diff --git a/dist/CoCreate-api.min.js b/dist/CoCreate-api.min.js deleted file mode 100644 index e1acd27..0000000 --- a/dist/CoCreate-api.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CoCreate=t():(e.CoCreate=e.CoCreate||{},e.CoCreate.api=t())}(this,(function(){return(()=>{"use strict";var e={499:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;const n={attribute:"data-actions",actions:{},selectedStage:[],stageIndex:0,selectedElement:null,completedEventName:"completedEvent",__init:function(){this.actionButtonEvent()},actionButtonEvent:function(){const e=this;document.addEventListener("click",(function(t){let n=t.target;if(n.getAttribute("data-actions")||(n=t.target.closest("[data-actions]")),!n)return;t.preventDefault();let o=(n.getAttribute(e.attribute)||"").replace(/\s/g,"").split(",");0!=o.length&&(e.stageIndex=0,e.selectedStage=o,e.selectedElement=n,e.__runActionFunc())}))},init:function({action:e,callback:t,endEvent:n}){this.registerEvent(e,t,null,n)},registerEvent:function(e,t,n,o){if(this.actions[e])return;this.actions[e]={key:e,runFunc:t,instance:n||window,endEvent:o};for(let t in this.actions)if(t!=e&&this.actions[t].endEvent===o)return;const i=this;document.addEventListener(o,(function(e){i.__nextAction(o,e.detail)}))},__runActionFunc:function(e){if(this.stageIndex>=this.selectedStage.length)return void(this.stageIndex==this.selectedStage.length&&this.__runAtag(this.selectedElement));const t=this.selectedStage[this.stageIndex],n=this.actions[t];if(n)n.runFunc?n.runFunc.call(null,this.selectedElement,e):this.__nextAction(n.endEvent,{});else{"next"===this.__runSpecialAction(t,e)&&this.__moveNextAction()}},__nextAction:function(e,t){const n=this.selectedStage[this.stageIndex];n&&e===this.actions[n].endEvent&&this.__moveNextAction(t)},__runAtag:function(e){e.querySelector("a")},__runSpecialAction:function(e,t){let n=/(\w+)\{([a-zA-Z0-9_ \-#$.]+)\}/gm.exec(e);if(!n||n.length<3)return"next";let o=n[1],i=n[2].trim();if(!i)return"next";const s=this;switch(o){case"event":document.addEventListener(i,(e=>{s.__moveNextAction(e)}),{once:!0});break;case"timeout":parseInt(i)>0&&setTimeout((function(){s.__moveNextAction(t)}),parseInt(i));break;case"action":let e=document.querySelector(i);e&&e.click();break;default:return"next"}},__moveNextAction:function(e){this.stageIndex++,this.__runActionFunc(e)}};n.__init();var o=n;t.default=o},556:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n={__getValueFromObject:function(e,t){try{if(void 0===e||!t)return!1;let n=e,o=t.split(".");for(let e=0;e=0;n--)i={[o[n]]:i};return i}catch(e){return!1}},__replaceValue:function(e,t){let n=!1,o=this,i=null,s=t.match(/{{([A-Za-z0-9_.,\- ]*)}}/g);return s&&(s.forEach((i=>{let s=o.__getValue(e,i);s&&"object"!=typeof s&&(n=!0,t=t.replace(i,s))})),n&&(i=t)),i},setArray:function(e,t){const n=e.getAttribute("data-render_array")||"data",o=e.getAttribute("data-render_key")||n,i=this,s=this.__getValueFromObject(t,n);n&&Array.isArray(s)&&s.forEach(((t,s)=>{let r=e.cloneNode(!0);r.classList.remove("template"),r.classList.add("clone_"+n),"object"!=typeof t?t={"--":t}:t.index=s;let a=i.__createObject(t,o);i.setValue([r],a),e.insertAdjacentHTML("beforebegin",r.outerHTML)}))},setValue:function(e,t,n,o){if(!t)return;const i=this;Array.from(e).forEach((e=>{let o=e.getAttribute("data-pass_id");if(!n||o==n){if(Array.from(e.attributes).forEach((n=>{let o=n.name.toLowerCase(),s=n.value;if(s=i.__replaceValue(t,s),s){if("value"==o){switch(e.tagName.toLowerCase()){case"input":e.setAttribute(o,s);break;case"textarea":e.setAttribute(o,s),e.textContent=s;break;default:0===e.children.length&&(e.innerHTML=s)}}e.setAttribute(o,s)}})),0==e.children.length&&e.textContent){let n=e.textContent;n=i.__replaceValue(t,n),n&&(e.textContent=n)}e.children.length>0&&(i.setValue(e.children,t),e.classList.contains("template")&&i.setArray(e,t))}}))},data:function({selector:e,data:t,elements:n,passTo:o}){e?this.render(e,t):n&&this.setValue(n,t,o)},render:function(e,t){let n=document.querySelector(e);n&&(Array.isArray(t)?(n.setAttribute("data-render_array","test"),this.setValue([n],{test:t})):this.setValue(n.children,t))}};t.default=n},974:(e,t)=>{var n;"undefined"!=typeof self&&self,void 0===(n=function(){return function(e,t,n){class o{constructor(e="crud"){this.prefix=e||"crud",this.sockets=new Map,this.listeners=new Map,this.messageQueue=new Map,this.saveFileName="",this.globalScope=""}setGlobalScope(e){this.globalScope=`${this.prefix}/${e}`}getGlobalScope(){return this.globalScope}create(o){const{namespace:i,room:s}=o,r=this.getKey(i,s);let a,c=this;if(this.sockets.get(r))return void(a=this.sockets.get(r));let l=e.location.protocol;"about:"===e.location.protocol&&(l=e.parent.location.protocol);let u="http:"===l?"ws":"wss";const d=o.port?o.port:8088;let f=`${u}://${e.location.host}:${d}/${r}`;o.host&&(f=o.host.includes("://")?`${o.host}/${r}`:o.host.includes(":")?`${u}://${o.host}/${r}`:`${u}://${o.host}:${d}/${r}`);try{a=new t(f)}catch(e){}a.onopen=function(e){(c.messageQueue.get(r)||[]).forEach((e=>a.send(JSON.stringify(e)))),c.sockets.set(r,a),c.messageQueue.set(r,[])},a.onclose=function(e){switch(e.code){case 1e3:break;default:c.destroy(a,r),c.reconnect(a,o)}},a.onerror=function(e){c.destroy(a,r),c.reconnect(a,o)},a.onmessage=function(t){try{if(e.Blob&&t.data instanceof n)return void c.saveFile(t.data);let i=JSON.parse(t.data);if(i.data.event){if(e.CustomEvent){var o=new e.CustomEvent(i.data.event,{detail:i.data});return void e.document.dispatchEvent(o)}return void process.emit(i.data.event,i.data)}i.action;const s=c.listeners.get(i.action);if(!s)return;s.forEach((e=>{e(i.data,r)}))}catch(e){}}}send(e,t,n){const o={action:e,data:t},i=this.getKeyByRoom(n),s=this.getByRoom(n);s?s.send(JSON.stringify(o)):this.messageQueue.get(i)?this.messageQueue.get(i).push(o):this.messageQueue.set(i,[o])}sendFile(e,t){const n=this.getByRoom(t);n&&n.send(e)}listen(e,t){this.listeners.get(e)?this.listeners.get(e).push(t):this.listeners.set(e,[t])}reconnect(e,t){let n=this;setTimeout((function(){n.create(t)}),1e3)}destroy(e,t){e&&(e.onerror=e.onopen=e.onclose=null,e.close(),e=null),this.sockets.get(t)&&this.sockets.delete(t)}destroyByKey(e){let t=this.sockets.get(e);t&&this.destroy(t,e)}getKey(e,t){let n=`${this.prefix}`;return e&&""!=e&&(n+=t&&""!=t?`/${e}/${t}`:`/${e}`),n}getByRoom(e){let t=this.getKeyByRoom(e);return this.sockets.get(t)}getKeyByRoom(e){let t=this.globalScope;return e&&(t=`${this.prefix}/${e}`),t}saveFile(t){if(e.document){const o=this.saveFileName||"downloadFile";var n=e.document.createElement("a");e.document.body.appendChild(n),n.style="display: none";let i=window.URL.createObjectURL(t);n.href=i,n.download=o,n.click(),e.URL.revokeObjectURL(i),this.saveFileName=""}}listenAsync(t){return new Promise(((n,o)=>{e.document?e.document.addEventListener(t,(function(e){n(e.detail)}),{once:!0}):process.once(t,(e=>{n(e)}))}))}}return o}(window,WebSocket,Blob)}.apply(t,[]))||(e.exports=n)}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var s=t[o]={exports:{}};return e[o](s,s.exports,n),s.exports}var o={};return(()=>{var e=o;e.default=void 0;var t=r(n(974)),i=r(n(499)),s=r(n(556));function r(e){return e&&e.__esModule?e:{default:e}}let a=new t.default("api");const c={modules:{},init:function({name:e,module:t}){this.register(e,t)},register:function(e,t){const n=this;void 0===this.modules[e]&&(this.modules[e]=t,a.listen(e,(t=>{n.__responseProcess(e,t)})),Array.isArray(t.actions)&&t.actions.forEach((e=>{"function"!=typeof t[`action_${e}`]&&(t[`action_${e}`]=function(o){n.__commonAction(t.id,e,o)}),i.default.init({action:e,endEvent:e,callback:n=>{t[`action_${e}`](n)}})})))},__responseProcess:function(e,t){const{type:n,response:o}=t,i=this.modules[e];n&&o&&i&&("function"==typeof i[`render_${n}`]&&i[`render_${n}`](o),this.render(n,o),document.dispatchEvent(new CustomEvent(n,{detail:{data:o}})))},__commonAction:function(e,t,n){const o=n.closest("form")||document;let i=c.getFormData(e,t,o);c.send(e,t,i)},getFormData:function(e,t,n){const o=`data-${e}`,i=this,s=n.querySelectorAll(`[${o}^="${t}."]`);let r={};s.forEach((n=>{let s=n.getAttribute(o),a=n.getAttribute(o+"_array"),c=i.__getElValue(n);if(s){if(t){let e=new RegExp(`^${t}.`,"i");if(!e.test(s))return;s=s.replace(e,"")}a?(r[s]||(r[s]=[]),r[s].push(i.getFormData(e,a,n))):null!=c&&(r[s]=c)}}));let a=Object.keys(r),c={};return a.forEach((e=>{if(e.split(".").length>1){let t=i.__createObject(r[e],e);delete r[e],c=i.__mergeObject(c,t)}else c[e]=r[e]})),c},__getElValue:function(e){let t=null;if(void 0!==e.value)switch(e.type.toLocaleLowerCase()){case"checkbox":e.checked&&(t=e.value);break;default:t=e.value}else t=e.getAttribute("value"),t||(t=e.innerHTML);return t},__mergeObject:function(e,t){e=e||{};for(let n of Object.keys(t))t[n]instanceof Object&&Object.assign(t[n],this.__mergeObject(e[n],t[n]));return Object.assign(e||{},t),e},__createObject:function(e,t){if(!t)return e;let n=t.split("."),o=e;for(var i=n.length-1;i>=0;i--)o={[n[i]]:o};return o},send:function(e,t,n){let o=this.getCommonParamsExtend(n||{});o={...o,data:n},a.send(e,{type:t,data:o})},render:function(e,t){s.default.data({selector:`[data-template_id="${e}"]`,data:t})},createApiSocket:function(e,t){t?(a.create({namespace:t,room:null,host:e}),a.setGlobalScope(t)):a.create({namespace:null,room:null,host:e})},getCommonParamsExtend:function(e){return{apiKey:e.apiKey||config.apiKey,securityKey:e.securityKey||config.securityKey,organization_id:e.organization_id||config.organization_Id}}};c.createApiSocket(window.config.host?window.config.host:"server.cocreate.app",window.config.organization_Id);var l=c;e.default=l})(),o=o.default})()})); \ No newline at end of file