scriptable-typings 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +1 -1
  3. package/src/types.d.ts +508 -39
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # scriptable-types
2
2
 
3
- Type definitions for [Scriptable](https://scriptable.app), using their [official documentation](https://docs.scriptable.app) as a reference
3
+ Type definitions for [Scriptable](https://scriptable.app), all heavily based off of their [official documentation](https://docs.scriptable.app).
4
+
5
+ We may use some of these types in our own projects. When we do confirm the typings for an item are correct, and we remember to update these typings, we will add a note to the item stating we have confirmed ourselves that the API works.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scriptable-typings",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "types": "src/types.d.ts",
6
6
  "files": [
package/src/types.d.ts CHANGED
@@ -1,18 +1,21 @@
1
- declare class Alert {
2
- title: string;
3
- message: string;
4
-
5
- constructor();
6
-
7
- addAction(title: string);
8
- addDestructiveAction(title: string);
9
- addCancelAction(title: string);
10
- addTextField(placeholder: string, text: string): TextField;
11
- addSecureTextField(placeholder: string, text: string): TextField;
12
- textFieldValue(index: number): string;
13
- present(): Promise<number>;
14
- presentAlert(): Promise<number>;
15
- presentSheet(): Promise<number>;
1
+ declare const config: Config;
2
+ declare type Config = {
3
+ readonly runsInApp: boolean;
4
+ readonly runsInActionExtension: boolean;
5
+ readonly runsWithSiri: boolean;
6
+ readonly runsInWidget: boolean;
7
+ readonly runsInAccessoryWidget: boolean;
8
+ readonly runsInNotification: boolean;
9
+ readonly runsFromHomeScreen: boolean;
10
+ readonly widgetFamily:
11
+ | "small"
12
+ | "medium"
13
+ | "large"
14
+ | "extraLarge"
15
+ | "accessoryRectangular"
16
+ | "accessoryInline"
17
+ | "accessoryCircular"
18
+ | null;
16
19
  };
17
20
 
18
21
  declare const args: Args;
@@ -43,16 +46,132 @@ declare type Args = {
43
46
  readonly notification: Notification;
44
47
  };
45
48
 
46
- declare class Calendar {
47
- readonly identifier: string;
49
+ /**
50
+ * Presents an alert
51
+ *
52
+ * Use this to configure an alert presented modally or as a sheet. After
53
+ * configuring the alert, call presentAlert() or presentSheet() to present the
54
+ * alert. The two presentation methods will return a value which carries the
55
+ * index of the action that was selected when fulfilled.
56
+ */
57
+ declare class Alert {
58
+ /**
59
+ * Title displayed in the alert (usually a short string)
60
+ */
48
61
  title: string;
49
- readonly isSubscribed: boolean;
50
- readonly allowsContentModifications: boolean;
51
- color: Color;
52
62
 
53
- supportsAvailability(availability: string): boolean;
54
- save();
55
- remove();
63
+ /**
64
+ * Detailed message displayed in the alert
65
+ */
66
+ message: string;
67
+
68
+ /**
69
+ * Constructs a new alert
70
+ */
71
+ constructor();
72
+
73
+ /**
74
+ * Adds an action button to the alert
75
+ *
76
+ * Use the number value returned from presentAlert() or presentSheet() to
77
+ * check which action was selected
78
+ *
79
+ * @param title Title of the action
80
+ */
81
+ addAction(title: string): void;
82
+
83
+ /**
84
+ * Adds a destructive action to the alert
85
+ *
86
+ * Destructive action titles have a red text color, signaling that the
87
+ * action may modify or delete data.
88
+ *
89
+ * @param title Title of the action
90
+ */
91
+ addDestructiveAction(title: string): void;
92
+
93
+ /**
94
+ * Adds a cancel action to the alert
95
+ *
96
+ * When a cancel action is selected, the number provided by presentAlert()
97
+ * or presentSheet() will be `-1`. Please note that when running on iPad
98
+ * and presenting using presentSheet(), the action will not be shown in the
99
+ * list of actions. The operation is cancelled by tapping outside the sheet.
100
+ *
101
+ * An alert can only contain a single cancel action. Attempting to add more
102
+ * cancel actions will remove any previously added cancel actions.
103
+ *
104
+ * @param title Title of the action
105
+ */
106
+ addCancelAction(title: string): void;
107
+
108
+ /**
109
+ * Adds a text field prompting for user input
110
+ *
111
+ * Retrieve the value for the text field using textFieldValue() and supply
112
+ * the index of the text field. Indices for text fields are assigned in the
113
+ * same order as they are added to the alert starting at 0.
114
+ *
115
+ * Text fields are not supported when using the sheet presentation.
116
+ *
117
+ * @param placeholder Optional placeholder displayed when the text field is empty
118
+ * @param text Optional default value for the text field
119
+ * @returns Text field added to the alert
120
+ */
121
+ // todo those two params are documented as optional? what does this mean typewise? is null/undefined fine?
122
+ addTextField(placeholder: string, text: string): TextField;
123
+
124
+ /**
125
+ * Adds a secure text field prompting for user input
126
+ *
127
+ * Values entered into a secure text field will be hidden behind dots.
128
+ * Retrieve the value for the text field using textFieldValue() and supply
129
+ * the index of the text field. Indices for text fields are assigned in the
130
+ * same order as they are added to the alert starting at 0.
131
+ *
132
+ * @param placeholder Optional placeholder displayed when the text field is empty
133
+ * @param text Optional default value for the text field
134
+ * @returns Text field added to the alert
135
+ */
136
+ // todo same as above, types of params are optional?
137
+ addSecureTextField(placeholder: string, text: string): TextField;
138
+
139
+ /**
140
+ * Retrieves value of a text field by index
141
+ *
142
+ * Indices for text fields are assigned in the same order as they are added
143
+ * to the alert starting at 0.
144
+ *
145
+ * @param index Index of text field to retrieve the value for
146
+ * @returns Value of text field at the specified index
147
+ */
148
+ textFieldValue(index: number): string;
149
+
150
+ /**
151
+ * Present the alert modally
152
+ *
153
+ * This is a shorthand for presentAlert().
154
+ *
155
+ * @returns Promise resolving to the chosen action index
156
+ */
157
+ present(): Promise<number>;
158
+
159
+ /**
160
+ * Present the alert modally
161
+ *
162
+ * @returns Promise resolving to the chosen action index
163
+ */
164
+ presentAlert(): Promise<number>;
165
+
166
+ /**
167
+ * Present the alert as a sheet
168
+ *
169
+ * @returns Promise resolving to the chosen action index
170
+ */
171
+ presentSheet(): Promise<number>;
172
+ }
173
+
174
+ declare class Calendar {
56
175
  static forReminders(): Promise<Array<Calendar>>;
57
176
  static forEvents(): Promise<Array<Calendar>>;
58
177
  static forRemindersByTitle(title: string): Promise<Calendar>;
@@ -64,62 +183,412 @@ declare class Calendar {
64
183
  // todo i'm guessing these, need to test
65
184
  static presentPicker(allowMultiple: true): Promise<Array<Calendar>>;
66
185
  static presentPicker(allowMultiple: false): Promise<[Calendar?]>;
67
- };
186
+
187
+ readonly identifier: string;
188
+ title: string;
189
+ readonly isSubscribed: boolean;
190
+ readonly allowsContentModifications: boolean;
191
+ color: Color;
192
+
193
+ // todo ???
194
+ private constructor();
195
+
196
+ supportsAvailability(availability: string): boolean;
197
+ save(): void;
198
+ remove(): void;
199
+ }
68
200
 
69
201
  // todo CalendarEvent
202
+
70
203
  // todo CallbackURL
71
- // todo Color
72
- // todo config
204
+
205
+ declare class Color {
206
+ static black(): Color;
207
+ static darkGray(): Color;
208
+ static lightGray(): Color;
209
+ static white(): Color;
210
+ static gray(): Color;
211
+ static red(): Color;
212
+ static green(): Color;
213
+ static blue(): Color;
214
+ static cyan(): Color;
215
+ static yellow(): Color;
216
+ static magenta(): Color;
217
+ static orange(): Color;
218
+ static purple(): Color;
219
+ static brown(): Color;
220
+ static clear(): Color;
221
+ static dynamic(lightColor: Color, darkColor: Color): Color;
222
+
223
+ readonly hex: string;
224
+ readonly red: number;
225
+ readonly green: number;
226
+ readonly blue: number;
227
+ readonly alpha: number;
228
+
229
+ constructor(hex: string, alpha: number);
230
+ }
231
+
73
232
  // todo console
233
+
74
234
  // todo Contact
235
+
75
236
  // todo ContactsContainer
237
+
76
238
  // todo ContactsGroup
77
- // todo Data
239
+
240
+ declare class Data {
241
+ static fromString(string: string): Data | null;
242
+ static fromFile(filepath: string): Data;
243
+ static fromBase64String(base64String: string): Data | null;
244
+ static fromJPEG(image: Image): Data;
245
+ static fromPNG(image: Image): Data;
246
+ static fromBytes(bytes: Array<number>): Data;
247
+
248
+ // todo ???
249
+ private constructor();
250
+
251
+ toRawString(): string;
252
+ toBase64String(): string;
253
+ getBytes(): Array<number>;
254
+ }
255
+
78
256
  // todo DateFormatter
257
+
79
258
  // todo DatePicker
259
+
80
260
  // todo Device
261
+
81
262
  // todo Dictation
263
+
82
264
  // todo DocumentPicker
265
+
83
266
  // todo DrawContext
267
+
84
268
  // todo FileManager
85
- // todo Font
86
- // todo Image
269
+
270
+ declare class Font {
271
+ static largeTitle(): Font;
272
+ static title1(): Font;
273
+ static title2(): Font;
274
+ static title3(): Font;
275
+ static headline(): Font;
276
+ static subheadline(): Font;
277
+ static body(): Font;
278
+ static callout(): Font;
279
+ static footnote(): Font;
280
+ static caption1(): Font;
281
+ static caption2(): Font;
282
+ static systemFont(size: number): Font;
283
+ static ultraLightSystemFont(size: number): Font;
284
+ static thinSystemFont(size: number): Font;
285
+ static lightSystemFont(size: number): Font;
286
+ static regularSystemFont(size: number): Font;
287
+ static mediumSystemFont(size: number): Font;
288
+ static semiboldSystemFont(size: number): Font;
289
+ static boldSystemFont(size: number): Font;
290
+ static heavySystemFont(size: number): Font;
291
+ static blackSystemFont(size: number): Font;
292
+ static italicSystemFont(size: number): Font;
293
+ static ultraLightMonospacedSystemFont(size: number): Font;
294
+ static thinMonospacedSystemFont(size: number): Font;
295
+ static lightMonospacedSystemFont(size: number): Font;
296
+ static regularMonospacedSystemFont(size: number): Font;
297
+ static mediumMonospacedSystemFont(size: number): Font;
298
+ static semiboldMonospacedSystemFont(size: number): Font;
299
+ static boldMonospacedSystemFont(size: number): Font;
300
+ static heavyMonospacedSystemFont(size: number): Font;
301
+ static blackMonospacedSystemFont(size: number): Font;
302
+ static ultraLightRoundedSystemFont(size: number): Font;
303
+ static thinRoundedSystemFont(size: number): Font;
304
+ static lightRoundedSystemFont(size: number): Font;
305
+ static regularRoundedSystemFont(size: number): Font;
306
+ static mediumRoundedSystemFont(size: number): Font;
307
+ static semiboldRoundedSystemFont(size: number): Font;
308
+ static boldRoundedSystemFont(size: number): Font;
309
+ static heavyRoundedSystemFont(size: number): Font;
310
+ static blackRoundedSystemFont(size: number): Font;
311
+
312
+ constructor(name: string, size: number);
313
+ }
314
+
315
+ declare class Image {
316
+ static fromFile(filePath: string): Image | null;
317
+ static fromData(data: Data): Image | null;
318
+
319
+ // todo ???
320
+ private constructor();
321
+
322
+ readonly size: Size;
323
+ }
324
+
87
325
  // todo importModule
326
+
88
327
  // todo Keychain
89
- // todo LinearGradient
328
+
329
+ declare class LinearGradient {
330
+ colors: Array<Color>;
331
+ locations: Array<number>;
332
+ startPoint: Point;
333
+ endPoint: Point;
334
+
335
+ constructor();
336
+ }
337
+
90
338
  // todo ListWidget
339
+
91
340
  // todo Location
341
+
92
342
  // todo Mail
343
+
93
344
  // todo Message
345
+
94
346
  // todo module
95
- // todo Notification
347
+
348
+ declare class Notification {
349
+ /**
350
+ * @deprecated
351
+ */
352
+ static current(): Notification;
353
+ static allPending(): Promise<Array<Notification>>;
354
+ static allDelivered(): Promise<Array<Notification>>;
355
+ static removeAllPending(): Promise<Array<Notification>>;
356
+ static removeAllDelivered(): Promise<Array<Notification>>;
357
+ static removePending(identifiers: Array<string>): Promise<void>;
358
+ static removeDelivered(identifiers: Array<string>): Promise<void>;
359
+ static resetCurrent(): void;
360
+
361
+ identifier: string;
362
+ title: string;
363
+ subtitle: string;
364
+ body: string;
365
+ preferredContentHeight: number;
366
+ badge: number;
367
+ threadIdentifier: string;
368
+ userInfo: { [k: string]: unknown };
369
+ sound:
370
+ | "default"
371
+ | "accept"
372
+ | "alert"
373
+ | "complete"
374
+ | "event"
375
+ | "failure"
376
+ | "piano_error"
377
+ | "piano_success"
378
+ | "popup"
379
+ | null;
380
+ openURL: string;
381
+ readonly deliveryDate: Date | null;
382
+ nextTriggerDate: Date;
383
+ scriptName: string;
384
+ actions: { [k: string]: string };
385
+
386
+ constructor();
387
+
388
+ schedule(): Promise<void>;
389
+ remove(): Promise<void>;
390
+ setTriggerDate(date: Date): void;
391
+ setDailyTrigger(hour: number, minute: number, repeats: boolean): void;
392
+ setWeeklyTrigger(weekday: number, hour: number, minute: number, repeats: boolean): void;
393
+ addAction(title: string, url: string, destructive: boolean): void;
394
+ }
395
+
96
396
  // todo Pasteboard
397
+
97
398
  // todo Path
399
+
98
400
  // todo Photos
99
- // todo Point
401
+
402
+ declare class Point {
403
+ x: number;
404
+ y: number;
405
+
406
+ constructor(x: number, y: number);
407
+ }
408
+
100
409
  // todo QuickLook
410
+
101
411
  // todo Rect
412
+
102
413
  // todo RecurrenceRule
414
+
103
415
  // todo RelativeDateTimeFormatter
416
+
104
417
  // todo Reminder
418
+
105
419
  // todo Request
420
+
106
421
  // todo Safari
422
+
107
423
  // todo Script
424
+
108
425
  // todo SFSymbol
426
+
109
427
  // todo ShareSheet
110
- // todo Size
428
+
429
+ declare class Size {
430
+ width: number;
431
+ height: number;
432
+
433
+ constructor(width: number, height: number);
434
+ }
435
+
111
436
  // todo Speech
112
- // todo TextField
437
+
438
+ declare class TextField {
439
+ text: string;
440
+ placeholder: string;
441
+ isSecure: boolean;
442
+ textColor: Color;
443
+ font: Font;
444
+
445
+ private constructor();
446
+
447
+ setDefaultKeyboard(): void;
448
+ setNumberPadKeyboard(): void;
449
+ setDecimalPadKeyboard(): void;
450
+ setNumbersAndPunctuationKeyboard(): void;
451
+ setPhonePadKeyboard(): void;
452
+ setWebSearchKeyboard(): void;
453
+ setEmailAddressKeyboard(): void;
454
+ setURLKeyboard(): void;
455
+ setTwitterKeyboard(): void;
456
+ leftAlignText(): void;
457
+ centerAlignText(): void;
458
+ rightAlignText(): void;
459
+
460
+ }
461
+
113
462
  // todo Timer
463
+
114
464
  // todo UITable
465
+
115
466
  // todo UITableCell
467
+
116
468
  // todo UITableRow
469
+
117
470
  // todo URLScheme
471
+
118
472
  // todo UUID
473
+
119
474
  // todo WebView
475
+
120
476
  // todo WidgetDate
121
- // todo WidgetImage
122
- // todo WidgetSpacer
123
- // todo WidgetStack
124
- // todo WidgetText
125
- // todo XMLParser
477
+ declare class WidgetDate {
478
+ date: Date;
479
+ textColor: Color;
480
+ font: Font;
481
+ textOpacity: number;
482
+ lineLimit: number;
483
+ minimumScaleFactor: number;
484
+ shadowColor: Color;
485
+ shadowRadius: number;
486
+ shadowOffset: Point;
487
+ url: string;
488
+
489
+ private constructor();
490
+
491
+ leftAlignText(): void;
492
+ centerAlignText(): void;
493
+ rightAlignText(): void;
494
+ applyTimeStyle(): void;
495
+ applyDateStyle(): void;
496
+ applyRelativeStyle(): void;
497
+ applyOffsetStyle(): void;
498
+ applyTimerStyle(): void;
499
+ }
500
+
501
+ declare class WidgetImage {
502
+ image: Image;
503
+ resizable: boolean;
504
+ imageSize: Size;
505
+ imageOpacity: number;
506
+ cornerRadius: number;
507
+ borderWidth: number;
508
+ borderColor: Color;
509
+ containerRelativeShape: boolean;
510
+ tintColor: Color;
511
+ url: string;
512
+
513
+ private constructor();
514
+
515
+ leftAlignImage(): void;
516
+ centerAlignImage(): void;
517
+ rightAlignImage(): void;
518
+ applyFittingContentMode(): void;
519
+ applyFillingContentMode(): void;
520
+ }
521
+
522
+ declare class WidgetSpacer {
523
+ length: number | null;
524
+
525
+ // todo ???
526
+ private constructor();
527
+ }
528
+
529
+ declare class WidgetStack {
530
+ backgroundColor: Color;
531
+ backgroundImage: Image;
532
+ backgroundGradient: LinearGradient;
533
+ spacing: number;
534
+ size: Size;
535
+ cornerRadius: number;
536
+ borderWidth: number;
537
+ borderColor: Color;
538
+ url: string;
539
+
540
+ // todo ???
541
+ private constructor();
542
+
543
+ addText(text: string): WidgetText;
544
+ addDate(date: Date): WidgetDate;
545
+ addImage(image: Image): WidgetImage;
546
+ addSpacer(length: number): WidgetSpacer;
547
+ addStack(): WidgetStack;
548
+ setPadding(top: number, leading: number, bottom: number, trailing: number): void;
549
+ useDefaultPadding(): void;
550
+ topAlignContent(): void;
551
+ centerAlignContent(): void;
552
+ bottomAlignContent(): void;
553
+ layoutHorizontally(): void;
554
+ layoutVertically(): void;
555
+ }
556
+
557
+ declare class WidgetText {
558
+ text: string;
559
+ textColor: Color;
560
+ font: Font;
561
+ textOpacity: number;
562
+ lineLimit: number;
563
+ minimumScaleFactor: number;
564
+ shadowColor: Color;
565
+ shadowRadius: number;
566
+ shadowOffset: Point;
567
+ url: string;
568
+
569
+ // todo ???
570
+ private constructor();
571
+
572
+ leftAlignText(): void;
573
+ centerAlignText(): void;
574
+ rightAlignText(): void;
575
+ }
576
+
577
+ // todo I set the event functions as optional because I'm guessing you can't
578
+ // read out a function from them before you set one, should verify this is true
579
+ declare class XMLParser {
580
+ didStartDocument?: () => void;
581
+ didEndDocument?: () => void;
582
+ didStartElement?: (
583
+ elementName: string,
584
+ attributes: { [k: string]: string }
585
+ ) => void;
586
+ didEndElement?: () => void;
587
+ foundCharacters?: () => void;
588
+ parseErrorOccured?: () => void;
589
+ string: string;
590
+
591
+ constructor(string: string);
592
+
593
+ parse(): boolean;
594
+ }