Files
yjs/y.js

2 lines
34 KiB
JavaScript
Raw Permalink Normal View History

!function t(e,n,r){function i(s,u){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!u&&l)return l(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var p=n[s]={exports:{}};e[s][0].call(p.exports,function(t){var n=e[s][1][t];return i(n?n:t)},p,p.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(t,e){var n,r;n=t("./ConnectorClass"),r=function(t,e,r,i){var o,s,u,l,p,c,a,h;for(c in n)u=n[c],t[c]=u;return t.setIsBoundToY(),h=function(e){return e.uid.creator===r.getUserId()&&"string"!=typeof e.uid.op_number&&"_temp"!==r.getUserId()?t.broadcast(e):void 0},null!=t.invokeSync&&r.setInvokeSyncHandler(t.invokeSync),i.push(h),s=function(t){var e,n;n=[];for(c in t)e=t[c],n.push({user:c,state:e});return n},a=function(t){var e,n,r,i;for(n={},r=0,i=t.length;i>r;r++)e=t[r],n[e.user]=e.state;return n},p=function(){return s(r.getOperationCounter())},l=function(t){var e,n,i;return i=a(t),e=r._encode(i),n={hb:e,state_vector:s(r.getOperationCounter())}},o=function(t,n){return e.applyOp(t,n)},t.getStateVector=p,t.getHB=l,t.applyHB=o,null==t.receive_handlers&&(t.receive_handlers=[]),t.receive_handlers.push(function(t,n){return n.uid.creator!==r.getUserId()?e.applyOp(n):void 0})},e.exports=r},{"./ConnectorClass":2}],2:[function(t,e){e.exports={init:function(t){var e;return e=function(e){return function(n,r){if(null!=t[n]){if(null==r||r.some(function(e){return e===t[n]}))return e[n]=t[n];throw new Error("You can set the '"+n+"' option to one of the following choices: "+JSON.encode(r))}throw new Error("You must specify "+n+", when initializing the Connector!")}}(this),e("syncMethod",["syncAll","master-slave"]),e("role",["master","slave"]),e("user_id"),"function"==typeof this.on_user_id_set&&this.on_user_id_set(this.user_id),this.perform_send_again=null!=t.perform_send_again?t.perform_send_again:!0,"master"===this.role&&(this.syncMethod="syncAll"),this.is_synced=!1,this.connections={},null==this.receive_handlers&&(this.receive_handlers=[]),this.connections={},this.current_sync_target=null,this.sent_hb_to_all_users=!1,this.is_initialized=!0},onUserEvent:function(t){return null==this.connections_listeners&&(this.connections_listeners=[]),this.connections_listeners.push(t)},isRoleMaster:function(){return"master"===this.role},isRoleSlave:function(){return"slave"===this.role},findNewSyncTarget:function(){var t,e,n;if(this.current_sync_target=null,"syncAll"===this.syncMethod){n=this.connections;for(e in n)if(t=n[e],!t.is_synced){this.performSync(e);break}}return null==this.current_sync_target&&this.setStateSynced(),null},userLeft:function(t){var e,n,r,i,o;if(delete this.connections[t],this.findNewSyncTarget(),null!=this.connections_listeners){for(i=this.connections_listeners,o=[],n=0,r=i.length;r>n;n++)e=i[n],o.push(e({action:"userLeft",user:t}));return o}},userJoined:function(t,e){var n,r,i,o,s,u;if(null==e)throw new Error("Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')");if(null==(r=this.connections)[t]&&(r[t]={}),this.connections[t].is_synced=!1,this.is_synced&&"syncAll"!==this.syncMethod||("syncAll"===this.syncMethod?this.performSync(t):"master"===e&&this.performSyncWithMaster(t)),null!=this.connections_listeners){for(s=this.connections_listeners,u=[],i=0,o=s.length;o>i;i++)n=s[i],u.push(n({action:"userJoined",user:t,role:e}));return u}},whenSynced:function(t){return t.constructore===Function&&(t=[t]),this.is_synced?t[0].apply(this,t.slice(1)):(null==this.compute_when_synced&&(this.compute_when_synced=[]),this.compute_when_synced.push(t))},onReceive:function(t){return this.receive_handlers.push(t)},performSync:function(t){var e,n,r,i,o;if(null==this.current_sync_target&&(this.current_sync_target=t,this.send(t,{sync_step:"getHB",send_again:"true",data:[]}),!this.sent_hb_to_all_users)){for(this.sent_hb_to_all_users=!0,e=this.getHB([]).hb,r=[],i=0,o=e.length;o>i;i++)n=e[i],r.push(n),r.length>10&&(this.broadcast({sync_step:"applyHB_",data:r}),r=[]);return this.broadcast({sync_step:"applyHB
}return i(n,t),n.prototype.type="ReplaceManager",n.prototype.callEventDecorator=function(t){var e,n,r,i,o,s;if(!this.isDeleted()){for(i=0,o=t.length;o>i;i++){e=t[i],s=this.event_properties;for(n in s)r=s[n],e[n]=r}this.event_this.callEvent(t)}return void 0},n.prototype.callOperationSpecificInsertEvents=function(t){var e;return"Delimiter"===t.next_cl.type&&"Delimiter"!==t.prev_cl.type?(t.is_deleted||(e=t.prev_cl.val(),this.callEventDecorator([{type:"update",changedBy:t.uid.creator,oldValue:e}])),t.prev_cl.applyDelete()):"Delimiter"!==t.next_cl.type?t.applyDelete():this.callEventDecorator([{type:"add",changedBy:t.uid.creator}]),void 0},n.prototype.callOperationSpecificDeleteEvents=function(t,e){return"Delimiter"===t.next_cl.type?this.callEventDecorator([{type:"delete",changedBy:e.uid.creator,oldValue:t.val()}]):void 0},n.prototype.replace=function(t,n){var r,i;return r=this.getLastOperation(),i=new e.Insert(null,t,null,this,n,r,r.next_cl).execute(),void 0},n.prototype.isContentDeleted=function(){return this.getLastOperation().isDeleted()},n.prototype.deleteContent=function(){var t;return t=this.getLastOperation(),t.isDeleted()||"Delimiter"===t.type||new e.Delete(null,void 0,this.getLastOperation().uid).execute(),void 0},n.prototype.val=function(){var t;return t=this.getLastOperation(),"function"==typeof t.val?t.val():void 0},n}(e.ListManager),t}},{"./Basic":6}],8:[function(t,e){var n,r,i,o,s;s=t("./Operations/Structured"),r=t("./HistoryBuffer"),n=t("./Engine"),i=t("./ConnectorAdapter"),o=function(t){var e,u,l,p,c,a,h;return h=null,null!=t.user_id?h=t.user_id:(h="_temp",t.on_user_id_set=function(t){return h=t,e.resetUserId(t)}),e=new r(h),a=s(e,this.constructor),c=a.operations,l=new n(e,c),i(t,l,e,a.execution_listener),c.Operation.prototype.HB=e,c.Operation.prototype.operations=c,c.Operation.prototype.engine=l,c.Operation.prototype.connector=t,c.Operation.prototype.custom_types=this.constructor,u=new o.Object,p=new c.MapManager(u,e.getReservedUniqueIdentifier()).execute(),u._setModel(p),u},e.exports=o,"undefined"!=typeof window&&null!==window&&(window.Y=o),o.Object=t("./ObjectType")},{"./ConnectorAdapter":1,"./Engine":3,"./HistoryBuffer":4,"./ObjectType":5,"./Operations/Structured":7}]},{},[8]);