-
Notifications
You must be signed in to change notification settings - Fork 8
/
api.types.ts
376 lines (356 loc) · 12.3 KB
/
api.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import type { SheetLayout } from 'src/runtime/types';
import type { HandlebarsTab } from './tab/HandlebarsTab';
import type { HtmlTab } from './tab/HtmlTab';
import type { SvelteTab } from './tab/SvelteTab';
import type { HtmlContent } from './content/HtmlContent';
import type { HandlebarsContent } from './content/HandlebarsContent';
import type { Actor5e } from 'src/types/types';
/**
* Data provided after custom content has been prepared for rendering.
*/
/** @category Content */
export interface OnContentReadyParams extends OnRenderParams {
/**
* An HTML string that is ready to be rendered to the sheet.
*/
content: string;
}
/**
* Data provided during the rendering of this item document sheet.
*/
/** @category Shared */
export interface OnRenderParams {
/**
* The sheet application instance.
*/
app: any;
/**
* The document sheet application element. This is the entire application window, including the header.
*/
element: HTMLElement;
/**
* The item sheet context which is typically passed to the handlebars template
*/
data: any;
/**
* Denotes whether this is a full/forced render or a change detection cycle. For non-svelte content, this field allows content to react to partial re-rendering.
*/
isFullRender: boolean;
}
/**
* Determines when custom content will be rendered.
* - `"handlebars"` - render on each change detection cycle (actor data changed, setting data changed, embedded item changed, etc.)
* - `"force"`, `undefined`, or any other unspecified value - render when the `render` function is called with `force=true`, i.e. a full re-render
*/
/** @category Shared */
export type RenderScheme = 'handlebars' | 'force';
/**
* The currently supported tab types.
*/
/** @category Tabs */
export type SupportedTab = HtmlTab | HandlebarsTab | SvelteTab;
/**
* Options for registering an item tab.
*/
export interface ItemTabRegistrationOptions {
/** When set to `true`, whenever this tab is navigated to, the window height will automatically adjust to match the content height. */
autoHeight?: boolean;
}
/**
* Options for registering an actor tab.
*/
/** @category Tabs */
export interface ActorTabRegistrationOptions {
/**
* An optional sheet layout or layouts (default: 'all')
*/
layout?: SheetLayout | SheetLayout[];
/**
* Determines whether a newly registered tab should override an existing of the same tab ID.
* Useful for replacing core Tidy 5e Sheet tabs.
*/
overrideExisting?: boolean;
}
/**
* The currently supported custom content types.
*/
/** @category Content */
export type SupportedContent = HtmlContent | HandlebarsContent;
/**
* Options for registering content.
*/
/** @category Content */
export interface ContentRegistrationOptions {
layout?: SheetLayout | SheetLayout[];
}
/**
* A command, such as a button or a menu item, which can be executed on behalf of an item.
*/
/** @category Configuration */
export interface ItemSummaryCommand {
/**
* A label to use when displaying the command. Localization keys also work.
*/
label?: string;
/**
* Optional string of CSS classes representing a FontAwesome icon to be rendered with the command.
*/
iconClass?: string;
/**
* Optional tooltip text for the target command.
*/
tooltip?: string;
/**
* An optional callback which allows for conditionally including a command. If not included, defaults to `true`.
* @param params contextual information to assist with determining whether a command is appropriate for a particular item
* @returns whether to include this command in the UI for the target item
*
* @remarks
* This option allows for scenarios such as showing a Versatile Damage button only when an item is tagged as versatile.
*/
enabled?: (params: ItemSummaryCommandEnabledParams) => boolean;
/**
* An optional callback to allow for executing logic when a user executes the command.
* @param item the item for which the command has been executed
* @returns void
*
* @remarks
* It is up to the user to execute commands, such as clicking a button that represents the command. This is the general-purpose event handler for that button click.
* Note that the command may instead be a menu item or other control for other scenarios, depending on the sheet and version of Tidy 5e.
*/
execute?: (params: ItemSummaryCommandExecuteParams) => void;
}
/**
* Contextual information to assist with determining whether a command is appropriate for a particular item
*/
/** @category Configuration */
export interface ItemSummaryCommandEnabledParams {
/**
* The item for which the command will show.
*/
item: any;
}
/**
* Contextual information related to the item for which the target command was executed.
*/
/** @category Configuration */
export interface ItemSummaryCommandExecuteParams {
/**
* The item for which the command was executed.
*/
item: any;
}
/**
* A command, eventually rendered as a control like a button or a menu item, which can be executed on behalf of an actor when accessing actor portrait menu options.
*/
/** @category Configuration */
export interface PortraitMenuCommand {
/**
* A label to use when displaying the command. Localization keys also work.
*/
label?: string;
/**
* Optional string of CSS classes representing a FontAwesome icon to be rendered with the command.
*/
iconClass?: string;
/**
* Optional tooltip text for the target command.
*/
tooltip?: string;
/**
* An optional callback which allows for conditionally including a command. If not included, defaults to `true`.
* @param params contextual information to assist with determining whether a command is appropriate for a particular actor
* @returns whether to include this command in the UI for the target actor
*/
enabled?: (params: PortraitMenuCommandEnabledParams) => boolean;
/**
* An optional callback to allow for executing logic when a user executes the command.
* @param params contextual information to assist with determining whether a command is appropriate for a particular actor
* @returns void
*
* @remarks
* It is up to the user to execute commands, such as clicking a button that represents the command. This is the general-purpose event handler for that button click.
* Note that the command may instead be a menu item or other control for other scenarios, depending on the sheet and version of Tidy 5e.
*/
execute?: (params: PortraitMenuCommandExecuteParams) => void;
}
/**
* Contextual information to assist with determining whether a command is appropriate for a particular actor
*/
/** @category Configuration */
export interface PortraitMenuCommandEnabledParams {
/**
* The actor for which the command will show.
*/
actor: any;
}
/**
* Contextual information related to the actor for which the target command was executed.
*/
/** @category Configuration */
export interface PortraitMenuCommandExecuteParams {
/**
* The actor for which the command was executed.
*/
actor: any;
/**
* The actor sheet context which is typically provided on render.
*/
context: any;
}
/**
* A command, eventually rendered as a control like a button or a menu item, which can be executed on behalf of an actor item section.
*/
/** @category Configuration */
export interface ActorItemSectionFooterCommand {
/**
* Optional label to use when displaying the command. Localization keys also work.
*/
label?: string;
/**
* Optional string of CSS classes representing a FontAwesome icon to be rendered with the command.
*/
iconClass?: string;
/**
* Optional tooltip text for the target command.
*/
tooltip?: string;
/**
* An optional callback which allows for conditionally including a command. If not included, defaults to `true`.
* @param params contextual information to assist with determining whether a command is appropriate for a particular item section
* @returns whether to include this command in the UI for the target item section
*
* @remarks
* This option allows for scenarios such as showing a Versatile Damage button only when an item is tagged as versatile.
*/
enabled?: (params: ActorItemSectionFooterCommandEnabledParams) => boolean;
/**
* An optional callback to allow for executing logic when a user executes the command.
* @param item the item for which the command has been executed
* @returns void
*
* @remarks
* It is up to the user to execute commands, such as clicking a button that represents the command. This is the general-purpose event handler for that button click.
* Note that the command may instead be a menu item or other control for other scenarios, depending on the sheet and version of Tidy 5e.
*/
execute?: (params: ActorItemSectionFooterCommandExecuteParams) => void;
}
/** @category Configuration */
export interface ActorItemSectionFooterCommandEnabledParams {
/**
* The actor for whom the command will show.
*/
actor: Actor5e;
/**
* The item section for which the command will show.
*/
section: any;
}
/** @category Configuration */
export interface ActorItemSectionFooterCommandExecuteParams {
/**
* The actor for whom the command was executed.
*/
actor: Actor5e;
/**
* The item section for which the command was executed.
*/
section: any;
/**
* Any user-initiated event which triggered the command execution. For example, a MouseEvent or PointerEvent.
*/
event: Event;
}
/**
* Information needed to configure specific-level exhaustion.
*/
/** @category Configuration */
export interface UseSpecificLevelExhaustionParams {
/**
* The max number of levels. If not specified or less than 1, will default to `1`.
*/
totalLevels?: number;
/**
* Optional hints (usually rendered as tooltips).
* Localization keys also work.
*
* @remarks
* This array should include level 0, meaning it is length `totalLevels + 1`.
* For example, with `totalLevels` of 3:
*
* 0. 'No exhaustion'
* 1. 'You are kind of tired'
* 2. 'You look unwell'
* 3. 'Dead 💀'
*
* > `['No exhaustion', 'You are kind of tired', 'You look unwell', 'Dead 💀']`
*/
hints?: string[];
}
/**
* Optional params which, when provided, will cause
* the custom content to be rendered at the designated `position`
* in relation to all instances of the found `selector`.
*
* @remarks
* This interface leverages the API for [Element: insertAdjacentHTML() method](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML).
*/
/** @category Content */
export interface CustomContentInjectParams {
/**
* A string representing the position relative to the element.
* Must be one of the following strings:
* - `"beforebegin"`: Before the element. Only valid if the element is in the DOM tree and has a parent element.
* - `"afterbegin"`: Just inside the element, before its first child.
* - `"beforeend"`: Just inside the element, after its last child.
* - `"afterend"`: After the element. Only valid if the element is in the DOM tree and has a parent element.
*
* @remarks
* See [Element: insertAdjacentHTML() method](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML) for more details.
*/
position: string;
/**
* The selector to use when looking for the place to insert adjacent HTML.
* This is scoped to the sheet where this content was registered.
*
* @example
* ```'[data-tidy-field="name"]'```
*/
selector: string;
}
/**
* A custom equipment type group, to be rendered in the Equipment Type section of the Item Sheet.
*
* @example Custom Helmet Types
* ```js
* {
* label: 'Helmet',
* types: {
* clothhat: 'Clothings Helmet',
* lighthat: 'Light Helmet',
* mediumhat: 'Medium Helmet',
* heavyhat: 'Heavy Helmet',
* }
* ```
*
* @example Custom Helmet Types (with Localization Keys)
* ```js
* {
* label: 'MyModuleId.HelmetType.Label',
* types: {
* clothhat: 'MyModuleId.HelmetType.ClothingsHelmet.Label',
* lighthat: 'MyModuleId.HelmetType.LightHelmet.Label',
* mediumhat: 'MyModuleId.HelmetType.MediumHelmet.Label',
* heavyhat: 'MyModuleId.HelmetType.HeavyHelmet.Label',
* }
* ```
*/
export type EquipmentTypeGroup = {
/** A group label. Localization keys also work. */
label: string;
/**
* An object where the key is the equipment type ID, and the value is the label text.
* Localization keys also work.
*/
types: Record<string, string>;
};