scratch-blocks 2.0.0-spork.1 → 2.0.0-spork.3

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 (81) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/main.js +1 -1
  3. package/package.json +2 -3
  4. package/src/{block_reporting.js → block_reporting.ts} +7 -5
  5. package/src/blocks/{colour.js → colour.ts} +6 -6
  6. package/src/blocks/{control.js → control.ts} +21 -54
  7. package/src/blocks/{data.js → data.ts} +134 -142
  8. package/src/blocks/{event.js → event.ts} +12 -33
  9. package/src/blocks/{looks.js → looks.ts} +24 -73
  10. package/src/blocks/{math.js → math.ts} +6 -11
  11. package/src/blocks/{matrix.js → matrix.ts} +2 -3
  12. package/src/blocks/{motion.js → motion.ts} +23 -70
  13. package/src/blocks/{note.js → note.ts} +2 -3
  14. package/src/blocks/{operators.js → operators.ts} +18 -55
  15. package/src/blocks/{procedures.js → procedures.ts} +418 -269
  16. package/src/blocks/{sensing.js → sensing.ts} +21 -61
  17. package/src/blocks/{sound.js → sound.ts} +9 -28
  18. package/src/blocks/{text.js → text.ts} +1 -2
  19. package/src/blocks/{vertical_extensions.js → vertical_extensions.ts} +63 -100
  20. package/src/checkable_continuous_flyout.js +2 -2
  21. package/src/{checkbox_bubble.js → checkbox_bubble.ts} +36 -53
  22. package/src/{colours.js → colours.ts} +11 -4
  23. package/src/{constants.js → constants.ts} +13 -0
  24. package/src/{context_menu_items.js → context_menu_items.ts} +18 -12
  25. package/src/{data_category.js → data_category.ts} +216 -150
  26. package/src/events/{events_block_comment_base.js → events_block_comment_base.ts} +23 -4
  27. package/src/events/{events_block_comment_change.js → events_block_comment_change.ts} +29 -5
  28. package/src/events/{events_block_comment_collapse.js → events_block_comment_collapse.ts} +24 -6
  29. package/src/events/{events_block_comment_create.js → events_block_comment_create.ts} +36 -10
  30. package/src/events/{events_block_comment_delete.js → events_block_comment_delete.ts} +6 -2
  31. package/src/events/{events_block_comment_move.js → events_block_comment_move.ts} +36 -6
  32. package/src/events/events_block_comment_resize.ts +88 -0
  33. package/src/events/events_block_drag_end.ts +49 -0
  34. package/src/events/events_block_drag_outside.ts +44 -0
  35. package/src/events/{events_scratch_variable_create.js → events_scratch_variable_create.ts} +28 -15
  36. package/src/fields/{field_colour_slider.js → field_colour_slider.ts} +117 -106
  37. package/src/fields/{field_matrix.js → field_matrix.ts} +189 -215
  38. package/src/fields/{field_note.js → field_note.ts} +227 -286
  39. package/src/fields/{field_textinput_removable.js → field_textinput_removable.ts} +17 -20
  40. package/src/fields/{field_variable_getter.js → field_variable_getter.ts} +28 -17
  41. package/src/fields/{field_vertical_separator.js → field_vertical_separator.ts} +14 -30
  42. package/src/fields/{field_angle.js → scratch_field_angle.ts} +124 -80
  43. package/src/fields/{field_dropdown.js → scratch_field_dropdown.ts} +9 -7
  44. package/src/fields/{field_number.js → scratch_field_number.ts} +60 -55
  45. package/src/fields/{field_variable.js → scratch_field_variable.ts} +46 -27
  46. package/src/{flyout_checkbox_icon.js → flyout_checkbox_icon.ts} +15 -19
  47. package/src/{glows.js → glows.ts} +29 -18
  48. package/src/index.ts +59 -60
  49. package/src/procedures.ts +462 -0
  50. package/src/{recyclable_block_flyout_inflater.js → recyclable_block_flyout_inflater.ts} +35 -35
  51. package/src/renderer/{bowler_hat.js → bowler_hat.ts} +1 -1
  52. package/src/renderer/{constants.js → constants.ts} +26 -12
  53. package/src/renderer/{drawer.js → drawer.ts} +8 -3
  54. package/src/renderer/{path_object.js → path_object.ts} +2 -2
  55. package/src/renderer/{render_info.js → render_info.ts} +19 -7
  56. package/src/renderer/renderer.ts +76 -0
  57. package/src/{scratch_block_paster.js → scratch_block_paster.ts} +9 -7
  58. package/src/scratch_blocks_utils.ts +39 -0
  59. package/src/{scratch_comment_icon.js → scratch_comment_icon.ts} +43 -26
  60. package/src/scratch_connection_checker.ts +44 -0
  61. package/src/{scratch_continuous_category.js → scratch_continuous_category.ts} +20 -13
  62. package/src/{scratch_continuous_toolbox.js → scratch_continuous_toolbox.ts} +20 -18
  63. package/src/{scratch_dragger.js → scratch_dragger.ts} +97 -28
  64. package/src/{scratch_variable_map.js → scratch_variable_map.ts} +4 -1
  65. package/src/scratch_variable_model.ts +30 -0
  66. package/src/{shadows.js → shadows.ts} +8 -4
  67. package/src/{status_indicator_label.js → status_indicator_label.ts} +24 -36
  68. package/src/{status_indicator_label_flyout_inflater.js → status_indicator_label_flyout_inflater.ts} +9 -7
  69. package/src/{variables.js → variables.ts} +153 -123
  70. package/tsconfig.json +4 -2
  71. package/src/categories.js +0 -15
  72. package/src/events/events_block_comment_resize.js +0 -52
  73. package/src/events/events_block_drag_end.js +0 -33
  74. package/src/events/events_block_drag_outside.js +0 -30
  75. package/src/procedures.js +0 -425
  76. package/src/renderer/renderer.js +0 -74
  77. package/src/scratch_blocks_utils.js +0 -148
  78. package/src/scratch_connection_checker.js +0 -29
  79. package/src/scratch_variable_model.js +0 -24
  80. /package/src/{css.js → css.ts} +0 -0
  81. /package/{continuous-toolbox.d.ts → types/continuous-toolbox.d.ts} +0 -0
