@minecraft/server-ui 2.1.0-beta.1.26.10-preview.20 → 2.1.0-beta.1.26.10-preview.23

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 +16 -16
  2. package/index.d.ts +505 -1
  3. package/package.json +19 -19
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # `@minecraft/server-ui`
2
-
3
- The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences.
4
-
5
-
6
-
7
- * [*@minecraft/server-ui.ActionFormData*](../../../scriptapi/minecraft/server-ui/ActionFormData.md) contain a list of buttons with captions and images that can be used for presenting a set of options to a player.
8
-
9
- * [*@minecraft/server-ui.MessageFormData*](../../../scriptapi/minecraft/server-ui/MessageFormData.md) are simple two-button message experiences that are functional for Yes/No or OK/Cancel questions.
10
-
11
- * [*@minecraft/server-ui.ModalFormData*](../../../scriptapi/minecraft/server-ui/ModalFormData.md) allow for a more flexible "questionnaire-style" list of controls that can be used to take input.
12
-
13
- ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
14
-
15
- See full documentation for this module here:
16
-
1
+ # `@minecraft/server-ui`
2
+
3
+ The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences.
4
+
5
+
6
+
7
+ * [*@minecraft/server-ui.ActionFormData*](../../../scriptapi/minecraft/server-ui/ActionFormData.md) contain a list of buttons with captions and images that can be used for presenting a set of options to a player.
8
+
9
+ * [*@minecraft/server-ui.MessageFormData*](../../../scriptapi/minecraft/server-ui/MessageFormData.md) are simple two-button message experiences that are functional for Yes/No or OK/Cancel questions.
10
+
11
+ * [*@minecraft/server-ui.ModalFormData*](../../../scriptapi/minecraft/server-ui/ModalFormData.md) allow for a more flexible "questionnaire-style" list of controls that can be used to take input.
12
+
13
+ ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
14
+
15
+ See full documentation for this module here:
16
+
17
17
  https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-ui/minecraft-server-ui
package/index.d.ts CHANGED
@@ -238,6 +238,142 @@ export class ActionFormResponse extends FormResponse {
238
238
  readonly selection?: number;
239
239
  }
240
240
 
