@cocreate/cursors
Advanced tools
Comparing version 1.1.9 to 1.1.10
@@ -0,1 +1,8 @@ | ||
## [1.1.10](https://github.com/CoCreate-app/CoCreate-cursors/compare/v1.1.9...v1.1.10) (2021-06-16) | ||
### Bug Fixes | ||
* added header for seo ([3530af4](https://github.com/CoCreate-app/CoCreate-cursors/commit/3530af46b0ca6f89f5a10f0978794e7a84bbf682)) | ||
## [1.1.9](https://github.com/CoCreate-app/CoCreate-cursors/compare/v1.1.8...v1.1.9) (2021-06-06) | ||
@@ -2,0 +9,0 @@ |
@@ -1,1 +0,1 @@ | ||
!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.cursors=t())}(this,(function(){return(()=>{var e={375:function(e,t,r){var n,o;"undefined"!=typeof self&&self,n=[r(446),r(965)],void 0===(o=function(e,t){return function(e,t,r){return{socket:null,setSocket:function(e){this.socket=e},readDocumentList(e){if(!e)return!1;let r=t.getCommonParams();return!!e.collection&&(r={...r,...e},this.socket.send("readDocumentList",r),!0)},createDocument:function(r){if(null===r)return!1;let n=t.getCommonParamsExtend(r),o={...r,...n},i=r.data||{};i.organization_id||(i.organization_id=e.config.organization_Id),r.data&&(i={...i,...r.data}),o.data=i;const a=t.generateSocketClient(r.namespace,r.room);return this.socket.send("createDocument",o,a),!0},updateDocument:function(e){if(!e||!r.checkDocumentId(e.document_id))return!1;let n=t.getCommonParamsExtend(e),o={...e,...n};if("object"==typeof e.data&&(o.set=e.data),Array.isArray(e.delete_fields)&&(o.unset=e.delete_fields),!o.set&&!o.unset)return!1;!1===e.broadcast&&(o.broadcast=!1),void 0===e.broadcast_sender&&(o.broadcast_sender=!0);const i=t.generateSocketClient(e.namespace,e.room);return this.socket.send("updateDocument",o,i),!0},readDocument:function(e){if(null===e)return!1;if(!e||!r.checkDocumentId(e.document_id))return!1;let n=t.getCommonParamsExtend(e),o={...e,...n};return this.socket.send("readDocument",o),!0},deleteDocument:function(e){if(!e||!r.checkDocumentId(e.document_id))return!1;let n=t.getCommonParamsExtend(e),o={...e,...n};const i=t.generateSocketClient(e.namespace,e.room);return this.socket.send("deleteDocument",o,i),!0},exportCollection:function(e){if(null===e)return;let r=t.getCommonParamsExtend(e);r.collection=e.collection,r.export_type=e.export_type,r.metadata=e.metadata,this.socket.send("exportDB",r)},importCollection:function(r){const{file:n}=r;if(null===r||!(n instanceof e.File))return;const o=n.name.split(".").pop();if(!["json","csv"].some((e=>e===o)))return;let i=t.getCommonParamsExtend(r);i.collection=r.collection,i.import_type=o,this.socket.send("importDB",i),this.socket.sendFile(n)},listen:function(e,t){this.socket.listen(e,t)},listenAsync:function(e){return this.socket.listenAsync(e)},createSocket:function(e,t){t?(this.socket.create({namespace:t,room:null,host:e}),this.socket.setGlobalScope(t)):this.socket.create({namespace:null,room:null,host:e})},...r}}(window,e,t)}.apply(t,n))||(e.exports=o)},611:function(e,t,r){var n,o;"undefined"!=typeof self&&self,n=[r(585),r(375)],void 0===(o=function(e,t){return function(e,t,r){if(e){let e=window.CoCreateCrudSocket;e||(e=new t("ws"),window.CoCreateCrudSocket=e),r.setSocket(e),r.createSocket(window.config.host?window.config.host:window.location.hostname,window.config.organization_Id)}return r}(!0,e,t)}.apply(t,n))||(e.exports=o)},965:function(e,t){var r;"undefined"!=typeof self&&self,void 0===(r=function(){return function(){function e(t,r){t=t||{};for(let n of Object.keys(r))r[n]instanceof Object&&Object.assign(r[n],e(t[n],r[n]));return Object.assign(t||{},r),t}function t(e,t){if(!t)return e;let r=t.split("."),n=e;for(var o=r.length-1;o>=0;o--)n={[r[o]]:n};return n}function r(e,t){try{let r=/([\w\W]+)\[(\d+)\]/gm.exec(e);if(r&&3==r.length){let n=r[1],o=parseInt(r[2]);t[n]&&Array.isArray(t[n])||(t[n]=[]),t[n][o]=t[e],delete t[e],e=n}}catch{}return e}function n(e){return!!e&&e.constructor===Object}function o(e){return!!e&&e.constructor===Array}function i(n){let o=Object.keys(n),i={};return o.forEach((o=>{if((o=r(o,n)).split(".").length>1){let r=t(n[o],o);delete n[o],i=e(i,r)}else i[o]=n[o]})),i}function a(e){let t=Object.keys(e),r={};return t.forEach((t=>{let i=e[t];if(n(e[t])){let n=a(e[t]);Object.keys(n).forEach((e=>{let o=n[e];r[e=t+"."+e]=o}))}else o(i)?i.forEach(((e,n)=>{r[`${t}[${n}]`]=e})):r[t]=e[t]})),r}function s(e){if(e)return{collection:e.getAttribute("data-collection"),document_id:e.getAttribute("data-document_id"),name:e.getAttribute("name")}}function c(e){return e?{is_realtime:f(e),is_save:d(e),is_read:l(e),is_update:u(e)}:{}}const l=e=>m(e,"data-read_value"),d=e=>m(e,"data-save_value"),u=e=>m(e,"data-update_value"),f=e=>!!e&&"false"!=e.getAttribute("data-realtime");function m(e,t){return!!e&&"false"!==e.getAttribute(t)}function p(e){return!!e&&!/{{\s*([\w\W]+)\s*}}/g.test(e)}function h(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!=t}catch(e){return!1}}function g(e){const{collection:t,document_id:r,name:n}=s(e);return!(h(t)||h(n)||!("INPUT"===e.tagName&&["text","email","tel","url"].includes(e.type)||"TEXTAREA"===e.tagName)||!n||!f(e)||"true"===e.getAttribute("data-unique")||"password"===e.type||!l(e))}function y(e){try{return!!e&&"null"!==e.toLowerCase()}catch(e){return!1}}return{decodeObject:i,encodeObject:a,getAttr:s,getFlagAttr:c,isRealtimeAttr:f,isReadAttr:l,isSaveAttr:d,isUpdateAttr:u,checkValue:p,isCRDT:g,checkDocumentId:y}}()}.apply(t,[]))||(e.exports=r)},366:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>o}),window.profiler={},window.counter=0,window.counter2=0,window.targets={},window.attributeName={},Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),r=t.length;--r>=0&&t.item(r)!==this;);return r>-1});const n={initTasks:new Map,attrTasks:new Map,rules:new Map,rulesArray:[],__init:function(){const e=this;new MutationObserver(((t,r)=>e.__callback(t,r))).observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!1,attributeOldValue:!0,characterData:!0})},init:function({observe:e,include:t,exclude:r,attributes:n,name:o,callback:i}){e.some((e=>"childList"==e))&&this.initTasks.set(i,{observe:e,include:t,exclude:r,attributes:n,name:o}),e.some((e=>"attributes"==e))&&this.attrTasks.set(i,{observe:e,include:t,exclude:r,attributes:n,name:o})},remove:function(e){this.initTasks.delete(e),this.attrTasks.delete(e)},addRule:function({include:e,exclude:t,name:r}){this.rules.set(r,{include:e,exclude:t}),this.rulesArray=Array.from(this.rules)},removeRule:function({name:e}){this.rules.delete(e),this.rulesArray=Array.from(this.rules)},__callback:function(e,t){window.counter++;for(let t of e)"childList"==t.type&&t.addedNodes.length>0&&this.__initCallback(t),"attributes"==t.type&&this.__attrCallback(t)},__initCallback:function(e){Array.from(e.addedNodes);this.initTasks.forEach((({observe:t,include:r,exclude:n,attributes:o,name:i},a)=>{e.addedNodes.forEach((t=>{t.tagName&&(!r||t.matches(r)||t.querySelector(r))&&(n&&(t.matches(n)||t.querySelector(n))||a.apply(null,[{type:e.type,target:t}]))}))}))},__attrCallback:function(e){for(let[t,{include:r,exclude:n}]of this.rulesArray){if(r&&!e.target.matches(r))return;if(n&&e.target.matches(n))return}this.attrTasks.forEach((({observe:t,include:r,exclude:n,attributes:o,name:i},a)=>{if((!o||!e.attributeName||o.includes(e.attributeName))&&(!r||e.target.matches(r))&&(!n||!e.target.matches(n))&&e.attributeName){e.target.getAttribute(e.attributeName)!=e.oldValue&&a.apply(null,[e])}}))},setInitialized:function(e,t){e["co_initialized_"+(t=t||"")]=!0},getInitialized:function(e,t){return!!e["co_initialized_"+(t=t||"")]}};n.__init();const o=n},446:function(e,t){var r;"undefined"!=typeof self&&self,void 0===(r=function(){return function(e){function t(){let t={};return e&&e.config&&(t=e.config),{apiKey:t.apiKey,organization_id:t.organization_Id}}function r(t){let r={};return e&&e.config&&(r=e.config),{apiKey:t.apiKey||r.apiKey,organization_id:t.organization_id||r.organization_Id}}function n(t,r){let n={};e&&e.config&&(n=e.config);let o=t||n.organization_Id,i=r||"";return i?`${o}/${i}`:o}function o(e=36){let t=(new Date).getTime(),r=0,n="uxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";if(e<=n.length)n=n.substr(0,e);else{let t=e-n.length,r="-xxxyyxxx",o=Math.floor(t/r.length);for(let e=0;e<o;e++)n+=r;o=t-o*r.length,n+=r.substr(0,o)}return n.replace(/[xy]/g,(function(e){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(r+n)%16|0,r=Math.floor(r/16)),("x"==e?n:7&n|8).toString(16)}))}return{getCommonParams:t,getCommonParamsExtend:r,generateSocketClient:n,GenerateUUID:o}}(window)}.apply(t,[]))||(e.exports=r)},585:function(e,t,r){var n,o;"undefined"!=typeof self&&self,n=[r(446)],void 0===(o=function(e){return function(e,t,r,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(e){const{namespace:o,room:i}=e,a=this.getKey(o,i);let s,c=this;if(o&&this.setGlobalScope(o),this.sockets.get(a))return void(s=this.sockets.get(a));let l=t.location.protocol;"about:"===t.location.protocol&&(l=t.parent.location.protocol,e.host||(e.host=t.parent.location.host));let d="http:"===l?"ws":"wss";const u=e.port?e.port:8088;let f=`${d}://${t.location.host}:${u}/${a}`;e.host&&(f=e.host.includes("://")?`${e.host}/${a}`:e.host.includes(":")?`${d}://${e.host}/${a}`:`${d}://${e.host}:${u}/${a}`);try{let e=null;t.localStorage&&(e=t.localStorage.getItem("token")),s=new r(f,e)}catch(e){return}s.onopen=function(e){(c.messageQueue.get(a)||[]).forEach((e=>s.send(JSON.stringify(e)))),c.sockets.set(a,s),c.messageQueue.set(a,[])},s.onclose=function(t){switch(t.code){case 1e3:break;default:c.destroy(s,a),c.reconnect(s,e)}},s.onerror=function(t){c.destroy(s,a),c.reconnect(s,e)},s.onmessage=function(e){try{if(t.Blob&&e.data instanceof n)return void c.saveFile(e.data);let o=JSON.parse(e.data);if(o.data&&o.data.event){if(t.CustomEvent){var r=new t.CustomEvent(o.data.event,{detail:o.data});return void t.document.dispatchEvent(r)}return void process.emit(o.data.event,o.data)}o.action;const i=c.listeners.get(o.action);if(!i)return;i.forEach((e=>{e(o.data,a)}))}catch(e){}}}send(t,r,n){const o={action:t,data:{...r,uid:e.GenerateUUID()}},i=this.getKeyByRoom(n),a=this.getByRoom(n);a?a.send(JSON.stringify(o)):this.messageQueue.get(i)?this.messageQueue.get(i).push(o):this.messageQueue.set(i,[o])}sendFile(e,t){const r=this.getByRoom(t);r&&r.send(e)}listen(e,t){this.listeners.get(e)?this.listeners.get(e).push(t):this.listeners.set(e,[t])}reconnect(e,t){let r=this;setTimeout((function(){r.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 r=`${this.prefix}`;return e&&""!=e&&(r+=t&&""!=t?`/${e}/${t}`:`/${e}`),r}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(e){if(t.document){const n=this.saveFileName||"downloadFile";var r=t.document.createElement("a");t.document.body.appendChild(r),r.style="display: none";let o=window.URL.createObjectURL(e);r.href=o,r.download=n,r.click(),t.URL.revokeObjectURL(o),this.saveFileName=""}}listenAsync(e){return new Promise(((r,n)=>{t.document?t.document.addEventListener(e,(function(e){r(e.detail)}),{once:!0}):process.once(e,(e=>{r(e)}))}))}}return o}(e,window,WebSocket,Blob)}.apply(t,n))||(e.exports=o)},605:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var n=r(483),o=r.n(n);const i=r.p+"4bae7f440ab1de156d0d0d0d0a566858.css";var a={injectType:"linkTag",insert:"head"};o()(i,a);const s={}},483:(e,t,r)=>{"use strict";var n,o=(n={},function(e){if(void 0===n[e]){var t=document.querySelector(e);if(window.HTMLIFrameElement&&t instanceof window.HTMLIFrameElement)try{t=t.contentDocument.head}catch(e){t=null}n[e]=t}return n[e]});e.exports=function(e,t){if((t=t||{}).attributes="object"==typeof t.attributes?t.attributes:{},void 0===t.attributes.nonce){var n=r.nc;n&&(t.attributes.nonce=n)}var i=document.createElement("link");if(i.rel="stylesheet",i.href=e,Object.keys(t.attributes).forEach((function(e){i.setAttribute(e,t.attributes[e])})),"function"==typeof t.insert)t.insert(i);else{var a=o(t.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(i)}return function(e){"string"==typeof e?i.href=e:i.parentNode.removeChild(i)}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.g.importScripts&&(e=r.g.location+"");var t=r.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})();var n={};return(()=>{"use strict";var e=n;e.default=void 0;var t=i(r(366)),o=i(r(611));function i(e){return e&&e.__esModule?e:{default:e}}r(605);var a=document.querySelectorAll("input,textarea,[contenteditable]"),s=!1,c=["boxSizing","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","marginTop","marginRight","marginBottom","marginLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","textRendering","webkitWritingMode","textTransform","textIndent","overflowWrap"];class l{static print(e,t){t=t||!1}static generateUUID(e=null){var t=(new Date).getTime(),r=performance&&performance.now&&1e3*performance.now()||0,n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=16*Math.random();if(t>0){n=(t+n)%16|0;t=Math.floor(t/16)}else{n=(r+n)%16|0;r=Math.floor(r/16)}return("x"==e?n:7&n|8).toString(16)}));return null!=e&&(n=n.substr(0,e)),n}}var d,u,f,m=function(e,t,r){e.getAttribute("name");if(""==(e.getAttribute("data-document_id")||""))return!1;var n=e.dataset.mirror_id;d=document.getElementById(n);e.className.indexOf("floating-label");d||((d=document.createElement("div")).id=n,d.className="mirror_color mirror_scroll mirror-width-scroll",e.insertAdjacentElement("afterend",d));e.offsetWidth,e.scrollWidth;f=d.style,u=getComputedStyle(e),getComputedStyle(e.parentElement);parseInt(u.marginTop),parseInt(u.marginLeft);"INPUT"!==e.nodeName?(f.wordWrap="break-word",f.whiteSpace="pre-wrap"):f.whiteSpace="pre",f.position="absolute";var o=e.getBoundingClientRect();document.documentElement.scrollTop;f.top=e.offsetTop+"px",f.left=e.offsetLeft+"px",f.width=o.width+"px",f.height=o.height+"px",f.visibility="visible",c.forEach((function(e){-1===["left","top"].indexOf(e.toLowerCase())&&(f[e]=u[e])})),f.overflowX="auto",f.overflowY="hidden",f.margin="0px",f.border=u.border,f.borderColor="transparent";let i=d.querySelectorAll(".cursor-container"),a=d.querySelectorAll(".selectors_by_users"),s=-1==["TEXTAREA","INPUT"].indexOf(e.nodeName)?e.innerHTML:e.value;d.textContent=s.substring(0,t),"INPUT"===e.nodeName&&(d.textContent=d.textContent.replace(/\s/g," "));var l=document.createElement("span");l.id=e.nodeName+"span_selections";let m=s.substring(t,r)||"";l.textContent=m,d.appendChild(l),i&&i.forEach((function(e,t,r){d.appendChild(e)})),a&&a.forEach((function(e,t,r){d.appendChild(e)}));let p=s.substring(r)||"";var h=document.createElement("span");d.appendChild(h),h.textContent=p;o=e.getBoundingClientRect();return{start:{top:l.offsetTop,left:l.offsetLeft},end:{top:h.offsetTop,left:h.offsetLeft}}};function p(e){l.print(["draw Cursor ",e],s);let t=e.element;if(!t.dataset.cursors||t.dataset.mirror_id){let i=e.startPosition,a=e.endPositon,c=e.clientId,d=t.getAttribute("data-document_id")||"";if(""!=d){l.print("action document_id "+d,s),void 0!==t.dataset.mirror_id&&""!=t.dataset.mirror_id||(t.dataset.mirror_id=l.generateUUID(30));let u=m(t,i,a);if(!u)return!1;t.getAttribute("name");let f=t.dataset.mirror_id,p=document.getElementById(f),h=!1,g=!1,y="_"+f,b=!(void 0===e||!e.hasOwnProperty("user"))&&e.user,x=!(void 0===e||!e.hasOwnProperty("user_id"))&&b.user_id;if(c){if(document.querySelectorAll("#socket_"+c+y).forEach((function(e,t,r){e.parentElement.getAttribute("id")!=f&&(l.print("remove old cursor others elements",s),e.remove())})),h=p.querySelector(".cursor-container#socket_"+c+y),!h&&e.hasOwnProperty("user")){if(b){l.print("Create Cursor",s);let e='<div style="color:blue;" class="cursor-container" id="socket_'+c+y+'" ><div class="cursor" style="background-color:'+b.color+'"></div> <div class="cursor-flag" data-collection="users" name="name" data-user_name="'+b.name+'" data-user_color="'+b.color+'" data-socket_id="'+c+'" data-id_mirror="'+f+'" data-document_id="'+x+'" style="background-color:'+b.color+'" flag>'+b.name+"</div></div>";p.innerHTML=e+p.innerHTML}x&&o.default.readDocument({collection:"users",document_id:x})}h=p.querySelector(".cursor-container#socket_"+c+y)}if(h){l.print(["Update Cursor",h,u],s);let e=function(e,t){if(window.getComputedStyle)var r=document.defaultView.getComputedStyle(e,null).getPropertyValue(t);return r}(t,"font-size");e=parseFloat(e.substring(0,e.length-2));let o=112.5*e/100,d=h.querySelector(".cursor");if(h.dataset.start=i,h.dataset.end=a,h.dataset.socket_id=c,h.style.top=u.end.top+"px",h.style.width="2px",d.style.height=o+"px",h.style.left=u.end.left+"px",g=document.getElementById("sel-"+c+y),i!=a&&b){g=document.getElementById("sel-"+c+y),g&&g.remove();var r=t.offsetWidth-t.scrollWidth,n=parseInt(getComputedStyle(t).paddingRight);g=document.createElement("span"),g.id="sel-"+c+y,g.className="selectors_by_users";let e=getComputedStyle(p);g.style.position="absolute",g.style.top=e.paddingTop,g.style.left=e.paddingLeft,g.style["padding-right"]=r+n+"px",p.insertBefore(g,p.firstChild);let o=document.createElement("span");o.id="selection-"+c+y,o.style.backgroundColor=b.color;let s=-1==["TEXTAREA","INPUT"].indexOf(t.nodeName)?t.innerHTML:t.value;g.textContent=s.substring(0,i);let l=s.substring(i,a)||"";o.textContent=l,g.appendChild(o)}else g&&g.remove()}}}}function h(e){var t="";let r=e.getAttribute("data-document_id")||"";if(""!=r){if(name=e.getAttribute("name"),!e.dataset.mirror_id)return;t=e.dataset.mirror_id;var n=document.getElementById(t);l.print(["refresh_mirror ",n],s);var o=e.nodeName+"[name='"+name+"'][data-document_id='"+r+"']";if(l.print(["selector -> "+o],s),n)u=getComputedStyle(e),(f=n.style).width=e.offsetWidth-(parseInt(u.borderLeftWidth)+parseInt(u.borderRightWidth))+"px",f.height=e.offsetHeight-(parseInt(u.borderTopWidth)+parseInt(u.borderBottomWidth))+"px",n.querySelectorAll(".cursor-container").forEach((function(t,r,n){let o=t.querySelector(".cursor-flag").dataset,i=t.dataset;p({element:e,startPosition:i.start,endPositon:i.end,clientId:i.socket_id,user:{color:o.user_color,name:i.user_name}})}))}}function g(e){let t,r=e.hasAttribute("data-realtime")?e.getAttribute("data-realtime"):"true";if("true"==r||t&&"true"==t.getAttribute("data-realtime")){if("false"==r)return!1;l.print(["Init Events ",e],s),e.addEventListener("scroll",(function(){l.print(["Move Scroll ",e],!0);e.getAttribute("name"),e.getAttribute("data-document_id");let t=e.dataset.mirror_id,r=document.getElementById(t);r&&r.scrollTo(e.scrollLeft,e.scrollTop)}),!1),new ResizeObserver((function(){a.forEach((function(t,r,n){t.getAttribute("name");let o=e.dataset.mirror_id;l.print(["Resize id_mirror -> "+o],s);let i=document.getElementById(o);i&&(i.style.width=t.offsetWidth+"px",i.style.height=t.offsetHeight+"px",document.activeElement===e&&m(e,e.selectionStart,e.selectionEnd),h(e))}))})).observe(e),e.addEventListener("mousemove",(function(t){e.getAttribute("name"),e.getAttribute("data-document_id");let r=e.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(e.scrollLeft,e.scrollTop)})),e.addEventListener("focusout",(function(t){e.getAttribute("name"),e.getAttribute("data-document_id");let r=e.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(e.scrollLeft,e.scrollTop)})),e.addEventListener("keydown",(function(t){e.getAttribute("name");let r=e.dataset.mirror_id,n=document.getElementById(r);n&&(n.scrollTo(e.scrollLeft,e.scrollTop),h(e))})),e.addEventListener("keyup",(function(t){e.getAttribute("name");let r=e.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(e.scrollLeft,e.scrollTop)}))}}o.default.listen("readDocument",(function(e){let t=document.querySelector('.cursor-flag[data-document_id="'+e.document_id+'"]');t&&(t.innerHTML=e.result[t.getAttribute("name")])})),Element.prototype.remove=function(){this.parentElement&&this.parentElement.removeChild(this)};window.addEventListener("resize",(function(e){document.querySelectorAll("[data-mirror_id]").forEach((function(e,t,r){h(e)}))}),!0),document.addEventListener("scroll",(function(e){document.querySelectorAll("[data-mirror_id]").forEach((function(e,t,r){h(e)}))}),!0),function(e){e.forEach((function(e,t,r){g(e)}))}(a),t.default.init({name:"CoCreateCursor",observe:["subtree","childList"],include:"[data-collection][data-document_id][name][data-realtime=true]",callback:function(e){!function(e){let t=e||window;t.querySelectorAll&&t.querySelectorAll("[data-realtime=true]").forEach((e=>{g(e)}))}(e.target)}});var y={draw_cursor:p,refresh_mirror:h,recalculate_local_cursors:function(e,t){l.print("count "+t,s);let r=e.hasAttribute("contenteditable")?parseInt(e.getAttribute("selection_start")):e.selectionStart,n=(e.getAttribute("name"),e.getAttribute("data-document_id"),e.getAttribute("data-collection"),e.dataset.mirror_id),o=document.getElementById(n),i=o?o.querySelectorAll(".cursor-container"):null;if(i){let n=[];i.forEach((function(o,i,a){let c=parseInt(o.getAttribute("data-start")),d=o.getAttribute("data-user_name");if(l.print(["my_start local",r,"start cursor "+d+" = ",c],s),c>r&&-1==n.indexOf(d)){l.print("Es mayor",s);let r=parseInt(o.getAttribute("data-end")),i=c+t,a=r+t;l.print(["pos_start",i,"pos_end",a],s);let u=o.querySelector(".cursor-flag").dataset,f=u.socket_id,m={element:e,startPosition:i,endPositon:a,clientId:f,user:{color:u.user_color,name:u.user_name}};l.print(["sent Draw Cursor ",m],s),p(m),n.push(d)}}))}}};e.default=y})(),n=n.default})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CoCreate=e():(t.CoCreate=t.CoCreate||{},t.CoCreate.cursors=e())}(this,(function(){return(()=>{var t={375:function(t,e,r){var n,o;"undefined"!=typeof self&&self,n=[r(446),r(965)],void 0===(o=function(t,e){return function(t,e,r){return{socket:null,setSocket:function(t){this.socket=t},readDocumentList(t){if(!t)return!1;let r=e.getCommonParams();return!!t.collection&&(r={...r,...t},this.socket.send("readDocumentList",r),!0)},createDocument:function(r){if(null===r)return!1;let n=e.getCommonParamsExtend(r),o={...r,...n},i=r.data||{};i.organization_id||(i.organization_id=t.config.organization_Id),r.data&&(i={...i,...r.data}),o.data=i;const a=e.generateSocketClient(r.namespace,r.room);return this.socket.send("createDocument",o,a),!0},updateDocument:function(t){if(!t||!r.checkDocumentId(t.document_id))return!1;let n=e.getCommonParamsExtend(t),o={...t,...n};if("object"==typeof t.data&&(o.set=t.data),Array.isArray(t.delete_fields)&&(o.unset=t.delete_fields),!o.set&&!o.unset)return!1;!1===t.broadcast&&(o.broadcast=!1),void 0===t.broadcast_sender&&(o.broadcast_sender=!0);const i=e.generateSocketClient(t.namespace,t.room);return this.socket.send("updateDocument",o,i),!0},readDocument:function(t){if(null===t)return!1;if(!t||!r.checkDocumentId(t.document_id))return!1;let n=e.getCommonParamsExtend(t),o={...t,...n};return this.socket.send("readDocument",o),!0},deleteDocument:function(t){if(!t||!r.checkDocumentId(t.document_id))return!1;let n=e.getCommonParamsExtend(t),o={...t,...n};const i=e.generateSocketClient(t.namespace,t.room);return this.socket.send("deleteDocument",o,i),!0},exportCollection:function(t){if(null===t)return;let r=e.getCommonParamsExtend(t);r.collection=t.collection,r.export_type=t.export_type,r.metadata=t.metadata,this.socket.send("exportDB",r)},importCollection:function(r){const{file:n}=r;if(null===r||!(n instanceof t.File))return;const o=n.name.split(".").pop();if(!["json","csv"].some((t=>t===o)))return;let i=e.getCommonParamsExtend(r);i.collection=r.collection,i.import_type=o,this.socket.send("importDB",i),this.socket.sendFile(n)},listen:function(t,e){this.socket.listen(t,e)},listenAsync:function(t){return this.socket.listenAsync(t)},createSocket:function(t,e){e?(this.socket.create({namespace:e,room:null,host:t}),this.socket.setGlobalScope(e)):this.socket.create({namespace:null,room:null,host:t})},...r}}(window,t,e)}.apply(e,n))||(t.exports=o)},611:function(t,e,r){var n,o;"undefined"!=typeof self&&self,n=[r(585),r(375)],void 0===(o=function(t,e){return function(t,e,r){if(t){let t=window.CoCreateCrudSocket;t||(t=new e("ws"),window.CoCreateCrudSocket=t),r.setSocket(t),r.createSocket(window.config.host?window.config.host:window.location.hostname,window.config.organization_Id)}return r}(!0,t,e)}.apply(e,n))||(t.exports=o)},965:function(t,e){var r;"undefined"!=typeof self&&self,void 0===(r=function(){return function(){function t(e,r){e=e||{};for(let n of Object.keys(r))r[n]instanceof Object&&Object.assign(r[n],t(e[n],r[n]));return Object.assign(e||{},r),e}function e(t,e){if(!e)return t;let r=e.split("."),n=t;for(var o=r.length-1;o>=0;o--)n={[r[o]]:n};return n}function r(t,e){try{let r=/([\w\W]+)\[(\d+)\]/gm.exec(t);if(r&&3==r.length){let n=r[1],o=parseInt(r[2]);e[n]&&Array.isArray(e[n])||(e[n]=[]),e[n][o]=e[t],delete e[t],t=n}}catch{}return t}function n(t){return!!t&&t.constructor===Object}function o(t){return!!t&&t.constructor===Array}function i(n){let o=Object.keys(n),i={};return o.forEach((o=>{if((o=r(o,n)).split(".").length>1){let r=e(n[o],o);delete n[o],i=t(i,r)}else i[o]=n[o]})),i}function a(t){let e=Object.keys(t),r={};return e.forEach((e=>{let i=t[e];if(n(t[e])){let n=a(t[e]);Object.keys(n).forEach((t=>{let o=n[t];r[t=e+"."+t]=o}))}else o(i)?i.forEach(((t,n)=>{r[`${e}[${n}]`]=t})):r[e]=t[e]})),r}function s(t){if(t)return{collection:t.getAttribute("data-collection"),document_id:t.getAttribute("data-document_id"),name:t.getAttribute("name")}}function c(t){return t?{is_realtime:f(t),is_save:u(t),is_read:l(t),is_update:d(t)}:{}}const l=t=>m(t,"data-read_value"),u=t=>m(t,"data-save_value"),d=t=>m(t,"data-update_value"),f=t=>!!t&&"false"!=t.getAttribute("data-realtime");function m(t,e){return!!t&&"false"!==t.getAttribute(e)}function p(t){return!!t&&!/{{\s*([\w\W]+)\s*}}/g.test(t)}function h(t){try{let e=JSON.parse(t);return"object"==typeof e&&null!=e}catch(t){return!1}}function g(t){const{collection:e,document_id:r,name:n}=s(t);return!(h(e)||h(n)||!("INPUT"===t.tagName&&["text","email","tel","url"].includes(t.type)||"TEXTAREA"===t.tagName)||!n||!f(t)||"true"===t.getAttribute("data-unique")||"password"===t.type||!l(t))}function y(t){try{return!!t&&"null"!==t.toLowerCase()}catch(t){return!1}}return{decodeObject:i,encodeObject:a,getAttr:s,getFlagAttr:c,isRealtimeAttr:f,isReadAttr:l,isSaveAttr:u,isUpdateAttr:d,checkValue:p,isCRDT:g,checkDocumentId:y}}()}.apply(e,[]))||(t.exports=r)},366:(t,e,r)=>{"use strict";r.r(e),r.d(e,{default:()=>o}),window.profiler={},window.counter=0,window.counter2=0,window.targets={},window.attributeName={},Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(t){for(var e=(this.document||this.ownerDocument).querySelectorAll(t),r=e.length;--r>=0&&e.item(r)!==this;);return r>-1});const n={initTasks:new Map,attrTasks:new Map,rules:new Map,rulesArray:[],__init:function(){const t=this;new MutationObserver(((e,r)=>t.__callback(e,r))).observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!1,attributeOldValue:!0,characterData:!0})},init:function({observe:t,include:e,exclude:r,attributes:n,name:o,callback:i}){t.some((t=>"childList"==t))&&this.initTasks.set(i,{observe:t,include:e,exclude:r,attributes:n,name:o}),t.some((t=>"attributes"==t))&&this.attrTasks.set(i,{observe:t,include:e,exclude:r,attributes:n,name:o})},remove:function(t){this.initTasks.delete(t),this.attrTasks.delete(t)},addRule:function({include:t,exclude:e,name:r}){this.rules.set(r,{include:t,exclude:e}),this.rulesArray=Array.from(this.rules)},removeRule:function({name:t}){this.rules.delete(t),this.rulesArray=Array.from(this.rules)},__callback:function(t,e){window.counter++;for(let e of t)"childList"==e.type&&e.addedNodes.length>0&&this.__initCallback(e),"attributes"==e.type&&this.__attrCallback(e)},__initCallback:function(t){Array.from(t.addedNodes);this.initTasks.forEach((({observe:e,include:r,exclude:n,attributes:o,name:i},a)=>{t.addedNodes.forEach((e=>{e.tagName&&(!r||e.matches(r)||e.querySelector(r))&&(n&&(e.matches(n)||e.querySelector(n))||a.apply(null,[{type:t.type,target:e}]))}))}))},__attrCallback:function(t){for(let[e,{include:r,exclude:n}]of this.rulesArray){if(r&&!t.target.matches(r))return;if(n&&t.target.matches(n))return}this.attrTasks.forEach((({observe:e,include:r,exclude:n,attributes:o,name:i},a)=>{if((!o||!t.attributeName||o.includes(t.attributeName))&&(!r||t.target.matches(r))&&(!n||!t.target.matches(n))&&t.attributeName){t.target.getAttribute(t.attributeName)!=t.oldValue&&a.apply(null,[t])}}))},setInitialized:function(t,e){t["co_initialized_"+(e=e||"")]=!0},getInitialized:function(t,e){return!!t["co_initialized_"+(e=e||"")]}};n.__init();const o=n},446:function(t,e){var r;"undefined"!=typeof self&&self,void 0===(r=function(){return function(t){function e(){let e={};return t&&t.config&&(e=t.config),{apiKey:e.apiKey,organization_id:e.organization_Id}}function r(e){let r={};return t&&t.config&&(r=t.config),{apiKey:e.apiKey||r.apiKey,organization_id:e.organization_id||r.organization_Id}}function n(e,r){let n={};t&&t.config&&(n=t.config);let o=e||n.organization_Id,i=r||"";return i?`${o}/${i}`:o}function o(t=36){let e=(new Date).getTime(),r=0,n="uxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";if(t<=n.length)n=n.substr(0,t);else{let e=t-n.length,r="-xxxyyxxx",o=Math.floor(e/r.length);for(let t=0;t<o;t++)n+=r;o=e-o*r.length,n+=r.substr(0,o)}return n.replace(/[xy]/g,(function(t){var n=16*Math.random();return e>0?(n=(e+n)%16|0,e=Math.floor(e/16)):(n=(r+n)%16|0,r=Math.floor(r/16)),("x"==t?n:7&n|8).toString(16)}))}return{getCommonParams:e,getCommonParamsExtend:r,generateSocketClient:n,GenerateUUID:o}}(window)}.apply(e,[]))||(t.exports=r)},585:function(t,e,r){var n,o;"undefined"!=typeof self&&self,n=[r(446)],void 0===(o=function(t){return function(t,e,r,n){class o{constructor(t="crud"){this.prefix=t||"crud",this.sockets=new Map,this.listeners=new Map,this.messageQueue=new Map,this.saveFileName="",this.globalScope=""}setGlobalScope(t){this.globalScope=`${this.prefix}/${t}`}getGlobalScope(){return this.globalScope}create(t){const{namespace:o,room:i}=t,a=this.getKey(o,i);let s,c=this;if(o&&this.setGlobalScope(o),this.sockets.get(a))return void(s=this.sockets.get(a));let l=e.location.protocol;"about:"===e.location.protocol&&(l=e.parent.location.protocol,t.host||(t.host=e.parent.location.host));let u="http:"===l?"ws":"wss";const d=t.port?t.port:8088;let f=`${u}://${e.location.host}:${d}/${a}`;t.host&&(f=t.host.includes("://")?`${t.host}/${a}`:t.host.includes(":")?`${u}://${t.host}/${a}`:`${u}://${t.host}:${d}/${a}`);try{let t=null;e.localStorage&&(t=e.localStorage.getItem("token")),s=new r(f,t)}catch(t){return}s.onopen=function(t){(c.messageQueue.get(a)||[]).forEach((t=>s.send(JSON.stringify(t)))),c.sockets.set(a,s),c.messageQueue.set(a,[])},s.onclose=function(e){switch(e.code){case 1e3:break;default:c.destroy(s,a),c.reconnect(s,t)}},s.onerror=function(e){c.destroy(s,a),c.reconnect(s,t)},s.onmessage=function(t){try{if(e.Blob&&t.data instanceof n)return void c.saveFile(t.data);let o=JSON.parse(t.data);if(o.data&&o.data.event){if(e.CustomEvent){var r=new e.CustomEvent(o.data.event,{detail:o.data});return void e.document.dispatchEvent(r)}return void process.emit(o.data.event,o.data)}o.action;const i=c.listeners.get(o.action);if(!i)return;i.forEach((t=>{t(o.data,a)}))}catch(t){}}}send(e,r,n){const o={action:e,data:{...r,uid:t.GenerateUUID()}},i=this.getKeyByRoom(n),a=this.getByRoom(n);a?a.send(JSON.stringify(o)):this.messageQueue.get(i)?this.messageQueue.get(i).push(o):this.messageQueue.set(i,[o])}sendFile(t,e){const r=this.getByRoom(e);r&&r.send(t)}listen(t,e){this.listeners.get(t)?this.listeners.get(t).push(e):this.listeners.set(t,[e])}reconnect(t,e){let r=this;setTimeout((function(){r.create(e)}),1e3)}destroy(t,e){t&&(t.onerror=t.onopen=t.onclose=null,t.close(),t=null),this.sockets.get(e)&&this.sockets.delete(e)}destroyByKey(t){let e=this.sockets.get(t);e&&this.destroy(e,t)}getKey(t,e){let r=`${this.prefix}`;return t&&""!=t&&(r+=e&&""!=e?`/${t}/${e}`:`/${t}`),r}getByRoom(t){let e=this.getKeyByRoom(t);return this.sockets.get(e)}getKeyByRoom(t){let e=this.globalScope;return t&&(e=`${this.prefix}/${t}`),e}saveFile(t){if(e.document){const n=this.saveFileName||"downloadFile";var r=e.document.createElement("a");e.document.body.appendChild(r),r.style="display: none";let o=window.URL.createObjectURL(t);r.href=o,r.download=n,r.click(),e.URL.revokeObjectURL(o),this.saveFileName=""}}listenAsync(t){return new Promise(((r,n)=>{e.document?e.document.addEventListener(t,(function(t){r(t.detail)}),{once:!0}):process.once(t,(t=>{r(t)}))}))}}return o}(t,window,WebSocket,Blob)}.apply(e,n))||(t.exports=o)},212:function(t,e){var r;"undefined"!=typeof self&&self,void 0===(r=function(){return function(t){const e={attribute:"data-uuid",init:function(e){if(!t.document)return;const r=e||t.document;if(!r.querySelectorAll)return;let n=r.querySelectorAll(`[${this.attribute}]`);const o=this;n.forEach((t=>{const e=parseInt(t.getAttribute(o.attribute))||36,r=o.generate(e);"INPUT"===t.tagName||"TEXTAREA"===t.tagName?t.value=r:t.innerHTML=r}))},generate:function(e=36){let r=(new Date).getTime(),n=t.performance&&t.performance.now&&1e3*t.performance.now()||0,o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";if(e<=o.length)o=o.substr(0,e);else{let t=e-o.length,r="-xxxyyxxx",n=Math.floor(t/r.length);for(let t=0;t<n;t++)o+=r;n=t-n*r.length,o+=r.substr(0,n)}return o.replace(/[xy]/g,(function(t){var e=16*Math.random();return r>0?(e=(r+e)%16|0,r=Math.floor(r/16)):(e=(n+e)%16|0,n=Math.floor(n/16)),("x"==t?e:7&e|8).toString(16)}))}};return e.init(),e}(window)}.apply(e,[]))||(t.exports=r)},605:(t,e,r)=>{"use strict";r.r(e),r.d(e,{default:()=>s});var n=r(483),o=r.n(n);const i=r.p+"4bae7f440ab1de156d0d0d0d0a566858.css";var a={injectType:"linkTag",insert:"head"};o()(i,a);const s={}},483:(t,e,r)=>{"use strict";var n,o=(n={},function(t){if(void 0===n[t]){var e=document.querySelector(t);if(window.HTMLIFrameElement&&e instanceof window.HTMLIFrameElement)try{e=e.contentDocument.head}catch(t){e=null}n[t]=e}return n[t]});t.exports=function(t,e){if((e=e||{}).attributes="object"==typeof e.attributes?e.attributes:{},void 0===e.attributes.nonce){var n=r.nc;n&&(e.attributes.nonce=n)}var i=document.createElement("link");if(i.rel="stylesheet",i.href=t,Object.keys(e.attributes).forEach((function(t){i.setAttribute(t,e.attributes[t])})),"function"==typeof e.insert)e.insert(i);else{var a=o(e.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(i)}return function(t){"string"==typeof t?i.href=t:i.parentNode.removeChild(i)}}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;r.g.importScripts&&(t=r.g.location+"");var e=r.g.document;if(!t&&e&&(e.currentScript&&(t=e.currentScript.src),!t)){var n=e.getElementsByTagName("script");n.length&&(t=n[n.length-1].src)}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=t})();var n={};return(()=>{"use strict";var t=n;t.default=void 0;var e=a(r(366)),o=a(r(611)),i=a(r(212));function a(t){return t&&t.__esModule?t:{default:t}}r(605);var s=document.querySelectorAll("input,textarea,[contenteditable]"),c=!1,l=["boxSizing","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","marginTop","marginRight","marginBottom","marginLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","textRendering","webkitWritingMode","textTransform","textIndent","overflowWrap"];class u{static print(t,e){e=e||!1}}var d,f,m,p=function(t,e,r){t.getAttribute("name");if(""==(t.getAttribute("data-document_id")||""))return!1;var n=t.dataset.mirror_id;d=document.getElementById(n);t.className.indexOf("floating-label");d||((d=document.createElement("div")).id=n,d.className="mirror_color mirror_scroll mirror-width-scroll",t.insertAdjacentElement("afterend",d));t.offsetWidth,t.scrollWidth;m=d.style,f=getComputedStyle(t),getComputedStyle(t.parentElement);parseInt(f.marginTop),parseInt(f.marginLeft);"INPUT"!==t.nodeName?(m.wordWrap="break-word",m.whiteSpace="pre-wrap"):m.whiteSpace="pre",m.position="absolute";var o=t.getBoundingClientRect();document.documentElement.scrollTop;m.top=t.offsetTop+"px",m.left=t.offsetLeft+"px",m.width=o.width+"px",m.height=o.height+"px",m.visibility="visible",l.forEach((function(t){-1===["left","top"].indexOf(t.toLowerCase())&&(m[t]=f[t])})),m.overflowX="auto",m.overflowY="hidden",m.margin="0px",m.border=f.border,m.borderColor="transparent";let i=d.querySelectorAll(".cursor-container"),a=d.querySelectorAll(".selectors_by_users"),s=-1==["TEXTAREA","INPUT"].indexOf(t.nodeName)?t.innerHTML:t.value;d.textContent=s.substring(0,e),"INPUT"===t.nodeName&&(d.textContent=d.textContent.replace(/\s/g," "));var c=document.createElement("span");c.id=t.nodeName+"span_selections";let u=s.substring(e,r)||"";c.textContent=u,d.appendChild(c),i&&i.forEach((function(t,e,r){d.appendChild(t)})),a&&a.forEach((function(t,e,r){d.appendChild(t)}));let p=s.substring(r)||"";var h=document.createElement("span");d.appendChild(h),h.textContent=p;o=t.getBoundingClientRect();return{start:{top:c.offsetTop,left:c.offsetLeft},end:{top:h.offsetTop,left:h.offsetLeft}}};function h(t){u.print(["draw Cursor ",t],c);let e=t.element;if(!e.dataset.cursors||e.dataset.mirror_id){let a=t.startPosition,s=t.endPositon,l=t.clientId,d=e.getAttribute("data-document_id")||"";if(""!=d){u.print("action document_id "+d,c),void 0!==e.dataset.mirror_id&&""!=e.dataset.mirror_id||(e.dataset.mirror_id=i.default.generate(30));let f=p(e,a,s);if(!f)return!1;e.getAttribute("name");let m=e.dataset.mirror_id,h=document.getElementById(m),g=!1,y=!1,b="_"+m,x=!(void 0===t||!t.hasOwnProperty("user"))&&t.user,v=!(void 0===t||!t.hasOwnProperty("user_id"))&&x.user_id;if(l){if(document.querySelectorAll("#socket_"+l+b).forEach((function(t,e,r){t.parentElement.getAttribute("id")!=m&&(u.print("remove old cursor others elements",c),t.remove())})),g=h.querySelector(".cursor-container#socket_"+l+b),!g&&t.hasOwnProperty("user")){if(x){u.print("Create Cursor",c);let t='<div style="color:blue;" class="cursor-container" id="socket_'+l+b+'" ><div class="cursor" style="background-color:'+x.color+'"></div> <div class="cursor-flag" data-collection="users" name="name" data-user_name="'+x.name+'" data-user_color="'+x.color+'" data-socket_id="'+l+'" data-id_mirror="'+m+'" data-document_id="'+v+'" style="background-color:'+x.color+'" flag>'+x.name+"</div></div>";h.innerHTML=t+h.innerHTML}v&&o.default.readDocument({collection:"users",document_id:v})}g=h.querySelector(".cursor-container#socket_"+l+b)}if(g){u.print(["Update Cursor",g,f],c);let t=function(t,e){if(window.getComputedStyle)var r=document.defaultView.getComputedStyle(t,null).getPropertyValue(e);return r}(e,"font-size");t=parseFloat(t.substring(0,t.length-2));let o=112.5*t/100,i=g.querySelector(".cursor");if(g.dataset.start=a,g.dataset.end=s,g.dataset.socket_id=l,g.style.top=f.end.top+"px",g.style.width="2px",i.style.height=o+"px",g.style.left=f.end.left+"px",y=document.getElementById("sel-"+l+b),a!=s&&x){y=document.getElementById("sel-"+l+b),y&&y.remove();var r=e.offsetWidth-e.scrollWidth,n=parseInt(getComputedStyle(e).paddingRight);y=document.createElement("span"),y.id="sel-"+l+b,y.className="selectors_by_users";let t=getComputedStyle(h);y.style.position="absolute",y.style.top=t.paddingTop,y.style.left=t.paddingLeft,y.style["padding-right"]=r+n+"px",h.insertBefore(y,h.firstChild);let o=document.createElement("span");o.id="selection-"+l+b,o.style.backgroundColor=x.color;let i=-1==["TEXTAREA","INPUT"].indexOf(e.nodeName)?e.innerHTML:e.value;y.textContent=i.substring(0,a);let c=i.substring(a,s)||"";o.textContent=c,y.appendChild(o)}else y&&y.remove()}}}}function g(t){var e="";let r=t.getAttribute("data-document_id")||"";if(""!=r){if(name=t.getAttribute("name"),!t.dataset.mirror_id)return;e=t.dataset.mirror_id;var n=document.getElementById(e);u.print(["refresh_mirror ",n],c);var o=t.nodeName+"[name='"+name+"'][data-document_id='"+r+"']";if(u.print(["selector -> "+o],c),n)f=getComputedStyle(t),(m=n.style).width=t.offsetWidth-(parseInt(f.borderLeftWidth)+parseInt(f.borderRightWidth))+"px",m.height=t.offsetHeight-(parseInt(f.borderTopWidth)+parseInt(f.borderBottomWidth))+"px",n.querySelectorAll(".cursor-container").forEach((function(e,r,n){let o=e.querySelector(".cursor-flag").dataset,i=e.dataset;h({element:t,startPosition:i.start,endPositon:i.end,clientId:i.socket_id,user:{color:o.user_color,name:i.user_name}})}))}}function y(t){let e,r=t.hasAttribute("data-realtime")?t.getAttribute("data-realtime"):"true";if("true"==r||e&&"true"==e.getAttribute("data-realtime")){if("false"==r)return!1;u.print(["Init Events ",t],c),t.addEventListener("scroll",(function(){u.print(["Move Scroll ",t],!0);t.getAttribute("name"),t.getAttribute("data-document_id");let e=t.dataset.mirror_id,r=document.getElementById(e);r&&r.scrollTo(t.scrollLeft,t.scrollTop)}),!1),new ResizeObserver((function(){s.forEach((function(e,r,n){e.getAttribute("name");let o=t.dataset.mirror_id;u.print(["Resize id_mirror -> "+o],c);let i=document.getElementById(o);i&&(i.style.width=e.offsetWidth+"px",i.style.height=e.offsetHeight+"px",document.activeElement===t&&p(t,t.selectionStart,t.selectionEnd),g(t))}))})).observe(t),t.addEventListener("mousemove",(function(e){t.getAttribute("name"),t.getAttribute("data-document_id");let r=t.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(t.scrollLeft,t.scrollTop)})),t.addEventListener("focusout",(function(e){t.getAttribute("name"),t.getAttribute("data-document_id");let r=t.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(t.scrollLeft,t.scrollTop)})),t.addEventListener("keydown",(function(e){t.getAttribute("name");let r=t.dataset.mirror_id,n=document.getElementById(r);n&&(n.scrollTo(t.scrollLeft,t.scrollTop),g(t))})),t.addEventListener("keyup",(function(e){t.getAttribute("name");let r=t.dataset.mirror_id,n=document.getElementById(r);n&&n.scrollTo(t.scrollLeft,t.scrollTop)}))}}o.default.listen("readDocument",(function(t){let e=document.querySelector('.cursor-flag[data-document_id="'+t.document_id+'"]');e&&(e.innerHTML=t.result[e.getAttribute("name")])})),Element.prototype.remove=function(){this.parentElement&&this.parentElement.removeChild(this)};window.addEventListener("resize",(function(t){document.querySelectorAll("[data-mirror_id]").forEach((function(t,e,r){g(t)}))}),!0),document.addEventListener("scroll",(function(t){document.querySelectorAll("[data-mirror_id]").forEach((function(t,e,r){g(t)}))}),!0),function(t){t.forEach((function(t,e,r){y(t)}))}(s),e.default.init({name:"CoCreateCursor",observe:["subtree","childList"],include:"[data-collection][data-document_id][name][data-realtime=true]",callback:function(t){!function(t){let e=t||window;e.querySelectorAll&&e.querySelectorAll("[data-realtime=true]").forEach((t=>{y(t)}))}(t.target)}});var b={draw_cursor:h,refresh_mirror:g,recalculate_local_cursors:function(t,e){u.print("count "+e,c);let r=t.hasAttribute("contenteditable")?parseInt(t.getAttribute("selection_start")):t.selectionStart,n=(t.getAttribute("name"),t.getAttribute("data-document_id"),t.getAttribute("data-collection"),t.dataset.mirror_id),o=document.getElementById(n),i=o?o.querySelectorAll(".cursor-container"):null;if(i){let n=[];i.forEach((function(o,i,a){let s=parseInt(o.getAttribute("data-start")),l=o.getAttribute("data-user_name");if(u.print(["my_start local",r,"start cursor "+l+" = ",s],c),s>r&&-1==n.indexOf(l)){u.print("Es mayor",c);let r=parseInt(o.getAttribute("data-end")),i=s+e,a=r+e;u.print(["pos_start",i,"pos_end",a],c);let d=o.querySelector(".cursor-flag").dataset,f=d.socket_id,m={element:t,startPosition:i,endPositon:a,clientId:f,user:{color:d.user_color,name:d.user_name}};u.print(["sent Draw Cursor ",m],c),h(m),n.push(l)}}))}}};t.default=b})(),n=n.default})()})); |
{ | ||
"name": "@cocreate/cursors", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"description": "Collaborative user cursor position for inputs, textarea's and contenteditable elements.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ /*global Element*/ | ||
import './CoCreate-cursors.css'; | ||
import './index.css'; | ||
@@ -9,0 +9,0 @@ /**Uso esta variable para mostrar errores en caso que no este en prod*/ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91244