@@ -26,37 +26,59 @@ import * as Blockly from "blockly/core";
26
26
  import {
27
27
  LIST_VARIABLE_TYPE,
28
28
  BROADCAST_MESSAGE_VARIABLE_TYPE,
29
- } from "./constants.js";
29
+ } from "./constants";
30
+ import { ScratchVariableModel } from "./scratch_variable_model";
31
+ import { ScratchContinuousToolbox } from "./scratch_continuous_toolbox";
32
+ import { CheckableContinuousFlyout } from "./checkable_continuous_flyout.js";
30
33
 
31
34
  /**
32
- * Constant prefix to differentiate cloud variable names from other types
33
- * of variables.
35
+ * Constant prefix to differentiate cloud variable names from other types of
36
+ * variables.
34
37
  * This is the \u2601 cloud unicode character followed by a space.
35
- * @type {string}
36
- * @package
37
38
  */
38
39
  const CLOUD_PREFIX = "☁ ";
39
40
 
40
- let prompt = null;
41
+ type PromptType = (
42
+ message: string,
43
+ defaultValue: string,
44
+ callback: (
45
+ variableName: string,
46
+ additionalVars: string[],
47
+ variableOptions?: { scope?: string; isCloud?: boolean }
48
+ ) => void,
49
+ title?: string,
50
+ varType?: string
51
+ ) => void;
41
52
 
