David Benson [draw.io] 5 年之前
父節點
當前提交
1be59a28fc

File diff suppressed because it is too large
+ 0 - 41
etc/header-conf/header.js


+ 0 - 171
etc/license-worker/license.js

@@ -1,171 +0,0 @@
-/**
- * Copyright (c) 2011-2020, JGraph Ltd
- */
-
-addEventListener('fetch', event => {
-  event.respondWith(handleRequest(event.request))
-})
-
-/**
- * @param {Request} request
- */
-async function handleRequest(request) 
-{
-	if (request.method !== 'POST') 
-	{
-		return new Response('Only POST method is supported', { status: 500 })
-	}
-	
-	let reqBody = await request.body.getReader().read();
-	let reqBodyTxt = new TextDecoder("utf-8").decode(reqBody.value);
-	let params = new URL('http://dummy.com?' + reqBodyTxt).searchParams;
-	let domain = params.get('domain');
-	let confLicense = params.get('confLicense');
-	let licenseDump = params.get('licenseDump');
-	let sParams = new URL(request.url).searchParams;
-	
-	//Try Query string parameters
-	if (domain == null)
-	{
-		domain = sParams.get('domain');
-	}
-	
-	if (confLicense == null)
-	{
-		confLicense = sParams.get('confLicense');
-	}
-	
-	if (licenseDump == null)
-	{
-		licenseDump = sParams.get('licenseDump');
-	}
-	
-	let email = params.get('email');
-//	let locale = params.get('lc');
-//	let displayName = params.get('ds');
-	
-	if (email != null)
-	{
-		let msg = encodeURIComponent(('license:GWE:' + email));
-		let url = "https://log.diagrams.net/" + msg;
-		fetch(url);
-	}
-	else if (confLicense != null && domain != null)
-	{
-		let msg = encodeURIComponent(('license:cc-domain=' + domain + ',confLicense=' + confLicense));
-		let url = "https://log.diagrams.net/" + msg;
-		fetch(url);
-	}
-	else if (domain != null)
-	{
-		let msg = encodeURIComponent(('license:cc-domain=' + domain));
-		let url = "https://log.diagrams.net/" + msg;
-		fetch(url);
-	}
-	
-	if (licenseDump != null)
-	{
-		let msg = encodeURIComponent('license:cc-licenseDump=') + licenseDump;
-		let url = 'https://log.diagrams.net/' + msg;
-		fetch(url);
-		
-		try
-		{
-			let licenseContent = decodeURIComponent(licenseDump);
-			let obj = JSON.parse(licenseContent);
-//			msg = encodeURIComponent(JSON.stringify(obj));
-//			url = 'https://log.diagrams.net/license:cc-obj-string' + msg;
-//			fetch(url);
-			
-			if (obj != null && obj.installedDate != null)
-			{
-				msg = encodeURIComponent('license:cc-installDate:' + obj.installedDate + ',eval:' + obj.license.evaluation + ',active:' + obj.license.active);
-				url = 'https://log.diagrams.net/' + msg;
-				fetch(url);
-				
-				if (obj.installedDate.startsWith('2019') && obj.license.active && obj.license.evaluation)
-				{
-					url = 'https://log.diagrams.net/license:cc-OMGWTFBBQ';
-					fetch(url);
-				}
-			}
-		}
-		catch (e)
-		{
-			let msg = encodeURIComponent('license:cc-error=') + e;
-			let url = 'https://log.diagrams.net/' + msg;
-			fetch(url);
-		}
-	}
-	
-	if (domain != null)
-	{
-		try
-		{
-			let licenseJson = await getLicense(domain);
-			
-			if (licenseJson == null)
-			{
-				return new Response(null, { status: 204 });
-			}
-			else
-			{
-				return new Response(licenseJson, {
-					status: 200,
-				    headers: {
-					    'Content-Type': 'application/json; charset=utf-8'
-				    }
-				});
-			}
-		}
-		catch (e)
-		{
-			return new Response('INTERNAL_SERVER_ERROR', { status: 500 });
-		}
-	}
-	else
-	{
-		return new Response('HTTP_BAD_REQUEST', { status: 400 });
-	}	
-}
-
-function formatDate(date)
-{
-	let m = date.getMonth() + 1;
-	let d = date.getDate();
-	return date.getFullYear() + '-' + (m < 10? '0' + m : m) + '-' + (d < 10? '0' + d : d);
-}
-
-async function getLicense(domain)
-{
-	// Returns test licences
-	if (domain == 'valid-example.test')
-	{
-		let d = new Date();
-		d.setDate(d.getDate() + 120);
-
-		return '{"expiry": "' + formatDate(d) + '"}';
-	}
-	else if (domain == 'expire-example.test')
-	{
-		let d = new Date();
-		d.setDate(d.getDate() + 30);
-
-		return '{"expiry": "' + formatDate(d) + '"}';
-	}
-	else if (domain == 'expired-example.test')
-	{
-		let d = new Date();
-		d.setDate(d.getDate() - 10);
-
-		return '{"expiry": "' + formatDate(d) + '"}';
-	}
-	else if (domain == 'drawio.atlassian.net')
-	{
-		return '{"atlasCloudLic": "expert"}';
-	}
-
-	// LATER: Check email first then domain
-	var val = await DRAWIO_LICENSE.get(domain, 'json');
-	return val? val.json : null;
-}

