You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-5Lines changed: 45 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,13 +84,47 @@ async () => {
84
84
85
85
Now we can use familiar Promises in our client-side code and have easy access to all server functions.
86
86
87
+
### Using the scriptHostFunctions
88
+
89
+
The `GASClient` also provides a `scriptHostFunctions` property that gives you access to Google's script host functions, which allow you to control UI elements like dialogs and sidebars:
90
+
91
+
```javascript
92
+
import { GASClient } from'gas-client';
93
+
const { scriptHostFunctions } =newGASClient();
94
+
95
+
// Close the current dialog or sidebar
96
+
scriptHostFunctions.close();
97
+
98
+
// Set the height of the current dialog (in pixels)
99
+
scriptHostFunctions.setHeight(500);
100
+
101
+
// Set the width of the current dialog (in pixels)
These functions provide the same functionality as the corresponding methods in `google.script.host` but work in both production and development environments:
109
+
110
+
-`close()`: Closes the current dialog or sidebar
111
+
-`setHeight(height)`: Sets the height of the current dialog (in pixels)
112
+
-`setWidth(width)`: Sets the width of the current dialog (in pixels)
113
+
-`focusEditor()`: Switches browser focus from the dialog or sidebar to the Google Docs, Sheets, or Forms editor
114
+
115
+
See reference here: https://developers.google.com/apps-script/guides/html/reference/host
116
+
117
+
In production, these functions call the native Google Apps Script host methods directly. In development mode, they dispatch appropriate messages to the parent iframe. See section below on how to set up the parent iframe.
118
+
119
+
## Setting up the dev server wrapper
120
+
121
+
Use the [React-Google-Apps-Script](https://github.com/enuchi/React-Google-Apps-Script/) project to get started. Or reference the [dev server wrapper](https://github.com/enuchi/React-Google-Apps-Script/blob/main/dev/dev-server-wrapper.html#L40-L41) on how to set up the parent wrapper to work with `gas-client`.
122
+
87
123
---
88
124
89
125
## Typescript
90
126
91
-
This project now supports typescript!
92
-
93
-
To use it, simply import your server functions and pass them as a type parameter when creating your server.
127
+
This project supports typescript. To use it, simply import your server functions and pass them as a type parameter when creating your server.
94
128
95
129
### On your server-side code
96
130
@@ -152,19 +186,25 @@ The config object takes:
152
186
153
187
### Production mode
154
188
155
-
In the normal Google Apps Script production environment, a `new GASClient()` instance will have one available method:
189
+
In the normal Google Apps Script production environment, a `new GASClient()` instance will have the following available methods:
156
190
157
191
-`serverFunctions`: an object containing all publicly exposed server functions (see example above).
192
+
-`scriptHostFunctions`: an object containing methods to interact with the script host UI, including:
193
+
-`close()`: Close the current dialog or sidebar
194
+
-`setHeight(height)`: Set the dialog height in pixels
195
+
-`setWidth(width)`: Set the dialog width in pixels
196
+
-`focusEditor()`: Switch focus from dialog/sidebar to the editor
158
197
159
198
Note that `allowedDevelopmentDomains` and `parentTargetOrigin` configurations will be ignored in production, so the same code can and should be used for development and production.
160
199
161
200
### Development mode
162
201
163
202
Development mode for the `gas-client` helper class will be run when the `google` client API cannot be loaded.
164
203
165
-
Calling `new GASClient({ allowedDevelopmentDomains })` will create an instance with the following method in development mode:
204
+
Calling `new GASClient({ allowedDevelopmentDomains })` will create an instance with the following methods in development mode:
166
205
167
206
-`serverFunctions`: a proxy object, used for development purposes, that mimics calling `google.script.run`. It will dispatch a message to the parent iframe (our custom Dev Server), which will call an app that actually interacts with the `google.script.run` API. Development mode will also handle the response and resolve or reject based on the response type. See the implementation for details on the event signature.
207
+
-`scriptHostFunctions`: a proxy object that simulates the behavior of `google.script.host` methods in development mode by sending appropriate messages to the parent iframe.
0 commit comments