Skip to content

Commit

Permalink
Make it compatible with superpowers-core v5: update compilation targe…
Browse files Browse the repository at this point in the history
…t from es5 to es6
  • Loading branch information
florentpoujol committed May 15, 2019
1 parent 7ce48c7 commit 00f36e1
Show file tree
Hide file tree
Showing 17 changed files with 154,050 additions and 101,883 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
gitignore/*
node_modules/*
!node_modules/operational-transform

project/**/*.js
# those js files are created when the typescript gulp tasks run
107 changes: 49 additions & 58 deletions data/fTextAsset.js
@@ -1,69 +1,62 @@
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var OT = require("operational-transform");
var fs = require("fs");
var path = require("path");
var FTextAsset = (function (_super) {
__extends(FTextAsset, _super);
Object.defineProperty(exports, "__esModule", { value: true });
const OT = require("operational-transform");
const fs = require("fs");
const path = require("path");
class FTextAsset extends SupCore.Data.Base.Asset {
// called from the editor onAssetReceived() as well as on server startup
function FTextAsset(id, pub, server) {
_super.call(this, id, pub, FTextAsset.schema, server);
constructor(id, pub, server) {
super(id, pub, FTextAsset.schema, server);
}
// called on asset creation
// options contain the asset's name
FTextAsset.prototype.init = function (options, callback) {
var defaultContent = "";
init(options, callback) {
let defaultContent = "";
this.pub = {
text: defaultContent,
draft: defaultContent,
revisionId: 0,
};
_super.prototype.init.call(this, options, callback);
};
FTextAsset.prototype.setup = function () {
super.init(options, callback);
}
setup() {
this.document = new OT.Document(this.pub.draft, this.pub.revisionId);
this.hasDraft = this.pub.text !== this.pub.draft;
};
FTextAsset.prototype.restore = function () {
}
restore() {
if (this.hasDraft)
this.emit("setBadge", "draft", "info");
};
FTextAsset.prototype.destroy = function (callback) {
}
destroy(callback) {
callback();
};
}
// called on server startup
FTextAsset.prototype.load = function (assetPath) {
load(assetPath) {
// NOTE: We must not set this.pub with temporary values here, otherwise
// the asset will be considered loaded by Dictionary.acquire
// and the acquire callback will be called immediately
var _this = this;
fs.readFile(path.join(assetPath, "ftext.txt"), { encoding: "utf8" }, function (err, text) {
fs.readFile(path.join(assetPath, "draft.txt"), { encoding: "utf8" }, function (err, draft) {
var pub = { revisionId: 0, text: text, draft: (draft != null) ? draft : text };
fs.readFile(path.join(assetPath, "ftext.txt"), { encoding: "utf8" }, (err, text) => {
fs.readFile(path.join(assetPath, "draft.txt"), { encoding: "utf8" }, (err, draft) => {
let pub = { revisionId: 0, text, draft: (draft != null) ? draft : text };
// this.setup();
// this.emit("load");
_this._onLoaded(assetPath, pub);
this._onLoaded(assetPath, pub);
});
});
};
}
// called when it is time to write the asset on disk, not when the user save the asset from the editor
FTextAsset.prototype.save = function (outputPath, callback) {
var _this = this;
this.write(fs.writeFile, outputPath, function (err) {
save(outputPath, callback) {
this.write(fs.writeFile, outputPath, (err) => {
if (err != null) {
callback(err);
return;
}
if (_this.hasDraft) {
fs.writeFile(path.join(outputPath, "draft.txt"), _this.pub.draft, { encoding: "utf8" }, callback);
if (this.hasDraft) {
fs.writeFile(path.join(outputPath, "draft.txt"), this.pub.draft, { encoding: "utf8" }, callback);
}
else {
// delete the draft.txt file if there is no draft to save and the file exists
fs.unlink(path.join(outputPath, "draft.txt"), function (err) {
fs.unlink(path.join(outputPath, "draft.txt"), (err) => {
if (err != null && err.code !== "ENOENT") {
callback(err);
return;
Expand All @@ -72,19 +65,19 @@ var FTextAsset = (function (_super) {
});
}
});
};
FTextAsset.prototype.clientExport = function (outputPath, callback) {
}
clientExport(outputPath, callback) {
this.write(SupApp.writeFile, outputPath, callback);
};
FTextAsset.prototype.write = function (writeFile, outputPath, callback) {
}
write(writeFile, outputPath, callback) {
writeFile(path.join(outputPath, "ftext.txt"), this.pub.text, { encoding: "utf8" }, callback);
};
FTextAsset.prototype.server_editText = function (client, operationData, revisionIndex, callback) {
}
server_editText(client, operationData, revisionIndex, callback) {
if (operationData.userId !== client.id) {
callback("Invalid client id");
return;
}
var operation = new OT.TextOperation();
let operation = new OT.TextOperation();
if (!operation.deserialize(operationData)) {
callback("Invalid operation data");
return;
Expand All @@ -104,31 +97,29 @@ var FTextAsset = (function (_super) {
this.emit("setBadge", "draft", "info");
}
this.emit("change");
};
FTextAsset.prototype.client_editText = function (operationData, revisionIndex) {
var operation = new OT.TextOperation();
}
client_editText(operationData, revisionIndex) {
let operation = new OT.TextOperation();
operation.deserialize(operationData);
this.document.apply(operation, revisionIndex);
this.pub.draft = this.document.text;
this.pub.revisionId++;
};
FTextAsset.prototype.server_applyDraftChanges = function (client, options, callback) {
}
server_applyDraftChanges(client, options, callback) {
this.pub.text = this.pub.draft;
callback(null);
if (this.hasDraft) {
this.hasDraft = false;
this.emit("clearBadge", "draft");
}
this.emit("change");
};
FTextAsset.prototype.client_applyDraftChanges = function () { this.pub.text = this.pub.draft; };
FTextAsset.prototype.client_unload = function () { return; }; // called when an asset is trashed
FTextAsset.schema = {
text: { type: "string" },
draft: { type: "string" },
revisionId: { type: "integer" },
};
return FTextAsset;
}(SupCore.Data.Base.Asset));
Object.defineProperty(exports, "__esModule", { value: true });
}
client_applyDraftChanges() { this.pub.text = this.pub.draft; }
client_unload() { return; } // called when an asset is trashed
}
FTextAsset.schema = {
text: { type: "string" },
draft: { type: "string" },
revisionId: { type: "integer" },
};
exports.default = FTextAsset;
61 changes: 27 additions & 34 deletions data/fTextSettingsResource.js
@@ -1,39 +1,32 @@
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var FTextSettingsResource = (function (_super) {
__extends(FTextSettingsResource, _super);
function FTextSettingsResource(id, pub, serverData) {
_super.call(this, id, pub, FTextSettingsResource.schema, serverData);
Object.defineProperty(exports, "__esModule", { value: true });
class FTextSettingsResource extends SupCore.Data.Base.Resource {
constructor(id, pub, serverData) {
super(id, pub, FTextSettingsResource.schema, serverData);
}
FTextSettingsResource.prototype.init = function (callback) {
var pub = {};
for (var name_1 in FTextSettingsResource.defaultValues) {
pub[name_1] = FTextSettingsResource.defaultValues[name_1];
init(callback) {
let pub = {};
for (let name in FTextSettingsResource.defaultValues) {
pub[name] = FTextSettingsResource.defaultValues[name];
}
this.pub = pub;
_super.prototype.init.call(this, callback);
};
FTextSettingsResource.schema = {
styleActiveLine: { type: "boolean", mutable: true },
showTrailingSpace: { type: "boolean", mutable: true },
autoCloseBrackets: { type: "boolean", mutable: true },
matchTags: { type: "boolean", mutable: true },
highlightSelectionMatches: { type: "boolean", mutable: true },
lint: { type: "boolean", mutable: true }
};
FTextSettingsResource.defaultValues = {
styleActiveLine: true,
autoCloseBrackets: true,
showTrailingSpace: true,
matchTags: true,
highlightSelectionMatches: true,
lint: true,
}; // note 07/09/15 for some reason, not having a coma after the last entry would cause the defaultValues not to be read in the settings editor...
return FTextSettingsResource;
}(SupCore.Data.Base.Resource));
Object.defineProperty(exports, "__esModule", { value: true });
super.init(callback);
}
}
FTextSettingsResource.schema = {
styleActiveLine: { type: "boolean", mutable: true },
showTrailingSpace: { type: "boolean", mutable: true },
autoCloseBrackets: { type: "boolean", mutable: true },
matchTags: { type: "boolean", mutable: true },
highlightSelectionMatches: { type: "boolean", mutable: true },
lint: { type: "boolean", mutable: true }
};
FTextSettingsResource.defaultValues = {
styleActiveLine: true,
autoCloseBrackets: true,
showTrailingSpace: true,
matchTags: true,
highlightSelectionMatches: true,
lint: true,
}; // note 07/09/15 for some reason, not having a coma after the last entry would cause the defaultValues not to be read in the settings editor...
exports.default = FTextSettingsResource;
1 change: 1 addition & 0 deletions editors/fText/index.js
@@ -1,3 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./ui");
require("./network");

0 comments on commit 00f36e1

Please sign in to comment.