+ 0 - 14
etc/license-worker/package.json

@@ -1,14 +0,0 @@
-{
-  "private": true,
-  "name": "license-worker",
-  "version": "1.0.0",
-  "description": "License verification for draw.io",
-  "main": "license.js",
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
-  },
-  "author": "draw.io",
-  "license": "MIT",
-  "devDependencies": {},
-  "dependencies": {}
-}

+ 0 - 6
etc/license-worker/wrangler.toml

@@ -1,6 +0,0 @@
-name = "license-worker"
-type = "javascript"
-account_id = ""
-workers_dev = true
-route = ""
-zone_id = ""

+ 0 - 14
etc/redirect-worker/package.json

@@ -1,14 +0,0 @@
-{
-  "private": true,
-  "name": "redirect-worker",
-  "version": "1.0.0",
-  "description": "Redirect worker for draw.io",
-  "main": "redirect.js",
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
-  },
-  "author": "draw.io",
-  "license": "MIT",
-  "devDependencies": {},
-  "dependencies": {}
-}

+ 0 - 203
etc/redirect-worker/redirect.js

@@ -1,203 +0,0 @@
-/**
- * Copyright (c) 2011-2020, JGraph Ltd
- */
-
-async function handleRequest(request) {
-  let requestURL = new URL(request.url)
-  let host = requestURL.host
-  let sub = host;
-  let path = requestURL.pathname
-  
-  if (host != null)
-  {
-	  let parts = host.split('.')
-	  sub = parts[0]
-  }
-
-  let hostRedirectMap = redirectMap.get(sub)
-  
-  if (hostRedirectMap)
-  {
-	  //Match full path then reduce one level at a time
-	  let redirect, notUsedPath = '', done = false
-	  
-	  do
-	  {
-		  redirect = hostRedirectMap.get(path) || hostRedirectMap.get(path + '/');
-		  
-		  if (redirect) 
-		  {
-			  //Complete the URL
-			  if (redirect.startsWith('/'))
-			  {
-				  redirect = requestURL.protocol + '//' + host + redirect;
-			  }
-			  
-			  return Response.redirect(redirect + notUsedPath, 301)
-		  }
-		  else
-		  {
-			  if (path.startsWith('/label') || path.startsWith('/rest') || path.startsWith('/login.action'))
-			  {
-				  // blah
-			  }
-			  else
-			  {
-				  let msg = encodeURIComponent('redirect-worker-404-' + requestURL);
-				  let url = 'https://log.diagrams.net/' + msg;
-				  fetch(url);
-			  }
-
-			  let lastSlash = path.lastIndexOf('/');
-			  
-			  if (lastSlash >= 0)
-			  {
-				  notUsedPath = path.substr(lastSlash) + notUsedPath;
-				  path = path.substr(0, lastSlash);
-			  }
-			  else
-			  {
-				  done = true
-			  }
-		  }
-	  } while (!done)
-
-
-  }
-
-  // If not in the map, return 404
-  return new Response('NOT_FOUND', { status: 404 });
-}
-
-addEventListener('fetch', async event => {
-  event.respondWith(handleRequest(event.request))
-})
-
-const redirectMap = new Map([
-	['about', new Map([
-		['/drawio-desktop-10-7-5-release', 'https://github.com/jgraph/drawio-desktop/releases/tag/v10.7.5'],
-		['/insert-from-text-now-supports-plantuml', '/use-plantuml-in-draw-io'],
-		['/integrate-draw-io/', '/integrations-ecosystem/'],
-		['/new-edge-styles/', '/connector-styles-and-animations-in-draw-io/'],
-		['/publish-diagrams-to-github/', '/github-support/'],
-		['/prefer-draw-io-in-an-atlassian-style/', '/pick-your-favorite-draw-io-theme-kennedy-atlas-dark-or-minimal/'],
-		['/drawio-desktop-10-7-5-release', 'https://github.com/jgraph/drawio-desktop/releases/tag/v10.7.5'],
-		['/insert-from-text-now-supports-plantuml', '/use-plantuml-in-draw-io'],
-		['/integrate-draw-io/', '/integrations-ecosystem/'],
-		['/new-edge-styles/', '/connector-styles-and-animations-in-draw-io/'],
-		['/publish-diagrams-to-github/', '/github-support/'],
-		['/prefer-draw-io-in-an-atlassian-style/', '/pick-your-favorite-draw-io-theme-kennedy-atlas-dark-or-minimal/'],
-		['/integrations/confluence-integration-2/', 'https://www.diagrams.net/integrations.html'],
-		['/integrations/jira-integration/', 'https://www.diagrams.net/integrations.html'],
-		['/integrations/', 'https://www.diagrams.net/integrations.html'],
-		['/features/examples/', 'https://drawio-app.com/'],
-		['/features/training-material/', 'https://drawio-app.com/tutorials/'],
-		['/features/', 'https://www.diagrams.net/'],
-		['/integrations-ecosystem/', 'https://www.diagrams.net/integrations'],
-		['/multiple-pages-per-diagram/', 'https://www.diagrams.net/blog/multiple-page-diagrams'],
-		['/drawio-data-protection/', 'https://www.diagrams.net/blog/data-protection'],
-		['/use-draw-io-offline/', 'https://www.diagrams.net/blog/diagrams-offline'],
-		['/use-your-own-fonts-in-draw-io/', 'https://www.diagrams.net/blog/external-fonts'],
-		['/4-ways-to-connect-shapes/', 'https://www.diagrams.net/blog/connect-shapes'],
-		['/export-cloudockit-architecture-to-drawio/', 'https://www.diagrams.net/blog/cloudockit-to-drawio'],
-		['/google-drive-connector-for-confluence-cloud/', 'https://www.diagrams.net/'],
-		['/document-your-aws-architecture-with-cloudcraft-and-draw-io/', 'https://www.diagrams.net/blog/drawio-aws-cloudcraft'],
-		['/use-draw-io-diagrams-in-google-docs/', 'https://www.diagrams.net/blog/diagrams-google-docs'],
-		['/improved-import/', 'https://www.diagrams.net/blog/import-formats'],
-		['/incremental-find-plugin/', 'https://www.diagrams.net/doc/faq/find-shapes'],
-		['/sidebar-click/', 'https://www.diagrams.net/blog/quick-add-shapes'],
-		['/find-plugin-update/', 'https://www.diagrams.net/doc/faq/find-shapes'],
-		['/how-to-quickly-remove-sensitive-information-from-draw-io-diagrams/', 'https://www.diagrams.net/doc/faq/anonymize-plugin'],
-		['/draw-io-privacy-and-google-analytics/', 'https://www.diagrams.net/blog/google-analytics'],
-		['/share-diagrams-with-draw-io/', 'https://www.diagrams.net/blog/online-diagram-viewer'],
-		['/publish-link-and-embed-html/', 'https://www.diagrams.net/blog/publish-link'],
-		['/public-google-files/', 'https://www.diagrams.net/blog/share-diagrams-via-google'],
-		['/export-diagrams-as-urls/', 'https://www.diagrams.net/blog/export-url'],
-		['/using-draw-io-diagrams-in-wordpress/', 'https://www.diagrams.net/blog/export-svg'],
-		['/insert-from-text-now-supports-lists-and-graphs/', 'https://www.diagrams.net/blog/insert-from-text'],
-		['/altdrop/', 'https://www.diagrams.net/blog/shortcut-overlay-shapes'],
-		['/animation-and-automatic-layout-explore-complex-diagrams/', 'https://www.diagrams.net/doc/faq/explore-plugin'],
-		['/google-team-drives-support/', 'https://www.diagrams.net/blog/google-shared-drives'],
-		['/30k-reviews/', 'https://www.diagrams.net'],
-		['/external-fonts-in-draw-io/', 'https://www.diagrams.net/blog/external-fonts'],
-		['/analysing-vulnerabilities-with-threat-modelling-in-draw-io/', 'https://www.diagrams.net/blog/threat-modelling'],
-		['/fosdem2020-sponsor/', 'https://www.diagrams.net/blog/fosdem-sponsor'],
-		['/google-docs-add-on-now-supports-high-resolution-images/', 'https://www.diagrams.net/blog/high-resolution-images-google-docs'],
-		['/sql-plugin/', 'https://www.diagrams.net/blog/insert-sql'],
-		['/properties-plugin/', 'https://www.diagrams.net/doc/faq/properties-plugin'],
-		['/number-plugin/', 'https://www.diagrams.net/doc/faq/plugins'],
-		['/40k-reviews/', 'https://www.diagrams.net'],
-		['/new-veeam-stencil-set/', 'https://www.diagrams.net/blog/veeam-stencils'],
-		['/new-github-repository/', 'https://www.diagrams.net/blog/example-diagrams-github'],
-		['/updates-to-draw-io-desktop/', 'https://www.diagrams.net/blog/desktop-updates'],
-		['/simplified-tags-plugin/', 'https://www.diagrams.net/doc/faq/tags-plugin'],
-		['/github-support/', 'https://www.diagrams.net/blog/github-support'],
-		['/support-for-your-language-in-draw-io/', 'https://www.diagrams.net/blog/translate-drawio'],
-		['/translate-drawio/', 'https://www.diagrams.net/blog/translate-drawio'],
-		['/altshiftcursor/', 'https://www.diagrams.net/blog/shortcut-clone-connect'],
-		['/altshiftselect-now-removes-selected-cells%ef%bb%bf/', 'https://www.diagrams.net/blog/shortcut-deselect-shapes'],
-		['/draw-io-diagrams-for-confluence/', 'https://www.diagrams.net/integrations'],
-		['/scratchpad-in-chrome-app/', 'https://www.diagrams.net/blog/drawio-chrome-app'],
-		['/find-and-tags/', 'https://www.diagrams.net/doc/faq/find-shapes'],
-		['/disable-recursive-resize/', 'https://www.diagrams.net/blog/disable-resize-children'],
-		['/placeholder-scope/', 'https://www.diagrams.net/blog/placeholder-scope'],
-		['/scissors-tool/', 'https://www.diagrams.net/blog/shortcut-move-area'],
-		['/shiftdelete-in-toolbar-now-deletes-cells-with-connections%ef%bb%bf/', 'https://www.diagrams.net/blog/shortcut-shift-delete'],
-		['/snap-to-point/', 'https://www.diagrams.net/blog/snap-to-point'],
-		['/features/examples/', 'https://drawio-app.com/'],
-		['/features/training-material/', 'https://drawio-app.com/tutorials/'],
-		['/terms-conditions/', 'https://seibert-media.com/general-terms/'],
-		['/support/', 'https://github.com/jgraph/drawio/wiki/Getting-Support'],
-		['/about-us/', 'https://www.diagrams.net/about.html'],
-		['/', 'https://drawio-app.com']
-	])],
-	['support', new Map([
-		['/label', 'https://127.0.0.1'],
-		['/rest', 'https://127.0.0.1'],
-		['/display/DFCS/draw.io+for+Confluence+Server', 'https://drawio-app.com'],
-		['/display/DO/Exporting+Files', 'https://desk.draw.io/a/solutions/articles/16000067785'],
-		['/display/DO/Online+Support', 'https://github.com/jgraph/drawio/wiki/Getting-Support'],
-		['/display/DO', 'https://github.com/jgraph/drawio/wiki/Getting-Support'],
-		['/display/DAFGD/draw.io+Add-on+for+Google+Docs', 'https://www.diagrams.net/blog/diagrams-google-docs.html'],
-		['/x/LYAk', 'https://seibert.biz/atlassianeula'],
-		['/display/DOB/2016/04/28/UML+State+Diagrams+with+draw.io', 'https://drawio-app.com/uml-state-diagrams-with-draw-io/'],
-		['/display/do/2015/01/08/gliffy+and+lucidchart+importing', 'https://desk.draw.io/support/solutions/articles/16000064013-mass-import-gliffy-diagrams-to-draw-io-in-confluence-server'],
-		['/display/DFCS/draw.io+for+Confluence+and+JIRA+support+terms+and+Service+Level+Agreement',
-		  'https://marketplace.atlassian.com/apps/1210933/draw-io-diagrams-for-confluence?hosting=server&tab=support'],
-		['/', 'https://github.com/jgraph/drawio/wiki/Getting-Support']
-	])],
-	['blog', new Map([
-		['/', 'https://www.diagrams.net/blog']
-	])],
-	['download', new Map([
-		['/', 'https://github.com/jgraph/drawio-desktop/releases/latest']
-	])],
-	['get', new Map([
-		['/', 'https://github.com/jgraph/drawio-desktop/releases/latest']
-	])],
-	['docsaddon', new Map([
-		['/', 'https://gsuite.google.com/marketplace/app/drawio_viewer_for_docs/224440279306']
-	])],
-	['gsuite', new Map([
-		['/', 'https://gsuite.google.com/marketplace/app/drawio_diagrams/671128082532']
-	])],
-	['office', new Map([
-		['/', 'https://appsource.microsoft.com/product/office/wa200000113']
-	])],
-	['slidesaddon', new Map([
-		['/', 'https://gsuite.google.com/marketplace/app/drawio_diagrams_for_slides/588283048931']
-	])],
-	['sheetsaddon', new Map([
-		['/', 'https://gsuite.google.com/marketplace/app/drawio_diagrams_for_sheets/948903782998']
-	])],
-	['doc', new Map([
-		['/i18n', 'https://docs.google.com/spreadsheets/d/1FoYdyEraEQuWofzbYCDPKN7EdKgS_2ZrsDrOA8scgwQ'],
-		['/', 'https://www.diagrams.net/doc/']
-	])],
-	['app', new Map([
-		['/', 'https://app.diagrams.net']
-	])],
-	['new', new Map([
-		['/', 'https://app.diagrams.net/?splash=0']
-	])]
-])