42
- export function setPromptHandler(handler) {
53
+ let prompt: PromptType | undefined = undefined;
54
+
55
+ /**
56
+ * Sets the handler for calls to prompt().
57
+ *
58
+ * @param handler The new prompt function.
59
+ */
60
+ export function setPromptHandler(handler: PromptType) {
43
61
  prompt = handler;
44
62
  }
45
63
 
46
64
  /**
47
65
  * Create a new variable on the given workspace.
48
- * @param {!Blockly.Workspace} workspace The workspace on which to create the
49
- * variable.
50
- * @param {function(?string=)=} opt_callback An optional callback function to act
51
- * on the id of the variable that is created from the user's input, or null
52
- * if the change is to be aborted (cancel button or an invalid name was provided).
53
- * @param {string} opt_type Optional type of the variable to be created,
54
- * like 'string' or 'list'.
66
+ *
67
+ * @param workspace The workspace on which to create the variable.
68
+ * @param opt_callback An optional callback function to act on the id of the
69
+ * variable that is created from the user's input, or null if the change is
70
+ * to be aborted (cancel button or an invalid name was provided).
71
+ * @param opt_type Optional type of the variable to be created, like 'string' or
72
+ * 'list'.
55
73
  */
56
- export function createVariable(workspace, opt_callback, opt_type) {
74
+ export function createVariable(
75
+ workspace: Blockly.WorkspaceSvg,
76
+ opt_callback?: (id?: string) => void,
77
+ opt_type?: string
78
+ ) {
57
79
  // Decide on a modal message based on the opt_type. If opt_type was not
58
80
  // provided, default to the original message for scalar variables.
59
- var newMsg, modalTitle;
81
+ let newMsg, modalTitle;
60
82
  if (opt_type === BROADCAST_MESSAGE_VARIABLE_TYPE) {
61
83
  newMsg = Blockly.Msg.NEW_BROADCAST_MESSAGE_TITLE;
62
84
  modalTitle = Blockly.Msg.BROADCAST_MODAL_TITLE;
@@ -67,29 +89,33 @@ export function createVariable(workspace, opt_callback, opt_type) {
67
89
  // Note: this case covers 1) scalar variables, 2) any new type of
68
90
  // variable not explicitly checked for above, and 3) a null or undefined
69
91
  // opt_type -- turns a falsey opt_type into ''
70
- // TODO (#1251) Warn developers that they didn't provide an opt_type/provided
71
- // a falsey opt_type
92
+ // TODO (#1251) Warn developers that they didn't provide an opt_type/
93
+ // provided a falsey opt_type
72
94
  opt_type = opt_type ? opt_type : "";
73
95
  newMsg = Blockly.Msg.NEW_VARIABLE_TITLE;
74
96
  modalTitle = Blockly.Msg.VARIABLE_MODAL_TITLE;
75
97
  }
76
- var validate = nameValidator.bind(null, opt_type);
98
+ const validate = nameValidator.bind(null, opt_type);
77
99
 
78
100
  // Prompt the user to enter a name for the variable
79
101
  prompt(
80
102
  newMsg,
81
103
  "",
82
- function (text, additionalVars, variableOptions) {
104
+ function (
105
+ text: string,
106
+ additionalVars: string[],
107
+ variableOptions?: { scope?: string; isCloud?: boolean }
108
+ ) {
83
109
  variableOptions = variableOptions || {};
84
- var scope = variableOptions.scope;
85
- var isLocal = scope === "local" || false;
86
- var isCloud = variableOptions.isCloud || false;
110
+ const scope = variableOptions.scope;
111
+ const isLocal = scope === "local" || false;
112
+ const isCloud = variableOptions.isCloud || false;
87
113
  // Default to [] if additionalVars is not provided
88
114
  additionalVars = additionalVars || [];
89
115
  // Only use additionalVars for global variable creation.
90
- var additionalVarNames = isLocal ? [] : additionalVars;
116
+ const additionalVarNames = isLocal ? [] : additionalVars;
91
117
 
92
- var validatedText = validate(
118
+ const validatedText = validate(
93
119
  text,
94
120
  workspace,
95
121
  additionalVarNames,
@@ -97,12 +123,7 @@ export function createVariable(workspace, opt_callback, opt_type) {
97
123
  opt_callback
98
124
  );
99
125
  if (validatedText) {
100
- const VariableModel = Blockly.registry.getObject(
101
- Blockly.registry.Type.VARIABLE_MODEL,
102
- Blockly.registry.DEFAULT,
103
- true
104
- );
105
- const variable = new VariableModel(
126
+ const variable = new ScratchVariableModel(
106
127
  workspace,
107
128
  validatedText,
108
129
  opt_type,
@@ -115,11 +136,17 @@ export function createVariable(workspace, opt_callback, opt_type) {
115
136
  new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(variable)
116
137
  );
117
138
 
118
- var flyout = workspace.isFlyout ? workspace : workspace.getFlyout();
119
- var variableBlockId = variable.getId();
120
- workspace.getToolbox()?.runAfterRerender(() => {
121
- flyout.setCheckboxState(variableBlockId, true);
122
- });
139
+ const toolbox = workspace.getToolbox();
140
+ const flyout = toolbox.getFlyout();
141
+ const variableBlockId = variable.getId();
142
+ if (
143
+ toolbox instanceof ScratchContinuousToolbox &&
144
+ flyout instanceof CheckableContinuousFlyout
145
+ ) {
146
+ toolbox.runAfterRerender(() => {
147
+ flyout.setCheckboxState(variableBlockId, true);
148
+ });
149
+ }
123
150
 
124
151
  if (opt_callback) {
125
152
  opt_callback(variableBlockId);
@@ -137,44 +164,44 @@ export function createVariable(workspace, opt_callback, opt_type) {
137
164
  }
138
165
 
139
166
  /**
140
- * This function provides a common interface for variable name validation agnostic
141
- * of type. This is so that functions like Blockly.Variables.createVariable and
142
- * Blockly.Variables.renameVariable can call a single function (with a single
143
- * type signature) to validate the user-provided name for a variable.
144
- * @param {string} type The type of the variable for which the provided name
145
- * should be validated.
146
- * @param {string} text The user-provided text that should be validated as a
147
- * variable name.
148
- * @param {!Blockly.Workspace} workspace The workspace on which to validate the
149
- * variable name. This is the workspace used to check whether the variable
150
- * already exists.
151
- * @param {Array<string>} additionalVars A list of additional var names to check
152
- * for conflicts against.
153
- * @param {boolean} isCloud Whether the variable is a cloud variable.
154
- * @param {function(?string=)=} opt_callback An optional function to be called on
155
- * a pre-existing variable of the user-provided name. This function is currently
156
- * only used for broadcast messages.
157
- * @return {string} The validated name according to the parameters given, if
158
- * the name is determined to be valid, or null if the name
159
- * is determined to be invalid/in-use, and the calling function should not
160
- * proceed with creating or renaming the variable.
161
- * @private
167
+ * This function provides a common interface for variable name validation
168
+ * agnostic of type. This is so that functions like createVariable and
169
+ * renameVariable can call a single function (with a single type signature) to
170
+ * validate the user-provided name for a variable.
171
+ *
172
+ * @param type The type of the variable for which the provided name should be
173
+ * validated.
174
+ * @param text The user-provided text that should be validated as a variable
175
+ * name.
176
+ * @param workspace The workspace on which to validate the variable name. This
177
+ * is the workspace used to check whether the variable already exists.
178
+ * @param additionalVars A list of additional var names to check for conflicts
179
+ * against.
180
+ * @param isCloud Whether the variable is a cloud variable.
181
+ * @param opt_callback An optional function to be called on a pre-existing
182
+ * variable of the user-provided name. This function is currently only used
183
+ * for broadcast messages.
184
+ * @returns The validated name according to the parameters given, if the name is
185
+ * determined to be valid, or null if the name is determined to be invalid/
186
+ * in-use, and the calling function should not proceed with creating or
187
+ * renaming the variable.
162
188
  */
163
189
  function nameValidator(
164
- type,
165
- text,
166
- workspace,
167
- additionalVars,
168
- isCloud,
169
- opt_callback
170
- ) {
171
- // The validators for the different variable types require slightly different arguments.
172
- // For broadcast messages, if a broadcast message of the provided name already exists,
173
- // the validator needs to call a function that updates the selected
174
- // field option of the dropdown menu of the block that was used to create the new message.
175
- // For scalar variables and lists, the validator has the same validation behavior, but needs
176
- // to know which type of variable to check for and needs a type-specific error message
177
- // that is displayed when a variable of the given name and type already exists.
190
+ type: string,
191
+ text: string,
192
+ workspace: Blockly.WorkspaceSvg,
193
+ additionalVars: string[],
194
+ isCloud: boolean,
195
+ opt_callback?: (id?: string) => void
196
+ ): string {
197
+ // The validators for the different variable types require slightly different
198
+ // arguments. For broadcast messages, if a broadcast message of the provided
199
+ // name already exists, the validator needs to call a function that updates
200
+ // the selected field option of the dropdown menu of the block that was used
201
+ // to create the new message. For scalar variables and lists, the validator
202
+ // has the same validation behavior, but needs to know which type of variable
203
+ // to check for and needs a type-specific error message that is displayed when
204
+ // a variable of the given name and type already exists.
178
205
 
179
206
  if (type === BROADCAST_MESSAGE_VARIABLE_TYPE) {
180
207
  return validateBroadcastMessageName(text, workspace, opt_callback);
@@ -201,21 +228,24 @@ function nameValidator(
201
228
 
202
229
  /**
203
230
  * Validate the given name as a broadcast message type.
204
- * @param {string} name The name to validate
205
- * @param {!Blockly.Workspace} workspace The workspace the name should be validated
206
- * against.
207
- * @param {function(?string=)=} opt_callback An optional function to call if a broadcast
208
- * message already exists with the given name. This function will be called on the id
209
- * of the existing variable.
210
- * @return {string} The validated name, or null if invalid.
211
- * @private
231
+ *
232
+ * @param name The name to validate
233
+ * @param workspace The workspace the name should be validated against.
234
+ * @param opt_callback An optional function to call if a broadcast message
235
+ * already exists with the given name. This function will be called on the
236
+ * id of the existing variable.
237
+ * @returns The validated name, or null if invalid.
212
238
  */
213
- function validateBroadcastMessageName(name, workspace, opt_callback) {
239
+ function validateBroadcastMessageName(
240
+ name: string,
241
+ workspace: Blockly.WorkspaceSvg,
242
+ opt_callback?: (id?: string) => void
243
+ ): string | null {
214
244
  if (!name) {
215
245
  // no name was provided or the user cancelled the prompt
216
246
  return null;
217
247
  }
218
- var variable = workspace.getVariable(name, BROADCAST_MESSAGE_VARIABLE_TYPE);
248
+ const variable = workspace.getVariable(name, BROADCAST_MESSAGE_VARIABLE_TYPE);
219
249
  if (variable) {
220
250
  // If the user provided a name for a broadcast message that already exists,
221
251
  // use the provided callback function to update the selected option in
@@ -237,27 +267,26 @@ function validateBroadcastMessageName(name, workspace, opt_callback) {
237
267
  /**
238
268
  * Validate the given name as a scalar variable or list type.
239
269
  * This function is also responsible for any user facing error-handling.
240
- * @param {string} name The name to validate
241
- * @param {!Blockly.Workspace} workspace The workspace the name should be validated
242
- * against.
243
- * @param {Array<string>} additionalVars A list of additional variable names to check
244
- * for conflicts against.
245
- * @param {boolean} isCloud Whether the variable is a cloud variable.
246
- * @param {string} type The type to validate the variable as. This should be one of
247
- * Blockly.SCALAR_VARIABLE_TYPE or Blockly.LIST_VARIABLE_TYPE.
248
- * @param {string} errorMsg The type-specific error message the user should see
249
- * if a variable of the validated, given name and type already exists.
250
- * @return {string} The validated name, or null if invalid.
251
- * @private
270
+ *
271
+ * @param name The name to validate
272
+ * @param workspace The workspace the name should be validated against.
273
+ * @param additionalVars A list of additional variable names to check for
274
+ * conflicts against.
275
+ * @param isCloud Whether the variable is a cloud variable.
276
+ * @param type The type to validate the variable as. This should be one of
277
+ * SCALAR_VARIABLE_TYPE or LIST_VARIABLE_TYPE.
278
+ * @param errorMsg The type-specific error message the user should see if a
279
+ * variable of the validated, given name and type already exists.
280
+ * @returns The validated name, or null if invalid.
252
281
  */
253
282
  function validateScalarVarOrListName(
254
- name,
255
- workspace,
256
- additionalVars,
257
- isCloud,
258
- type,
259
- errorMsg
260
- ) {
283
+ name: string,
284
+ workspace: Blockly.WorkspaceSvg,
285
+ additionalVars: string[],
286
+ isCloud: boolean,
287
+ type: string,
288
+ errorMsg: string
289
+ ): string | null {
261
290
  // For scalar variables, we don't want leading or trailing white space
262
291
  name = name.trim();
263
292
  if (!name) {
@@ -278,24 +307,25 @@ function validateScalarVarOrListName(
278
307
 
279
308
  /**
280
309
  * Rename a variable with the given workspace, variableType, and oldName.
281
- * @param {!Blockly.Workspace} workspace The workspace on which to rename the
282
- * variable.
283
- * @param {Blockly.VariableModel} variable Variable to rename.
284
- * @param {function(?string=)=} opt_callback A callback. It will
285
- * be passed an acceptable new variable name, or null if change is to be
286
- * aborted (cancel button), or undefined if an existing variable was chosen.
310
+ *
311
+ * @param workspace The workspace on which to rename the variable.
312
+ * @param variable Variable to rename.
313
+ * @param opt_callback A callback. It will be passed an acceptable new variable
314
+ * name, or null if change is to be aborted (cancel button), or undefined if
315
+ * an existing variable was chosen.
287
316
  */
288
- export function renameVariable(workspace, variable, opt_callback) {
317
+ export function renameVariable(
318
+ workspace: Blockly.WorkspaceSvg,
319
+ variable: ScratchVariableModel,
320
+ opt_callback?: (id?: string) => void
321
+ ) {
289
322
  // Validation and modal message/title depends on the variable type
290
- var promptMsg, modalTitle;
291
- var varType = variable.type;
323
+ let promptMsg, modalTitle;
324
+ const varType = variable.getType();
292
325
  if (varType === BROADCAST_MESSAGE_VARIABLE_TYPE) {
293
326
  console.warn(
294
- "Unexpected attempt to rename a broadcast message with " +
295
- "id: " +
296
- variable.getId() +
297
- " and name: " +
298
- variable.name
327
+ `Unexpected attempt to rename a broadcast message with
328
+ id: "${variable.getId()} and name: ${variable.getName()}`
299
329
  );
300
330
  return;
301
331
  }
@@ -307,18 +337,18 @@ export function renameVariable(workspace, variable, opt_callback) {
307
337
  promptMsg = Blockly.Msg.RENAME_VARIABLE_TITLE;
308
338
  modalTitle = Blockly.Msg.RENAME_VARIABLE_MODAL_TITLE;
309
339
  }
310
- var validate = nameValidator.bind(null, varType);
340
+ const validate = nameValidator.bind(null, varType);
311
341
 
312
- var promptText = promptMsg.replace("%1", variable.name);
313
- var promptDefaultText = variable.name;
314
- if (variable.isCloud && variable.name.indexOf(CLOUD_PREFIX) == 0) {
342
+ const promptText = promptMsg.replace("%1", variable.getName());
343
+ let promptDefaultText = variable.getName();
344
+ if (variable.isCloud && variable.getName().indexOf(CLOUD_PREFIX) == 0) {
315
345
  promptDefaultText = promptDefaultText.substring(CLOUD_PREFIX.length);
316
346
  }
317
347
 
318
348
  prompt(
319
349
  promptText,
320
350
  promptDefaultText,
321
- function (newName, additionalVars) {
351
+ (newName: string, additionalVars: string[]) => {
322
352
  if (
323
353
  variable.isCloud &&
324
354
  newName.length > 0 &&
@@ -328,8 +358,8 @@ export function renameVariable(workspace, variable, opt_callback) {
328
358
  // The name validator will add the prefix back
329
359
  }
330
360
  additionalVars = additionalVars || [];
331
- var additionalVarNames = variable.isLocal ? [] : additionalVars;
332
- var validatedText = validate(
361
+ const additionalVarNames = variable.isLocal ? [] : additionalVars;
362
+ const validatedText = validate(
333
363
  newName,
334
364
  workspace,
335
365
  additionalVarNames,
@@ -352,4 +382,4 @@ export function renameVariable(workspace, variable, opt_callback) {
352
382
  );
353
383
  }
354
384
 
355
- export { getVariablesCategory } from "./data_category.js";
385
+ export { getVariablesCategory } from "./data_category";
package/tsconfig.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
- "exclude": [
3
- "./blockly-rc/"
2
+ "include": [
3
+ "./src/",
4
+ "./tests/",
5
+ "./types/"
4
6
  ],
5
7
  "compilerOptions": {
6
8
  "outDir": "./dist/",
package/src/categories.js DELETED
@@ -1,15 +0,0 @@
1
- const Categories = {
2
- motion: "motion",
3
- looks: "looks",
4
- sound: "sounds",
5
- pen: "pen",
6
- data: "data",
7
- dataLists: "data-lists",
8
- event: "events",
9
- control: "control",
10
- sensing: "sensing",
11
- operators: "operators",
12
- more: "more",
13
- };
14
-
15
- export { Categories };
@@ -1,52 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Blockly from "blockly/core";
8
- import { BlockCommentBase } from "./events_block_comment_base.js";
9
-
10
- class BlockCommentResize extends BlockCommentBase {
11
- constructor(opt_blockComment, oldSize, newSize) {
12
- super(opt_blockComment);
13
- this.type = "block_comment_resize";
14
- this.oldSize = oldSize;
15
- this.newSize = newSize;
16
- }
17
-
18
- toJson() {
19
- return {
20
- ...super.toJson(),
21
- newSize: this.newSize,
22
- oldSize: this.oldSize,
23
- };
24
- }
25
-
26
- static fromJson(json, workspace, event) {
27
- const newEvent = super.fromJson(json, workspace, event);
28
- newEvent.newSize = new Blockly.utils.Size(
29
- json["newSize"]["width"],
30
- json["newSize"]["height"]
31
- );
32
- newEvent.oldSize = new Blockly.utils.Size(
33
- json["oldSize"]["width"],
34
- json["oldSize"]["height"]
35
- );
36
-
37
- return newEvent;
38
- }
39
-
40
- run(forward) {
41
- const workspace = this.getEventWorkspace_();
42
- const block = workspace?.getBlockById(this.blockId);
43
- const comment = block?.getIcon(Blockly.icons.IconType.COMMENT);
44
- comment?.setBubbleSize(forward ? this.newSize : this.oldSize);
45
- }
46
- }
47
-
48
- Blockly.registry.register(
49
- Blockly.registry.Type.EVENT,
50
- "block_comment_resize",
51
- BlockCommentResize
52
- );
@@ -1,33 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Blockly from "blockly/core";
8
-
9
- export class BlockDragEnd extends Blockly.Events.BlockBase {
10
- constructor(block, isOutside) {
11
- super(block);
12
- this.type = "endDrag";
13
- this.isOutside = isOutside;
14
- this.recordUndo = false;
15
- this.xml = Blockly.Xml.blockToDom(block, true);
16
- }
17
-
18
- toJson() {
19
- return {
20
- ...super.toJson(),
21
- isOutside: this.isOutside,
22
- xml: this.xml,
23
- };
24
- }
25
-
26
- static fromJson(json, workspace, event) {
27
- const newEvent = super.fromJson(json, workspace, event);
28
- newEvent.isOutside = json["isOutside"];
29
- newEvent.xml = json["xml"];
30
-
31
- return newEvent;
32
- }
33
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2024 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Blockly from "blockly/core";
8
-
9
- export class BlockDragOutside extends Blockly.Events.BlockBase {
10
- constructor(block, isOutside) {
11
- super(block);
12
- this.type = "dragOutside";
13
- this.isOutside = isOutside;
14
- this.recordUndo = false;
15
- }
16
-
17
- toJson() {
18
- return {
19
- ...super.toJson(),
20
- isOutside: this.isOutside,
21
- };
22
- }
23
-
24
- static fromJson(json, workspace, event) {
25
- const newEvent = super.fromJson(json, workspace, event);
26
- newEvent.isOutside = json["isOutside"];
27
-
28
- return newEvent;
29
- }
30
- }