├── .babelrc ├── .eslintrc ├── .gitignore ├── README.md ├── React Transform Boilerplate LICENSE ├── devServer.js ├── index.html ├── jsconfig.json ├── manifest.xml ├── package.json ├── src ├── App.js ├── Constants.js ├── ShareCountControl.jsx ├── colors.js ├── index.js └── office.js ├── webpack.config.dev.js └── webpack.config.prod.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "stage": 0, 3 | "env": { 4 | "development": { 5 | "plugins": ["react-transform"], 6 | "extra": { 7 | "react-transform": { 8 | "transforms": [{ 9 | "transform": "react-transform-hmr", 10 | "imports": ["react"], 11 | "locals": ["module"] 12 | }, { 13 | "transform": "react-transform-catch-errors", 14 | "imports": ["react", "redbox-react"] 15 | }] 16 | } 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "jsx": true, 4 | "modules": true 5 | }, 6 | "env": { 7 | "browser": true, 8 | "node": true 9 | }, 10 | "parser": "babel-eslint", 11 | "rules": { 12 | "quotes": [2, "single"], 13 | "strict": [2, "never"], 14 | "react/jsx-uses-react": 2, 15 | "react/jsx-uses-vars": 2, 16 | "react/react-in-jsx-scope": 2 17 | }, 18 | "plugins": [ 19 | "react" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | npm-debug.log 4 | dist -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Excel Plugin Social Sharing Addin with ReactJs, ES6 and Office Fabric 2 | ======================================================== 3 | 4 | The addin pulls data from social media providers, thanks to [Jonathan Moore](https://gist.github.com/jonathanmoore/2640302), about a link and puts this data into excel for the user to work with. 5 | 6 | Technical 7 | ============================ 8 | 9 | The solution uses React Transform Boilerplate to transpile the ES6 and give you a nice development environment. 10 | With chrome, on updating a react component and saving the file, the browser will pull in the changes and display them live. 11 | With the addin running in Excel, on save the transpile will kick off you then then refresh the addin. [Would be great to get this live reloading too](https://github.com/UKDXOfficeDev/office-reactjs-taskpane-addin/issues/3) 12 | 13 | To get going clone the repo, install the npm packages and do npm start to start the development server: 14 | 15 | git clone https://github.com/UKDXOfficeDev/office-reactjs-taskpane-addin.git 16 | cd office-reactjs-taskpane-addin 17 | npm install 18 | npm start 19 | 20 | Once you've done that you can now add the addin into Excel, heres a quick guide showing how 21 | 22 | ![Install into excel, gif](https://cloud.githubusercontent.com/assets/1939288/10243776/f4a00cee-68f2-11e5-95ce-07a7b1a57914.gif) 23 | 24 | The solution uses: 25 | 26 | - React 27 | - [React Transform Boilerplate](https://github.com/gaearon/react-transform-boilerplate) 28 | - [NPM & Nodejs](https://nodejs.org/en/) 29 | - [Office Fabric](http://officeuifabric.com/) 30 | - [Visual Studio Code for the editor](https://code.visualstudio.com/) - Could use another editor if you liked. 31 | 32 | Live Reload & Excel Startup/Editing Demos 33 | ============================ 34 | 35 | ![exceladdinlivereload-chrome](https://cloud.githubusercontent.com/assets/1939288/10243829/5032b8cc-68f3-11e5-8135-2bc134c87d30.gif) 36 | 37 | ![exceladdineditinginexcel](https://cloud.githubusercontent.com/assets/1939288/10244113/1210dfea-68f5-11e5-9520-d042b35f8927.gif) 38 | 39 | Notes 40 | ============================ 41 | 42 | I'm new to ReactJS at the moment and still finding the ropes, if you spot something I've done wrong or that doesn't follow best practices please raise an issue or submit a Pull Request. 43 | 44 | Current backlog: I'd like to refactor the ShareControl into multiple different controls to better fit ReactJs. 45 | 46 | 47 | -------------------------------------------------------------------------------- /React Transform Boilerplate LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /devServer.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var express = require('express'); 3 | var webpack = require('webpack'); 4 | var config = require('./webpack.config.dev'); 5 | 6 | var app = express(); 7 | var compiler = webpack(config); 8 | 9 | app.use(require('webpack-dev-middleware')(compiler, { 10 | noInfo: true, 11 | publicPath: config.output.publicPath 12 | })); 13 | 14 | app.use(require('webpack-hot-middleware')(compiler)); 15 | 16 | app.get('*', function(req, res) { 17 | res.sendFile(path.join(__dirname, 'index.html')); 18 | }); 19 | 20 | app.listen(3000, 'localhost', function(err) { 21 | if (err) { 22 | console.log(err); 23 | return; 24 | } 25 | 26 | console.log('Listening at http://localhost:3000'); 27 | }); 28 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | React Transform Boilerplate 6 | 7 | 8 | 9 | 10 | 16 | 17 | 25 | 26 | 27 | 28 |
29 |
30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "compilerOptions": { 4 | 5 | "target": "ES6", 6 | 7 | "module": "commonjs", 8 | 9 | "experimentalDecorators" : true 10 | 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 08afd7fe-1631-42f4-84f1-5ba51e242f99 6 | 1.0 7 | Gripdev 8 | EN-US 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ReadWriteDocument 22 | 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-transform-boilerplate", 3 | "version": "1.0.0", 4 | "description": "A new Webpack boilerplate with hot reloading React components, and error handling on module and component level.", 5 | "scripts": { 6 | "clean": "rimraf dist", 7 | "build:webpack": "NODE_ENV=production webpack --config webpack.config.prod.js", 8 | "build": "npm run clean && npm run build:webpack", 9 | "start": "node devServer.js", 10 | "lint": "eslint src" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/gaearon/react-transform-boilerplate.git" 15 | }, 16 | "keywords": [ 17 | "react", 18 | "reactjs", 19 | "boilerplate", 20 | "hot", 21 | "reload", 22 | "hmr", 23 | "live", 24 | "edit", 25 | "webpack", 26 | "babel", 27 | "react-transform" 28 | ], 29 | "author": "Dan Abramov (http://github.com/gaearon)", 30 | "license": "CC0-1.0", 31 | "bugs": { 32 | "url": "https://github.com/gaearon/react-transform-boilerplate/issues" 33 | }, 34 | "homepage": "https://github.com/gaearon/react-transform-boilerplate", 35 | "devDependencies": { 36 | "babel-core": "^5.4.7", 37 | "babel-eslint": "^3.1.9", 38 | "babel-loader": "^5.1.2", 39 | "babel-plugin-react-transform": "^1.1.1", 40 | "eslint": "^1.3.1", 41 | "eslint-plugin-react": "^2.3.0", 42 | "express": "^4.13.3", 43 | "react-transform-catch-errors": "^1.0.0", 44 | "react-transform-hmr": "^1.0.0", 45 | "redbox-react": "^1.0.1", 46 | "rimraf": "^2.4.3", 47 | "webpack": "^1.9.6", 48 | "webpack-dev-middleware": "^1.2.0", 49 | "webpack-hot-middleware": "^2.0.0" 50 | }, 51 | "dependencies": { 52 | "react": "^0.13.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { NICE, SUPER_NICE } from './colors'; 3 | import { ShareCountControl } from './ShareCountControl.jsx'; 4 | 5 | export class App extends Component { 6 | render() { 7 | 8 | return ( 9 |
10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Constants.js: -------------------------------------------------------------------------------- 1 | export class SocialProvider { 2 | constructor(url, field, title) { 3 | this.url = url; 4 | this.field = field; 5 | this.title = title; 6 | } 7 | } 8 | 9 | export class Constants { 10 | 11 | 12 | static get SocialProviders() { 13 | return [new SocialProvider('http://graph.facebook.com/?id=', 'shares', 'Facebook') 14 | ]; 15 | } 16 | } 17 | //new SocialProvider('http://cdn.api.twitter.com/1/urls/count.json?url=', 'count', "Twitter"), 18 | //new SocialProvider('http://graph.facebook.com/?id=', 'shares', 'Facebook'), 19 | //new SocialProvider('https://www.linkedin.com/countserv/count/share?format=json&url=', 'count', 'Linkedin') -------------------------------------------------------------------------------- /src/ShareCountControl.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Constants, SocialProvider } from './Constants'; 3 | 4 | export class ShareCountControl extends Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = { shareCounts: [], url: 'http://bing.com', showResults: false}; 8 | } 9 | 10 | getSocialData() 11 | { 12 | this.setState({shareCounts: []}); 13 | var that = this; 14 | Constants.SocialProviders.map(function (socialProvider, index){ 15 | that.getDataForProvider(socialProvider); 16 | }); 17 | } 18 | 19 | getDataForProvider(socialProvider) { 20 | var request = new XMLHttpRequest(); 21 | var call = socialProvider.url + this.state.url; 22 | var that = this; 23 | request.open('GET', call, true); 24 | request.onload = function (e) { 25 | var data = JSON.parse(request.responseText); 26 | var currentShareCounts = that.state.shareCounts; 27 | var newItem = { title: socialProvider.title, count: data[socialProvider.field]} 28 | currentShareCounts.push(newItem); 29 | that.setState({ shareCounts : currentShareCounts, showResults: true }); 30 | 31 | }; 32 | 33 | request.onerror = function () { 34 | console.debug("Error calling resource: " + request.responseBody); 35 | }; 36 | 37 | request.send(); 38 | } 39 | 40 | putDataOnExcelPage() { 41 | var matrixToInsert = this.state.shareCounts.map(function(item){ 42 | return [item.title, item.count]; 43 | }); 44 | var matrixWithHeader = [['Social Network', 'Share Count']] 45 | var matrix = matrixWithHeader.concat(matrixToInsert); 46 | 47 | //NB. Review: Currently using global window object to share OfficeJs instance due to ES6 Scoping. Doesn't feel like the nicest solution. 48 | window.office.context.document.setSelectedDataAsync( 49 | matrix, 50 | { CoercionType: window.office.CoercionType.Matrix }, 51 | function (asyncResult) { 52 | if (asyncResult.status == "failed") { 53 | showMessage("Action failed with error: " + asyncResult.error.message); 54 | } else { 55 | showMessage("You wrote a matrix! Click Next to see how to bind to it."); 56 | } 57 | }); 58 | } 59 | 60 | handleChange(event) { 61 | this.setState({url: event.target.value}); 62 | } 63 | 64 | render() { 65 | var results = this.state.shareCounts.map(function(item, i){ 66 | return
67 | {item.title} 68 | {item.count} 69 |
; 70 | }); 71 | return
72 |
73 | 74 | 75 |
76 | 80 |
81 |

Results

82 |
83 |
84 | Social Network 85 | Share Count 86 |
87 | {results} 88 |
89 | 93 |
94 |
; 95 | } 96 | } -------------------------------------------------------------------------------- /src/colors.js: -------------------------------------------------------------------------------- 1 | export const NICE = 'pink'; 2 | export const SUPER_NICE = 'darkred'; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { App } from './App'; 3 | 4 | React.render(, document.getElementById('root')); 5 | -------------------------------------------------------------------------------- /src/office.js: -------------------------------------------------------------------------------- 1 | /* Office JavaScript API library */ 2 | /* Version: 16.0.6207.1000 */ 3 | /* 4 | Copyright (c) Microsoft Corporation. All rights reserved. 5 | */ 6 | 7 | /* 8 | Your use of this file is governed by the Microsoft Services Agreement http://go.microsoft.com/fwlink/?LinkId=266419. 9 | */ 10 | 11 | var OSF=OSF||{};OSF.HostSpecificFileVersion="16.00";OSF.SupportedLocales={"ar-sa":true,"bg-bg":true,"ca-es":true,"cs-cz":true,"da-dk":true,"de-de":true,"el-gr":true,"en-us":true,"es-es":true,"et-ee":true,"eu-es":true,"fi-fi":true,"fr-fr":true,"gl-es":true,"he-il":true,"hi-in":true,"hr-hr":true,"hu-hu":true,"id-id":true,"it-it":true,"ja-jp":true,"kk-kz":true,"ko-kr":true,"lt-lt":true,"lv-lv":true,"ms-my":true,"nb-no":true,"nl-nl":true,"pl-pl":true,"pt-br":true,"pt-pt":true,"ro-ro":true,"ru-ru":true,"sk-sk":true,"sl-si":true,"sr-cyrl-cs":true,"sr-cyrl-rs":true,"sr-latn-cs":true,"sr-latn-rs":true,"sv-se":true,"th-th":true,"tr-tr":true,"uk-ua":true,"vi-vn":true,"zh-cn":true,"zh-tw":true};OSF.AssociatedLocales={ar:"ar-sa",bg:"bg-bg",ca:"ca-es",cs:"cs-cz",da:"da-dk",de:"de-de",el:"el-gr",en:"en-us",es:"es-es",et:"et-ee",eu:"eu-es",fi:"fi-fi",fr:"fr-fr",gl:"gl-es",he:"he-il",hi:"hi-in",hr:"hr-hr",hu:"hu-hu",id:"id-id",it:"it-it",ja:"ja-jp",kk:"kk-kz",ko:"ko-kr",lt:"lt-lt",lv:"lv-lv",ms:"ms-my",nb:"nb-no",nl:"nl-nl",pl:"pl-pl",pt:"pt-br",ro:"ro-ro",ru:"ru-ru",sk:"sk-sk",sl:"sl-si",sr:"sr-cyrl-cs",sv:"sv-se",th:"th-th",tr:"tr-tr",uk:"uk-ua",vi:"vi-vn",zh:"zh-cn"};var ScriptLoading;(function(e){var a=false,b=function(){function b(g,e,d,f,c){var b=this;b.url=g;b.isReady=e;b.hasStarted=d;b.timer=f;b.hasError=a;b.pendingCallbacks=[];b.pendingCallbacks.push(c)}return b}(),d=function(){function a(c,b,a){this.scriptId=c;this.startTime=b;this.msResponseTime=a}return a}(),c=function(){var c=true,e=null;function f(){var a=this;a.defaultScriptLoadingTimeout=1e4;a.loadedScriptByIds={};a.scriptTelemetryBuffer=[];a.osfControlAppCorrelationId=""}f.prototype.isScriptLoading=function(a){return !!(this.loadedScriptByIds[a]&&this.loadedScriptByIds[a].hasStarted)};f.prototype.loadScript=function(e,d,c,a,b){this.loadScriptInternal(e,d,c,a,b)};f.prototype.loadScriptParallel=function(d,c,b){this.loadScriptInternal(d,c,e,a,b)};f.prototype.waitForFunction=function(g,e,h,i){var b=h,f,d=function(){b--;if(g()){e(c);return}else if(b>0){f=window.setTimeout(d,i);b--}else{window.clearTimeout(f);e(a)}};d()};f.prototype.waitForScripts=function(b,e){var f=this;if(this.invokeCallbackIfScriptsReady(b,e)==a)for(var c=0;c1){var e=b[1],f=new RegExp("[&#]","g"),a=e.split(f);if(a.length>0)c=a[0]}}return c},q=function(){var h="hostInfoValue",f=l("_host_Info"),k=function(){var a=d;try{if(window.sessionStorage)a=window.sessionStorage}catch(b){}return a},i=k();if(!f&&i&&i.getItem(h))f=i.getItem(h);if(f){f=decodeURIComponent(f);e.isO15=b;var g=f.split("$");if(typeof g[2]==a)g=f.split("|");e.hostType=g[0];e.hostPlatform=g[1];e.hostSpecificFileVersion=g[2];e.hostLocale=g[3];e.osfControlAppCorrelationId=typeof g[4]==a?"":g[4];var j=parseFloat(e.hostSpecificFileVersion);if(j>OSF.ConstantNames.HostSpecificFallbackVersion)e.hostSpecificFileVersion=OSF.ConstantNames.HostSpecificFallbackVersion.toString();if(i)try{i.setItem(h,f)}catch(m){}}else{e.isO15=c;e.hostLocale=l("locale")}},p=function(b,a){OSF.AppTelemetry&&OSF.AppTelemetry.logAppCommonMessage&&OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync starts");g.getAppContext(b,a)},r=function(){q();f.setAppCorrelationId(e.osfControlAppCorrelationId);for(var B=function(b,d){var e,a,c;c=b.toLowerCase();a=c.indexOf(d);if(a>=0&&a===b.length-d.length&&(a===0||b.charAt(a-1)==="/"||b.charAt(a-1)==="\\"))e=b.substring(0,a);return e},t=document.getElementsByTagName("script"),D=t.length,y=[OSF.ConstantNames.OfficeJS,OSF.ConstantNames.OfficeDebugJS],z=y.length,n,i,l=0;!i&&l0)b=OSF.ConstantNames.AssociatedLocales[c[0]]}if(!b)b=OSF.ConstantNames.DefaultLocale;return b},d=b,e=function(){if(typeof Strings==a||typeof Strings.OfficeOM==a)if(!d){d=c;var h=i+OSF.ConstantNames.DefaultLocale+"/"+OSF.ConstantNames.OfficeStringJS;f.loadScript(h,OSF.ConstantNames.OfficeStringsId,e,c,OSF.ConstantNames.LocaleStringLoadingTimeout);return b}else throw"Neither the locale, "+g.toLowerCase()+", provided by the host app nor the fallback locale "+OSF.ConstantNames.DefaultLocale+" are supported.";else{d=b;r=Strings.OfficeOM}};if(!o()){window.Type=Function;Type.registerNamespace=function(a){window[a]=window[a]||{}};Type.prototype.registerClass=function(a){a={}}}var j=i+h(g)+"/"+OSF.ConstantNames.OfficeStringJS;f.loadScript(j,OSF.ConstantNames.OfficeStringsId,e,c,OSF.ConstantNames.LocaleStringLoadingTimeout)},u=function(b){if(b){g=new OSF.InitializationHelper(e,h,k,s,j);g.setAgaveHostCommunication();p(h.wnd,function(a){OSF.AppTelemetry&&OSF.AppTelemetry.logAppCommonMessage&&OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync callback start");m=a._appInstanceId;var b=function(){g.prepareApiSurface&&g.prepareApiSurface(a);f.waitForFunction(function(){return Microsoft.Office.WebExtension.initialize!=undefined},function(b){if(b)if(g.prepareApiSurface)Microsoft.Office.WebExtension.initialize(g.getInitializationReason(a));else g.prepareRightBeforeWebExtensionInitialize(a);else throw"Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function."},400,50)};!f.isScriptLoading(OSF.ConstantNames.OfficeStringsId)&&w(a.get_appUILocale());f.waitForScripts([OSF.ConstantNames.OfficeStringsId],function(){if(r&&!Strings.OfficeOM)Strings.OfficeOM=r;g.loadAppSpecificScriptAndCreateOM(a,b,i)})})}else{var a="MicrosoftAjax.js is not loaded successfully.";OSF.AppTelemetry&&OSF.AppTelemetry.logAppException&&OSF.AppTelemetry.logAppException(a);throw a}},x=function(){OSF.AppTelemetry&&OSF.AppTelemetry.setOsfControlAppCorrelationId&&OSF.AppTelemetry.setOsfControlAppCorrelationId(e.osfControlAppCorrelationId);if(f.isScriptLoading(OSF.ConstantNames.MicrosoftAjaxId))f.waitForScripts([OSF.ConstantNames.MicrosoftAjaxId],u);else f.waitForFunction(o,u,500,100)};if(e.isO15)f.loadScript(i+OSF.ConstantNames.O15InitHelper,OSF.ConstantNames.O15MappingId,x);else{var v;v=e.hostType+"-"+e.hostPlatform+"-"+e.hostSpecificFileVersion+".js";f.loadScript(i+v.toLowerCase(),OSF.ConstantNames.HostFileId,x)}e.hostLocale&&w(e.hostLocale);if(A&&!o()){var C=(window.location.protocol.toLowerCase()==="https:"?"https:":"http:")+"//ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js";f.loadScriptParallel(C,OSF.ConstantNames.MicrosoftAjaxId)}window.confirm=function(){throw"Function window.confirm is not supported.";return b};window.alert=function(){throw"Function window.alert is not supported."};window.prompt=function(){throw"Function window.prompt is not supported.";return d};window.history.replaceState=d;window.history.pushState=d};r();return {getId:function(){return h.id},getClientEndPoint:function(){return h.clientEndPoint},getContext:function(){return k},setContext:function(a){k=a},getHostFacade:function(){return j},setHostFacade:function(a){j=a},getInitializationHelper:function(){return g},getCachedSessionSettingsKey:function(){return (h.conversationID!=d?h.conversationID:m)+"CachedSessionSettings"},getWebAppState:function(){return h},getWindowLocationHash:function(){return o},getWindowLocationSearch:function(){return n},getLoadScriptHelper:function(){return f}}}() 12 | -------------------------------------------------------------------------------- /webpack.config.dev.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | devtool: 'eval', 6 | entry: [ 7 | 'webpack-hot-middleware/client', 8 | './src/index' 9 | ], 10 | output: { 11 | path: path.join(__dirname, 'dist'), 12 | filename: 'bundle.js', 13 | publicPath: '/static/' 14 | }, 15 | plugins: [ 16 | new webpack.HotModuleReplacementPlugin(), 17 | new webpack.NoErrorsPlugin() 18 | ], 19 | module: { 20 | loaders: [{ 21 | test: /\.js$/, 22 | loaders: ['babel'], 23 | include: path.join(__dirname, 'src') 24 | }, { 25 | test: /\.jsx$/, 26 | loaders: ['babel'], 27 | include: path.join(__dirname, 'src') 28 | }] 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /webpack.config.prod.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | devtool: 'source-map', 6 | entry: [ 7 | './src/index' 8 | ], 9 | output: { 10 | path: path.join(__dirname, 'dist'), 11 | filename: 'bundle.js', 12 | publicPath: '/static/' 13 | }, 14 | plugins: [ 15 | new webpack.optimize.OccurenceOrderPlugin(), 16 | new webpack.DefinePlugin({ 17 | 'process.env': { 18 | 'NODE_ENV': JSON.stringify('production') 19 | } 20 | }), 21 | new webpack.optimize.UglifyJsPlugin({ 22 | compressor: { 23 | warnings: false 24 | } 25 | }) 26 | ], 27 | module: { 28 | loaders: [{ 29 | test: /\.js$/, 30 | loaders: ['babel'], 31 | include: path.join(__dirname, 'src') 32 | }] 33 | } 34 | }; 35 | --------------------------------------------------------------------------------