241
+ /**
242
+ * @beta
243
+ * A customizable form that lets you put buttons, labels,
244
+ * toggles, dropdowns, sliders, and more into a form! Built on
245
+ * top of Observable, the form will update when the
246
+ * Observables' value changes.
247
+ */
248
+ export declare class CustomForm {
249
+ /**
250
+ * @remarks
251
+ * Inserts a button into the Custom form. onClick is called
252
+ * when the button is pressed.
253
+ *
254
+ */
255
+ button(
256
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
257
+ onClick: () => void,
258
+ options?: ButtonOptions,
259
+ ): CustomForm;
260
+ /**
261
+ * @remarks
262
+ * Can this form be shown to the player right now?
263
+ *
264
+ */
265
+ canShow(): boolean;
266
+ /**
267
+ * @remarks
268
+ * Closes the form. Throws an error if the form is not open.
269
+ *
270
+ */
271
+ close(): void;
272
+ /**
273
+ * @remarks
274
+ * Adds a close "X" button to the form.
275
+ *
276
+ */
277
+ closeButton(): CustomForm;
278
+ /**
279
+ * @remarks
280
+ * Inserts a divider (i.e. a line) into the Custom form.
281
+ *
282
+ */
283
+ divider(options?: DividerOptions): CustomForm;
284
+ /**
285
+ * @remarks
286
+ * Inserts a dropdown into the Custom form with the provided
287
+ * items. The value is based on the items value that selected.
288
+ *
289
+ */
290
+ dropdown(
291
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
292
+ value: Observable<number>,
293
+ items: DropdownItem[],
294
+ options?: DropdownOptions,
295
+ ): CustomForm;
296
+ /**
297
+ * @remarks
298
+ * Inserts a header (i.e. large sized text) into the Custom
299
+ * form.
300
+ *
301
+ */
302
+ header(
303
+ text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
304
+ options?: TextOptions,
305
+ ): CustomForm;
306
+ /**
307
+ * @remarks
308
+ * Inserts a label (i.e. medium sized text) into the Custom
309
+ * form.
310
+ *
311
+ */
312
+ label(
313
+ text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
314
+ options?: TextOptions,
315
+ ): CustomForm;
316
+ /**
317
+ * @remarks
318
+ * Shows the form to the player. Will throw errors if the form
319
+ * is currently being shown or if another behavior pack is
320
+ * showing a form.
321
+ *
322
+ */
323
+ show(): Promise<void>;
324
+ /**
325
+ * @remarks
326
+ * Creates a slider that lets players pick a number between
327
+ * minValue and maxValue. value must be client writable.
328
+ *
329
+ */
330
+ slider(
331
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
332
+ value: Observable<number>,
333
+ minValue: Observable<number> | number,
334
+ maxValue: Observable<number> | number,
335
+ options?: SliderOptions,
336
+ ): CustomForm;
337
+ /**
338
+ * @remarks
339
+ * Inserts a space into the Custom form.
340
+ *
341
+ */
342
+ spacer(options?: SpacingOptions): CustomForm;
343
+ /**
344
+ * @remarks
345
+ * Inserts a text field into the Custom for that players can
346
+ * enter text into.
347
+ *
348
+ */
349
+ textField(
350
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
351
+ text: Observable<string>,
352
+ options?: TextFieldOptions,
353
+ ): CustomForm;
354
+ /**
355
+ * @remarks
356
+ * Inserts an on/off toggle that players can interact with into
357
+ * the Custom form.
358
+ *
359
+ */
360
+ toggle(
361
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
362
+ toggled: Observable<boolean>,
363
+ options?: ToggleOptions,
364
+ ): CustomForm;
365
+ /**
366
+ * @remarks
367
+ * Creates a Custom form to show to the player. Use this
368
+ * instead of a constructor.
369
+ *
370
+ */
371
+ static create(
372
+ player: minecraftserver.Player,
373
+ title: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
374
+ ): CustomForm;
375
+ }
376
+
241
377
  /**
242
378
  * Base type for a form response.
243
379
  */
@@ -258,6 +394,62 @@ export class FormResponse {
258
394
  readonly canceled: boolean;
259
395
  }
260
396
 
