Skip to content

Commit da257b2

Browse files
authored
Merge pull request #57 from Roll20/story/SD-8311
SD-8311: Add new writeToClipboard method
2 parents 5eadf51 + 8ddd157 commit da257b2

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed
33.8 KB
Loading

content/docs/components/dispatch.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Join to get access to the Beacon SDK, the community sheet repo for Beacon sheet,
2424

2525
The dispatch is returned by the `initRelay` and provides methods for sending commands from the character sheet back to the host. Except when specified every method below will return a promise.
2626

27-
#### update
27+
## update
2828
```javascript
2929
dispatch.update({
3030
options: { overwrite?: boolean }
@@ -35,7 +35,7 @@ The `update` method sends character changes to the host (Roll20 Tabletop or Roll
3535

3636
The partial character passed in here must contain the character's id, and can contain any combination of the attributes, bio, and gmNotes properties. When updating a character’s attributes, only include those attributes that have changed.
3737

38-
#### updateCharacter
38+
## updateCharacter
3939
```javascript
4040
dispatch.updateCharacter({
4141
character: Partial<Character>
@@ -45,7 +45,7 @@ Like the `update` method, `updateCharacter` sends character changes to the host
4545

4646
However, this method takes a full set of character attributes as the character argument, and automatically computes the diff with existing character attributes, so that only changed attributes are sent to the data store.
4747

48-
#### roll
48+
## roll
4949
```javascript
5050
dispatch.roll({
5151
rolls: { [rollName: string]: string } // Ex. {attack: '1d20+4', damage: `3d6+2`}
@@ -58,7 +58,7 @@ If messageId is omitted, the roll will be associated with a new chat message and
5858

5959
The method returns a promise that resolves with an object containing the messageId and the RollResult (see Types). The roll result is returned in the same format as in the non-beacon dice rolls computed roll system.
6060

61-
#### post
61+
## post
6262
```javascript
6363
dispatch.post({
6464
characterId: string,
@@ -78,7 +78,7 @@ The secret option is ignored unless whisper is also set, toggling to true will c
7878

7979
Like roll, messageId can be provided to update an existing chat message, but if omitted the method will generate a new messageId and post a new chat message. The method returns the messageId.
8080

81-
#### query
81+
## query
8282
```javascript
8383
dispatch.query(options: Swal2Options): {
8484
isConfirmed: boolean,
@@ -102,7 +102,7 @@ The `query` method takes an options object and uses them to display a [SweetAler
102102

103103
`titleText, text, iconColor, input, width, padding, background, position, grow, timer, timerProgressBar, showConfirmButton, showDenyButton, showCancelButton, ariaLabel, confirmButtonText, denyButtonText, cancelButtonText, confirmButtonAriaLabel, confirmButtonColor, cancelButtonAriaLabel, cancelButtonColor, denyButtonAriaLabel, denyButtonColor, reverseButtons, showCloseButton, closeButtonAriaLabel, returnInputValueOnDeny, imageUrl, imageWidth, imageHeight, imageAlt, inputLabel, inputPlaceholder, inputValue, inputOptions, inputPlaceholder, inputAutoTrim, inputAttributes, validationMessage, progressSteps, currentProgressStep, progressStepsDistance.`
104104

105-
#### Perform
105+
## Perform
106106
```javascript
107107
dispatch.perform({
108108
characterId: string,
@@ -112,7 +112,7 @@ dispatch.perform({
112112
```
113113
`perform` executes the specified action on behalf of the character (designated by the character id), passing in args to the action method. This method can perform actions on behalf of any character, even a character that the sheet does not have data for.
114114

115-
#### getComputed
115+
## getComputed
116116
```javascript
117117
dispatch.getComputed({
118118
characterId: string,
@@ -132,7 +132,7 @@ dispatch.setComputed({
132132
```
133133
`getComputed` and `setComputed` are both nearly identical in how they are called, taking a character id and a property with the name of the computed property you wish to get or set, and an array of string args. Both methods return a promise that resolves with the computed value.
134134

135-
#### compendiumRequest
135+
## compendiumRequest
136136
```javascript
137137
dispatch.compendiumRequest({
138138
query: string
@@ -144,7 +144,7 @@ dispatch.compendiumRequest({
144144
```
145145
`compendiumRequest` executes an AJAX request to the compendium service’s graphQL endpoint. It takes in a graphQL query string written according to the Compendium service’s schema. The query string does not need to include the ruleSystem shortName as this is set automatically according to the campaign override or sheet.json value in the Roll20 Tabletop.
146146

147-
#### debouncedCompendiumRequest
147+
## debouncedCompendiumRequest
148148
```javascript
149149
dispatch.debouncedCompendiumRequest({
150150
query: string
@@ -154,7 +154,7 @@ dispatch.debouncedCompendiumRequest({
154154
```
155155
Like `compendiumRequest`, except that calls to this method are automatically debounced (at 100ms) and grouped together into a single request to the compendium service. Note that this method will only return the requested data, it does not return errors or extensions.
156156

157-
#### getTokens
157+
## getTokens
158158
```javascript
159159
dispatch.getTokens({
160160
characterId: string
@@ -168,7 +168,7 @@ dispatch.getTokens({
168168
```
169169
`getTokens` requires a character id string and returns information about tokens on the user’s current page. The return value contains two arrays of tokens. The tokens array contains all tokens on the current page that represent the character whose id was provided to the method. The selected array contains any tokens that are currently selected, regardless of which character they represent. The returned token objects contain all of the token attributes available to the API, you can find documentation here and here.
170170

171-
#### addToTracker
171+
## addToTracker
172172
```javascript
173173
dispatch.addToTracker({
174174
tokenId?: string,
@@ -182,7 +182,7 @@ dispatch.addToTracker({
182182
```
183183
`addToTracker` adds or updates a single item in the turn tracker. Passing in a tokenId will add the specified token to the tracker, while passing in custom with a name and an optional image url (img) will add a custom item, not connected to any character or token. A round calculation string can be added via the optional formula parameter. value is the initiative number for the item.
184184

185-
#### addMacrosToHost
185+
## addMacrosToHost
186186
```javascript
187187
dispatch.addMacrosToHost({
188188
macro: {
@@ -206,7 +206,7 @@ Passing in a `location` will add it either to the player's macroBar, the charact
206206

207207
[See Actions page for examples on the usuage of `addMacrosToHost`](/beacon-docs/docs/components/actions)
208208

209-
#### getCharacterMacros
209+
## getCharacterMacros
210210
```javascript
211211
dispatch.getCharacterMacros({
212212
args: {
@@ -224,7 +224,7 @@ dispatch.getCharacterMacros({
224224
```
225225
`getCharacterMacros` gets a specific character’s macros. The `ids` returned from this list can be used in conjuction with `addMacrosToHost` update their locations. In jumpgate games, character macros can also be found in the `Advanced Tools -> Characters Macros` tab.
226226

227-
#### setContainerSize
227+
## setContainerSize
228228
```javascript
229229
dispatch.setContainerSize({
230230
args: {
@@ -235,7 +235,7 @@ dispatch.setContainerSize({
235235
```
236236
`setContainerSize` updates the size of the container which holds the sheet shared settings. Returns a promise that can be awaited. This can be used in conjunction with something like the ResizeSensor event listener from npm: css-element-queries to automatically resize the container on the host.
237237

238-
#### updateTokensByCharacter
238+
## updateTokensByCharacter
239239
```javascript
240240
dispatch.updateTokensByCharacter({
241241
args: {
@@ -246,7 +246,7 @@ dispatch.updateTokensByCharacter({
246246
```
247247
`updateTokensByCharacter` updates a particular character’s default token as well as all existing tokens representing that character. Returns a promise that can be awaited.
248248

249-
#### updateTokensByIds
249+
## updateTokensByIds
250250
```javascript
251251
dispatch.updateTokensByIds({
252252
args: {
@@ -257,7 +257,7 @@ dispatch.updateTokensByIds({
257257
```
258258
`updateTokensByIds` updates a single or several tokens. Returns a promise that can be awaited.
259259

260-
#### autoLinkText
260+
## autoLinkText
261261
```javascript
262262
dispatch.autoLinkText({
263263
args: {
@@ -267,7 +267,7 @@ dispatch.autoLinkText({
267267
```
268268
`autoLinkText` goes through the text to find handout names between square brackets and converts them into links with the handoutID. For example in a game with a handout named `Dragon`, passing in the text string of `this is a [Dragon]` to autoLinkText returns something similar to this is a `<a href="https://journal.roll20.net/8je02j0kd02k">Dragon</a>`.
269269

270-
#### openDialogFromLink
270+
## openDialogFromLink
271271
```javascript
272272
dispatch.openDialogFromLink({
273273
args: {
@@ -278,4 +278,16 @@ dispatch.openDialogFromLink({
278278
`openDialogFromLink` opens the supplied urlString through the Roll20 Tabletop.
279279
- If the url is for a handout, it will open the corresponding handout in the campaign. This will also check if the user opening the link has access to the handout.
280280
- If the url is for a compendium, it will open a pop up to the compendium page, it will also check to ensure the user has access to view the page.
281-
- If the url is for an external page, a confirmation pop up will display to warn the user that the link is for an external site and open a new tab in their main window if confirmed.
281+
- If the url is for an external page, a confirmation pop up will display to warn the user that the link is for an external site and open a new tab in their main window if confirmed.
282+
283+
## writeToClipboard
284+
```javascript
285+
dispatch.writeToClipboard(text)
286+
```
287+
`writeToClipboard` allows writing text such as macro commands or roll templates from the sheet to the player's OS clipboard.
288+
289+
This command will trigger a dialog model to pop up in the host, the dialog will include a warning urging the player to fully understand what their copying to their clipboard; The dialog will also include a preview of the text.
290+
291+
Clicking `allow` will copy the text to the player's clipboard, while clicking `deny` will prevent it and log `"user refused copy action"`
292+
293+
![writeToClipboard_dialog](images/writeToClipboard_dialog.png)

0 commit comments

Comments
 (0)