+ 0 - 6
etc/redirect-worker/wrangler.toml

@@ -1,6 +0,0 @@
-name = "redirect-worker"
-type = "javascript"
-account_id = ""
-workers_dev = true
-route = ""
-zone_id = ""

+ 0 - 479
etc/sheetsaddon/Code.gs

@@ -1,479 +0,0 @@
-/**
- * diagrams.net Diagrams Sheets add-on v1.1
- * Copyright (c) 2020, JGraph Ltd
- */
-var EXPORT_URL = "https://exp.draw.io/ImageExport4/export";
-var DIAGRAMS_URL = "https://app.diagrams.net/";
-var DRAW_URL = "https://www.draw.io/";
-
-/**
- * Creates a menu entry in the Google Docs UI when the document is opened.
- */
-function onOpen()
-{
-  SpreadsheetApp.getUi().createAddonMenu()
-      .addItem("Insert Diagrams...", "insertDiagrams")
-      .addSeparator()
-      .addItem("Update Current Sheet", "updateCurrent")
-      .addItem("Update All Sheets", "updateAll")
-      .addSeparator()
-      .addItem("New Diagram...", "newDiagram")
-      .addToUi();
-  
-  //We cannot get selected image yet! So we cannot do update/edit selected
-}
-
-/**
- * Runs when the add-on is installed.
- */
-function onInstall()
-{
-  onOpen();
-}
-
-/**
- * Gets the user's OAuth 2.0 access token so that it can be passed to Picker.
- * This technique keeps Picker from needing to show its own authorization
- * dialog, but is only possible if the OAuth scope that Picker needs is
- * available in Apps Script. In this case, the function includes an unused call
- * to a DriveApp method to ensure that Apps Script requests access to all files
- * in the user's Drive.
- *
- * @return {string} The user's OAuth 2.0 access token.
- */
-function getOAuthToken() {
-  DriveApp.getFolders();
-  return ScriptApp.getOAuthToken();
-}
-
-/**
- * Shows a picker and lets the user select multiple diagrams to insert.
- */
-function insertDiagrams()
-{
-  var html = HtmlService.createHtmlOutputFromFile('Picker.html')
-      .setWidth(640).setHeight(480)
-      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
-  SpreadsheetApp.getUi().showModalDialog(html, 'Select files');
-}
-
-function refreshSheet()
-{
-  var cur = SpreadsheetApp.getActiveSheet();
-  var dummy = SpreadsheetApp.getActive().insertSheet('Working...');
-  SpreadsheetApp.setActiveSheet(dummy);
-  SpreadsheetApp.flush();
-  SpreadsheetApp.setActiveSheet(cur, true);
-  SpreadsheetApp.getActive().deleteSheet(dummy);
-}
-
-/**
- * Inserts an image for the given diagram.
- */
-function pickerHandler(items)
-{
-  if (items != null && items.length > 0)
-  {
-      var errors = [];
-
-      var sheet = SpreadsheetApp.getActiveSheet();
-      var curCell = sheet.getSelection().getCurrentCell();
-      var col = 1, row = 1;
-
-      if (curCell != null)
-      {
-          col = curCell.getColumn();
-          row = curCell.getRow();
-      }
-
-      var step = 1;
-    
-      for (var i = 0; i < items.length; i++)
-      {
-        try
-        {
-          var ins = insertDiagram(items[i].id, items[i].page, col, row); 
-          
-          if (ins != null)
-          { 
-            col = col + step;
-            row = row + step;
-          }
-	      else
-	      {
-	    	errors.push("- " + items[i].name + ": Unknown error");
-	      }
-        }
-        catch (e)
-        {
-          errors.push("- " + items[i].name + ": " + e.message);
-        }
-      }
-    
-      // Shows message only in case of errors
-      if (errors.length > 0)
-      {
-        var msg = "";
-
-        if (errors.length > 0)
-        {
-          msg += errors.length + " insert" + ((errors.length > 1) ? "s" : "") + " failed:\n";
-        }
-        
-        msg += errors.join("\n");
-        SpreadsheetApp.getUi().alert(msg);
-      }
-    
-      refreshSheet();
-  }
-}
-
-/**
- * Inserts the given diagram at the given position.
- */
-function insertDiagram(id, page, col, row)
-{
-  var result = fetchImage(id, page, 'auto'); //We should set scale to 1 as with 'auto' we cannot scale it back (see below) 
-  
-  var blob = result[0];
-  var w = result[1];
-  var h = result[2];
-  var s = result[3] < 1? 1: result[3];
-  var img = null;
-  
-  if (blob != null)
-  {
-      img = SpreadsheetApp.getActiveSheet().insertImage(blob, col, row);
-      //Setting width/height force the image to disappear, and a refresh is needed!
-      img.setWidth( w / s );
-	  img.setHeight( h / s );
-      var link = createLink(id, page, result[4], 'auto');
-	  img.setAltTextDescription(link);
-  }
-  else
-  {
-    throw new Error("Invalid image " + id);
-  }
-  
-  return img;
-}
-
-/**
- * Get draw.io diagrams images in a given sheet
- */
-function getSheetDrawioDiagrams(sheet)
-{
-  var allImages = sheet.getImages();
-  var drawioImages = [];
-  
-  for (var i = 0; i < allImages.length; i++)
-  {
-      if (isValidLink(allImages[i].getAltTextDescription()))
-      {
-          drawioImages.push(allImages[i]);
-      }
-  }
-  
-  return drawioImages;
-}
-
-/**
- * Updates the current sheet diagrams in-place.
- */
-function updateCurrent()
-{
-  var drawioImages = getSheetDrawioDiagrams(SpreadsheetApp.getActiveSheet());
-  
-  if (drawioImages.length > 0)
-  {
-      updateElements(drawioImages);
-  }
-  else
-  {
-      SpreadsheetApp.getUi().alert("No diagrams found in current sheet");
-  }
-}
-
-/**
- * Updates all diagrams in the document.
- */
-function updateAll()
-{
-  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
-  
-  var drawioImages = [];
-  
-  for (var i = 0; i < sheets.length; i++)
-  {
-      var imgs = getSheetDrawioDiagrams(sheets[i]);
-      drawioImages.push.apply(drawioImages, imgs);
-  }
-
-  updateElements(drawioImages);
-}
-
-/**
- * Updates all given diagrams.
- */
-function updateElements(elts)
-{
-  if (elts != null)
-  {
-    var updated = 0;
-    var errors = [];
-    
-    for (var i = 0; i < elts.length; i++)
-    {
-      try
-      {
-        var upd = updateElement(elts[i]); 
-      
-        if (upd != null)
-        {
-          updated++;
-        }
-        else
-        {
-          errors.push("- Unknown Error");
-        }
-      }
-      catch (e)
-      {
-        errors.push("- " + e.message);
-      }
-    }
-    
-    // Shows status in case of errors or multiple updates
-    if (errors.length > 0 || updated > 0)
-    {
-      var msg = "";
-      
-      if (updated > 0)
-      {
-        msg += updated + " diagram" + ((updated > 1) ? "s" : "") + " updated\n";
-        refreshSheet();
-      }
-      
-      if (errors.length > 0)
-      {
-        msg += errors.length + " update" + ((errors.length > 1) ? "s" : "") + " failed:\n";
-      }
-      
-      msg += errors.join("\n");
-      SpreadsheetApp.getUi().alert(msg);
-    }
-  }
-}
-
-/**
- * Returns true if the given URL points to draw.io
- */
-function createLink(id, page, pageId, scale)
-{
-  var params = [];
-  
-  if (pageId != null)
-  {
-  	params.push('page-id=' + pageId);
-  }
-  else if (page != null && page != "0")
-  {
-    params.push('page=' + page);
-  }
-  
-  params.push('scale=' + (scale || '1'));
-  
-  return DIAGRAMS_URL + ((params.length > 0) ? "?" + params.join("&") : "") + "#G" + id;
-}
-
-/**
- * Returns true if the given URL points to draw.io
- */
-function isValidLink(url)
-{
-  return url != null && (url.substring(0, DRAW_URL.length) == DRAW_URL ||
-  	url.substring(0, DIAGRAMS_URL.length) == DIAGRAMS_URL ||
-  	url.substring(0, 22) == "https://drive.draw.io/");
-}
-
-/**
- * Returns the diagram ID for the given URL.
- */
-function getDiagramId(url)
-{
-  return url.substring(url.lastIndexOf("#G") + 2);
-}
-
-/**
- * Returns the diagram ID for the given URL.
- */
-function getUrlParams(url)
-{
-  var result = {};
-  var idx = url.indexOf("?");
-  
-  if (idx > 0)
-  {
-    var idx2 = url.indexOf("#", idx + 1);
-    
-    if (idx2 < 0)
-    {
-      idx2 = url.length;
-    }
-    
-    if (idx2 > idx)
-    {
-      var search = url.substring(idx + 1, idx2);
-      var tokens = search.split("&");
-      
-      for (var i = 0; i < tokens.length; i++)
-      {
-         var idx3 = tokens[i].indexOf('=');
-        
-         if (idx3 > 0)
-         {
-           result[tokens[i].substring(0, idx3)] = tokens[i].substring(idx3 + 1);
-         }
-      }
-    }
-  }
-  
-  return result;
-}
-
-/**
- * Updates the diagram in the given inline image and returns the new inline image.
- */
-function updateElement(elt)
-{
-  var result = null;
-  var url = elt.getAltTextDescription();
-  var id = getDiagramId(url);
-  var params = getUrlParams(url);
-  
-  if (id != null && id.length > 0)
-  {
-    result = updateDiagram(id, params["page"], params["scale"] || 1, elt, params["page-id"]);
-  }
-  else
-  {
-    // commenting this out as well - invalid link might indicate image is not coming from draw.io
-    // throw new Error("Invalid link " + url);
-  }
-  
-  return result;
-}
-
-/**
- * Updates the diagram in the given inline image and returns the new inline image.
- */
-function updateDiagram(id, page, scale, elt, pageId)
-{
-  var img = null;
-  var result = fetchImage(id, page, scale, pageId);
-  
-  var isOK = false;
-  
-  if (result != null) 
-  {
-    var blob = result[0];
-    var w = result[1];
-    var h = result[2];
-    var s = result[3] < 1? 1: result[3];
-    
-    if (blob != null)
-    {
-      isOK = true;
-
-      // replace image with the same link
-      var img = elt.replace(blob);
-      img.setWidth( w / s );
-	  img.setHeight( h / s );
-      var link = createLink(id, page, result[4], scale);
-      img.setAltTextDescription(link);
-    }
-  }
-  if (!isOK)
-  {
-    throw new Error("Invalid image " + id);
-  }
-  
-  return img;
-}
-
-/**
- * Fetches the diagram for the given document ID.
- */
-function fetchImage(id, page, scale, pageId)
-{
-    var file = DriveApp.getFileById(id);
-
-    if (file != null && file.getSize() > 0)
-    {
-    	var isPng = file.getMimeType() == "image/png";
-        
-        var fileData = isPng? Utilities.base64Encode(file.getBlob().getBytes()) : encodeURIComponent(file.getBlob().getDataAsString());
-      
-    	var data = {
-		  "format": "png",
-          "scale": scale || "1",
-		  "xml": fileData,
-		  "extras": "{\"isPng\": " + isPng + ", \"isGoogleApp\": true, \"isGoogleSheet\": true}"
-		};
-    
-    	if (pageId != null)
-		{
-			data.pageId = pageId;
-		}
-		else
-		{
-			data.from = page || "0";
-		}
-    
-	    var response = UrlFetchApp.fetch(EXPORT_URL,
-	    {
-		  "method": "post",
-		  "payload": data
-		});
-      
-      var headers = response.getHeaders();
-
-      return [response.getBlob(), headers["content-ex-width"] || 0, headers["content-ex-height"] || 0, headers["content-scale"] || 1, headers["content-page-id"]];
-    }
-    else
-    {
-    	// Returns an empty, transparent 1x1 PNG image as a placeholder
-    	return [Utilities.newBlob(Utilities.base64Decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNg+M9QDwADgQF/e5IkGQAAAABJRU5ErkJggg=="), "image/png")];
-    }
-}
-
-/**
- * Creates a new diagram.
- */
-function newDiagram()
-{
-  openUrl('https://app.diagrams.net/?mode=google');
-}
-
-/**
- * Open a URL in a new tab.
- */
-function openUrl(url)
-{
-  var html = HtmlService.createHtmlOutput('<html><script>'
-  +'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
-  +'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
-  +'if(document.createEvent){'
-  +'  var event=document.createEvent("MouseEvents");'
-  +'  if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'                          
-  +'  event.initEvent("click",true,true); a.dispatchEvent(event);'
-  +'}else{ a.click() }'
-  +'close();'
-  +'</script>'
-  // Offer URL as clickable link in case above code fails.
-  +'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="'+url+'" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
-  +'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
-  +'</html>')
-  .setWidth(90).setHeight(1);
-  SpreadsheetApp.getUi().showModalDialog(html, "Opening...");
-}

+ 0 - 252
etc/sheetsaddon/Picker.html

@@ -1,252 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
-<script type="text/javascript">
-  var DIALOG_DIMENSIONS = {width: 620, height: 460};
-  var DEVELOPER_KEY = 'AIzaSyB4sU8tc25bR_87qNb7eUVQN72_vv8mpbU';
-
-  /**
-   * Loads the Google Picker API.
-   */
-  function onApiLoad()
-  {
-    gapi.load('picker', {'callback': function()
-    {
-      getOAuthToken();
-    }});
-  }
-
-  /**
-   * Gets the user's OAuth 2.0 access token from the server-side script so that
-   * it can be passed to Picker. This technique keeps Picker from needing to
-   * show its own authorization dialog, but is only possible if the OAuth scope
-   * that Picker needs is available in Apps Script. Otherwise, your Picker code
-   * will need to declare its own OAuth scopes.
-   */
-  function getOAuthToken()
-  {
-	try
-	{
-    	google.script.run.withSuccessHandler(createPicker)
-        	.withFailureHandler(showError).getOAuthToken();
-	}
-	catch (e)
-	{
-		showError(e.message);
-	}
-  }
-
-  /**
-   * Creates a Picker that can access the user's spreadsheets. This function
-   * uses advanced options to hide the Picker's left navigation panel and
-   * default title bar.
-   *
-   * @param {string} token An OAuth 2.0 access token that lets Picker access the
-   *     file type specified in the addView call.
-   */
-  function createPicker(token)
-  {
-    if (token)
-    {
-		var view1 = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
-	    	.setParent('root')
-	    	.setIncludeFolders(true)
-			.setMimeTypes('*/*');
-		
-		var view2 = new google.picker.DocsView()
-			.setIncludeFolders(true);
-		
-		var view3 = new google.picker.DocsView()
-			.setEnableDrives(true)
-			.setIncludeFolders(true);
-
-		var view4 = new google.picker.DocsUploadView()
-			.setIncludeFolders(true);
-
-		var picker = new google.picker.PickerBuilder()
-		    .addView(view1)
-		    .addView(view2)
-		    .addView(view3)
-	    	.addView(view4)
-	    	.addView(google.picker.ViewId.RECENTLY_PICKED)
-		    .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
-		    .enableFeature(google.picker.Feature.SUPPORT_DRIVES)
-		    .hideTitleBar()
-		    .setOAuthToken(token)
-		    .setDeveloperKey(DEVELOPER_KEY)
-		    .setCallback(pickerCallback)
-		    .setOrigin(google.script.host.origin)
-		    .setSize(DIALOG_DIMENSIONS.width - 2, DIALOG_DIMENSIONS.height - 2)
-		    .build();
-		picker.setVisible(true);
-    }
-    else
-    {
-      	showError('Unable to load the file picker.');
-    }
-  }
-
-  /**
-   * A callback function that extracts the chosen document's metadata from the
-   * response object. For details on the response object, see
-   * https://developers.google.com/picker/docs/result
-   *
-   * @param {object} data The response object.
-   */
-  function pickerCallback(data)
-  {
-    var action = data[google.picker.Response.ACTION];
-    
-    if (action == google.picker.Action.PICKED)
-    {
-      var items = [];
-      var docs = data[google.picker.Response.DOCUMENTS];
-      
-      for (var i = 0; i < docs.length; i++)
-      {
-        items.push({name: docs[i][google.picker.Document.NAME], id: docs[i][google.picker.Document.ID]}); 
-      }
-      
-      if (items.length > 0)
-      {
-        selectPages(items, function(execute)
-        {
-          if (execute)
-          {
-            document.getElementById('status').innerHTML = (items.length > 1) ?
-              'Inserting ' + items.length + ' Diagrams...' : "Inserting Diagram...";
-            google.script.run.withSuccessHandler(closeWindow).pickerHandler(items);
-          }
-          else
-          {
-            google.script.host.close();
-          }
-        });
-      }
-      else
-      {
-        google.script.host.close();
-      }
-    }
-    else if (action == google.picker.Action.CANCEL)
-    {
-      google.script.host.close();
-    }
-  }
-    
-  /**
-   * Closes the window after all diagrams have been inserted.
-   */
-  function selectPages(items, handler)
-  {
-    document.getElementById('spinner').style.display = 'none';
-    
-    var pageInputs = [];
-    var table = document.createElement('table');
-    table.setAttribute('cellpadding', '4');
-    table.style.width = '100%';
-    var tbody = document.createElement('tbody');
-    
-    var title = document.createElement('td');
-    title.setAttribute('colspan', '2');
-    title.innerHTML = '<font size="3">Select ' + ((items.length > 1) ? 'Pages' : 'Page') +
-      ' and Click Insert</font>';
-    
-    var row = document.createElement('tr');
-    row.appendChild(title);
-    tbody.appendChild(row);
-    
-    for (var i = 0; i < items.length; i++)
-    {
-      var row = document.createElement('tr');
-      
-      var td1 = document.createElement('td');
-      td1.appendChild(document.createTextNode(items[i].name));
-      td1.setAttribute('title', 'ID ' + items[i].id);
-      row.appendChild(td1);
-      
-      var td2 = document.createElement('td');
-      td2.style.textAlign = 'right';
-      td2.style.paddingLeft = '10px';
-      td2.innerHTML = 'Page: ';
-      var input = document.createElement('input');
-      input.setAttribute('type', 'number');
-      input.setAttribute('min', '1');
-      input.setAttribute('value', '1');
-      input.style.width = '60px';
-      td2.appendChild(input);
-      pageInputs.push(input);
-      row.appendChild(td2);
-      
-      tbody.appendChild(row);
-    }
-    
-    var buttons = document.createElement('td');
-    buttons.setAttribute('colspan', '2');
-    buttons.setAttribute('align', 'right');
-
-    var insertButton = document.createElement('button');
-    insertButton.innerHTML = 'Insert';
-    insertButton.className = 'blue';
-    buttons.appendChild(insertButton);
-
-    insertButton.addEventListener('click', function()
-    {
-      table.parentNode.removeChild(table);
-      document.getElementById('spinner').style.display = '';
-      
-      for (var i = 0; i < items.length; i++)
-      {
-        items[i].page = (parseInt(pageInputs[i].value) || 1) - 1;
-      }
-      
-      handler(true);
-    });
-
-    var cancelButton = document.createElement('button');
-    cancelButton.innerHTML = 'Cancel';
-    buttons.appendChild(cancelButton);
-
-    cancelButton.addEventListener('click', function()
-    {
-      handler(false);
-    });
-
-    var row = document.createElement('tr');
-    row.appendChild(buttons);
-    tbody.appendChild(row);
-    
-    table.appendChild(tbody);
-    document.body.appendChild(table);
-  }
-
-  /**
-   * Closes the window after all diagrams have been inserted.
-   */
-  function closeWindow()
-  {
-    google.script.host.close();
-  }
-
-  /**
-   * Displays an error message within the #result element.
-   *
-   * @param {string} message The error message to display.
-   */
-  function showError(message)
-  {
-	document.getElementById('icon').setAttribute('src', 'https://www.draw.io/images/stop-flat-icon-80.png');
-    document.getElementById('status').innerHTML = 'Error: ' + message;
-  }
-</script>
-</head>
-<body>
-<div id="spinner" style="text-align:center;padding-top:100px;">
-<img id="icon" src="https://www.draw.io/images/ajax-loader.gif"/>
-<h3 id="status" style="margin-top:6px;">Loading...</h3>
-</div>
-<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
-</body>
-</html>
-

+ 0 - 13
etc/sheetsaddon/README

@@ -1,13 +0,0 @@
-For Deployment:
-
-As david@jgraph.com use (see Tools, Script Editor):
-https://docs.google.com/spreadsheets/d/1yUT6UE9bKDJCx7Kj1VEbrEaLyigcTO_bxyRXBDlFoLU/edit
-
-Open the web app script in the script editor.
-Make the changes you wanted. Test the code to ensure it functions as intended and is bug-free.
-Click File > Manage Versions. Enter a new version description and click Save New Version. Click OK to close the dialog.
-Click Publish > Deploy as Sheets add-on. Update the Project version to the new version you just created.
-Click Update web shop draft.
-In the new window, click on Publish changes.
-
-If you get error "Sorry, unable to open the file at this time.", try Incognito mode.