Skip to content

Commit 79e9170

Browse files
committed
Use latest gas-client and support closing dialogs
1 parent 85223ca commit 79e9170

File tree

10 files changed

+2563
-2572
lines changed

10 files changed

+2563
-2572
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ google.script.run
309309
.addSheet(sheetTitle);
310310

311311
// Using gas-client we can use more familiar promises style like this:
312-
import Server from 'gas-client';
313-
const { serverFunctions } = new Server();
312+
import { GASClient } from 'gas-client';
313+
const { serverFunctions, scriptHostFunctions } = new GASClient({});
314314

315315
// We now have access to all our server functions, which return promises!
316316
serverFunctions
@@ -327,6 +327,12 @@ async () => {
327327
handleError(err);
328328
}
329329
};
330+
331+
// Use scriptHostFunctions to control dialogs
332+
scriptHostFunctions.close(); // close a dialog or sidebar
333+
scriptHostFunctions.setWidth(400); // set dialog width to 400px
334+
scriptHostFunctions.setHeight(800); // set dialog height to 800px
335+
330336
```
331337

332338
In development, `gas-client` will allow you to call server-side functions from your local environment. In production, it will use Google's underlying `google.script.run` utility.

dev/dev-server-wrapper.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<base target="_top" />
2121
<title>Dev Server</title>
2222
<!-- Load gas-client as external. Exposed global variable is GASClient. -->
23-
<script src="https://unpkg.com/gas-client@1.1.1/dist/index.js"></script>
23+
<script src="https://unpkg.com/gas-client@1.2.0/dist/index.js"></script>
2424
<style>
2525
body,
2626
html {
@@ -37,15 +37,21 @@
3737

3838
const iframe = document.getElementById('iframe');
3939
iframe.src = 'https://localhost:' + PORT + '/' + FILE_NAME;
40-
const { serverFunctions } = new window.GASClient.GASClient({
41-
allowedDevelopmentDomains: (origin) =>
42-
/https:\/\/.*\.googleusercontent\.com$/.test(origin),
43-
});
40+
41+
const { serverFunctions, scriptHostFunctions } =
42+
new window.GASClient.GASClient({
43+
allowedDevelopmentDomains: (origin) =>
44+
/https:\/\/.*\.googleusercontent\.com$/.test(origin),
45+
});
4446

4547
const handleRequest = (event) => {
4648
const request = event.data;
4749
const { type, functionName, id, args } = request;
4850

51+
if (type === 'SCRIPT_HOST_FUNCTION_REQUEST') {
52+
scriptHostFunctions[functionName](...args);
53+
}
54+
4955
if (type !== 'REQUEST') return;
5056

5157
serverFunctions[functionName](...args)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-google-apps-script",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"type": "module",
55
"description": "Starter project for using React with Google Apps Script",
66
"repository": {
@@ -41,7 +41,7 @@
4141
"@emotion/react": "^11.10.6",
4242
"@emotion/styled": "^11.10.6",
4343
"@mui/material": "^5.11.11",
44-
"gas-client": "^1.1.1",
44+
"gas-client": "^1.2.0",
4545
"prop-types": "^15.8.1",
4646
"react": "^18.2.0",
4747
"react-bootstrap": "^2.4.0",

src/client/dialog-demo-bootstrap/components/SheetEditor.jsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { Button, ListGroup } from 'react-bootstrap';
44
import FormInput from './FormInput';
55

66
// This is a wrapper for google.script.run that lets us use promises.
7-
import { serverFunctions } from '../../utils/serverFunctions';
7+
import {
8+
serverFunctions,
9+
scriptHostFunctions,
10+
} from '../../utils/serverFunctions';
811

912
const SheetEditor = () => {
1013
const [names, setNames] = useState([]);
14+
const [isExpanded, setIsExpanded] = useState(false);
1115

1216
useEffect(() => {
1317
serverFunctions.getSheetsData().then(setNames).catch(alert);
@@ -77,6 +81,29 @@ const SheetEditor = () => {
7781
))}
7882
</TransitionGroup>
7983
</ListGroup>
84+
{names.length > 0 && (
85+
<div className="d-flex justify-content-end py-3">
86+
{!isExpanded ? (
87+
<Button
88+
variant="light"
89+
className="mr-2"
90+
onClick={() => {
91+
scriptHostFunctions.setHeight(1000);
92+
scriptHostFunctions.setWidth(1000);
93+
setIsExpanded(true);
94+
}}
95+
>
96+
Expand Dialog
97+
</Button>
98+
) : null}
99+
<Button
100+
variant="outline-dark"
101+
onClick={() => scriptHostFunctions.close()}
102+
>
103+
Close Dialog Window
104+
</Button>
105+
</div>
106+
)}
80107
</div>
81108
);
82109
};

src/client/dialog-demo-bootstrap/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
></script>
2222
<script
2323
crossorigin
24-
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
24+
src="https://unpkg.com/gas-client@1.2.0/dist/index.js"
2525
></script>
2626
<script
2727
crossorigin

src/client/dialog-demo-mui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
></script>
1818
<script
1919
crossorigin
20-
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
20+
src="https://unpkg.com/gas-client@1.2.0/dist/index.js"
2121
></script>
2222
<script
2323
crossorigin

src/client/dialog-demo-tailwindcss/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
></script>
1818
<script
1919
crossorigin
20-
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
20+
src="https://unpkg.com/gas-client@1.2.0/dist/index.js"
2121
></script>
2222
<script
2323
crossorigin

src/client/dialog-demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
></script>
1818
<script
1919
crossorigin
20-
src="https://unpkg.com/gas-client@1.1.1/dist/index.js"
20+
src="https://unpkg.com/gas-client@1.2.0/dist/index.js"
2121
></script>
2222
<script
2323
crossorigin
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { GASClient } from 'gas-client';
22
import * as publicServerFunctions from '../../server';
33

4-
const { serverFunctions } = new GASClient<typeof publicServerFunctions>({
4+
const { serverFunctions, scriptHostFunctions } = new GASClient<
5+
typeof publicServerFunctions
6+
>({
57
// this is necessary for local development but will be ignored in production
68
allowedDevelopmentDomains: (origin) =>
79
/https:\/\/.*\.googleusercontent\.com$/.test(origin),
810
});
911

10-
export { serverFunctions };
12+
export { serverFunctions, scriptHostFunctions };

0 commit comments

Comments
 (0)