Merge pull request #17 from enuchi/support-multiple-entrypoints
Support multiple entrypoints
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.clasp*
|
.clasp*
|
||||||
|
creds.json
|
||||||
Vendored
+5306
File diff suppressed because it is too large
Load Diff
Vendored
+15
-7
@@ -2,6 +2,8 @@ function onOpen() {
|
|||||||
}
|
}
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
}
|
}
|
||||||
|
function openAboutSidebar() {
|
||||||
|
}
|
||||||
function getSheetsData() {
|
function getSheetsData() {
|
||||||
}
|
}
|
||||||
function addSheet() {
|
function addSheet() {
|
||||||
@@ -60,22 +62,27 @@ function setActiveSheet() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
__webpack_require__.d(__webpack_exports__, "d", function() {
|
__webpack_require__.d(__webpack_exports__, "d", function() {
|
||||||
return onOpen;
|
return onOpen;
|
||||||
}), __webpack_require__.d(__webpack_exports__, "e", function() {
|
}), __webpack_require__.d(__webpack_exports__, "f", function() {
|
||||||
return openDialog;
|
return openDialog;
|
||||||
|
}), __webpack_require__.d(__webpack_exports__, "e", function() {
|
||||||
|
return openAboutSidebar;
|
||||||
}), __webpack_require__.d(__webpack_exports__, "c", function() {
|
}), __webpack_require__.d(__webpack_exports__, "c", function() {
|
||||||
return getSheetsData;
|
return getSheetsData;
|
||||||
}), __webpack_require__.d(__webpack_exports__, "a", function() {
|
}), __webpack_require__.d(__webpack_exports__, "a", function() {
|
||||||
return addSheet;
|
return addSheet;
|
||||||
}), __webpack_require__.d(__webpack_exports__, "b", function() {
|
}), __webpack_require__.d(__webpack_exports__, "b", function() {
|
||||||
return deleteSheet;
|
return deleteSheet;
|
||||||
}), __webpack_require__.d(__webpack_exports__, "f", function() {
|
}), __webpack_require__.d(__webpack_exports__, "g", function() {
|
||||||
return setActiveSheet;
|
return setActiveSheet;
|
||||||
});
|
});
|
||||||
var onOpen = function() {
|
var onOpen = function() {
|
||||||
SpreadsheetApp.getUi().createMenu("Custom scripts").addItem("Edit sheets [sample React project]", "openDialog").addToUi();
|
SpreadsheetApp.getUi().createMenu("Custom scripts").addItem("Edit sheets [sample React project]", "openDialog").addItem("About me", "openAboutSidebar").addToUi();
|
||||||
}, openDialog = function() {
|
}, openDialog = function() {
|
||||||
var html = HtmlService.createHtmlOutputFromFile("dialog").setWidth(400).setHeight(600);
|
var html = HtmlService.createHtmlOutputFromFile("main").setWidth(400).setHeight(600);
|
||||||
SpreadsheetApp.getUi().showModalDialog(html, "Sheet Editor");
|
SpreadsheetApp.getUi().showModalDialog(html, "Sheet Editor");
|
||||||
|
}, openAboutSidebar = function() {
|
||||||
|
var html = HtmlService.createHtmlOutputFromFile("about");
|
||||||
|
SpreadsheetApp.getUi().showSidebar(html);
|
||||||
}, getSheets = function() {
|
}, getSheets = function() {
|
||||||
return SpreadsheetApp.getActive().getSheets();
|
return SpreadsheetApp.getActive().getSheets();
|
||||||
}, getSheetsData = function() {
|
}, getSheetsData = function() {
|
||||||
@@ -100,9 +107,10 @@ function setActiveSheet() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
__webpack_require__.r(__webpack_exports__), function(global) {
|
__webpack_require__.r(__webpack_exports__), function(global) {
|
||||||
var _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
var _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
||||||
global.onOpen = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.d, global.openDialog = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.e,
|
global.onOpen = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["d"], global.openDialog = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["f"],
|
||||||
global.getSheetsData = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.c, global.addSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.a,
|
global.openAboutSidebar = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["e"],
|
||||||
global.deleteSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.b, global.setActiveSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__.f;
|
global.getSheetsData = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["c"], global.addSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["a"],
|
||||||
|
global.deleteSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["b"], global.setActiveSheet = _sheets_utilities_js__WEBPACK_IMPORTED_MODULE_0__["g"];
|
||||||
}.call(this, __webpack_require__(2));
|
}.call(this, __webpack_require__(2));
|
||||||
}, function(module, exports) {
|
}, function(module, exports) {
|
||||||
var g;
|
var g;
|
||||||
|
|||||||
Vendored
+4
-4
@@ -5812,7 +5812,7 @@
|
|||||||
var react = __webpack_require__(0), react_default = __webpack_require__.n(react), react_dom = __webpack_require__(3), react_dom_default = __webpack_require__.n(react_dom), react_addons_css_transition_group = __webpack_require__(8), react_addons_css_transition_group_default = __webpack_require__.n(react_addons_css_transition_group), prop_types = __webpack_require__(1), prop_types_default = __webpack_require__.n(prop_types);
|
var react = __webpack_require__(0), react_default = __webpack_require__.n(react), react_dom = __webpack_require__(3), react_dom_default = __webpack_require__.n(react_dom), react_addons_css_transition_group = __webpack_require__(8), react_addons_css_transition_group_default = __webpack_require__.n(react_addons_css_transition_group), prop_types = __webpack_require__(1), prop_types_default = __webpack_require__.n(prop_types);
|
||||||
__webpack_require__(7);
|
__webpack_require__(7);
|
||||||
function FormInput(props) {
|
function FormInput(props) {
|
||||||
const [text, setText] = Object(react.useState)("");
|
const [text, setText] = Object(react["useState"])("");
|
||||||
return react_default.a.createElement("div", {
|
return react_default.a.createElement("div", {
|
||||||
className: "formBlock"
|
className: "formBlock"
|
||||||
}, react_default.a.createElement("span", null, "Add a sheet: "), react_default.a.createElement("form", {
|
}, react_default.a.createElement("span", null, "Add a sheet: "), react_default.a.createElement("form", {
|
||||||
@@ -5845,14 +5845,14 @@
|
|||||||
deleteButtonHandler: prop_types_default.a.func,
|
deleteButtonHandler: prop_types_default.a.func,
|
||||||
clickSheetNameHandler: prop_types_default.a.func
|
clickSheetNameHandler: prop_types_default.a.func
|
||||||
};
|
};
|
||||||
const ignoredMethods = [ "withFailureHandler", "withLogger", "withSuccessHandler", "withUserObject" ], serverMethods = {};
|
const serverMethods = {}, ignoredMethods = [ "withFailureHandler", "withLogger", "withSuccessHandler", "withUserObject" ];
|
||||||
for (const method in google.script.run) ignoredMethods.includes(method) || (serverMethods[method] = ((...args) => new Promise((resolve, reject) => {
|
for (const method in google.script.run) ignoredMethods.includes(method) || (serverMethods[method] = ((...args) => new Promise((resolve, reject) => {
|
||||||
google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
|
google.script.run.withSuccessHandler(resolve).withFailureHandler(reject)[method](...args);
|
||||||
})));
|
})));
|
||||||
var server = serverMethods;
|
var server = serverMethods;
|
||||||
react_dom_default.a.render(react_default.a.createElement(function() {
|
react_dom_default.a.render(react_default.a.createElement(function() {
|
||||||
const {getSheetsData: getSheetsData, addSheet: addSheet, deleteSheet: deleteSheet, setActiveSheet: setActiveSheet} = server, [names, setNames] = Object(react.useState)([]);
|
const {getSheetsData: getSheetsData, addSheet: addSheet, deleteSheet: deleteSheet, setActiveSheet: setActiveSheet} = server, [names, setNames] = Object(react["useState"])([]);
|
||||||
Object(react.useEffect)(() => {
|
Object(react["useEffect"])(() => {
|
||||||
getSheetsData().then(setNames)["catch"](alert);
|
getSheetsData().then(setNames)["catch"](alert);
|
||||||
}, []);
|
}, []);
|
||||||
const deleteButtonHandler = (e, sheetIndex) => {
|
const deleteButtonHandler = (e, sheetIndex) => {
|
||||||
Generated
+1715
-1709
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,8 @@
|
|||||||
"description": "Starter project for using React with Google Apps Script",
|
"description": "Starter project for using React with Google Apps Script",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "test",
|
"test": "test",
|
||||||
|
"login": "clasp login",
|
||||||
|
"setup": "clasp create --type sheets --title 'My React Project' --rootDir ./dist",
|
||||||
"start": "webpack --mode development",
|
"start": "webpack --mode development",
|
||||||
"build": "webpack --mode production",
|
"build": "webpack --mode production",
|
||||||
"deploy": "npm run build && npx clasp push"
|
"deploy": "npm run build && npx clasp push"
|
||||||
@@ -34,6 +36,7 @@
|
|||||||
"babel-plugin-add-module-exports": "^0.2.1",
|
"babel-plugin-add-module-exports": "^0.2.1",
|
||||||
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
|
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
|
||||||
"babel-plugin-transform-es3-property-literals": "^6.22.0",
|
"babel-plugin-transform-es3-property-literals": "^6.22.0",
|
||||||
|
"clasp": "^1.0.0",
|
||||||
"clean-webpack-plugin": "^0.1.19",
|
"clean-webpack-plugin": "^0.1.19",
|
||||||
"copy-webpack-plugin": "^4.6.0",
|
"copy-webpack-plugin": "^4.6.0",
|
||||||
"css-loader": "^1.0.1",
|
"css-loader": "^1.0.1",
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import {AboutPage} from './components/about-sidebar';
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<AboutPage />,
|
||||||
|
document.getElementById('index')
|
||||||
|
);
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import '../styles.css';
|
||||||
|
|
||||||
|
export const AboutPage = () => (
|
||||||
|
<div className="sheetNameText">
|
||||||
|
<div>Github repo:</div>
|
||||||
|
<a
|
||||||
|
href="https://www.github.com/enuchi/React-Google-Apps-Script"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
React + Google Apps Script
|
||||||
|
</a>
|
||||||
|
<div>-Elisha Nuchi</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -3,6 +3,7 @@ import * as publicFunctions from './sheets-utilities.js';
|
|||||||
// Expose public functions
|
// Expose public functions
|
||||||
global.onOpen = publicFunctions.onOpen;
|
global.onOpen = publicFunctions.onOpen;
|
||||||
global.openDialog = publicFunctions.openDialog;
|
global.openDialog = publicFunctions.openDialog;
|
||||||
|
global.openAboutSidebar = publicFunctions.openAboutSidebar;
|
||||||
global.getSheetsData = publicFunctions.getSheetsData;
|
global.getSheetsData = publicFunctions.getSheetsData;
|
||||||
global.addSheet = publicFunctions.addSheet;
|
global.addSheet = publicFunctions.addSheet;
|
||||||
global.deleteSheet = publicFunctions.deleteSheet;
|
global.deleteSheet = publicFunctions.deleteSheet;
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ const onOpen = () => {
|
|||||||
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
|
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
|
||||||
.createMenu('Custom scripts')
|
.createMenu('Custom scripts')
|
||||||
.addItem('Edit sheets [sample React project]', 'openDialog')
|
.addItem('Edit sheets [sample React project]', 'openDialog')
|
||||||
|
.addItem('About me', 'openAboutSidebar')
|
||||||
.addToUi();
|
.addToUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
const openDialog = () => {
|
const openDialog = () => {
|
||||||
let html = HtmlService.createHtmlOutputFromFile('dialog')
|
const html = HtmlService.createHtmlOutputFromFile('main')
|
||||||
.setWidth(400)
|
.setWidth(400)
|
||||||
.setHeight(600);
|
.setHeight(600);
|
||||||
SpreadsheetApp
|
SpreadsheetApp
|
||||||
@@ -15,6 +16,13 @@ const openDialog = () => {
|
|||||||
.showModalDialog(html, 'Sheet Editor');
|
.showModalDialog(html, 'Sheet Editor');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openAboutSidebar = () => {
|
||||||
|
const html = HtmlService.createHtmlOutputFromFile('about');
|
||||||
|
SpreadsheetApp
|
||||||
|
.getUi()
|
||||||
|
.showSidebar(html);
|
||||||
|
};
|
||||||
|
|
||||||
const getSheets = () => SpreadsheetApp
|
const getSheets = () => SpreadsheetApp
|
||||||
.getActive()
|
.getActive()
|
||||||
.getSheets();
|
.getSheets();
|
||||||
@@ -24,9 +32,9 @@ const getActiveSheetName = () => SpreadsheetApp
|
|||||||
.getSheetName();
|
.getSheetName();
|
||||||
|
|
||||||
const getSheetsData = () => {
|
const getSheetsData = () => {
|
||||||
let activeSheetName = getActiveSheetName();
|
const activeSheetName = getActiveSheetName();
|
||||||
return getSheets().map((sheet, index) => {
|
return getSheets().map((sheet, index) => {
|
||||||
let sheetName = sheet.getName();
|
const sheetName = sheet.getName();
|
||||||
return {
|
return {
|
||||||
text: sheetName,
|
text: sheetName,
|
||||||
sheetIndex: index,
|
sheetIndex: index,
|
||||||
@@ -43,7 +51,7 @@ const addSheet = (sheetTitle) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deleteSheet = (sheetIndex) => {
|
const deleteSheet = (sheetIndex) => {
|
||||||
let sheets = getSheets();
|
const sheets = getSheets();
|
||||||
SpreadsheetApp
|
SpreadsheetApp
|
||||||
.getActive()
|
.getActive()
|
||||||
.deleteSheet(sheets[sheetIndex]);
|
.deleteSheet(sheets[sheetIndex]);
|
||||||
@@ -61,6 +69,7 @@ const setActiveSheet = (sheetName) => {
|
|||||||
export {
|
export {
|
||||||
onOpen,
|
onOpen,
|
||||||
openDialog,
|
openDialog,
|
||||||
|
openAboutSidebar,
|
||||||
getSheetsData,
|
getSheetsData,
|
||||||
addSheet,
|
addSheet,
|
||||||
deleteSheet,
|
deleteSheet,
|
||||||
|
|||||||
+42
-21
@@ -4,19 +4,30 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|||||||
const GasPlugin = require('gas-webpack-plugin');
|
const GasPlugin = require('gas-webpack-plugin');
|
||||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||||
const WebpackCleanPlugin = require('webpack-clean');
|
const WebpackCleanPlugin = require('webpack-clean');
|
||||||
|
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
|
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
|
||||||
|
|
||||||
|
// settings
|
||||||
const destination = 'dist';
|
const destination = 'dist';
|
||||||
|
const htmlTemplate = './src/client/dialog-template.html';
|
||||||
const htmlPlugin = new HtmlWebpackPlugin({
|
|
||||||
template: "./src/client/dialog-template.html",
|
|
||||||
filename: "dialog.html",
|
|
||||||
inlineSource: '.(js|css)$' // embed all javascript and css inline
|
|
||||||
});
|
|
||||||
|
|
||||||
const htmlWebpackInlineSourcePlugin = new HtmlWebpackInlineSourcePlugin();
|
const htmlWebpackInlineSourcePlugin = new HtmlWebpackInlineSourcePlugin();
|
||||||
|
const webpackCleanPlugin = new WebpackCleanPlugin([
|
||||||
|
destination + '/' + 'main.js',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Client entrypoints:
|
||||||
|
const clientEntrypoints = [
|
||||||
|
{
|
||||||
|
name: "CLIENT - main dialog",
|
||||||
|
entry: "./src/client/main.jsx",
|
||||||
|
filename: "main.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "CLIENT - about sidebar",
|
||||||
|
entry: "./src/client/about.jsx",
|
||||||
|
filename: "about.html"
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const sharedConfigSettings = {
|
const sharedConfigSettings = {
|
||||||
optimization: {
|
optimization: {
|
||||||
@@ -64,9 +75,8 @@ const appsscriptConfig = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const clientConfig = Object.assign({}, sharedConfigSettings, {
|
const clientConfig = {
|
||||||
name: "CLIENT",
|
...sharedConfigSettings,
|
||||||
entry: "./src/client/index.jsx",
|
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, destination),
|
path: path.resolve(__dirname, destination),
|
||||||
},
|
},
|
||||||
@@ -89,16 +99,27 @@ const clientConfig = Object.assign({}, sharedConfigSettings, {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
};
|
||||||
htmlPlugin,
|
|
||||||
new HtmlWebpackInlineSourcePlugin(),
|
const clientConfigs = clientEntrypoints.map((clientEntrypoint) => {
|
||||||
new WebpackCleanPlugin([
|
return ({
|
||||||
destination + '/' + 'main.js',
|
...clientConfig,
|
||||||
])
|
name: clientEntrypoint.name,
|
||||||
]
|
entry: clientEntrypoint.entry,
|
||||||
|
plugins: [
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: htmlTemplate,
|
||||||
|
filename: clientEntrypoint.filename,
|
||||||
|
inlineSource: '.(js|css)$' // embed all javascript and css inline
|
||||||
|
}),
|
||||||
|
htmlWebpackInlineSourcePlugin,
|
||||||
|
webpackCleanPlugin,
|
||||||
|
],
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const serverConfig = Object.assign({}, sharedConfigSettings, {
|
const serverConfig = {
|
||||||
|
...sharedConfigSettings,
|
||||||
name: "SERVER",
|
name: "SERVER",
|
||||||
entry: "./src/server/code.js",
|
entry: "./src/server/code.js",
|
||||||
output: {
|
output: {
|
||||||
@@ -121,10 +142,10 @@ const serverConfig = Object.assign({}, sharedConfigSettings, {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new GasPlugin()
|
new GasPlugin()
|
||||||
]
|
]
|
||||||
});
|
};
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
appsscriptConfig,
|
appsscriptConfig,
|
||||||
clientConfig,
|
...clientConfigs,
|
||||||
serverConfig,
|
serverConfig,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user