gojs
Version:
Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams
1,188 lines (1,168 loc) • 111 kB
JavaScript
/*! Copyright (C) 1998-2020 by Northwoods Software Corporation. All Rights Reserved. */
var gcs =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var go = __webpack_require__(1);
var GoCloudStorage = (function () {
function GoCloudStorage(managedDiagrams, defaultModel, clientId, iconsRelativeDirectory) {
if (managedDiagrams instanceof go.Diagram)
managedDiagrams = [managedDiagrams];
this._managedDiagrams = managedDiagrams;
this._currentDiagramFile = { name: null, id: null, path: null };
this._isAutoSaving = true;
if (clientId)
this._clientId = clientId;
else
clientId = null;
if (defaultModel) {
var firstChar = defaultModel.trim().charAt(0);
if (defaultModel && firstChar === '{')
this._defaultModel = defaultModel;
if (firstChar !== '{' && !iconsRelativeDirectory)
this._iconsRelativeDirectory = defaultModel;
else
this._iconsRelativeDirectory = (!!iconsRelativeDirectory) ? iconsRelativeDirectory : '../goCloudStorageIcons/';
}
else {
this._defaultModel = null;
this._iconsRelativeDirectory = (!!iconsRelativeDirectory) ? iconsRelativeDirectory : '../goCloudStorageIcons/';
}
var lastChar = this._iconsRelativeDirectory.charAt(this._iconsRelativeDirectory.length - 1);
if (lastChar !== '/') {
this._iconsRelativeDirectory += '/';
}
var menu = document.createElement('div');
menu.className = 'goCustomFilepicker';
menu.style.visibility = 'hidden';
document.getElementsByTagName('body')[0].appendChild(menu);
this._ui = menu;
this._deferredPromise = { promise: this.makeDeferredPromise() };
function addAutoSave(d) {
d.addModelChangedListener(function (e) {
if (e.isTransactionFinished && storage.isAutoSaving && e.oldValue !== '') {
if (storage.currentDiagramFile.name) {
storage.save();
}
}
});
}
var d = this.managedDiagrams;
var storage = this;
if (d instanceof go.Diagram) {
addAutoSave(d);
}
else {
for (var i = 0; i < d.length; i++) {
addAutoSave(d[i]);
}
}
}
Object.defineProperty(GoCloudStorage.prototype, "managedDiagrams", {
get: function () { return this._managedDiagrams; },
set: function (value) { this._managedDiagrams = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "defaultModel", {
get: function () { return this._defaultModel; },
set: function (value) { this._defaultModel = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "iconsRelativeDirectory", {
get: function () { return this._iconsRelativeDirectory; },
set: function (value) { this._iconsRelativeDirectory = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "clientId", {
get: function () { return this._clientId; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "currentDiagramFile", {
get: function () { return this._currentDiagramFile; },
set: function (value) { this._currentDiagramFile = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "isAutoSaving", {
get: function () { return this._isAutoSaving; },
set: function (value) { this._isAutoSaving = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "serviceName", {
get: function () { return this._serviceName; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "className", {
get: function () { return this._className; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoCloudStorage.prototype, "ui", {
get: function () { return this._ui; },
enumerable: true,
configurable: true
});
GoCloudStorage.prototype.authorize = function (refreshToken) {
if (refreshToken === void 0) { refreshToken = false; }
return new Promise(function (resolve, reject) {
reject('authorize not implemented');
});
};
GoCloudStorage.prototype.makeDeferredPromise = function () {
var res;
var rej;
var promise = new Promise(function (resolve, reject) {
res = resolve;
rej = reject;
});
promise.resolve = res;
promise.reject = rej;
return promise;
};
GoCloudStorage.prototype.getUserInfo = function () {
return new Promise(function (resolve, reject) {
reject('getUserInfo not implemented');
});
};
GoCloudStorage.prototype.hideUI = function (isActionCanceled) {
if (isActionCanceled === void 0) { isActionCanceled = false; }
var storage = this;
storage.ui.style.visibility = 'hidden';
if (isActionCanceled) {
var action = document.getElementById('actionButton').innerHTML;
storage._deferredPromise.promise.resolve(action + ' canceled by user');
storage._deferredPromise.promise = storage.makeDeferredPromise();
}
};
GoCloudStorage.prototype.checkFileExists = function (path) {
return new Promise(function (resolve, reject) {
reject('checkFileExists not implemented');
});
};
GoCloudStorage.prototype.getFile = function (path) {
return new Promise(function (resolve, reject) {
throw Error('getFile not implemented');
});
};
GoCloudStorage.prototype.showUI = function (action) {
return new Promise(function (resolve, reject) {
throw Error('showUI not implemented');
});
};
GoCloudStorage.prototype.create = function (path, saveBefore) {
if (saveBefore === void 0) { saveBefore = false; }
var storage = this;
function makeNewDiagram(d) {
if (storage.defaultModel)
d.model = go.Model.fromJson(JSON.parse(storage.defaultModel));
else
d.model = new go.GraphLinksModel();
}
return new Promise(function (resolve, reject) {
if (saveBefore) {
storage.promptUserToSaveBeforeNew().then(function (resp) {
if (resp) {
storage.saveWithUI().then(function (diagramFile) {
storage.currentDiagramFile = { name: null, id: null, path: null };
if (storage.managedDiagrams instanceof go.Diagram) {
makeNewDiagram(storage.managedDiagrams);
}
else {
for (var i = 0; i < storage.managedDiagrams.length; i++) {
makeNewDiagram(storage.managedDiagrams[i]);
}
}
if (storage.isAutoSaving) {
if (path) {
resolve(storage.save(path));
}
else
resolve(storage.saveWithUI());
}
else
resolve('New diagram created.');
});
}
else {
storage.currentDiagramFile = { name: null, id: null, path: null };
if (storage.managedDiagrams instanceof go.Diagram) {
makeNewDiagram(storage.managedDiagrams);
}
else {
for (var i = 0; i < storage.managedDiagrams.length; i++) {
makeNewDiagram(storage.managedDiagrams[i]);
}
}
if (storage.isAutoSaving) {
if (path) {
resolve(storage.save(path));
}
else
resolve(storage.saveWithUI());
}
else
resolve('New diagram created.');
}
});
}
if (!saveBefore) {
storage.currentDiagramFile = { name: null, id: null, path: null };
if (storage.managedDiagrams instanceof go.Diagram) {
makeNewDiagram(storage.managedDiagrams);
}
else {
for (var i = 0; i < storage.managedDiagrams.length; i++) {
makeNewDiagram(storage.managedDiagrams[i]);
}
}
if (storage.isAutoSaving) {
if (path) {
resolve(storage.save(path));
}
else
resolve(storage.saveWithUI());
}
else
resolve('New diagram created.');
}
});
};
GoCloudStorage.prototype.promptUserToSaveBeforeNew = function () {
return new Promise(function (resolve, reject) {
var d = document.getElementById('gcs-save-before-new');
if (d) {
document.body.removeChild(d);
}
var div = document.createElement('div');
div.id = 'gcs-save-before-new';
var p = document.createElement('p');
p.innerText = 'Save current diagram(s) before creating a new file?';
var yb = document.createElement('button');
yb.innerText = 'Yes';
var nb = document.createElement('button');
nb.innerText = 'No';
yb.onclick = function () {
document.body.removeChild(div);
resolve(true);
};
nb.onclick = function () {
document.body.removeChild(div);
resolve(false);
};
nb.style['float'] = 'right';
div.style['font-family'] = 'Arial, Helvetica, sans-serif';
div.style['width'] = '400px';
div.style['top'] = '25%';
div.style['left'] = '40%';
div.style['position'] = 'absolute';
div.style['border'] = '1px solid black';
div.style['padding'] = '10px';
div.style['box-shadow'] = '10px 10px 5px #888888';
div.style['background'] = 'white';
div.style['z-index'] = '100';
div.appendChild(p);
div.appendChild(yb);
div.appendChild(nb);
document.body.appendChild(div);
});
};
GoCloudStorage.prototype.makeSaveFile = function () {
var item = '{\n';
var storage = this;
if (storage.managedDiagrams.length === 0)
return;
for (var i = 0; i < storage.managedDiagrams.length; i++) {
var diagram = storage.managedDiagrams[i];
var div = diagram.div.id;
var _model = diagram.model.toJson();
item += '"' + div + '"' + ': ' + diagram.model.toJson();
if (i + 1 !== storage.managedDiagrams.length)
item += ',\n';
}
item += '\n}';
return item;
};
GoCloudStorage.prototype.loadFromFileContents = function (fileContents) {
var models = JSON.parse(fileContents);
for (var divId in models) {
var model = models[divId];
var div = document.getElementById(divId);
var diagram = go.Diagram.fromDiv(div);
if (diagram) {
diagram.model = go.Model.fromJson(JSON.stringify(model));
}
else {
throw Error('No Diagram on page is associated with a div with id ' + divId);
}
}
};
GoCloudStorage.prototype.saveWithUI = function () {
return new Promise(function (resolve, reject) {
reject('saveWithUI not implemented');
});
};
GoCloudStorage.prototype.save = function (path) {
return new Promise(function (resolve, reject) {
reject('save not implemented');
});
};
GoCloudStorage.prototype.load = function (path) {
return new Promise(function (resolve, reject) {
reject('load not implemented');
});
};
GoCloudStorage.prototype.loadWithUI = function () {
return new Promise(function (resolve, reject) {
reject('loadWithUI not implemented');
});
};
GoCloudStorage.prototype.remove = function (path) {
return new Promise(function (resolve, reject) {
reject('remove not implemented');
});
};
GoCloudStorage.prototype.removeWithUI = function () {
return new Promise(function (resolve, reject) {
reject('removeWithUI not implemented');
});
};
return GoCloudStorage;
}());
exports.GoCloudStorage = GoCloudStorage;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = go;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = {
GoLocalStorage: __webpack_require__(3).GoLocalStorage,
GoDropBox: __webpack_require__(4).GoDropBox,
GoGoogleDrive: __webpack_require__(5).GoGoogleDrive,
GoOneDrive: __webpack_require__(6).GoOneDrive,
GoNetCore: __webpack_require__(7).GoNetCore,
GoCloudStorageManager: __webpack_require__(8).GoCloudStorageManager
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var gcs = __webpack_require__(0);
var GoLocalStorage = (function (_super) {
__extends(GoLocalStorage, _super);
function GoLocalStorage(managedDiagrams, defaultModel, iconsRelativeDirectory) {
var _this = _super.call(this, managedDiagrams, defaultModel, null, iconsRelativeDirectory) || this;
try {
_this._localStorage = window.localStorage;
}
catch (e) {
throw new Error('Cannot access localStorage. Make sure your browser supports localStorage.' +
'If so, and this issue persists, try unblocking third-party cookies and site data in your browser settings');
}
_this.ui.id = 'goLocalStorageCustomFilepicker';
_this._serviceName = 'Local Storage';
_this._className = 'GoLocalStorage';
return _this;
}
Object.defineProperty(GoLocalStorage.prototype, "localStorage", {
get: function () { return this._localStorage; },
enumerable: true,
configurable: true
});
GoLocalStorage.prototype.authorize = function (refreshToken) {
if (refreshToken === void 0) { refreshToken = false; }
var storage = this;
return new Promise(function (resolve, reject) {
try {
storage.localStorage.setItem('item', 'item');
storage.localStorage.removeItem('item');
resolve(true);
}
catch (e) {
resolve(false);
}
});
};
GoLocalStorage.prototype.showUI = function (action, numAdditionalFiles) {
var storage = this;
var ui = storage.ui;
var spacestring = 'qwe45qw34';
if (!numAdditionalFiles)
numAdditionalFiles = 0;
var maxFilesToShow = GoLocalStorage._MIN_FILES_IN_UI + numAdditionalFiles;
ui.innerHTML = "<img class='icons' src='" + storage.iconsRelativeDirectory + "localStorage.png'></img>";
var title = action + ' Diagram File';
ui.innerHTML += '<strong>' + title + '</strong><hr></hr>';
ui.style.visibility = 'visible';
var filesDiv = document.createElement('div');
filesDiv.id = 'fileOptions';
var savedDiagrams = [];
var numFilesToCheck = GoLocalStorage._MIN_FILES_IN_UI + numAdditionalFiles;
var numFilesChecked = 0;
var hasCheckedAllFiles = false;
if (storage.localStorage.length !== 0) {
for (var key in storage.localStorage) {
if (savedDiagrams.length < maxFilesToShow) {
numFilesChecked++;
var fileContent = storage.localStorage.getItem(key);
if (fileContent && (fileContent.indexOf('GraphLinksModel') !== -1 || fileContent.indexOf('TreeModel') !== -1)) {
var file = { key: key, model: fileContent };
savedDiagrams.push(file);
}
if (numFilesChecked === storage.localStorage.length)
hasCheckedAllFiles = true;
}
}
}
else
hasCheckedAllFiles = true;
if (savedDiagrams.length !== 0) {
for (var i = 0; i < savedDiagrams.length; i++) {
var kvp = savedDiagrams[i];
var file = kvp['key'];
var fileId = file.replace(/ /g, spacestring);
if (action !== 'Save') {
filesDiv.innerHTML +=
"<div class='fileOption'>" +
'<input id=' + fileId + " type='radio' name='localStorageFile' />" +
'<label id =' + fileId + '-label' + " for='" + fileId + "'>" + file + '</label>' +
'</div>';
}
else {
filesDiv.innerHTML +=
"<div class='fileOption'>" +
'<label id =' + fileId + '-label' + " for='" + fileId + "'>" + file + '</label>' +
'</div>';
}
}
}
if (!hasCheckedAllFiles) {
var num_1 = numAdditionalFiles + 50;
filesDiv.innerHTML += "<p>There may be more diagram files not shown. <a id='localStorageLoadMoreFiles'>Click here</a> to try loading more.</p>";
document.getElementById('localStorageLoadMoreFiles').onclick = function () {
storage.showUI(action, num_1);
};
}
ui.appendChild(filesDiv);
if (storage.currentDiagramFile.id) {
var str = storage.currentDiagramFile.id.replace(/ /g, spacestring);
var el = document.getElementById(str + '-label');
if (el)
el.style.fontStyle = 'italic';
}
if (action === 'Save') {
var userInputDiv = document.createElement('div');
userInputDiv.id = 'userInputDiv';
userInputDiv.innerHTML += '<span>Save Diagram As </span><input id="userInput" placeholder="Enter filename"></input>';
ui.appendChild(userInputDiv);
}
var submitDiv = document.createElement('div');
submitDiv.id = 'submitDiv';
var actionButton = document.createElement('button');
actionButton.textContent = action;
actionButton.id = 'actionButton';
actionButton.onclick = function () {
storage.processUIResult(action);
};
submitDiv.appendChild(actionButton);
ui.appendChild(submitDiv);
var cancelDiv = document.createElement('div');
var cancelButton = document.createElement('button');
cancelButton.id = 'cancelButton';
cancelButton.textContent = 'Cancel';
cancelButton.onclick = function () {
storage.hideUI(true);
};
cancelDiv.appendChild(cancelButton);
ui.appendChild(cancelDiv);
return storage._deferredPromise['promise'];
};
GoLocalStorage.prototype.processUIResult = function (action) {
var storage = this;
function getSelectedFile() {
var radios = document.getElementsByName('localStorageFile');
var selectedFile = null;
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
selectedFile = radios[i].id.replace(/qwe45qw34/g, ' ');
}
}
if (selectedFile)
return selectedFile;
else
return null;
}
var file = getSelectedFile();
switch (action) {
case 'Save': {
var name_1 = document.getElementById('userInput').value;
if (name_1) {
name_1 += '.diagram';
storage.save(name_1);
}
else {
}
break;
}
case 'Load': {
storage.load(file);
break;
}
case 'Delete': {
storage.remove(file);
break;
}
}
storage.hideUI();
};
GoLocalStorage.prototype.getFile = function (path) {
if (path.indexOf('.diagram') === -1)
path += '.diagram';
return new Promise(function (resolve, reject) {
var fileContent = (!!window.localStorage.getItem(path)) ? window.localStorage.getItem(path) : null;
var file = { name: path, content: fileContent, path: path, id: path };
resolve(file);
});
};
GoLocalStorage.prototype.checkFileExists = function (path) {
if (path.indexOf('.diagram') === -1)
path += '.diagram';
return new Promise(function (resolve, reject) {
var fileExists = !!(window.localStorage.getItem(path));
resolve(fileExists);
});
};
GoLocalStorage.prototype.saveWithUI = function () {
var storage = this;
return new Promise(function (resolve, reject) {
resolve(storage.showUI('Save'));
});
};
GoLocalStorage.prototype.save = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
if (path.indexOf('.diagram') === -1)
path += '.diagram';
var item = storage.makeSaveFile();
storage.localStorage.setItem(path, item);
var savedFile = { name: path, id: path, path: path };
storage.currentDiagramFile = savedFile;
resolve(savedFile);
storage._deferredPromise['promise'].resolve(savedFile);
storage._deferredPromise['promise'] = storage.makeDeferredPromise();
}
else if (storage.currentDiagramFile.path) {
var saveName = storage.currentDiagramFile['path'];
var savedFile = { name: saveName, path: saveName, id: saveName };
var item = storage.makeSaveFile();
storage.localStorage.setItem(saveName, item);
resolve(saveName);
}
else {
resolve(storage.saveWithUI());
}
});
};
GoLocalStorage.prototype.loadWithUI = function () {
var storage = this;
return new Promise(function (resolve, reject) {
resolve(storage.showUI('Load'));
}).catch(function (e) {
throw Error(e);
});
};
GoLocalStorage.prototype.load = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
var fileContents = storage.localStorage.getItem(path);
if (fileContents) {
storage.loadFromFileContents(fileContents);
var loadedFile = { name: path, id: path, path: path };
storage.currentDiagramFile = loadedFile;
resolve(loadedFile);
storage._deferredPromise.promise.resolve(loadedFile);
storage._deferredPromise.promise = storage.makeDeferredPromise();
}
else
throw Error('Cannot load file from local storage with path ' + path);
}
else
throw Error('Cannot load file from local storage with path ' + path);
}).catch(function (e) {
throw Error(e);
});
};
GoLocalStorage.prototype.removeWithUI = function () {
var storage = this;
return new Promise(function (resolve, reject) {
resolve(storage.showUI('Delete'));
});
};
GoLocalStorage.prototype.remove = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
var deletedFile = { name: path, path: path, id: path };
if (storage.currentDiagramFile && path === storage.currentDiagramFile['name'])
storage.currentDiagramFile = { name: null, path: null, id: null };
storage.localStorage.removeItem(path);
resolve(deletedFile);
storage._deferredPromise['promise'].resolve(deletedFile);
storage._deferredPromise['promise'] = storage.makeDeferredPromise();
}
else
throw Error('Cannot delete file from local storage with path ' + path);
});
};
GoLocalStorage._MIN_FILES_IN_UI = 100;
return GoLocalStorage;
}(gcs.GoCloudStorage));
exports.GoLocalStorage = GoLocalStorage;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var gcs = __webpack_require__(0);
var GoDropBox = (function (_super) {
__extends(GoDropBox, _super);
function GoDropBox(managedDiagrams, clientId, defaultModel, iconsRelativeDirectory) {
var _this = _super.call(this, managedDiagrams, defaultModel, clientId, iconsRelativeDirectory) || this;
if (window['Dropbox']) {
var Dropbox = window['Dropbox'];
_this._dropbox = new Dropbox({ clientId: clientId });
}
_this.menuPath = '';
_this.ui.id = 'goDropBoxCustomFilepicker';
_this._serviceName = 'Dropbox';
_this._className = 'GoDropBox';
_this._options = {
success: function (files) {
alert("Here's the file link: " + files[0].link);
},
cancel: function () {
},
linkType: 'direct',
multiselect: false,
extensions: ['.pdf', '.doc', '.docx', '.diagram'],
folderselect: false
};
return _this;
}
Object.defineProperty(GoDropBox.prototype, "dropbox", {
get: function () { return this._dropbox; },
enumerable: true,
configurable: true
});
Object.defineProperty(GoDropBox.prototype, "menuPath", {
get: function () { return this._menuPath; },
set: function (value) { this._menuPath = value; },
enumerable: true,
configurable: true
});
GoDropBox.prototype.authorize = function (refreshToken) {
if (refreshToken === void 0) { refreshToken = false; }
var storage = this;
return new Promise(function (resolve, reject) {
if (refreshToken) {
storage.maybeSaveAppState();
var authUrl = storage.dropbox.getAuthenticationUrl(window.location.href);
window.location.href = authUrl;
resolve(false);
}
else if (!storage.dropbox.getAccessToken()) {
if (storage.getAccessTokenFromUrl()) {
storage.dropbox.setAccessToken(storage.getAccessTokenFromUrl());
resolve(true);
}
else {
storage.maybeSaveAppState();
var authUrl = storage.dropbox.getAuthenticationUrl(window.location.href);
window.location.href = authUrl;
resolve(false);
}
}
storage.maybeLoadAppState();
resolve(true);
});
};
GoDropBox.prototype.getAccessTokenFromUrl = function () {
var accessToken = window.location.hash.substring(window.location.hash.indexOf('=') + 1, window.location.hash.indexOf('&'));
return !!accessToken ? accessToken : null;
};
GoDropBox.prototype.maybeSaveAppState = function () {
var storage = this;
try {
var item = storage.makeSaveFile();
window.localStorage.setItem('gdb-' + storage.clientId, item);
}
catch (e) {
throw new Error('Local storage not supported; diagrams model data will not be preserved during Dropboc authentication.');
}
};
GoDropBox.prototype.maybeLoadAppState = function () {
var storage = this;
try {
var fileContents = window.localStorage.getItem('gdb-' + storage.clientId);
storage.loadFromFileContents(fileContents);
localStorage.removeItem('gdb-' + storage.clientId);
}
catch (e) { }
};
GoDropBox.prototype.signOut = function () {
var storage = this;
var dbx = storage.dropbox;
storage.maybeSaveAppState();
dbx.setAccessToken(null);
dbx.authTokenRevoke();
};
GoDropBox.prototype.getUserInfo = function () {
var storage = this;
return new Promise(function (resolve, reject) {
if (!storage.dropbox.getAccessToken() && window.location.hash.indexOf('access_token') === -1) {
storage.authorize(true);
}
else if (!storage.dropbox.getAccessToken() && window.location.hash.indexOf('access_token') === 1) {
storage.authorize(false);
}
storage.dropbox.usersGetCurrentAccount(null).then(function (userData) {
resolve(userData);
}).catch(function (e) {
if (e.status === 400) {
storage.authorize(true);
}
});
});
};
GoDropBox.prototype.showUI = function () {
var storage = this;
var ui = storage.ui;
ui.innerHTML = '';
ui.style.visibility = 'visible';
ui.innerHTML = "<img class='icons' src='" + storage.iconsRelativeDirectory + "dropBox.png'></img><strong>Save Diagram As</strong><hr></hr>";
var userInputDiv = document.createElement('div');
userInputDiv.id = 'userInputDiv';
userInputDiv.innerHTML += '<input id="gdb-userInput" placeholder="Enter filename"></input>';
ui.appendChild(userInputDiv);
var submitDiv = document.createElement('div');
submitDiv.id = 'submitDiv';
var actionButton = document.createElement('button');
actionButton.id = 'actionButton';
actionButton.textContent = 'Save';
actionButton.onclick = function () {
var input = (document.getElementById('gdb-userInput'));
var val = input.value;
if (val !== '' && val !== undefined && val != null) {
ui.style.visibility = 'hidden';
storage.saveWithUI(val);
}
};
submitDiv.appendChild(actionButton);
ui.appendChild(submitDiv);
var cancelDiv = document.createElement('div');
cancelDiv.id = 'cancelDiv';
var cancelButton = document.createElement('button');
cancelButton.id = 'cancelButton';
cancelButton.textContent = 'Cancel';
cancelButton.onclick = function () {
storage.hideUI(true);
};
cancelDiv.appendChild(cancelButton);
ui.appendChild(cancelDiv);
return storage._deferredPromise.promise;
};
GoDropBox.prototype.hideUI = function (isActionCanceled) {
var storage = this;
storage.menuPath = '';
_super.prototype.hideUI.call(this, isActionCanceled);
};
GoDropBox.prototype.processUIResult = function (action) {
var storage = this;
function getSelectedFilepath() {
var radios = document.getElementsByName('dropBoxFile');
var selectedFile = null;
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
selectedFile = radios[i].getAttribute('data');
}
}
return selectedFile;
}
var filePath = getSelectedFilepath();
switch (action) {
case 'Save': {
if (storage.menuPath || storage.menuPath === '') {
var name_1 = document.getElementById('userInput').value;
if (name_1) {
if (name_1.indexOf('.diagram') === -1)
name_1 += '.diagram';
storage.save(storage.menuPath + '/' + name_1);
}
else {
console.log('Proposed file name is not valid');
}
}
break;
}
case 'Load': {
storage.load(filePath);
break;
}
case 'Delete': {
storage.remove(filePath);
break;
}
}
storage.hideUI();
};
GoDropBox.prototype.checkFileExists = function (path) {
var storage = this;
if (path.indexOf('.diagram') === -1)
path += '.diagram';
return new Promise(function (resolve, reject) {
storage.dropbox.filesGetMetadata({ path: path }).then(function (resp) {
if (resp)
resolve(true);
}).catch(function (err) {
resolve(false);
});
});
};
GoDropBox.prototype.getFile = function (path) {
var storage = this;
if (path.indexOf('.diagram') === -1)
path += '.diagram';
return storage.dropbox.filesGetMetadata({ path: path }).then(function (resp) {
if (resp)
return resp;
}).catch(function (err) {
return null;
});
};
GoDropBox.prototype.saveWithUI = function (filename) {
var storage = this;
if (filename === undefined || filename == null) {
return new Promise(function (resolve, reject) {
resolve(storage.showUI());
});
}
else {
if (filename.length < 8) {
filename += '.diagram';
}
else {
var lastEight = filename.substring(filename.length - 8, filename.length);
if (lastEight !== '.diagram') {
filename += '.diagram';
}
}
return new Promise(function (resolve, reject) {
storage._options.success = function (resp) {
var a = 3;
var savedFile = null;
storage.dropbox.filesListFolder({
path: '',
recursive: true
}).then(function (r) {
var files = r.entries;
var possibleFiles = [];
var latestestDate = new Date(-8400000);
var latestFile = null;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var dateModified = new Date(file.server_modified);
if (dateModified != null && dateModified !== undefined && dateModified instanceof Date) {
if (dateModified > latestestDate) {
dateModified = latestestDate;
latestFile = file;
}
}
}
var savedFile = { name: latestFile.name, path: latestFile.path_lower, id: latestFile.id };
storage.currentDiagramFile = savedFile;
resolve(savedFile);
storage._deferredPromise.promise.resolve(savedFile);
storage._deferredPromise.promise = storage.makeDeferredPromise();
});
};
function makeTextFile(text) {
var data = new Blob([text], { type: 'text/plain' });
var uri = '';
uri = window.URL.createObjectURL(data);
return uri;
}
var dataURI = 'data:text/html,' + encodeURIComponent(storage.makeSaveFile());
var Dropbox = window['Dropbox'];
Dropbox.save(dataURI, filename, storage._options);
});
}
};
GoDropBox.prototype.save = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
storage.dropbox.filesUpload({
contents: storage.makeSaveFile(),
path: path,
autorename: true,
mode: { '.tag': 'add' },
mute: false
}).then(function (resp) {
var savedFile = { name: resp.name, id: resp.id, path: resp.path_lower };
storage.currentDiagramFile = savedFile;
resolve(savedFile);
storage._deferredPromise.promise.resolve(savedFile);
storage._deferredPromise.promise = storage.makeDeferredPromise();
}).catch(function (e) {
if (e.status === 400) {
storage.authorize(true);
}
});
}
else if (storage.currentDiagramFile.path) {
path = storage.currentDiagramFile.path;
storage.dropbox.filesUpload({
contents: storage.makeSaveFile(),
path: path,
autorename: false,
mode: { '.tag': 'overwrite' },
mute: true
}).then(function (resp) {
var savedFile = { name: resp.name, id: resp.id, path: resp.path_lower };
resolve(savedFile);
}).catch(function (e) {
if (e.status === 400) {
storage.authorize(true);
}
});
}
else {
resolve(storage.saveWithUI());
}
});
};
GoDropBox.prototype.loadWithUI = function () {
var storage = this;
storage._options.success = function (r) {
var file = r[0];
storage.dropbox.filesGetMetadata({ path: file.id }).then(function (resp) {
var path = resp.path_display;
storage.load(path);
});
};
var Dropbox = window['Dropbox'];
Dropbox.choose(storage._options);
return storage._deferredPromise.promise;
};
GoDropBox.prototype.load = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
storage.dropbox.filesGetTemporaryLink({ path: path }).then(function (resp) {
var link = resp.link;
storage.currentDiagramFile.name = resp.metadata.name;
storage.currentDiagramFile.id = resp.metadata.id;
storage.currentDiagramFile.path = path;
var xhr = new XMLHttpRequest();
xhr.open('GET', link, true);
xhr.setRequestHeader('Authorization', 'Bearer ' + storage.dropbox.getAccessToken());
xhr.onload = function () {
if (xhr.readyState === 4 && (xhr.status === 200)) {
storage.loadFromFileContents(xhr.response);
var loadedFile = { name: resp.metadata.name, id: resp.metadata.id, path: resp.metadata.path_lower };
resolve(loadedFile);
storage._deferredPromise.promise.resolve(loadedFile);
storage._deferredPromise.promise = storage.makeDeferredPromise();
}
else {
throw Error('Cannot load file from Dropbox with path ' + path);
}
};
xhr.send();
}).catch(function (e) {
if (e.status === 400) {
storage.authorize(true);
}
});
}
else
throw Error('Cannot load file from Dropbox with path ' + path);
});
};
GoDropBox.prototype.removeWithUI = function () {
var storage = this;
storage._options.success = function (r) {
var file = r[0];
storage.dropbox.filesGetMetadata({ path: file.id }).then(function (resp) {
var path = resp.path_display;
storage.remove(path);
});
};
var Dropbox = window['Dropbox'];
Dropbox.choose(storage._options);
return storage._deferredPromise.promise;
};
GoDropBox.prototype.remove = function (path) {
var storage = this;
return new Promise(function (resolve, reject) {
if (path) {
storage.dropbox.filesDelete({ path: path }).then(function (resp) {
if (storage.currentDiagramFile && storage.currentDiagramFile['id'] === resp['id'])
storage.currentDiagramFile = { name: null, path: null, id: null };
var deletedFile = { name: resp.name, id: resp['id'], path: resp.path_lower };
resolve(deletedFile);
storage._deferredPromise.promise.resolve(deletedFile);
storage._deferredPromise.promise = storage.makeDeferredPromise();
}).catch(function (e) {
if (e.status === 400) {
storage.authorize(true);
}
});
}
else
throw Error('Cannot delete file from Dropbox with path ' + path);
});
};
return GoDropBox;
}(gcs.GoCloudStorage));
exports.GoDropBox = GoDropBox;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var gcs = __webpack_require__(0);
var GoGoogleDrive = (function (_super) {
__extends(GoGoogleDrive, _super);
function GoGoogleDrive(managedDiagrams, clientId, pickerApiKey, defaultModel, iconsRelativeDirectory) {
var _this = _super.call(this, managedDiagrams, def