397
+ /**
398
+ * @beta
399
+ * A simple message form UI, 2 buttons and a text body.
400
+ */
401
+ export declare class MessageBox {
402
+ /**
403
+ * @remarks
404
+ * Sets the data for the text in the body of the form. It is
405
+ * contained within a scroll view to allow for lots of text.
406
+ *
407
+ */
408
+ body(text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage): MessageBox;
409
+ /**
410
+ * @remarks
411
+ * Sets the data for the top button in the form.
412
+ *
413
+ */
414
+ button1(
415
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
416
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
417
+ ): MessageBox;
418
+ /**
419
+ * @remarks
420
+ * Sets the data for the bottom button in the form.
421
+ *
422
+ */
423
+ button2(
424
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
425
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
426
+ ): MessageBox;
427
+ /**
428
+ * @remarks
429
+ * Closes the form. Will throw an error if the form is not
430
+ * open.
431
+ *
432
+ */
433
+ close(): void;
434
+ /**
435
+ * @remarks
436
+ * Show this modal to the player. Will throw an error if the
437
+ * modal is already showing.
438
+ *
439
+ */
440
+ show(): Promise<MessageBoxResult>;
441
+ /**
442
+ * @remarks
443
+ * Creates a message form for a certain player. Use this
444
+ * instead of a constructor.
445
+ *
446
+ */
447
+ static create(
448
+ player: minecraftserver.Player,
449
+ title: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
450
+ ): MessageBox;
451
+ }
452
+
261
453
  /**
262
454
  * Builds a simple two-button modal dialog.
263
455
  * @example showBasicMessageForm.ts
@@ -653,6 +845,52 @@ export class ModalFormResponse extends FormResponse {
653
845
  readonly formValues?: (boolean | number | string | undefined)[];
654
846
  }
655
847
 
848
+ /**
849
+ * @beta
850
+ * A class that represents data that can be Observed.
851
+ * Extensively used for UI.
852
+ */
853
+ export declare class Observable<T extends string | number | boolean | UIRawMessage> {
854
+ /**
855
+ * @remarks
856
+ * Gets the data from the Observable.
857
+ *
858
+ */
859
+ getData(): T;
860
+ /**
861
+ * @remarks
862
+ * Sets the data on this Observable and notifies the
863
+ * subscribers.
864
+ *
865
+ */
866
+ setData(data: T): void;
867
+ /**
868
+ * @remarks
869
+ * Subscribes a callback to any changes that occur to the
870
+ * Observable. The return value can be passed into the
871
+ * `unsubscribe` function to stop listening to changes.
872
+ *
873
+ */
874
+ subscribe(listener: (newValue: T) => void): (newValue: T) => void;
875
+ /**
876
+ * @remarks
877
+ * Unsubscribe a callback from any changes that occur to the
878
+ * Observable. This takes the return value from the `subscribe`
879
+ * function.
880
+ *
881
+ */
882
+ unsubscribe(listener: (newValue: T) => void): void;
883
+ /**
884
+ * @remarks
885
+ * Creates an Observable, use this instead of a constructor.
886
+ *
887
+ */
888
+ static create<T extends string | number | boolean | UIRawMessage>(
889
+ data: T,
890
+ options?: ObservableOptions,
891
+ ): Observable<T>;
892
+ }
893
+
656
894
  export class UIManager {
657
895
  private constructor();
658
896
  /**
@@ -664,6 +902,110 @@ export class UIManager {
664
902
  closeAllForms(player: minecraftserver.Player): void;
665
903
  }
666
904
 
905
+ /**
906
+ * @beta
907
+ * The options for including a button in {@link CustomForm}.
908
+ */
909
+ export interface ButtonOptions {
910
+ /**
911
+ * @remarks
912
+ * Whether or not this button is disabled.
913
+ *
914
+ */
915
+ disabled?: Observable<boolean> | boolean;
916
+ /**
917
+ * @remarks
918
+ * The tooltip for this button, shown when hovering the button.
919
+ *
920
+ */
921
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
922
+ /**
923
+ * @remarks
924
+ * Whether or not this button is visible.
925
+ *
926
+ */
927
+ visible?: Observable<boolean> | boolean;
928
+ }
929
+
930
+ /**
931
+ * @beta
932
+ * The options for including a spacer in {@link CustomForm}.
933
+ */
934
+ export interface DividerOptions {
935
+ /**
936
+ * @remarks
937
+ * Whether or not this divider is visible
938
+ *
939
+ */
940
+ visible?: Observable<boolean> | boolean;
941
+ }
942
+
943
+ /**
944
+ * @beta
945
+ * Dropdown data for use in {@link CustomForm}.
946
+ */
947
+ export interface DropdownItem {
948
+ /**
949
+ * @remarks
950
+ * The description of the dropdown item shown when it is
951
+ * selected.
952
+ *
953
+ */
954
+ description?: string;
955
+ /**
956
+ * @remarks
957
+ * The label of the dropdown item in the dropdown.
958
+ *
959
+ */
960
+ label: string;
961
+ /**
962
+ * @remarks
963
+ * The value the dropdown will be set to when this item is
964
+ * selected.
965
+ *
966
+ */
967
+ value: number;
968
+ }
969
+
970
+ /**
971
+ * @beta
972
+ * The options for including a dropdown in {@link CustomForm}.
973
+ */
974
+ export interface DropdownOptions {
975
+ /**
976
+ * @remarks
977
+ * The description of the dropdown, shown in the UI.
978
+ *
979
+ */
980
+ description?: Observable<string> | string | UIRawMessage;
981
+ /**
982
+ * @remarks
983
+ * Whether or not this dropdown is disabled.
984
+ *
985
+ */
986
+ disabled?: Observable<boolean> | boolean;
987
+ /**
988
+ * @remarks
989
+ * Whether or not this dropdown is visible.
990
+ *
991
+ */
992
+ visible?: Observable<boolean> | boolean;
993
+ }
994
+
995
+ /**
996
+ * @beta
997
+ * The result when a {@link MessageBox} is closed.
998
+ */
999
+ export interface MessageBoxResult {
1000
+ /**
1001
+ * @remarks
1002
+ * The button that was selected, undefined if it was closed
1003
+ * without pressing a button.
1004
+ *
1005
+ */
1006
+ selection?: number;
1007
+ }
1008
+
667
1009
  /**
668
1010
  * An interface that is passed into {@link
669
1011
  * @minecraft/Server-ui.ModalFormData.dropdown} to provide
@@ -756,6 +1098,168 @@ export interface ModalFormDataToggleOptions {
756
1098
  tooltip?: minecraftserver.RawMessage | string;
757
1099
  }
758
1100
 
1101
+ /**
1102
+ * @beta
1103
+ * An interface passed into `Observable.create`.
1104
+ */
1105
+ export interface ObservableOptions {
1106
+ /**
1107
+ * @remarks
1108
+ * If set to true, the client can update this value. This
1109
+ * should be used for things like dropdown values, toggles,
1110
+ * textfields, etc. If unset or false, the client cannot write
1111
+ * to this observable.
1112
+ *
1113
+ */
1114
+ clientWritable?: boolean;
1115
+ }
1116
+
1117
+ /**
1118
+ * @beta
1119
+ * The options for including a slider in {@link CustomForm}.
1120
+ */
1121
+ export interface SliderOptions {
1122
+ /**
1123
+ * @remarks
1124
+ * The description of the slider, shown in the UI.
1125
+ *
1126
+ */
1127
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1128
+ /**
1129
+ * @remarks
1130
+ * Whether or not this slider is disabled.
1131
+ *
1132
+ */
1133
+ disabled?: Observable<boolean> | boolean;
1134
+ /**
1135
+ * @remarks
1136
+ * The step size of the slider. For example, if this is 2 and
1137
+ * the min is 0 and the max is 10, the only selectable values
1138
+ * will be 0, 2, 4, 6, 8, 10.
1139
+ *
1140
+ */
1141
+ step?: Observable<number> | number;
1142
+ /**
1143
+ * @remarks
1144
+ * Whether or not this slider is visible.
1145
+ *
1146
+ */
1147
+ visible?: Observable<boolean> | boolean;
1148
+ }
1149
+
1150
+ /**
1151
+ * @beta
1152
+ * The options for including a spacer in {@link CustomForm}.
1153
+ */
1154
+ export interface SpacingOptions {
1155
+ /**
1156
+ * @remarks
1157
+ * Whether or not this spacer is visible
1158
+ *
1159
+ */
1160
+ visible?: Observable<boolean> | boolean;
1161
+ }
1162
+
1163
+ /**
1164
+ * @beta
1165
+ * The options for including a textfield in {@link CustomForm}.
1166
+ */
1167
+ export interface TextFieldOptions {
1168
+ /**
1169
+ * @remarks
1170
+ * The description for this text field, shown in the UI.
1171
+ *
1172
+ */
1173
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1174
+ /**
1175
+ * @remarks
1176
+ * Whether or not this text field is disabled.
1177
+ *
1178
+ */
1179
+ disabled?: Observable<boolean> | boolean;
1180
+ /**
1181
+ * @remarks
1182
+ * Whether or not this text field is visible.
1183
+ *
1184
+ */
1185
+ visible?: Observable<boolean> | boolean;
1186
+ }
1187
+
1188
+ /**
1189
+ * @beta
1190
+ * The options for including a label or header in {@link
1191
+ * CustomForm}.
1192
+ */
1193
+ export interface TextOptions {
1194
+ /**
1195
+ * @remarks
1196
+ * Whether or not this label is visible
1197
+ *
1198
+ */
1199
+ visible?: Observable<boolean> | boolean;
1200
+ }
1201
+
1202
+ /**
1203
+ * @beta
1204
+ * The options for including a toggle in {@link CustomForm}.
1205
+ */
1206
+ export interface ToggleOptions {
1207
+ /**
1208
+ * @remarks
1209
+ * The description for this toggle, shown in the UI.
1210
+ *
1211
+ */
1212
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1213
+ /**
1214
+ * @remarks
1215
+ * Whether or not this toggle is disabled.
1216
+ *
1217
+ */
1218
+ disabled?: Observable<boolean> | boolean;
1219
+ /**
1220
+ * @remarks
1221
+ * Whether or not this toggle is visible.
1222
+ *
1223
+ */
1224
+ visible?: Observable<boolean> | boolean;
1225
+ }
1226
+
1227
+ /**
1228
+ * @beta
1229
+ * A message that can be sent to the client. This is a subset
1230
+ * of the RawMessage type, and is used for UI messages.
1231
+ */
1232
+ export interface UIRawMessage {
1233
+ /**
1234
+ * @remarks
1235
+ * Provides a raw-text equivalent of the current message.
1236
+ *
1237
+ */
1238
+ rawtext?: UIRawMessage[];
1239
+ /**
1240
+ * @remarks
1241
+ * Provides a string literal value to use.
1242
+ *
1243
+ */
1244
+ text?: string;
1245
+ /**
1246
+ * @remarks
1247
+ * Provides a translation token where, if the client has an
1248
+ * available resource in the players' language which matches
1249
+ * the token, will get translated on the client.
1250
+ *
1251
+ */
1252
+ translate?: string;
1253
+ /**
1254
+ * @remarks
1255
+ * Arguments for the translation token. Can be either an array
1256
+ * of strings or UIRawMessage containing an array of raw text
1257
+ * objects.
1258
+ *
1259
+ */
1260
+ with?: string[] | UIRawMessage;
1261
+ }
1262
+
759
1263
  // @ts-ignore Class inheritance allowed for native defined classes
760
1264
  export class FormRejectError extends Error {
761
1265
  private constructor();
@@ -764,7 +1268,7 @@ export class FormRejectError extends Error {
764
1268
  * This property can be read in early-execution mode.
765
1269
  *
766
1270
  */
767
- reason: FormRejectReason;
1271
+ readonly reason: FormRejectReason;
768
1272
  }
769
1273
 
770
1274
  export const uiManager: UIManager;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "name": "@minecraft/server-ui",
3
- "version": "2.1.0-beta.1.26.10-preview.20",
4
- "description": "",
5
- "contributors": [
6
- {
7
- "name": "Jake Shirley",
8
- "email": "jake@xbox.com"
9
- },
10
- {
11
- "name": "Mike Ammerlaan",
12
- "email": "mikeam@microsoft.com"
13
- }
14
- ],
15
- "peerDependencies": {
16
- "@minecraft/common": "^1.0.0",
17
- "@minecraft/server": "^2.0.0 || ^2.7.0-beta.1.26.10-preview.20"
18
- },
19
- "license": "MIT"
1
+ {
2
+ "name": "@minecraft/server-ui",
3
+ "version": "2.1.0-beta.1.26.10-preview.23",
4
+ "description": "",
5
+ "contributors": [
6
+ {
7
+ "name": "Jake Shirley",
8
+ "email": "jake@xbox.com"
9
+ },
10
+ {
11
+ "name": "Mike Ammerlaan",
12
+ "email": "mikeam@microsoft.com"
13
+ }
14
+ ],
15
+ "peerDependencies": {
16
+ "@minecraft/common": "^1.0.0",
17
+ "@minecraft/server": "^2.0.0 || ^2.7.0-beta.1.26.10-preview.23"
18
+ },
19
+ "license": "MIT"
20
20
  }