Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: skyisle/ShareJS
base: bc5784144f
...
head fork: skyisle/ShareJS
compare: 94f9b1fddd
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
218 src/client/ace.coffee
View
@@ -1,128 +1,128 @@
# This is some utility code to connect an ace editor to a sharejs document.
-
-Range = require("ace/range").Range
-
-# Convert an ace delta into an op understood by share.js
-applyToShareJS = (editorDoc, delta, doc) ->
- # Get the start position of the range, in no. of characters
- getStartOffsetPosition = (range) ->
- # This is quite inefficient - getLines makes a copy of the entire
- # lines array in the document. It would be nice if we could just
- # access them directly.
- lines = editorDoc.getLines 0, range.start.row
+define "ace/range", ->
+ Range = require("ace/range").Range
+
+ # Convert an ace delta into an op understood by share.js
+ applyToShareJS = (editorDoc, delta, doc) ->
+ # Get the start position of the range, in no. of characters
+ getStartOffsetPosition = (range) ->
+ # This is quite inefficient - getLines makes a copy of the entire
+ # lines array in the document. It would be nice if we could just
+ # access them directly.
+ lines = editorDoc.getLines 0, range.start.row
+
+ offset = 0
+
+ for line, i in lines
+ offset += if i < range.start.row
+ line.length
+ else
+ range.start.column
+
+ # Add the row number to include newlines.
+ offset + range.start.row
+
+ pos = getStartOffsetPosition(delta.range)
+
+ switch delta.action
+ when 'insertText' then doc.insert pos, delta.text
+ when 'removeText' then doc.del pos, delta.text.length
- offset = 0
-
- for line, i in lines
- offset += if i < range.start.row
- line.length
- else
- range.start.column
-
- # Add the row number to include newlines.
- offset + range.start.row
+ when 'insertLines'
+ text = delta.lines.join('\n') + '\n'
+ doc.insert pos, text
+
+ when 'removeLines'
+ text = delta.lines.join('\n') + '\n'
+ doc.del pos, text.length
+
+ else throw new Error "unknown action: #{delta.action}"
+
+ return
+
+ # Attach an ace editor to the document. The editor's contents are replaced
+ # with the document's contents unless keepEditorContents is true. (In which case the document's
+ # contents are nuked and replaced with the editor's).
+ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents) ->
+ throw new Error 'Only text documents can be attached to ace' unless @provides['text']
+
+ doc = this
+ editorDoc = editor.getSession().getDocument()
+ editorDoc.setNewLineMode 'unix'
+
+ check = ->
+ window.setTimeout ->
+ editorText = editorDoc.getValue()
+ otText = doc.getText()
+
+ if editorText != otText
+ console.error "Text does not match!"
+ console.error "editor: #{editorText}"
+ console.error "ot: #{otText}"
+ # Should probably also replace the editor text with the doc snapshot.
+ , 0
+
+ if keepEditorContents
+ doc.del 0, doc.getText().length
+ doc.insert 0, editorDoc.getValue()
+ else
+ editorDoc.setValue doc.getText()
- pos = getStartOffsetPosition(delta.range)
+ check()
- switch delta.action
- when 'insertText' then doc.insert pos, delta.text
- when 'removeText' then doc.del pos, delta.text.length
+ # When we apply ops from sharejs, ace emits edit events. We need to ignore those
+ # to prevent an infinite typing loop.
+ suppress = false
- when 'insertLines'
- text = delta.lines.join('\n') + '\n'
- doc.insert pos, text
-
- when 'removeLines'
- text = delta.lines.join('\n') + '\n'
- doc.del pos, text.length
-
- else throw new Error "unknown action: #{delta.action}"
-
- return
-
-# Attach an ace editor to the document. The editor's contents are replaced
-# with the document's contents unless keepEditorContents is true. (In which case the document's
-# contents are nuked and replaced with the editor's).
-window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents) ->
- throw new Error 'Only text documents can be attached to ace' unless @provides['text']
-
- doc = this
- editorDoc = editor.getSession().getDocument()
- editorDoc.setNewLineMode 'unix'
-
- check = ->
- window.setTimeout ->
- editorText = editorDoc.getValue()
- otText = doc.getText()
-
- if editorText != otText
- console.error "Text does not match!"
- console.error "editor: #{editorText}"
- console.error "ot: #{otText}"
- # Should probably also replace the editor text with the doc snapshot.
- , 0
-
- if keepEditorContents
- doc.del 0, doc.getText().length
- doc.insert 0, editorDoc.getValue()
- else
- editorDoc.setValue doc.getText()
-
- check()
-
- # When we apply ops from sharejs, ace emits edit events. We need to ignore those
- # to prevent an infinite typing loop.
- suppress = false
-
- # Listen for edits in ace
- editorListener = (change) ->
- return if suppress
- applyToShareJS editorDoc, change.data, doc
+ # Listen for edits in ace
+ editorListener = (change) ->
+ return if suppress
+ applyToShareJS editorDoc, change.data, doc
- check()
+ check()
- editorDoc.on 'change', editorListener
+ editorDoc.on 'change', editorListener
- # Listen for remote ops on the sharejs document
- docListener = (op) ->
- suppress = true
- applyToDoc editorDoc, op
- suppress = false
+ # Listen for remote ops on the sharejs document
+ docListener = (op) ->
+ suppress = true
+ applyToDoc editorDoc, op
+ suppress = false
- check()
+ check()
- # Horribly inefficient.
- offsetToPos = (offset) ->
- # Again, very inefficient.
- lines = editorDoc.getAllLines()
+ # Horribly inefficient.
+ offsetToPos = (offset) ->
+ # Again, very inefficient.
+ lines = editorDoc.getAllLines()
- row = 0
- for line, row in lines
- break if offset <= line.length
+ row = 0
+ for line, row in lines
+ break if offset <= line.length
- # +1 for the newline.
- offset -= lines[row].length + 1
+ # +1 for the newline.
+ offset -= lines[row].length + 1
- row:row, column:offset
+ row:row, column:offset
- doc.on 'insert', (pos, text) ->
- suppress = true
- editorDoc.insert offsetToPos(pos), text
- suppress = false
- check()
+ doc.on 'insert', (pos, text) ->
+ suppress = true
+ editorDoc.insert offsetToPos(pos), text
+ suppress = false
+ check()
- doc.on 'delete', (pos, text) ->
- suppress = true
- range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
- editorDoc.remove range
- suppress = false
- check()
+ doc.on 'delete', (pos, text) ->
+ suppress = true
+ range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
+ editorDoc.remove range
+ suppress = false
+ check()
- doc.detach_ace = ->
- doc.removeListener 'remoteop', docListener
- editorDoc.removeListener 'change', editorListener
- delete doc.detach_ace
+ doc.detach_ace = ->
+ doc.removeListener 'remoteop', docListener
+ editorDoc.removeListener 'change', editorListener
+ delete doc.detach_ace
- return
+ return
2  src/server/socketio.coffee
View
@@ -19,7 +19,7 @@ i = ->#util.inspect
#
# Options = {}
exports.attach = (server, createClient, options) ->
- io = socketio.listen server
+ io = options.io || socketio.listen server
io.configure ->
io.set 'log level', 1
206 webclient/ace.js
View
@@ -1,114 +1,114 @@
(function() {
- var Range, applyToShareJS;
- Range = require("ace/range").Range;
-
- applyToShareJS = function(editorDoc, delta, doc) {
- var getStartOffsetPosition, pos, text;
- getStartOffsetPosition = function(range) {
- var i, line, lines, offset, _len;
- lines = editorDoc.getLines(0, range.start.row);
- offset = 0;
- for (i = 0, _len = lines.length; i < _len; i++) {
- line = lines[i];
- offset += i < range.start.row ? line.length : range.start.column;
- }
- return offset + range.start.row;
- };
- pos = getStartOffsetPosition(delta.range);
- switch (delta.action) {
- case 'insertText':
- doc.insert(pos, delta.text);
- break;
- case 'removeText':
- doc.del(pos, delta.text.length);
- break;
- case 'insertLines':
- text = delta.lines.join('\n') + '\n';
- doc.insert(pos, text);
- break;
- case 'removeLines':
- text = delta.lines.join('\n') + '\n';
- doc.del(pos, text.length);
- break;
- default:
- throw new Error("unknown action: " + delta.action);
- }
- };
-
- window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
- var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
- if (!this.provides['text']) {
- throw new Error('Only text documents can be attached to ace');
- }
- doc = this;
- editorDoc = editor.getSession().getDocument();
- editorDoc.setNewLineMode('unix');
- check = function() {
- return window.setTimeout(function() {
- var editorText, otText;
- editorText = editorDoc.getValue();
- otText = doc.getText();
- if (editorText !== otText) {
- console.error("Text does not match!");
- console.error("editor: " + editorText);
- return console.error("ot: " + otText);
+ define("ace/range", function() {
+ var Range, applyToShareJS;
+ Range = require("ace/range").Range;
+ applyToShareJS = function(editorDoc, delta, doc) {
+ var getStartOffsetPosition, pos, text;
+ getStartOffsetPosition = function(range) {
+ var i, line, lines, offset, _len;
+ lines = editorDoc.getLines(0, range.start.row);
+ offset = 0;
+ for (i = 0, _len = lines.length; i < _len; i++) {
+ line = lines[i];
+ offset += i < range.start.row ? line.length : range.start.column;
}
- }, 0);
- };
- if (keepEditorContents) {
- doc.del(0, doc.getText().length);
- doc.insert(0, editorDoc.getValue());
- } else {
- editorDoc.setValue(doc.getText());
- }
- check();
- suppress = false;
- editorListener = function(change) {
- if (suppress) return;
- applyToShareJS(editorDoc, change.data, doc);
- return check();
- };
- editorDoc.on('change', editorListener);
- docListener = function(op) {
- suppress = true;
- applyToDoc(editorDoc, op);
- suppress = false;
- return check();
+ return offset + range.start.row;
+ };
+ pos = getStartOffsetPosition(delta.range);
+ switch (delta.action) {
+ case 'insertText':
+ doc.insert(pos, delta.text);
+ break;
+ case 'removeText':
+ doc.del(pos, delta.text.length);
+ break;
+ case 'insertLines':
+ text = delta.lines.join('\n') + '\n';
+ doc.insert(pos, text);
+ break;
+ case 'removeLines':
+ text = delta.lines.join('\n') + '\n';
+ doc.del(pos, text.length);
+ break;
+ default:
+ throw new Error("unknown action: " + delta.action);
+ }
};
- offsetToPos = function(offset) {
- var line, lines, row, _len;
- lines = editorDoc.getAllLines();
- row = 0;
- for (row = 0, _len = lines.length; row < _len; row++) {
- line = lines[row];
- if (offset <= line.length) break;
- offset -= lines[row].length + 1;
+ return window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
+ var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
+ if (!this.provides['text']) {
+ throw new Error('Only text documents can be attached to ace');
}
- return {
- row: row,
- column: offset
+ doc = this;
+ editorDoc = editor.getSession().getDocument();
+ editorDoc.setNewLineMode('unix');
+ check = function() {
+ return window.setTimeout(function() {
+ var editorText, otText;
+ editorText = editorDoc.getValue();
+ otText = doc.getText();
+ if (editorText !== otText) {
+ console.error("Text does not match!");
+ console.error("editor: " + editorText);
+ return console.error("ot: " + otText);
+ }
+ }, 0);
};
- };
- doc.on('insert', function(pos, text) {
- suppress = true;
- editorDoc.insert(offsetToPos(pos), text);
- suppress = false;
- return check();
- });
- doc.on('delete', function(pos, text) {
- var range;
- suppress = true;
- range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
- editorDoc.remove(range);
+ if (keepEditorContents) {
+ doc.del(0, doc.getText().length);
+ doc.insert(0, editorDoc.getValue());
+ } else {
+ editorDoc.setValue(doc.getText());
+ }
+ check();
suppress = false;
- return check();
+ editorListener = function(change) {
+ if (suppress) return;
+ applyToShareJS(editorDoc, change.data, doc);
+ return check();
+ };
+ editorDoc.on('change', editorListener);
+ docListener = function(op) {
+ suppress = true;
+ applyToDoc(editorDoc, op);
+ suppress = false;
+ return check();
+ };
+ offsetToPos = function(offset) {
+ var line, lines, row, _len;
+ lines = editorDoc.getAllLines();
+ row = 0;
+ for (row = 0, _len = lines.length; row < _len; row++) {
+ line = lines[row];
+ if (offset <= line.length) break;
+ offset -= lines[row].length + 1;
+ }
+ return {
+ row: row,
+ column: offset
+ };
+ };
+ doc.on('insert', function(pos, text) {
+ suppress = true;
+ editorDoc.insert(offsetToPos(pos), text);
+ suppress = false;
+ return check();
+ });
+ doc.on('delete', function(pos, text) {
+ var range;
+ suppress = true;
+ range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
+ editorDoc.remove(range);
+ suppress = false;
+ return check();
+ });
+ doc.detach_ace = function() {
+ doc.removeListener('remoteop', docListener);
+ editorDoc.removeListener('change', editorListener);
+ return delete doc.detach_ace;
+ };
});
- doc.detach_ace = function() {
- doc.removeListener('remoteop', docListener);
- editorDoc.removeListener('change', editorListener);
- return delete doc.detach_ace;
- };
});
}).call(this);
2  webclient/json.js
View
@@ -1 +1 @@
-((function(){var a,b,c,d,e,f,g,h,i,j=!0,k=Array.prototype.slice,l=window.sharejs;typeof j!="undefined"&&j!==null?h=l.types.text:h=require("./text"),f={},f.name="json",f.create=function(){return null},f.invertComponent=function(a){var b={p:a.p};return a.si!==void 0&&(b.sd=a.si),a.sd!==void 0&&(b.si=a.sd),a.oi!==void 0&&(b.od=a.oi),a.od!==void 0&&(b.oi=a.od),a.li!==void 0&&(b.ld=a.li),a.ld!==void 0&&(b.li=a.ld),a.na!==void 0&&(b.na=-a.na),a.lm!==void 0&&(b.lm=a.p[a.p.length-1],b.p=a.p.slice(0,a.p.length-1).concat([a.lm])),b},f.invert=function(a){var b,c,d,e=a.slice().reverse(),g=[];for(c=0,d=e.length;c<d;c++)b=e[c],g.push(f.invertComponent(b));return g},f.checkValidOp=function(){},e=function(a){return Object.prototype.toString.call(a)==="[object Array]"},f.checkList=function(a){if(!e(a))throw new Error("Referenced element not a list")},f.checkObj=function(a){if(a.constructor!==Object)throw new Error("Referenced element not an object (it was "+JSON.stringify(a)+")")},f.apply=function(a,c){var d,e,g,h,i,j,k,l,m,n,o,p,q;f.checkValidOp(c),c=b(c),e={data:b(a)};try{for(i=0,o=c.length;i<o;i++){d=c[i],l=null,m=null,h=e,j="data",q=d.p;for(n=0,p=q.length;n<p;n++){k=q[n],l=h,m=j,h=h[j],j=k;if(l==null)throw new Error("Path invalid")}if(d.na!==void 0){if(typeof h[j]!="number")throw new Error("Referenced element not a number");h[j]+=d.na}else if(d.si!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string (it was "+JSON.stringify(h)+")");l[m]=h.slice(0,j)+d.si+h.slice(j)}else if(d.sd!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string");if(h.slice(j,j+d.sd.length)!==d.sd)throw new Error("Deleted string does not match");l[m]=h.slice(0,j)+h.slice(j+d.sd.length)}else if(d.li!==void 0&&d.ld!==void 0)f.checkList(h),h[j]=d.li;else if(d.li!==void 0)f.checkList(h),h.splice(j,0,d.li);else if(d.ld!==void 0)f.checkList(h),h.splice(j,1);else if(d.lm!==void 0)f.checkList(h),d.lm!==j&&(g=h[j],h.splice(j,1),h.splice(d.lm,0,g));else if(d.oi!==void 0)f.checkObj(h),h[j]=d.oi;else{if(d.od===void 0)throw new Error("invalid / missing instruction in op");f.checkObj(h),delete h[j]}}}catch(r){throw r}return e.data},f.pathMatches=function(a,b,c){var d,e,f;if(a.length!==b.length)return!1;for(d=0,f=a.length;d<f;d++){e=a[d];if(e!==b[d]&&(!c||d!==a.length-1))return!1}return!0},f.append=function(a,c){var d;return c=b(c),a.length!==0&&f.pathMatches(c.p,(d=a[a.length-1]).p)?d.na!==void 0&&c.na!==void 0?a[a.length-1]={p:d.p,na:d.na+c.na}:d.li!==void 0&&c.li===void 0&&c.ld===d.li?d.ld!==void 0?delete d.li:a.pop():d.od!==void 0&&d.oi===void 0&&c.oi!==void 0&&c.od===void 0?d.oi=c.oi:c.lm!==void 0&&c.p[c.p.length-1]===c.lm?null:a.push(c):a.push(c)},f.compose=function(a,c){var d,e,g,h;f.checkValidOp(a),f.checkValidOp(c),e=b(a);for(g=0,h=c.length;g<h;g++)d=c[g],f.append(e,d);return e},f.normalize=function(a){var b,c,d,g=[];e(a)||(a=[a]);for(c=0,d=a.length;c<d;c++)b=a[c],b.p==null&&(b.p=[]),f.append(g,b);return g},b=function(a){return JSON.parse(JSON.stringify(a))},f.commonPath=function(a,b){var c;a=a.slice(),b=b.slice(),a.unshift("data"),b.unshift("data"),a=a.slice(0,a.length-1),b=b.slice(0,b.length-1);if(b.length===0)return-1;c=0;while(a[c]===b[c]&&c<a.length){c++;if(c===b.length)return c-1}},f.transformComponent=function(a,c,d,e){var g,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;c=b(c),c.na!==void 0&&c.p.push(0),d.na!==void 0&&d.p.push(0),g=f.commonPath(c.p,d.p),i=f.commonPath(d.p,c.p),l=c.p.length,p=d.p.length,c.na!==void 0&&c.p.pop(),d.na!==void 0&&d.p.pop();if(d.na)return i!=null&&p>=l&&d.p[i]===c.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o]))),f.append(a,c),a;i!=null&&p>l&&c.p[i]===d.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o])));if(g!=null){j=l===p;if(d.na===void 0)if(d.si!==void 0||d.sd!==void 0){if(c.si!==void 0||c.sd!==void 0){if(!j)throw new Error("must be a string?");k=function(a){var b={p:a.p[a.p.length-1]};return a.si?b.i=a.si:b.d=a.sd,b},v=k(c),w=k(d),t=[],h._tc(t,v,w,e);for(y=0,z=t.length;y<z;y++)u=t[y],n={p:c.p.slice(0,g)},n.p.push(u.p),u.i!=null&&(n.si=u.i),u.d!=null&&(n.sd=u.d),f.append(a,n);return a}}else if(d.li!==void 0&&d.ld!==void 0){if(d.p[g]===c.p[g]){if(!j)return a;if(c.ld!==void 0){if(c.li===void 0||e!=="left")return a;c.ld=b(d.li)}}}else if(d.li!==void 0)c.li!==void 0&&c.ld===void 0&&j&&c.p[g]===d.p[g]?e==="right"&&c.p[g]++:d.p[g]<=c.p[g]&&c.p[g]++,c.lm!==void 0&&j&&d.p[g]<=c.lm&&c.lm++;else if(d.ld!==void 0){if(c.lm!==void 0&&j){if(d.p[g]===c.p[g])return a;s=d.p[g],m=c.p[g],x=c.lm,(s<x||s===x&&m<x)&&c.lm--}if(d.p[g]<c.p[g])c.p[g]--;else if(d.p[g]===c.p[g]){if(p<l)return a;if(c.ld!==void 0){if(c.li===void 0)return a;delete c.ld}}}else if(d.lm!==void 0)if(c.lm!==void 0&&l===p){m=c.p[g],x=c.lm,q=d.p[g],r=d.lm;if(q!==r)if(m===q){if(e!=="left")return a;c.p[g]=r,m===x&&(c.lm=r)}else m>q&&c.p[g]--,m>r?c.p[g]++:m===r&&q>r&&(c.p[g]++,m===x&&c.lm++),x>q?c.lm--:x===q&&x>m&&c.lm--,x>r?c.lm++:x===r&&(r>q&&x>m||r<q&&x<m?e==="right"&&c.lm++:x>m?c.lm++:x===q&&c.lm--)}else c.li!==void 0&&c.ld===void 0&&j?(m=d.p[g],x=d.lm,s=c.p[g],s>m&&c.p[g]--,s>x&&c.p[g]++):(m=d.p[g],x=d.lm,s=c.p[g],s===m?c.p[g]=x:(s>m&&c.p[g]--,s>x?c.p[g]++:s===x&&m>x&&c.p[g]++));else if(d.oi!==void 0&&d.od!==void 0){if(c.p[g]===d.p[g]){if(c.oi===void 0||!j)return a;if(e==="right")return a;c.od=d.oi}}else if(d.oi!==void 0){if(c.oi!==void 0&&c.p[g]===d.p[g]){if(e!=="left")return a;f.append(a,{p:c.p,od:d.oi})}}else if(d.od!==void 0&&c.p[g]===d.p[g]){if(!j)return a;if(c.oi===void 0)return a;delete c.od}}return f.append(a,c),a},typeof j!="undefined"&&j!==null?(l.types||(l.types={}),l._bt(f,f.transformComponent,f.checkValidOp,f.append),l.types.json=f):(module.exports=f,require("./helpers").bootstrapTransform(f,f.transformComponent,f.checkValidOp,f.append)),typeof j=="undefined"&&(f=require("./json")),typeof j!="undefined"&&j!==null&&(d=l.extendDoc,l.extendDoc=function(b,c){return a.prototype[b]=c,d(b,c)}),c=function(a){return a.length===1&&a[0].constructor===Array?a[0]:a},a=function(){function a(a,b){this.doc=a,this.path=b}return a.prototype.at=function(){var a=1<=arguments.length?k.call(arguments,0):[];return this.doc.at(this.path.concat(c(a)))},a.prototype.get=function(){return this.doc.getAt(this.path)},a.prototype.set=function(a,b){return this.doc.setAt(this.path,a,b)},a.prototype.insert=function(a,b,c){return this.doc.insertAt(this.path,a,b,c)},a.prototype.del=function(a,b,c){return this.doc.deleteTextAt(this.path,b,a,c)},a.prototype.remove=function(a){return this.doc.removeAt(this.path,a)},a.prototype.push=function(a,b){return this.insert(this.get().length,a,b)},a.prototype.move=function(a,b,c){return this.doc.moveAt(this.path,a,b,c)},a.prototype.add=function(a,b){return this.doc.addAt(this.path,a,b)},a.prototype.on=function(a,b){return this.doc.addListener(this.path,a,b)},a.prototype.removeListener=function(a){return this.doc.removeListener(a)},a.prototype.getLength=function(){return this.get().length},a.prototype.getText=function(){return this.get()},a}(),i=function(a,b){var c,d,e,f={data:a},g="data",h=f;for(d=0,e=b.length;d<e;d++){c=b[d],h=h[g],g=c;if(typeof h=="undefined")throw new Error("bad path")}return{elem:h,key:g}},g=function(a,b){var c,d,e;if(a.length!==b.length)return!1;for(d=0,e=a.length;d<e;d++){c=a[d];if(c!==b[d])return!1}return!0},f.api={provides:{json:!0},at:function(){var b=1<=arguments.length?k.call(arguments,0):[];return new a(this,c(b))},get:function(){return this.snapshot},set:function(a,b){return this.setAt([],a,b)},getAt:function(a){var b=i(this.snapshot,a),c=b.elem,d=b.key;return c[d]},setAt:function(a,b,c){var d=i(this.snapshot,a),e=d.elem,f=d.key,g={p:a};if(e.constructor===Array)g.li=b,typeof e[f]!="undefined"&&(g.ld=e[f]);else{if(typeof e!="object")throw new Error("bad path");g.oi=b,typeof e[f]!="undefined"&&(g.od=e[f])}return this.submitOp([g],c)},removeAt:function(a,b){var c,d=i(this.snapshot,a),e=d.elem,f=d.key;if(typeof e[f]=="undefined")throw new Error("no element at that path");c={p:a};if(e.constructor===Array)c.ld=e[f];else{if(typeof e!="object")throw new Error("bad path");c.od=e[f]}return this.submitOp([c],b)},insertAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h={p:a.concat(b)};return f[g].constructor===Array?h.li=c:typeof f[g]=="string"&&(h.si=c),this.submitOp([h],d)},moveAt:function(a,b,c,d){var e=[{p:a.concat(b),lm:c}];return this.submitOp(e,d)},addAt:function(a,b,c){var d=[{p:a,na:b}];return this.submitOp(d,c)},deleteTextAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h=[{p:a.concat(c),sd:f[g].slice(c,c+b)}];return this.submitOp(h,d)},addListener:function(a,b,c){var d={path:a,event:b,cb:c};return this._listeners.push(d),d},removeListener:function(a){var b=this._listeners.indexOf(a);return b<0?!1:(this._listeners.splice(b,1),!0)},_register:function(){return this._listeners=[],this.on("change",function(a){var b,c,d,e,f,g,h,i,j,k,l=[];for(h=0,i=a.length;h<i;h++){b=a[h];if(b.na!==void 0||b.si!==void 0||b.sd!==void 0)continue;f=[],k=this._listeners;for(d=0,j=k.length;d<j;d++){e=k[d],c={p:e.path,na:0},g=this.type.transformComponent([],c,b,"left");if(g.length===0)f.push(d);else{if(g.length!==1)throw new Error("Bad assumption in json-api: xforming an 'si' op will always result in 0 or 1 components.");e.path=g[0].p}}f.sort(function(a,b){return b-a}),l.push(function(){var a,b,c=[];for(a=0,b=f.length;a<b;a++)d=f[a],c.push(this._listeners.splice(d,1));return c}.call(this))}return l}),this.on("remoteop",function(a){var b,c,d,e,f,h,i,j,k,l=[];for(j=0,k=a.length;j<k;j++)b=a[j],h=b.na===void 0?b.p.slice(0,b.p.length-1):b.p,l.push(function(){var a,j,k,l,m=this._listeners,n=[];for(a=0,j=m.length;a<j;a++){k=m[a],i=k.path,f=k.event,c=k.cb;if(g(i,h))switch(f){case"insert":b.li!==void 0&&b.ld===void 0?n.push(c(b.p[b.p.length-1],b.li)):b.oi!==void 0&&b.od===void 0?n.push(c(b.p[b.p.length-1],b.oi)):b.si!==void 0?n.push(c(b.p[b.p.length-1],b.si)):n.push(void 0);break;case"delete":b.li===void 0&&b.ld!==void 0?n.push(c(b.p[b.p.length-1],b.ld)):b.oi===void 0&&b.od!==void 0?n.push(c(b.p[b.p.length-1],b.od)):b.sd!==void 0?n.push(c(b.p[b.p.length-1],b.sd)):n.push(void 0);break;case"replace":b.li!==void 0&&b.ld!==void 0?n.push(c(b.p[b.p.length-1],b.ld,b.li)):b.oi!==void 0&&b.od!==void 0?n.push(c(b.p[b.p.length-1],b.od,b.oi)):n.push(void 0);break;case"move":b.lm!==void 0?n.push(c(b.p[b.p.length-1],b.lm)):n.push(void 0);break;case"add":b.na!==void 0?n.push(c(b.na)):n.push(void 0);break;default:n.push(void 0)}else if((e=this.type.commonPath(h,i))!=null)if(f==="child op"){if(h.length===(l=i.length)&&l===e)throw new Error("paths match length and have commonality, but aren't equal?");d=b.p.slice(e+1),n.push(c(d,b))}else n.push(void 0);else n.push(void 0)}return n}.call(this));return l})}}})).call(this)
+(function(){var a,b,c,d,e,f,g,h,i,j=!0,k=Array.prototype.slice,l=window.sharejs;typeof j!="undefined"&&j!==null?h=l.types.text:h=require("./text"),f={},f.name="json",f.create=function(){return null},f.invertComponent=function(a){var b={p:a.p};return a.si!==void 0&&(b.sd=a.si),a.sd!==void 0&&(b.si=a.sd),a.oi!==void 0&&(b.od=a.oi),a.od!==void 0&&(b.oi=a.od),a.li!==void 0&&(b.ld=a.li),a.ld!==void 0&&(b.li=a.ld),a.na!==void 0&&(b.na=-a.na),a.lm!==void 0&&(b.lm=a.p[a.p.length-1],b.p=a.p.slice(0,a.p.length-1).concat([a.lm])),b},f.invert=function(a){var b,c,d,e=a.slice().reverse(),g=[];for(c=0,d=e.length;c<d;c++)b=e[c],g.push(f.invertComponent(b));return g},f.checkValidOp=function(){},e=function(a){return Object.prototype.toString.call(a)==="[object Array]"},f.checkList=function(a){if(!e(a))throw new Error("Referenced element not a list")},f.checkObj=function(a){if(a.constructor!==Object)throw new Error("Referenced element not an object (it was "+JSON.stringify(a)+")")},f.apply=function(a,c){var d,e,g,h,i,j,k,l,m,n,o,p,q;f.checkValidOp(c),c=b(c),e={data:b(a)};try{for(i=0,o=c.length;i<o;i++){d=c[i],l=null,m=null,h=e,j="data",q=d.p;for(n=0,p=q.length;n<p;n++){k=q[n],l=h,m=j,h=h[j],j=k;if(l==null)throw new Error("Path invalid")}if(d.na!==void 0){if(typeof h[j]!="number")throw new Error("Referenced element not a number");h[j]+=d.na}else if(d.si!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string (it was "+JSON.stringify(h)+")");l[m]=h.slice(0,j)+d.si+h.slice(j)}else if(d.sd!==void 0){if(typeof h!="string")throw new Error("Referenced element not a string");if(h.slice(j,j+d.sd.length)!==d.sd)throw new Error("Deleted string does not match");l[m]=h.slice(0,j)+h.slice(j+d.sd.length)}else if(d.li!==void 0&&d.ld!==void 0)f.checkList(h),h[j]=d.li;else if(d.li!==void 0)f.checkList(h),h.splice(j,0,d.li);else if(d.ld!==void 0)f.checkList(h),h.splice(j,1);else if(d.lm!==void 0)f.checkList(h),d.lm!==j&&(g=h[j],h.splice(j,1),h.splice(d.lm,0,g));else if(d.oi!==void 0)f.checkObj(h),h[j]=d.oi;else{if(d.od===void 0)throw new Error("invalid / missing instruction in op");f.checkObj(h),delete h[j]}}}catch(r){throw r}return e.data},f.pathMatches=function(a,b,c){var d,e,f;if(a.length!==b.length)return!1;for(d=0,f=a.length;d<f;d++){e=a[d];if(e!==b[d]&&(!c||d!==a.length-1))return!1}return!0},f.append=function(a,c){var d;return c=b(c),a.length!==0&&f.pathMatches(c.p,(d=a[a.length-1]).p)?d.na!==void 0&&c.na!==void 0?a[a.length-1]={p:d.p,na:d.na+c.na}:d.li!==void 0&&c.li===void 0&&c.ld===d.li?d.ld!==void 0?delete d.li:a.pop():d.od!==void 0&&d.oi===void 0&&c.oi!==void 0&&c.od===void 0?d.oi=c.oi:c.lm!==void 0&&c.p[c.p.length-1]===c.lm?null:a.push(c):a.push(c)},f.compose=function(a,c){var d,e,g,h;f.checkValidOp(a),f.checkValidOp(c),e=b(a);for(g=0,h=c.length;g<h;g++)d=c[g],f.append(e,d);return e},f.normalize=function(a){var b,c,d,g=[];e(a)||(a=[a]);for(c=0,d=a.length;c<d;c++)b=a[c],b.p==null&&(b.p=[]),f.append(g,b);return g},b=function(a){return JSON.parse(JSON.stringify(a))},f.commonPath=function(a,b){var c;a=a.slice(),b=b.slice(),a.unshift("data"),b.unshift("data"),a=a.slice(0,a.length-1),b=b.slice(0,b.length-1);if(b.length===0)return-1;c=0;while(a[c]===b[c]&&c<a.length){c++;if(c===b.length)return c-1}},f.transformComponent=function(a,c,d,e){var g,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;c=b(c),c.na!==void 0&&c.p.push(0),d.na!==void 0&&d.p.push(0),g=f.commonPath(c.p,d.p),i=f.commonPath(d.p,c.p),l=c.p.length,p=d.p.length,c.na!==void 0&&c.p.pop(),d.na!==void 0&&d.p.pop();if(d.na)return i!=null&&p>=l&&d.p[i]===c.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o]))),f.append(a,c),a;i!=null&&p>l&&c.p[i]===d.p[i]&&(c.ld!==void 0?(o=b(d),o.p=o.p.slice(l),c.ld=f.apply(b(c.ld),[o])):c.od!==void 0&&(o=b(d),o.p=o.p.slice(l),c.od=f.apply(b(c.od),[o])));if(g!=null){j=l===p;if(d.na===void 0)if(d.si!==void 0||d.sd!==void 0){if(c.si!==void 0||c.sd!==void 0){if(!j)throw new Error("must be a string?");k=function(a){var b={p:a.p[a.p.length-1]};return a.si?b.i=a.si:b.d=a.sd,b},v=k(c),w=k(d),t=[],h._tc(t,v,w,e);for(y=0,z=t.length;y<z;y++)u=t[y],n={p:c.p.slice(0,g)},n.p.push(u.p),u.i!=null&&(n.si=u.i),u.d!=null&&(n.sd=u.d),f.append(a,n);return a}}else if(d.li!==void 0&&d.ld!==void 0){if(d.p[g]===c.p[g]){if(!j)return a;if(c.ld!==void 0){if(c.li===void 0||e!=="left")return a;c.ld=b(d.li)}}}else if(d.li!==void 0)c.li!==void 0&&c.ld===void 0&&j&&c.p[g]===d.p[g]?e==="right"&&c.p[g]++:d.p[g]<=c.p[g]&&c.p[g]++,c.lm!==void 0&&j&&d.p[g]<=c.lm&&c.lm++;else if(d.ld!==void 0){if(c.lm!==void 0&&j){if(d.p[g]===c.p[g])return a;s=d.p[g],m=c.p[g],x=c.lm,(s<x||s===x&&m<x)&&c.lm--}if(d.p[g]<c.p[g])c.p[g]--;else if(d.p[g]===c.p[g]){if(p<l)return a;if(c.ld!==void 0){if(c.li===void 0)return a;delete c.ld}}}else if(d.lm!==void 0)if(c.lm!==void 0&&l===p){m=c.p[g],x=c.lm,q=d.p[g],r=d.lm;if(q!==r)if(m===q){if(e!=="left")return a;c.p[g]=r,m===x&&(c.lm=r)}else m>q&&c.p[g]--,m>r?c.p[g]++:m===r&&q>r&&(c.p[g]++,m===x&&c.lm++),x>q?c.lm--:x===q&&x>m&&c.lm--,x>r?c.lm++:x===r&&(r>q&&x>m||r<q&&x<m?e==="right"&&c.lm++:x>m?c.lm++:x===q&&c.lm--)}else c.li!==void 0&&c.ld===void 0&&j?(m=d.p[g],x=d.lm,s=c.p[g],s>m&&c.p[g]--,s>x&&c.p[g]++):(m=d.p[g],x=d.lm,s=c.p[g],s===m?c.p[g]=x:(s>m&&c.p[g]--,s>x?c.p[g]++:s===x&&m>x&&c.p[g]++));else if(d.oi!==void 0&&d.od!==void 0){if(c.p[g]===d.p[g]){if(c.oi===void 0||!j)return a;if(e==="right")return a;c.od=d.oi}}else if(d.oi!==void 0){if(c.oi!==void 0&&c.p[g]===d.p[g]){if(e!=="left")return a;f.append(a,{p:c.p,od:d.oi})}}else if(d.od!==void 0&&c.p[g]===d.p[g]){if(!j)return a;if(c.oi===void 0)return a;delete c.od}}return f.append(a,c),a},typeof j!="undefined"&&j!==null?(l.types||(l.types={}),l._bt(f,f.transformComponent,f.checkValidOp,f.append),l.types.json=f):(module.exports=f,require("./helpers").bootstrapTransform(f,f.transformComponent,f.checkValidOp,f.append)),typeof j=="undefined"&&(f=require("./json")),typeof j!="undefined"&&j!==null&&(d=l.extendDoc,l.extendDoc=function(b,c){return a.prototype[b]=c,d(b,c)}),c=function(a){return a.length===1&&a[0].constructor===Array?a[0]:a},a=function(){function a(a,b){this.doc=a,this.path=b}return a.prototype.at=function(){var a=1<=arguments.length?k.call(arguments,0):[];return this.doc.at(this.path.concat(c(a)))},a.prototype.get=function(){return this.doc.getAt(this.path)},a.prototype.set=function(a,b){return this.doc.setAt(this.path,a,b)},a.prototype.insert=function(a,b,c){return this.doc.insertAt(this.path,a,b,c)},a.prototype.del=function(a,b,c){return this.doc.deleteTextAt(this.path,b,a,c)},a.prototype.remove=function(a){return this.doc.removeAt(this.path,a)},a.prototype.push=function(a,b){return this.insert(this.get().length,a,b)},a.prototype.move=function(a,b,c){return this.doc.moveAt(this.path,a,b,c)},a.prototype.add=function(a,b){return this.doc.addAt(this.path,a,b)},a.prototype.on=function(a,b){return this.doc.addListener(this.path,a,b)},a.prototype.removeListener=function(a){return this.doc.removeListener(a)},a.prototype.getLength=function(){return this.get().length},a.prototype.getText=function(){return this.get()},a}(),i=function(a,b){var c,d,e,f={data:a},g="data",h=f;for(d=0,e=b.length;d<e;d++){c=b[d],h=h[g],g=c;if(typeof h=="undefined")throw new Error("bad path")}return{elem:h,key:g}},g=function(a,b){var c,d,e;if(a.length!==b.length)return!1;for(d=0,e=a.length;d<e;d++){c=a[d];if(c!==b[d])return!1}return!0},f.api={provides:{json:!0},at:function(){var b=1<=arguments.length?k.call(arguments,0):[];return new a(this,c(b))},get:function(){return this.snapshot},set:function(a,b){return this.setAt([],a,b)},getAt:function(a){var b=i(this.snapshot,a),c=b.elem,d=b.key;return c[d]},setAt:function(a,b,c){var d=i(this.snapshot,a),e=d.elem,f=d.key,g={p:a};if(e.constructor===Array)g.li=b,typeof e[f]!="undefined"&&(g.ld=e[f]);else{if(typeof e!="object")throw new Error("bad path");g.oi=b,typeof e[f]!="undefined"&&(g.od=e[f])}return this.submitOp([g],c)},removeAt:function(a,b){var c,d=i(this.snapshot,a),e=d.elem,f=d.key;if(typeof e[f]=="undefined")throw new Error("no element at that path");c={p:a};if(e.constructor===Array)c.ld=e[f];else{if(typeof e!="object")throw new Error("bad path");c.od=e[f]}return this.submitOp([c],b)},insertAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h={p:a.concat(b)};return f[g].constructor===Array?h.li=c:typeof f[g]=="string"&&(h.si=c),this.submitOp([h],d)},moveAt:function(a,b,c,d){var e=[{p:a.concat(b),lm:c}];return this.submitOp(e,d)},addAt:function(a,b,c){var d=[{p:a,na:b}];return this.submitOp(d,c)},deleteTextAt:function(a,b,c,d){var e=i(this.snapshot,a),f=e.elem,g=e.key,h=[{p:a.concat(c),sd:f[g].slice(c,c+b)}];return this.submitOp(h,d)},addListener:function(a,b,c){var d={path:a,event:b,cb:c};return this._listeners.push(d),d},removeListener:function(a){var b=this._listeners.indexOf(a);return b<0?!1:(this._listeners.splice(b,1),!0)},_register:function(){return this._listeners=[],this.on("change",function(a){var b,c,d,e,f,g,h,i,j,k,l=[];for(h=0,i=a.length;h<i;h++){b=a[h];if(b.na!==void 0||b.si!==void 0||b.sd!==void 0)continue;f=[],k=this._listeners;for(d=0,j=k.length;d<j;d++){e=k[d],c={p:e.path,na:0},g=this.type.transformComponent([],c,b,"left");if(g.length===0)f.push(d);else{if(g.length!==1)throw new Error("Bad assumption in json-api: xforming an 'si' op will always result in 0 or 1 components.");e.path=g[0].p}}f.sort(function(a,b){return b-a}),l.push(function(){var a,b,c=[];for(a=0,b=f.length;a<b;a++)d=f[a],c.push(this._listeners.splice(d,1));return c}.call(this))}return l}),this.on("remoteop",function(a){var b,c,d,e,f,h,i,j,k,l=[];for(j=0,k=a.length;j<k;j++)b=a[j],h=b.na===void 0?b.p.slice(0,b.p.length-1):b.p,l.push(function(){var a,j,k,l,m=this._listeners,n=[];for(a=0,j=m.length;a<j;a++){k=m[a],i=k.path,f=k.event,c=k.cb;if(g(i,h))switch(f){case"insert":b.li!==void 0&&b.ld===void 0?n.push(c(b.p[b.p.length-1],b.li)):b.oi!==void 0&&b.od===void 0?n.push(c(b.p[b.p.length-1],b.oi)):b.si!==void 0?n.push(c(b.p[b.p.length-1],b.si)):n.push(void 0);break;case"delete":b.li===void 0&&b.ld!==void 0?n.push(c(b.p[b.p.length-1],b.ld)):b.oi===void 0&&b.od!==void 0?n.push(c(b.p[b.p.length-1],b.od)):b.sd!==void 0?n.push(c(b.p[b.p.length-1],b.sd)):n.push(void 0);break;case"replace":b.li!==void 0&&b.ld!==void 0?n.push(c(b.p[b.p.length-1],b.ld,b.li)):b.oi!==void 0&&b.od!==void 0?n.push(c(b.p[b.p.length-1],b.od,b.oi)):n.push(void 0);break;case"move":b.lm!==void 0?n.push(c(b.p[b.p.length-1],b.lm)):n.push(void 0);break;case"add":b.na!==void 0?n.push(c(b.na)):n.push(void 0);break;default:n.push(void 0)}else if((e=this.type.commonPath(h,i))!=null)if(f==="child op"){if(h.length===(l=i.length)&&l===e)throw new Error("paths match length and have commonality, but aren't equal?");d=b.p.slice(e+1),n.push(c(d,b))}else n.push(void 0);else n.push(void 0)}return n}.call(this));return l})}}}).call(this)
206 webclient/share-ace.js
View
@@ -1,114 +1,114 @@
(function() {
- var Range, applyToShareJS;
- Range = require("ace/range").Range;
-
- applyToShareJS = function(editorDoc, delta, doc) {
- var getStartOffsetPosition, pos, text;
- getStartOffsetPosition = function(range) {
- var i, line, lines, offset, _len;
- lines = editorDoc.getLines(0, range.start.row);
- offset = 0;
- for (i = 0, _len = lines.length; i < _len; i++) {
- line = lines[i];
- offset += i < range.start.row ? line.length : range.start.column;
- }
- return offset + range.start.row;
- };
- pos = getStartOffsetPosition(delta.range);
- switch (delta.action) {
- case 'insertText':
- doc.insert(pos, delta.text);
- break;
- case 'removeText':
- doc.del(pos, delta.text.length);
- break;
- case 'insertLines':
- text = delta.lines.join('\n') + '\n';
- doc.insert(pos, text);
- break;
- case 'removeLines':
- text = delta.lines.join('\n') + '\n';
- doc.del(pos, text.length);
- break;
- default:
- throw new Error("unknown action: " + delta.action);
- }
- };
-
- window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
- var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
- if (!this.provides['text']) {
- throw new Error('Only text documents can be attached to ace');
- }
- doc = this;
- editorDoc = editor.getSession().getDocument();
- editorDoc.setNewLineMode('unix');
- check = function() {
- return window.setTimeout(function() {
- var editorText, otText;
- editorText = editorDoc.getValue();
- otText = doc.getText();
- if (editorText !== otText) {
- console.error("Text does not match!");
- console.error("editor: " + editorText);
- return console.error("ot: " + otText);
+ define("ace/range", function() {
+ var Range, applyToShareJS;
+ Range = require("ace/range").Range;
+ applyToShareJS = function(editorDoc, delta, doc) {
+ var getStartOffsetPosition, pos, text;
+ getStartOffsetPosition = function(range) {
+ var i, line, lines, offset, _len;
+ lines = editorDoc.getLines(0, range.start.row);
+ offset = 0;
+ for (i = 0, _len = lines.length; i < _len; i++) {
+ line = lines[i];
+ offset += i < range.start.row ? line.length : range.start.column;
}
- }, 0);
- };
- if (keepEditorContents) {
- doc.del(0, doc.getText().length);
- doc.insert(0, editorDoc.getValue());
- } else {
- editorDoc.setValue(doc.getText());
- }
- check();
- suppress = false;
- editorListener = function(change) {
- if (suppress) return;
- applyToShareJS(editorDoc, change.data, doc);
- return check();
- };
- editorDoc.on('change', editorListener);
- docListener = function(op) {
- suppress = true;
- applyToDoc(editorDoc, op);
- suppress = false;
- return check();
+ return offset + range.start.row;
+ };
+ pos = getStartOffsetPosition(delta.range);
+ switch (delta.action) {
+ case 'insertText':
+ doc.insert(pos, delta.text);
+ break;
+ case 'removeText':
+ doc.del(pos, delta.text.length);
+ break;
+ case 'insertLines':
+ text = delta.lines.join('\n') + '\n';
+ doc.insert(pos, text);
+ break;
+ case 'removeLines':
+ text = delta.lines.join('\n') + '\n';
+ doc.del(pos, text.length);
+ break;
+ default:
+ throw new Error("unknown action: " + delta.action);
+ }
};
- offsetToPos = function(offset) {
- var line, lines, row, _len;
- lines = editorDoc.getAllLines();
- row = 0;
- for (row = 0, _len = lines.length; row < _len; row++) {
- line = lines[row];
- if (offset <= line.length) break;
- offset -= lines[row].length + 1;
+ return window.sharejs.extendDoc('attach_ace', function(editor, keepEditorContents) {
+ var check, doc, docListener, editorDoc, editorListener, offsetToPos, suppress;
+ if (!this.provides['text']) {
+ throw new Error('Only text documents can be attached to ace');
}
- return {
- row: row,
- column: offset
+ doc = this;
+ editorDoc = editor.getSession().getDocument();
+ editorDoc.setNewLineMode('unix');
+ check = function() {
+ return window.setTimeout(function() {
+ var editorText, otText;
+ editorText = editorDoc.getValue();
+ otText = doc.getText();
+ if (editorText !== otText) {
+ console.error("Text does not match!");
+ console.error("editor: " + editorText);
+ return console.error("ot: " + otText);
+ }
+ }, 0);
};
- };
- doc.on('insert', function(pos, text) {
- suppress = true;
- editorDoc.insert(offsetToPos(pos), text);
- suppress = false;
- return check();
- });
- doc.on('delete', function(pos, text) {
- var range;
- suppress = true;
- range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
- editorDoc.remove(range);
+ if (keepEditorContents) {
+ doc.del(0, doc.getText().length);
+ doc.insert(0, editorDoc.getValue());
+ } else {
+ editorDoc.setValue(doc.getText());
+ }
+ check();
suppress = false;
- return check();
+ editorListener = function(change) {
+ if (suppress) return;
+ applyToShareJS(editorDoc, change.data, doc);
+ return check();
+ };
+ editorDoc.on('change', editorListener);
+ docListener = function(op) {
+ suppress = true;
+ applyToDoc(editorDoc, op);
+ suppress = false;
+ return check();
+ };
+ offsetToPos = function(offset) {
+ var line, lines, row, _len;
+ lines = editorDoc.getAllLines();
+ row = 0;
+ for (row = 0, _len = lines.length; row < _len; row++) {
+ line = lines[row];
+ if (offset <= line.length) break;
+ offset -= lines[row].length + 1;
+ }
+ return {
+ row: row,
+ column: offset
+ };
+ };
+ doc.on('insert', function(pos, text) {
+ suppress = true;
+ editorDoc.insert(offsetToPos(pos), text);
+ suppress = false;
+ return check();
+ });
+ doc.on('delete', function(pos, text) {
+ var range;
+ suppress = true;
+ range = Range.fromPoints(offsetToPos(pos), offsetToPos(pos + text.length));
+ editorDoc.remove(range);
+ suppress = false;
+ return check();
+ });
+ doc.detach_ace = function() {
+ doc.removeListener('remoteop', docListener);
+ editorDoc.removeListener('change', editorListener);
+ return delete doc.detach_ace;
+ };
});
- doc.detach_ace = function() {
- doc.removeListener('remoteop', docListener);
- editorDoc.removeListener('change', editorListener);
- return delete doc.detach_ace;
- };
});
}).call(this);
2  webclient/share.js
View
@@ -1 +1 @@
-((function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=Array.prototype.slice,r=function(a,b){return function(){return a.apply(b,arguments)}},s=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};window.sharejs=i={version:"0.5.0-pre"},k=function(a){return setTimeout(a,0)},d=function(){function a(){}return a.prototype.on=function(a,b){var c;return this._events||(this._events={}),(c=this._events)[a]||(c[a]=[]),this._events[a].push(b),this},a.prototype.removeListener=function(a,b){var c,d,e,f=this;this._events||(this._events={}),d=(e=this._events)[a]||(e[a]=[]),c=0;while(c<d.length)d[c]===b&&(d[c]=void 0),c++;return k(function(){var b;return f._events[a]=function(){var c,d,e=this._events[a],f=[];for(c=0,d=e.length;c<d;c++)b=e[c],b&&f.push(b);return f}.call(f)}),this},a.prototype.emit=function(){var a,b,c,d,e,f=arguments[0],g=2<=arguments.length?q.call(arguments,1):[];if((d=this._events)!=null?!d[f]:!void 0)return this;e=this._events[f];for(b=0,c=e.length;b<c;b++)a=e[b],a&&a.apply(this,g);return this},a}(),d.mixin=function(a){var b=a.prototype||a;return b.on=d.prototype.on,b.removeListener=d.prototype.removeListener,b.emit=d.prototype.emit,a},i._bt=f=function(a,b,c,d){var e,f=function(a,c,d,e){return b(d,a,c,"left"),b(e,c,a,"right")};return a.transformX=a.transformX=e=function(a,b){var g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;c(a),c(b),k=[];for(p=0,t=b.length;p<t;p++){o=b[p],j=[],g=0;while(g<a.length){l=[],f(a[g],o,j,l),g++;if(l.length!==1){if(l.length===0){x=a.slice(g);for(q=0,u=x.length;q<u;q++)h=x[q],d(j,h);o=null;break}y=e(a.slice(g),l),i=y[0],n=y[1];for(r=0,v=i.length;r<v;r++)h=i[r],d(j,h);for(s=0,w=n.length;s<w;s++)m=n[s],d(k,m);o=null;break}o=l[0]}o!=null&&d(k,o),a=j}return[a,k]},a.transform=a.transform=function(a,c,d){var f,g,h,i,j;if(d!=="left"&&d!=="right")throw new Error("type must be 'left' or 'right'");return c.length===0?a:a.length===1&&c.length===1?b([],a[0],c[0],d):d==="left"?(i=e(a,c),f=i[0],h=i[1],f):(j=e(c,a),h=j[0],g=j[1],g)}},m={},m.name="text",m.create=function(){return""},l=function(a,b,c){return a.slice(0,b)+c+a.slice(b)},g=function(a){var b,c;if(typeof a.p!="number")throw new Error("component missing position field");c=typeof a.i,b=typeof a.d;if(!(c==="string"^b==="string"))throw new Error("component needs an i or d field");if(!(a.p>=0))throw new Error("position cannot be negative")},h=function(a){var b,c,d;for(c=0,d=a.length;c<d;c++)b=a[c],g(b);return!0},m.apply=function(a,b){var c,d,e,f;h(b);for(e=0,f=b.length;e<f;e++){c=b[e];if(c.i!=null)a=l(a,c.p,c.i);else{d=a.slice(c.p,c.p+c.d.length);if(c.d!==d)throw new Error("Delete component '"+c.d+"' does not match deleted text '"+d+"'");a=a.slice(0,c.p)+a.slice(c.p+c.d.length)}}return a},m._append=e=function(a,b){var c,d,e;if(b.i===""||b.d==="")return;return a.length===0?a.push(b):(c=a[a.length-1],c.i!=null&&b.i!=null&&c.p<=(d=b.p)&&d<=c.p+c.i.length?a[a.length-1]={i:l(c.i,b.p-c.p,b.i),p:c.p}:c.d!=null&&b.d!=null&&b.p<=(e=c.p)&&e<=b.p+b.d.length?a[a.length-1]={d:l(b.d,c.p-b.p,c.d),p:b.p}:a.push(b))},m.compose=function(a,b){var c,d,f,g;h(a),h(b),d=a.slice();for(f=0,g=b.length;f<g;f++)c=b[f],e(d,c);return d},m.compress=function(a){return m.compose([],a)},m.normalize=function(a){var b,c,d,f=[];if(a.i!=null||a.p!=null)a=[a];for(c=0,d=a.length;c<d;c++)b=a[c],b.p==null&&(b.p=0),e(f,b);return f},o=function(a,b,c){return b.i!=null?b.p<a||b.p===a&&c?a+b.i.length:a:a<=b.p?a:a<=b.p+b.d.length?b.p:a-b.d.length},m.transformCursor=function(a,b,c){var d,e,f;for(e=0,f=b.length;e<f;e++)d=b[e],a=o(a,d,c);return a},m._tc=n=function(a,b,c,d){var f,g,i,j,k,l;h([b]),h([c]);if(b.i!=null)e(a,{i:b.i,p:o(b.p,c,d==="right")});else if(c.i!=null)l=b.d,b.p<c.p&&(e(a,{d:l.slice(0,c.p-b.p),p:b.p}),l=l.slice(c.p-b.p)),l!==""&&e(a,{d:l,p:b.p+c.i.length});else if(b.p>=c.p+c.d.length)e(a,{d:b.d,p:b.p-c.d.length});else if(b.p+b.d.length<=c.p)e(a,b);else{j={d:"",p:b.p},b.p<c.p&&(j.d=b.d.slice(0,c.p-b.p)),b.p+b.d.length>c.p+c.d.length&&(j.d+=b.d.slice(c.p+c.d.length-b.p)),i=Math.max(b.p,c.p),g=Math.min(b.p+b.d.length,c.p+c.d.length),f=b.d.slice(i-b.p,g-b.p),k=c.d.slice(i-c.p,g-c.p);if(f!==k)throw new Error("Delete ops delete different text in the same region of the document");j.d!==""&&(j.p=o(j.p,c),e(a,j))}return a},j=function(a){return a.i!=null?{d:a.i,p:a.p}:{i:a.d,p:a.p}},m.invert=function(a){var b,c,d,e=a.slice().reverse(),f=[];for(c=0,d=e.length;c<d;c++)b=e[c],f.push(j(b));return f},i.types||(i.types={}),f(m,n,h,e),i.types.text=m,m.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(a,b,c){var d=[{p:a,i:b}];return this.submitOp(d,c),d},del:function(a,b,c){var d=[{p:a,d:this.snapshot.slice(a,a+b)}];return this.submitOp(d,c),d},_register:function(){return this.on("remoteop",function(a){var b,c,d,e=[];for(c=0,d=a.length;c<d;c++)b=a[c],b.i!==void 0?e.push(this.emit("insert",b.p,b.i)):e.push(this.emit("delete",b.p,b.d));return e})}},i.extendDoc=function(a,b){return c.prototype[a]=b},c=function(){function a(a,b,c){this.connection=a,this.name=b,this.shout=r(this.shout,this),this.flush=r(this.flush,this),c||(c={}),this.version=c.v,this.snapshot=c.snaphot,c.type&&this._setType(c.type),this.state="closed",this.autoOpen=!1,this._create=c.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return a.prototype._xf=function(a,b){var c,d;return this.type.transformX?this.type.transformX(a,b):(c=this.type.transform(a,b,"left"),d=this.type.transform(b,a,"right"),[c,d])},a.prototype._otApply=function(a,b){var c=this.snapshot;this.snapshot=this.type.apply(this.snapshot,a),this.emit("change",a,c);if(b)return this.emit("remoteop",a,c)},a.prototype._connectionStateChanged=function(a,b){switch(a){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(b)}return this.emit(a,b)},a.prototype._setType=function(a){var b,c,d;typeof a=="string"&&(a=p[a]);if(!a||!a.compose)throw new Error("Support for types without compose() is not implemented");this.type=a;if(a.api){d=a.api;for(b in d)c=d[b],this[b]=c;return typeof this._register=="function"?this._register():void 0}return this.provides={}},a.prototype._onMessage=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,v;if(a.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!a.create),a.type&&this._setType(a.type),a.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),a.snapshot!==void 0&&(this.snapshot=a.snapshot)),a.v!=null&&(this.version=a.v),this.inflightOp?(h={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(h.dupIfSource=this.inflightSubmittedIds),this.connection.send(h)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(a.open===!1)return a.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+a.error),this.emit("error",a.error),typeof this._openCallback=="function"&&this._openCallback(a.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(a.op!==null||d!=="Op already submitted"){if(a.op===void 0&&a.v!==void 0||a.op&&(o=a.meta.source,s.call(this.inflightSubmittedIds,o)>=0)){e=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,d=a.error;if(d){this.type.invert?(i=this.type.invert(e),this.pendingOp&&(p=this._xf(this.pendingOp,i),this.pendingOp=p[0],i=p[1]),this._otApply(i,!0)):this.emit("error","Op apply failed ("+d+") and the op could not be reverted"),q=this.inflightCallbacks;for(k=0,m=q.length;k<m;k++)b=q[k],b(d)}else{if(a.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=e,this.version++,r=this.inflightCallbacks;for(l=0,n=r.length;l<n;l++)b=r[l],b(null,e)}return this.flush()}if(a.op){if(a.v<this.version)return;return a.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+a.doc):a.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+a.v):(f=a.op,this.serverOps[this.version]=f,c=f,this.inflightOp!==null&&(t=this._xf(this.inflightOp,c),this.inflightOp=t[0],c=t[1]),this.pendingOp!==null&&(u=this._xf(this.pendingOp,c),this.pendingOp=u[0],c=u[1]),this.version++,this._otApply(c,!0))}if(!a.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",a):void 0;v=a.meta,g=v.path,j=v.value;switch(g!=null?g[0]:void 0){case"shout":return this.emit("shout",j);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",a):void 0}}},a.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},a.prototype.submitOp=function(a,b){return this.type.normalize!=null&&(a=this.type.normalize(a)),this.snapshot=this.type.apply(this.snapshot,a),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,a):this.pendingOp=a,b&&this.pendingCallbacks.push(b),this.emit("change",a),setTimeout(this.flush,0)},a.prototype.shout=function(a){return this.connection.send({doc:this.name,meta:{path:["shout"],value:a}})},a.prototype.open=function(a){var b,c=this;this.autoOpen=!0;if(this.state!=="closed")return;return b={doc:this.name,open:!0},this.snapshot===void 0&&(b.snapshot=null),this.type&&(b.type=this.type.name),this.version!=null&&(b.v=this.version),this._create&&(b.create=!0),this.connection.send(b),this.state="opening",this._openCallback=function(b){return c._openCallback=null,typeof a=="function"?a(b):void 0}},a.prototype.close=function(a){return this.autoOpen=!1,this.state==="closed"?typeof a=="function"?a():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=a)},a}(),d.mixin(c),i.Doc=c,p||(p=i.types);if(!window.BCSocket)throw new Error("Must load browserchannel before this library");a=window.BCSocket,b=function(){function b(b){var c=this;this.docs={},this.state="connecting",this.socket=new a(b,{reconnect:!0}),this.socket.onmessage=function(a){var b;if(a.auth===null)return c.lastError=a.error,c.disconnect(),c.emit("connect failed",a.error);if(a.auth){c.id=a.auth,c.setState("ok");return}return b=a.doc,b!==void 0?c.lastReceivedDoc=b:a.doc=b=c.lastReceivedDoc,c.docs[b]?c.docs[b]._onMessage(a):typeof console!="undefined"&&console!==null?console.error("Unhandled message",a):void 0},this.connected=!1,this.socket.onclose=function(a){c.setState("disconnected",a);if(a==="Closed"||a==="Stopped by server")return c.setState("stopped",c.lastError||a)},this.socket.onerror=function(a){return c.emit("error",a)},this.socket.onopen=function(){return c.lastError=c.lastReceivedDoc=c.lastSentDoc=null,c.setState("handshaking")},this.socket.onconnecting=function(){return c.setState("connecting")}}return b.prototype.setState=function(a,b){var c,d,e,f;if(this.state===a)return;this.state=a,a==="disconnected"&&delete this.id,this.emit(a,b),e=this.docs,f=[];for(d in e)c=e[d],f.push(c._connectionStateChanged(a,b));return f},b.prototype.send=function(a){var b=a.doc;return b===this.lastSentDoc?delete a.doc:this.lastSentDoc=b,this.socket.send(a)},b.prototype.disconnect=function(){return this.socket.close()},b.prototype.makeDoc=function(a,b,d){var e,f=this;if(this.docs[a])throw new Error("Doc "+a+" already open");return e=new c(this,a,b),this.docs[a]=e,e.open(function(b){return b&&delete f.docs[a],d(b,b?void 0:e)})},b.prototype.openExisting=function(a,b){var c;return this.state==="stopped"?b("connection closed"):this.docs[a]?b(null,this.docs[a]):c=this.makeDoc(a,{},b)},b.prototype.open=function(a,b,c){var d;if(this.state==="stopped")return c("connection closed");typeof b=="function"&&(c=b,b="text"),c||(c=function(){}),typeof b=="string"&&(b=p[b]);if(!b)throw new Error("OT code for document type missing");if(a==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[a]){d=this.docs[a],d.type===b?c(null,d):c("Type mismatch",d);return}return this.makeDoc(a,{create:!0,type:b.name},c)},b}(),d.mixin(b),i.Connection=b,i.open=function(){var a={},c=function(c){var d,e,f;return f=window.location,c==null&&(c=""+f.protocol+"//"+f.host+"/channel"),a[c]||(d=new b(c),e=function(){return delete a[c]},d.on("disconnecting",e),d.on("connect failed",e),a[c]=d),a[c]},d=function(a){var b,c,d=0,e=a.docs;for(c in e)b=e[c],(b.state!=="closed"||b.autoOpen)&&d++;if(d===0)return a.disconnect()};return function(a,b,e,f){var g;return typeof e=="function"&&(f=e,e=null),g=c(e),g.numDocs++,g.open(a,b,function(a,b){return a?(f(a),d(g)):(b.on("closed",function(){return d(g)}),f(null,b))}),g.on("connect failed"),g}}()})).call(this)
+(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=Array.prototype.slice,r=function(a,b){return function(){return a.apply(b,arguments)}},s=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};window.sharejs=i={version:"0.5.0-pre"},k=function(a){return setTimeout(a,0)},d=function(){function a(){}return a.prototype.on=function(a,b){var c;return this._events||(this._events={}),(c=this._events)[a]||(c[a]=[]),this._events[a].push(b),this},a.prototype.removeListener=function(a,b){var c,d,e,f=this;this._events||(this._events={}),d=(e=this._events)[a]||(e[a]=[]),c=0;while(c<d.length)d[c]===b&&(d[c]=void 0),c++;return k(function(){var b;return f._events[a]=function(){var c,d,e=this._events[a],f=[];for(c=0,d=e.length;c<d;c++)b=e[c],b&&f.push(b);return f}.call(f)}),this},a.prototype.emit=function(){var a,b,c,d,e,f=arguments[0],g=2<=arguments.length?q.call(arguments,1):[];if((d=this._events)!=null?!d[f]:!void 0)return this;e=this._events[f];for(b=0,c=e.length;b<c;b++)a=e[b],a&&a.apply(this,g);return this},a}(),d.mixin=function(a){var b=a.prototype||a;return b.on=d.prototype.on,b.removeListener=d.prototype.removeListener,b.emit=d.prototype.emit,a},i._bt=f=function(a,b,c,d){var e,f=function(a,c,d,e){return b(d,a,c,"left"),b(e,c,a,"right")};return a.transformX=a.transformX=e=function(a,b){var g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;c(a),c(b),k=[];for(p=0,t=b.length;p<t;p++){o=b[p],j=[],g=0;while(g<a.length){l=[],f(a[g],o,j,l),g++;if(l.length!==1){if(l.length===0){x=a.slice(g);for(q=0,u=x.length;q<u;q++)h=x[q],d(j,h);o=null;break}y=e(a.slice(g),l),i=y[0],n=y[1];for(r=0,v=i.length;r<v;r++)h=i[r],d(j,h);for(s=0,w=n.length;s<w;s++)m=n[s],d(k,m);o=null;break}o=l[0]}o!=null&&d(k,o),a=j}return[a,k]},a.transform=a.transform=function(a,c,d){var f,g,h,i,j;if(d!=="left"&&d!=="right")throw new Error("type must be 'left' or 'right'");return c.length===0?a:a.length===1&&c.length===1?b([],a[0],c[0],d):d==="left"?(i=e(a,c),f=i[0],h=i[1],f):(j=e(c,a),h=j[0],g=j[1],g)}},m={},m.name="text",m.create=function(){return""},l=function(a,b,c){return a.slice(0,b)+c+a.slice(b)},g=function(a){var b,c;if(typeof a.p!="number")throw new Error("component missing position field");c=typeof a.i,b=typeof a.d;if(!(c==="string"^b==="string"))throw new Error("component needs an i or d field");if(!(a.p>=0))throw new Error("position cannot be negative")},h=function(a){var b,c,d;for(c=0,d=a.length;c<d;c++)b=a[c],g(b);return!0},m.apply=function(a,b){var c,d,e,f;h(b);for(e=0,f=b.length;e<f;e++){c=b[e];if(c.i!=null)a=l(a,c.p,c.i);else{d=a.slice(c.p,c.p+c.d.length);if(c.d!==d)throw new Error("Delete component '"+c.d+"' does not match deleted text '"+d+"'");a=a.slice(0,c.p)+a.slice(c.p+c.d.length)}}return a},m._append=e=function(a,b){var c,d,e;if(b.i===""||b.d==="")return;return a.length===0?a.push(b):(c=a[a.length-1],c.i!=null&&b.i!=null&&c.p<=(d=b.p)&&d<=c.p+c.i.length?a[a.length-1]={i:l(c.i,b.p-c.p,b.i),p:c.p}:c.d!=null&&b.d!=null&&b.p<=(e=c.p)&&e<=b.p+b.d.length?a[a.length-1]={d:l(b.d,c.p-b.p,c.d),p:b.p}:a.push(b))},m.compose=function(a,b){var c,d,f,g;h(a),h(b),d=a.slice();for(f=0,g=b.length;f<g;f++)c=b[f],e(d,c);return d},m.compress=function(a){return m.compose([],a)},m.normalize=function(a){var b,c,d,f=[];if(a.i!=null||a.p!=null)a=[a];for(c=0,d=a.length;c<d;c++)b=a[c],b.p==null&&(b.p=0),e(f,b);return f},o=function(a,b,c){return b.i!=null?b.p<a||b.p===a&&c?a+b.i.length:a:a<=b.p?a:a<=b.p+b.d.length?b.p:a-b.d.length},m.transformCursor=function(a,b,c){var d,e,f;for(e=0,f=b.length;e<f;e++)d=b[e],a=o(a,d,c);return a},m._tc=n=function(a,b,c,d){var f,g,i,j,k,l;h([b]),h([c]);if(b.i!=null)e(a,{i:b.i,p:o(b.p,c,d==="right")});else if(c.i!=null)l=b.d,b.p<c.p&&(e(a,{d:l.slice(0,c.p-b.p),p:b.p}),l=l.slice(c.p-b.p)),l!==""&&e(a,{d:l,p:b.p+c.i.length});else if(b.p>=c.p+c.d.length)e(a,{d:b.d,p:b.p-c.d.length});else if(b.p+b.d.length<=c.p)e(a,b);else{j={d:"",p:b.p},b.p<c.p&&(j.d=b.d.slice(0,c.p-b.p)),b.p+b.d.length>c.p+c.d.length&&(j.d+=b.d.slice(c.p+c.d.length-b.p)),i=Math.max(b.p,c.p),g=Math.min(b.p+b.d.length,c.p+c.d.length),f=b.d.slice(i-b.p,g-b.p),k=c.d.slice(i-c.p,g-c.p);if(f!==k)throw new Error("Delete ops delete different text in the same region of the document");j.d!==""&&(j.p=o(j.p,c),e(a,j))}return a},j=function(a){return a.i!=null?{d:a.i,p:a.p}:{i:a.d,p:a.p}},m.invert=function(a){var b,c,d,e=a.slice().reverse(),f=[];for(c=0,d=e.length;c<d;c++)b=e[c],f.push(j(b));return f},i.types||(i.types={}),f(m,n,h,e),i.types.text=m,m.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(a,b,c){var d=[{p:a,i:b}];return this.submitOp(d,c),d},del:function(a,b,c){var d=[{p:a,d:this.snapshot.slice(a,a+b)}];return this.submitOp(d,c),d},_register:function(){return this.on("remoteop",function(a){var b,c,d,e=[];for(c=0,d=a.length;c<d;c++)b=a[c],b.i!==void 0?e.push(this.emit("insert",b.p,b.i)):e.push(this.emit("delete",b.p,b.d));return e})}},i.extendDoc=function(a,b){return c.prototype[a]=b},c=function(){function a(a,b,c){this.connection=a,this.name=b,this.shout=r(this.shout,this),this.flush=r(this.flush,this),c||(c={}),this.version=c.v,this.snapshot=c.snaphot,c.type&&this._setType(c.type),this.state="closed",this.autoOpen=!1,this._create=c.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return a.prototype._xf=function(a,b){var c,d;return this.type.transformX?this.type.transformX(a,b):(c=this.type.transform(a,b,"left"),d=this.type.transform(b,a,"right"),[c,d])},a.prototype._otApply=function(a,b){var c=this.snapshot;this.snapshot=this.type.apply(this.snapshot,a),this.emit("change",a,c);if(b)return this.emit("remoteop",a,c)},a.prototype._connectionStateChanged=function(a,b){switch(a){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(b)}return this.emit(a,b)},a.prototype._setType=function(a){var b,c,d;typeof a=="string"&&(a=p[a]);if(!a||!a.compose)throw new Error("Support for types without compose() is not implemented");this.type=a;if(a.api){d=a.api;for(b in d)c=d[b],this[b]=c;return typeof this._register=="function"?this._register():void 0}return this.provides={}},a.prototype._onMessage=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,v;if(a.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!a.create),a.type&&this._setType(a.type),a.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),a.snapshot!==void 0&&(this.snapshot=a.snapshot)),a.v!=null&&(this.version=a.v),this.inflightOp?(h={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(h.dupIfSource=this.inflightSubmittedIds),this.connection.send(h)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(a.open===!1)return a.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+a.error),this.emit("error",a.error),typeof this._openCallback=="function"&&this._openCallback(a.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(a.op!==null||d!=="Op already submitted"){if(a.op===void 0&&a.v!==void 0||a.op&&(o=a.meta.source,s.call(this.inflightSubmittedIds,o)>=0)){e=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,d=a.error;if(d){this.type.invert?(i=this.type.invert(e),this.pendingOp&&(p=this._xf(this.pendingOp,i),this.pendingOp=p[0],i=p[1]),this._otApply(i,!0)):this.emit("error","Op apply failed ("+d+") and the op could not be reverted"),q=this.inflightCallbacks;for(k=0,m=q.length;k<m;k++)b=q[k],b(d)}else{if(a.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=e,this.version++,r=this.inflightCallbacks;for(l=0,n=r.length;l<n;l++)b=r[l],b(null,e)}return this.flush()}if(a.op){if(a.v<this.version)return;return a.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+a.doc):a.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+a.v):(f=a.op,this.serverOps[this.version]=f,c=f,this.inflightOp!==null&&(t=this._xf(this.inflightOp,c),this.inflightOp=t[0],c=t[1]),this.pendingOp!==null&&(u=this._xf(this.pendingOp,c),this.pendingOp=u[0],c=u[1]),this.version++,this._otApply(c,!0))}if(!a.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",a):void 0;v=a.meta,g=v.path,j=v.value;switch(g!=null?g[0]:void 0){case"shout":return this.emit("shout",j);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",a):void 0}}},a.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},a.prototype.submitOp=function(a,b){return this.type.normalize!=null&&(a=this.type.normalize(a)),this.snapshot=this.type.apply(this.snapshot,a),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,a):this.pendingOp=a,b&&this.pendingCallbacks.push(b),this.emit("change",a),setTimeout(this.flush,0)},a.prototype.shout=function(a){return this.connection.send({doc:this.name,meta:{path:["shout"],value:a}})},a.prototype.open=function(a){var b,c=this;this.autoOpen=!0;if(this.state!=="closed")return;return b={doc:this.name,open:!0},this.snapshot===void 0&&(b.snapshot=null),this.type&&(b.type=this.type.name),this.version!=null&&(b.v=this.version),this._create&&(b.create=!0),this.connection.send(b),this.state="opening",this._openCallback=function(b){return c._openCallback=null,typeof a=="function"?a(b):void 0}},a.prototype.close=function(a){return this.autoOpen=!1,this.state==="closed"?typeof a=="function"?a():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=a)},a}(),d.mixin(c),i.Doc=c,p||(p=i.types);if(!window.BCSocket)throw new Error("Must load browserchannel before this library");a=window.BCSocket,b=function(){function b(b){var c=this;this.docs={},this.state="connecting",this.socket=new a(b,{reconnect:!0}),this.socket.onmessage=function(a){var b;if(a.auth===null)return c.lastError=a.error,c.disconnect(),c.emit("connect failed",a.error);if(a.auth){c.id=a.auth,c.setState("ok");return}return b=a.doc,b!==void 0?c.lastReceivedDoc=b:a.doc=b=c.lastReceivedDoc,c.docs[b]?c.docs[b]._onMessage(a):typeof console!="undefined"&&console!==null?console.error("Unhandled message",a):void 0},this.connected=!1,this.socket.onclose=function(a){c.setState("disconnected",a);if(a==="Closed"||a==="Stopped by server")return c.setState("stopped",c.lastError||a)},this.socket.onerror=function(a){return c.emit("error",a)},this.socket.onopen=function(){return c.lastError=c.lastReceivedDoc=c.lastSentDoc=null,c.setState("handshaking")},this.socket.onconnecting=function(){return c.setState("connecting")}}return b.prototype.setState=function(a,b){var c,d,e,f;if(this.state===a)return;this.state=a,a==="disconnected"&&delete this.id,this.emit(a,b),e=this.docs,f=[];for(d in e)c=e[d],f.push(c._connectionStateChanged(a,b));return f},b.prototype.send=function(a){var b=a.doc;return b===this.lastSentDoc?delete a.doc:this.lastSentDoc=b,this.socket.send(a)},b.prototype.disconnect=function(){return this.socket.close()},b.prototype.makeDoc=function(a,b,d){var e,f=this;if(this.docs[a])throw new Error("Doc "+a+" already open");return e=new c(this,a,b),this.docs[a]=e,e.open(function(b){return b&&delete f.docs[a],d(b,b?void 0:e)})},b.prototype.openExisting=function(a,b){var c;return this.state==="stopped"?b("connection closed"):this.docs[a]?b(null,this.docs[a]):c=this.makeDoc(a,{},b)},b.prototype.open=function(a,b,c){var d;if(this.state==="stopped")return c("connection closed");typeof b=="function"&&(c=b,b="text"),c||(c=function(){}),typeof b=="string"&&(b=p[b]);if(!b)throw new Error("OT code for document type missing");if(a==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[a]){d=this.docs[a],d.type===b?c(null,d):c("Type mismatch",d);return}return this.makeDoc(a,{create:!0,type:b.name},c)},b}(),d.mixin(b),i.Connection=b,i.open=function(){var a={},c=function(c){var d,e,f;return f=window.location,c==null&&(c=""+f.protocol+"//"+f.host+"/channel"),a[c]||(d=new b(c),e=function(){return delete a[c]},d.on("disconnecting",e),d.on("connect failed",e),a[c]=d),a[c]},d=function(a){var b,c,d=0,e=a.docs;for(c in e)b=e[c],(b.state!=="closed"||b.autoOpen)&&d++;if(d===0)return a.disconnect()};return function(a,b,e,f){var g;return typeof e=="function"&&(f=e,e=null),g=c(e),g.numDocs++,g.open(a,b,function(a,b){return a?(f(a),d(g)):(b.on("closed",function(){return d(g)}),f(null,b))}),g.on("connect failed"),g}}()}).call(this)
2  webclient/text-tp2.js
View
@@ -1 +1 @@
-((function(){var a,b,c,d,e,f,g,h=!0,i=window.sharejs,j={name:"text-tp2",tp2:!0,create:function(){return{charLength:0,totalLength:0,positionCache:[],data:[]}},serialize:function(a){if(!a.data)throw new Error("invalid doc snapshot");return a.data},deserialize:function(a){var b,c,d,e=j.create();e.data=a;for(c=0,d=a.length;c<d;c++)b=a[c],typeof b=="string"?(e.charLength+=b.length,e.totalLength+=b.length):e.totalLength+=b;return e}},k=function(a){var b,c,d,e,f;if(!Array.isArray(a))throw new Error("Op must be an array of components");c=null,f=[];for(d=0,e=a.length;d<e;d++){b=a[d];if(typeof b=="object")if(b.i!==void 0){if(!(typeof b.i=="string"&&b.i.length>0||typeof b.i=="number"&&b.i>0))throw new Error("Inserts must insert a string or a +ive number")}else{if(b.d===void 0)throw new Error("Operation component must define .i or .d");if(!(typeof b.d=="number"&&b.d>0))throw new Error("Deletes must be a +ive number")}else{if(typeof b!="number")throw new Error("Op components must be objects or numbers");if(!(b>0))throw new Error("Skip components must be a positive number");if(typeof c=="number")throw new Error("Adjacent skip components should be combined")}f.push(c=b)}return f};j._takeDoc=f=function(a,b,c,d){var e,f,g;if(b.index>=a.data.length)throw new Error("Operation goes past the end of the document");return e=a.data[b.index],f=typeof e=="string"?c!==void 0?e.slice(b.offset,b.offset+c):e.slice(b.offset):c===void 0||d?e-b.offset:Math.min(c,e-b.offset),g=f.length||f,(e.length||e)-b.offset>g?b.offset+=g:(b.index++,b.offset=0),f},j._appendDoc=b=function(a,b){var c;if(b===0||b==="")return;typeof b=="string"?(a.charLength+=b.length,a.totalLength+=b.length):a.totalLength+=b,c=a.data,c.length===0?c.push(b):typeof c[c.length-1]==typeof b?c[c.length-1]+=b:c.push(b)},j.apply=function(a,c){var d,e,g,h,i,l,m;if(a.totalLength===void 0||a.charLength===void 0||a.data.length===void 0)throw new Error("Snapshot is invalid");k(c),e=j.create(),h={index:0,offset:0};for(l=0,m=c.length;l<m;l++){d=c[l];if(typeof d=="number"){i=d;while(i>0)g=f(a,h,i),b(e,g),i-=g.length||g}else if(d.i!==void 0)b(e,d.i);else if(d.d!==void 0){i=d.d;while(i>0)g=f(a,h,i),i-=g.length||g;b(e,d.d)}}return e},j._append=a=function(a,b){var c;if(b!==0&&b.i!==""&&b.i!==0&&b.d!==0)return a.length===0?a.push(b):(c=a[a.length-1],typeof b=="number"&&typeof c=="number"?a[a.length-1]+=b:b.i!==void 0&&c.i!=null&&typeof c.i==typeof b.i?c.i+=b.i:b.d!==void 0&&c.d!=null?c.d+=b.d:a.push(b))},e=function(a){var b=0,c=0,d=function(d,e){var f,g,h,i;return b===a.length?null:(h=a[b],typeof (g=h)=="number"||typeof (g=h.i)=="number"||(g=h.d)!==void 0?(d==null||g-c<=d||e&&h.i!==void 0?(f=g-c,++b,c=0):(c+=d,f=d),h.i!==void 0?{i:f}:h.d!==void 0?{d:f}:f):(d==null||h.i.length-c<=d||e?(i={i:h.i.slice(c)},++b,c=0):(i={i:h.i.slice(c,c+d)},c+=d),i))},e=function(){return a[b]};return[d,e]},d=function(a){return typeof a=="number"?a:typeof a.i=="string"?a.i.length:a.d||a.i},j.normalize=function(b){var c,d,e,f=[];for(d=0,e=b.length;d<e;d++)c=b[d],a(f,c);return f},g=function(b,c,f,g){var h,i,j,l,m,n,o,p,q,r;k(b),k(c),l=[],q=e(b),n=q[0],m=q[1];for(o=0,p=c.length;o<p;o++){i=c[o],j=d(i);if(i.i!==void 0)if(f){if(g==="left")while(((r=m())!=null?r.i:void 0)!==void 0)a(l,n());a(l,j)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The transformed op is invalid");if(h.d!==void 0)throw new Error("The transformed op deletes locally inserted characters - it cannot be purged of the insert.");typeof h=="number"?j-=h:a(l,h)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The op traverses more elements than the document has");a(l,h),h.i||(j-=d(h))}}while(i=n()){if(i.i===void 0)throw new Error("Remaining fragments in the op: "+i);a(l,i)}return l},j.transform=function(a,b,c){if(c!=="left"&&c!=="right")throw new Error("side ("+c+") should be 'left' or 'right'");return g(a,b,!0,c)},j.prune=function(a,b){return g(a,b,!1)},j.compose=function(b,c){var f,g,h,i,j,l,m,n,o,p;if(b===null||b===void 0)return c;k(b),k(c),j=[],p=e(b),l=p[0],m=p[1];for(n=0,o=c.length;n<o;n++){h=c[n];if(typeof h=="number"){i=h;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");a(j,f),i-=d(f)}}else if(h.i!==void 0)a(j,{i:h.i});else{i=h.d;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");g=d(f),f.i!==void 0?a(j,{i:g}):a(j,{d:g}),i-=g}}}while(h=l()){if(h.i===void 0)throw new Error("Remaining fragments in op1: "+h);a(j,h)}return j},typeof h!="undefined"&&h!==null?i.types["text-tp2"]=j:module.exports=j,typeof h!="undefined"&&h!==null?j=i.types["text-tp2"]:j=require("./text-tp2"),f=j._takeDoc,a=j._append,c=function(b,c,d,e){var g,h=[];while((e===void 0||e>0)&&d.index<c.data.length)g=f(c,d,e,!0),e!==void 0&&typeof g=="string"&&(e-=g.length),h.push(a(b,g.length||g));return h},j.api={provides:{text:!0},getLength:function(){return this.snapshot.charLength},getText:function(){var a,b=function(){var b,c,d=this.snapshot.data,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],typeof a=="string"&&e.push(a);return e}.call(this);return b.join("")},insert:function(b,d,e){var f,g;return b===void 0&&(b=0),g=[],f={index:0,offset:0},c(g,this.snapshot,f,b),a(g,{i:d}),c(g,this.snapshot,f),this.submitOp(g,e),g},del:function(b,d,e){var g,h=[],i={index:0,offset:0};c(h,this.snapshot,i,b);while(d>0)g=f(this.snapshot,i,d,!0),typeof g=="string"?(a(h,{d:g.length}),d-=g.length):a(h,g);return c(h,this.snapshot,i),this.submitOp(h,e),h},_register:function(){return this.on("remoteop",function(a,b){var c,d,e,g,h,i=0,j={index:0,offset:0};for(g=0,h=a.length;g<h;g++){c=a[g];if(typeof c=="number"){e=c;while(e>0)d=f(b,j,e),typeof d=="string"&&(i+=d.length),e-=d.length||d}else if(c.i!==void 0)typeof c.i=="string"&&(this.emit("insert",i,c.i),i+=c.i.length);else{e=c.d;while(e>0)d=f(b,j,e),typeof d=="string"&&this.emit("delete",i,d),e-=d.length||d}}})}}})).call(this)
+(function(){var a,b,c,d,e,f,g,h=!0,i=window.sharejs,j={name:"text-tp2",tp2:!0,create:function(){return{charLength:0,totalLength:0,positionCache:[],data:[]}},serialize:function(a){if(!a.data)throw new Error("invalid doc snapshot");return a.data},deserialize:function(a){var b,c,d,e=j.create();e.data=a;for(c=0,d=a.length;c<d;c++)b=a[c],typeof b=="string"?(e.charLength+=b.length,e.totalLength+=b.length):e.totalLength+=b;return e}},k=function(a){var b,c,d,e,f;if(!Array.isArray(a))throw new Error("Op must be an array of components");c=null,f=[];for(d=0,e=a.length;d<e;d++){b=a[d];if(typeof b=="object")if(b.i!==void 0){if(!(typeof b.i=="string"&&b.i.length>0||typeof b.i=="number"&&b.i>0))throw new Error("Inserts must insert a string or a +ive number")}else{if(b.d===void 0)throw new Error("Operation component must define .i or .d");if(!(typeof b.d=="number"&&b.d>0))throw new Error("Deletes must be a +ive number")}else{if(typeof b!="number")throw new Error("Op components must be objects or numbers");if(!(b>0))throw new Error("Skip components must be a positive number");if(typeof c=="number")throw new Error("Adjacent skip components should be combined")}f.push(c=b)}return f};j._takeDoc=f=function(a,b,c,d){var e,f,g;if(b.index>=a.data.length)throw new Error("Operation goes past the end of the document");return e=a.data[b.index],f=typeof e=="string"?c!==void 0?e.slice(b.offset,b.offset+c):e.slice(b.offset):c===void 0||d?e-b.offset:Math.min(c,e-b.offset),g=f.length||f,(e.length||e)-b.offset>g?b.offset+=g:(b.index++,b.offset=0),f},j._appendDoc=b=function(a,b){var c;if(b===0||b==="")return;typeof b=="string"?(a.charLength+=b.length,a.totalLength+=b.length):a.totalLength+=b,c=a.data,c.length===0?c.push(b):typeof c[c.length-1]==typeof b?c[c.length-1]+=b:c.push(b)},j.apply=function(a,c){var d,e,g,h,i,l,m;if(a.totalLength===void 0||a.charLength===void 0||a.data.length===void 0)throw new Error("Snapshot is invalid");k(c),e=j.create(),h={index:0,offset:0};for(l=0,m=c.length;l<m;l++){d=c[l];if(typeof d=="number"){i=d;while(i>0)g=f(a,h,i),b(e,g),i-=g.length||g}else if(d.i!==void 0)b(e,d.i);else if(d.d!==void 0){i=d.d;while(i>0)g=f(a,h,i),i-=g.length||g;b(e,d.d)}}return e},j._append=a=function(a,b){var c;if(b!==0&&b.i!==""&&b.i!==0&&b.d!==0)return a.length===0?a.push(b):(c=a[a.length-1],typeof b=="number"&&typeof c=="number"?a[a.length-1]+=b:b.i!==void 0&&c.i!=null&&typeof c.i==typeof b.i?c.i+=b.i:b.d!==void 0&&c.d!=null?c.d+=b.d:a.push(b))},e=function(a){var b=0,c=0,d=function(d,e){var f,g,h,i;return b===a.length?null:(h=a[b],typeof (g=h)=="number"||typeof (g=h.i)=="number"||(g=h.d)!==void 0?(d==null||g-c<=d||e&&h.i!==void 0?(f=g-c,++b,c=0):(c+=d,f=d),h.i!==void 0?{i:f}:h.d!==void 0?{d:f}:f):(d==null||h.i.length-c<=d||e?(i={i:h.i.slice(c)},++b,c=0):(i={i:h.i.slice(c,c+d)},c+=d),i))},e=function(){return a[b]};return[d,e]},d=function(a){return typeof a=="number"?a:typeof a.i=="string"?a.i.length:a.d||a.i},j.normalize=function(b){var c,d,e,f=[];for(d=0,e=b.length;d<e;d++)c=b[d],a(f,c);return f},g=function(b,c,f,g){var h,i,j,l,m,n,o,p,q,r;k(b),k(c),l=[],q=e(b),n=q[0],m=q[1];for(o=0,p=c.length;o<p;o++){i=c[o],j=d(i);if(i.i!==void 0)if(f){if(g==="left")while(((r=m())!=null?r.i:void 0)!==void 0)a(l,n());a(l,j)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The transformed op is invalid");if(h.d!==void 0)throw new Error("The transformed op deletes locally inserted characters - it cannot be purged of the insert.");typeof h=="number"?j-=h:a(l,h)}else while(j>0){h=n(j,!0);if(h===null)throw new Error("The op traverses more elements than the document has");a(l,h),h.i||(j-=d(h))}}while(i=n()){if(i.i===void 0)throw new Error("Remaining fragments in the op: "+i);a(l,i)}return l},j.transform=function(a,b,c){if(c!=="left"&&c!=="right")throw new Error("side ("+c+") should be 'left' or 'right'");return g(a,b,!0,c)},j.prune=function(a,b){return g(a,b,!1)},j.compose=function(b,c){var f,g,h,i,j,l,m,n,o,p;if(b===null||b===void 0)return c;k(b),k(c),j=[],p=e(b),l=p[0],m=p[1];for(n=0,o=c.length;n<o;n++){h=c[n];if(typeof h=="number"){i=h;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");a(j,f),i-=d(f)}}else if(h.i!==void 0)a(j,{i:h.i});else{i=h.d;while(i>0){f=l(i);if(f===null)throw new Error("The op traverses more elements than the document has");g=d(f),f.i!==void 0?a(j,{i:g}):a(j,{d:g}),i-=g}}}while(h=l()){if(h.i===void 0)throw new Error("Remaining fragments in op1: "+h);a(j,h)}return j},typeof h!="undefined"&&h!==null?i.types["text-tp2"]=j:module.exports=j,typeof h!="undefined"&&h!==null?j=i.types["text-tp2"]:j=require("./text-tp2"),f=j._takeDoc,a=j._append,c=function(b,c,d,e){var g,h=[];while((e===void 0||e>0)&&d.index<c.data.length)g=f(c,d,e,!0),e!==void 0&&typeof g=="string"&&(e-=g.length),h.push(a(b,g.length||g));return h},j.api={provides:{text:!0},getLength:function(){return this.snapshot.charLength},getText:function(){var a,b=function(){var b,c,d=this.snapshot.data,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],typeof a=="string"&&e.push(a);return e}.call(this);return b.join("")},insert:function(b,d,e){var f,g;return b===void 0&&(b=0),g=[],f={index:0,offset:0},c(g,this.snapshot,f,b),a(g,{i:d}),c(g,this.snapshot,f),this.submitOp(g,e),g},del:function(b,d,e){var g,h=[],i={index:0,offset:0};c(h,this.snapshot,i,b);while(d>0)g=f(this.snapshot,i,d,!0),typeof g=="string"?(a(h,{d:g.length}),d-=g.length):a(h,g);return c(h,this.snapshot,i),this.submitOp(h,e),h},_register:function(){return this.on("remoteop",function(a,b){var c,d,e,g,h,i=0,j={index:0,offset:0};for(g=0,h=a.length;g<h;g++){c=a[g];if(typeof c=="number"){e=c;while(e>0)d=f(b,j,e),typeof d=="string"&&(i+=d.length),e-=d.length||d}else if(c.i!==void 0)typeof c.i=="string"&&(this.emit("insert",i,c.i),i+=c.i.length);else{e=c.d;while(e>0)d=f(b,j,e),typeof d=="string"&&this.emit("delete",i,d),e-=d.length||d}}})}}}).call(this)

No commit comments for this range

Something went wrong with that request. Please try again.