blockly 11.0.0-beta.8 → 11.0.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 (303) hide show
  1. package/blockly.min.js +456 -475
  2. package/blockly.mjs +143 -0
  3. package/blockly_compressed.js +426 -445
  4. package/blockly_compressed.js.map +1 -1
  5. package/blocks.js +4 -0
  6. package/blocks.mjs +12 -0
  7. package/blocks_compressed.js +22 -23
  8. package/blocks_compressed.js.map +1 -1
  9. package/core/block.d.ts +52 -4
  10. package/core/block_svg.d.ts +22 -2
  11. package/core/blockly.d.ts +0 -4
  12. package/core/clipboard/block_paster.d.ts +3 -1
  13. package/core/clipboard/workspace_comment_paster.d.ts +5 -4
  14. package/core/comments/comment_view.d.ts +6 -1
  15. package/core/comments/rendered_workspace_comment.d.ts +22 -4
  16. package/core/constants.d.ts +5 -0
  17. package/core/contextmenu.d.ts +1 -34
  18. package/core/contextmenu_items.d.ts +8 -0
  19. package/core/contextmenu_registry.d.ts +18 -3
  20. package/core/dragging/block_drag_strategy.d.ts +1 -8
  21. package/core/dragging/comment_drag_strategy.d.ts +1 -0
  22. package/core/events/events_block_change.d.ts +15 -0
  23. package/core/events/utils.d.ts +1 -3
  24. package/core/field.d.ts +20 -4
  25. package/core/field_input.d.ts +4 -3
  26. package/core/field_registry.d.ts +35 -3
  27. package/core/flyout_base.d.ts +8 -0
  28. package/core/grid.d.ts +9 -0
  29. package/core/interfaces/i_flyout.d.ts +10 -0
  30. package/core/keyboard_nav/ast_node.d.ts +10 -1
  31. package/core/layer_manager.d.ts +11 -0
  32. package/core/serialization/blocks.d.ts +1 -0
  33. package/core/serialization/workspace_comments.d.ts +1 -1
  34. package/core/utils/toolbox.d.ts +1 -0
  35. package/core/workspace.d.ts +9 -1
  36. package/core/workspace_svg.d.ts +10 -2
  37. package/core.js +4 -0
  38. package/dart.js +4 -0
  39. package/dart.mjs +6 -0
  40. package/index.mjs +143 -0
  41. package/javascript.js +4 -0
  42. package/javascript.mjs +6 -0
  43. package/lua.js +4 -0
  44. package/lua.mjs +6 -0
  45. package/media/resize-handle.svg +1 -1
  46. package/msg/ab.js +8 -7
  47. package/msg/ab.mjs +423 -0
  48. package/msg/ace.js +8 -7
  49. package/msg/ace.mjs +423 -0
  50. package/msg/af.js +8 -7
  51. package/msg/af.mjs +423 -0
  52. package/msg/am.js +8 -7
  53. package/msg/am.mjs +423 -0
  54. package/msg/ar.js +8 -7
  55. package/msg/ar.mjs +423 -0
  56. package/msg/ast.js +8 -7
  57. package/msg/ast.mjs +423 -0
  58. package/msg/az.js +8 -7
  59. package/msg/az.mjs +423 -0
  60. package/msg/ba.js +8 -7
  61. package/msg/ba.mjs +423 -0
  62. package/msg/bcc.js +8 -7
  63. package/msg/bcc.mjs +423 -0
  64. package/msg/be-tarask.js +8 -7
  65. package/msg/be-tarask.mjs +423 -0
  66. package/msg/be.js +8 -7
  67. package/msg/be.mjs +423 -0
  68. package/msg/bg.js +8 -7
  69. package/msg/bg.mjs +423 -0
  70. package/msg/bn.js +8 -7
  71. package/msg/bn.mjs +423 -0
  72. package/msg/br.js +8 -7
  73. package/msg/br.mjs +423 -0
  74. package/msg/bs.js +8 -7
  75. package/msg/bs.mjs +423 -0
  76. package/msg/ca.js +8 -7
  77. package/msg/ca.mjs +423 -0
  78. package/msg/cdo.js +8 -7
  79. package/msg/cdo.mjs +423 -0
  80. package/msg/ce.js +8 -7
  81. package/msg/ce.mjs +423 -0
  82. package/msg/cs.js +8 -7
  83. package/msg/cs.mjs +423 -0
  84. package/msg/da.js +8 -7
  85. package/msg/da.mjs +423 -0
  86. package/msg/de.js +27 -26
  87. package/msg/de.mjs +423 -0
  88. package/msg/diq.js +8 -7
  89. package/msg/diq.mjs +423 -0
  90. package/msg/dtp.js +8 -7
  91. package/msg/dtp.mjs +423 -0
  92. package/msg/dty.js +8 -7
  93. package/msg/dty.mjs +423 -0
  94. package/msg/ee.js +8 -7
  95. package/msg/ee.mjs +423 -0
  96. package/msg/el.js +123 -122
  97. package/msg/el.mjs +423 -0
  98. package/msg/en-gb.js +8 -7
  99. package/msg/en-gb.mjs +423 -0
  100. package/msg/en.js +8 -7
  101. package/msg/en.mjs +423 -0
  102. package/msg/eo.js +8 -7
  103. package/msg/eo.mjs +423 -0
  104. package/msg/es.js +8 -7
  105. package/msg/es.mjs +423 -0
  106. package/msg/et.js +8 -7
  107. package/msg/et.mjs +423 -0
  108. package/msg/eu.js +8 -7
  109. package/msg/eu.mjs +423 -0
  110. package/msg/fa.js +10 -9
  111. package/msg/fa.mjs +423 -0
  112. package/msg/fi.js +8 -7
  113. package/msg/fi.mjs +423 -0
  114. package/msg/fo.js +8 -7
  115. package/msg/fo.mjs +423 -0
  116. package/msg/fr.js +11 -10
  117. package/msg/fr.mjs +423 -0
  118. package/msg/frr.js +8 -7
  119. package/msg/frr.mjs +423 -0
  120. package/msg/gl.js +8 -7
  121. package/msg/gl.mjs +423 -0
  122. package/msg/gn.js +8 -7
  123. package/msg/gn.mjs +423 -0
  124. package/msg/gor.js +8 -7
  125. package/msg/gor.mjs +423 -0
  126. package/msg/ha.js +8 -7
  127. package/msg/ha.mjs +423 -0
  128. package/msg/hak.js +8 -7
  129. package/msg/hak.mjs +423 -0
  130. package/msg/he.js +8 -7
  131. package/msg/he.mjs +423 -0
  132. package/msg/hi.js +8 -7
  133. package/msg/hi.mjs +423 -0
  134. package/msg/hr.js +8 -7
  135. package/msg/hr.mjs +423 -0
  136. package/msg/hrx.js +8 -7
  137. package/msg/hrx.mjs +423 -0
  138. package/msg/hsb.js +8 -7
  139. package/msg/hsb.mjs +423 -0
  140. package/msg/hu.js +8 -7
  141. package/msg/hu.mjs +423 -0
  142. package/msg/hy.js +8 -7
  143. package/msg/hy.mjs +423 -0
  144. package/msg/ia.js +8 -7
  145. package/msg/ia.mjs +423 -0
  146. package/msg/id.js +8 -7
  147. package/msg/id.mjs +423 -0
  148. package/msg/ig.js +8 -7
  149. package/msg/ig.mjs +423 -0
  150. package/msg/inh.js +8 -7
  151. package/msg/inh.mjs +423 -0
  152. package/msg/is.js +8 -7
  153. package/msg/is.mjs +423 -0
  154. package/msg/it.js +8 -7
  155. package/msg/it.mjs +423 -0
  156. package/msg/ja.js +8 -7
  157. package/msg/ja.mjs +423 -0
  158. package/msg/ka.js +8 -7
  159. package/msg/ka.mjs +423 -0
  160. package/msg/kab.js +8 -7
  161. package/msg/kab.mjs +423 -0
  162. package/msg/kbd-cyrl.js +8 -7
  163. package/msg/kbd-cyrl.mjs +423 -0
  164. package/msg/km.js +8 -7
  165. package/msg/km.mjs +423 -0
  166. package/msg/kn.js +8 -7
  167. package/msg/kn.mjs +423 -0
  168. package/msg/ko.js +9 -8
  169. package/msg/ko.mjs +423 -0
  170. package/msg/ksh.js +8 -7
  171. package/msg/ksh.mjs +423 -0
  172. package/msg/ku-latn.js +8 -7
  173. package/msg/ku-latn.mjs +423 -0
  174. package/msg/ky.js +8 -7
  175. package/msg/ky.mjs +423 -0
  176. package/msg/la.js +8 -7
  177. package/msg/la.mjs +423 -0
  178. package/msg/lb.js +8 -7
  179. package/msg/lb.mjs +423 -0
  180. package/msg/lki.js +8 -7
  181. package/msg/lki.mjs +423 -0
  182. package/msg/lo.js +8 -7
  183. package/msg/lo.mjs +423 -0
  184. package/msg/lrc.js +8 -7
  185. package/msg/lrc.mjs +423 -0
  186. package/msg/lt.js +8 -7
  187. package/msg/lt.mjs +423 -0
  188. package/msg/lv.js +8 -7
  189. package/msg/lv.mjs +423 -0
  190. package/msg/mg.js +8 -7
  191. package/msg/mg.mjs +423 -0
  192. package/msg/mk.js +8 -7
  193. package/msg/mk.mjs +423 -0
  194. package/msg/ml.js +8 -7
  195. package/msg/ml.mjs +423 -0
  196. package/msg/mnw.js +8 -7
  197. package/msg/mnw.mjs +423 -0
  198. package/msg/ms.js +9 -8
  199. package/msg/ms.mjs +423 -0
  200. package/msg/my.js +8 -7
  201. package/msg/my.mjs +423 -0
  202. package/msg/mzn.js +8 -7
  203. package/msg/mzn.mjs +423 -0
  204. package/msg/nb.js +8 -7
  205. package/msg/nb.mjs +423 -0
  206. package/msg/ne.js +225 -224
  207. package/msg/ne.mjs +423 -0
  208. package/msg/nl.js +15 -14
  209. package/msg/nl.mjs +423 -0
  210. package/msg/oc.js +8 -7
  211. package/msg/oc.mjs +423 -0
  212. package/msg/olo.js +8 -7
  213. package/msg/olo.mjs +423 -0
  214. package/msg/pa.js +8 -7
  215. package/msg/pa.mjs +423 -0
  216. package/msg/pl.js +8 -7
  217. package/msg/pl.mjs +423 -0
  218. package/msg/pms.js +8 -7
  219. package/msg/pms.mjs +423 -0
  220. package/msg/ps.js +8 -7
  221. package/msg/ps.mjs +423 -0
  222. package/msg/pt-br.js +10 -9
  223. package/msg/pt-br.mjs +423 -0
  224. package/msg/pt.js +8 -7
  225. package/msg/pt.mjs +423 -0
  226. package/msg/ro.js +8 -7
  227. package/msg/ro.mjs +423 -0
  228. package/msg/ru.js +9 -8
  229. package/msg/ru.mjs +423 -0
  230. package/msg/sc.js +8 -7
  231. package/msg/sc.mjs +423 -0
  232. package/msg/sco.js +8 -7
  233. package/msg/sco.mjs +423 -0
  234. package/msg/sd.js +8 -7
  235. package/msg/sd.mjs +423 -0
  236. package/msg/shn.js +8 -7
  237. package/msg/shn.mjs +423 -0
  238. package/msg/si.js +8 -7
  239. package/msg/si.mjs +423 -0
  240. package/msg/sk.js +8 -7
  241. package/msg/sk.mjs +423 -0
  242. package/msg/skr-arab.js +8 -7
  243. package/msg/skr-arab.mjs +423 -0
  244. package/msg/sl.js +8 -7
  245. package/msg/sl.mjs +423 -0
  246. package/msg/smn.js +8 -7
  247. package/msg/smn.mjs +423 -0
  248. package/msg/sq.js +8 -7
  249. package/msg/sq.mjs +423 -0
  250. package/msg/sr-latn.js +8 -7
  251. package/msg/sr-latn.mjs +423 -0
  252. package/msg/sr.js +8 -7
  253. package/msg/sr.mjs +423 -0
  254. package/msg/sv.js +8 -7
  255. package/msg/sv.mjs +423 -0
  256. package/msg/sw.js +8 -7
  257. package/msg/sw.mjs +423 -0
  258. package/msg/ta.js +14 -13
  259. package/msg/ta.mjs +423 -0
  260. package/msg/tcy.js +8 -7
  261. package/msg/tcy.mjs +423 -0
  262. package/msg/tdd.js +11 -10
  263. package/msg/tdd.mjs +423 -0
  264. package/msg/te.js +8 -7
  265. package/msg/te.mjs +423 -0
  266. package/msg/th.js +8 -7
  267. package/msg/th.mjs +423 -0
  268. package/msg/ti.js +8 -7
  269. package/msg/ti.mjs +423 -0
  270. package/msg/tl.js +8 -7
  271. package/msg/tl.mjs +423 -0
  272. package/msg/tlh.js +8 -7
  273. package/msg/tlh.mjs +423 -0
  274. package/msg/tr.js +10 -9
  275. package/msg/tr.mjs +423 -0
  276. package/msg/ug-arab.js +8 -7
  277. package/msg/ug-arab.mjs +423 -0
  278. package/msg/uk.js +8 -7
  279. package/msg/uk.mjs +423 -0
  280. package/msg/ur.js +8 -7
  281. package/msg/ur.mjs +423 -0
  282. package/msg/uz.js +8 -7
  283. package/msg/uz.mjs +423 -0
  284. package/msg/vi.js +11 -10
  285. package/msg/vi.mjs +423 -0
  286. package/msg/xmf.js +8 -7
  287. package/msg/xmf.mjs +423 -0
  288. package/msg/yo.js +8 -7
  289. package/msg/yo.mjs +423 -0
  290. package/msg/zgh.js +8 -7
  291. package/msg/zgh.mjs +423 -0
  292. package/msg/zh-hans.js +9 -8
  293. package/msg/zh-hans.mjs +423 -0
  294. package/msg/zh-hant.js +18 -17
  295. package/msg/zh-hant.mjs +423 -0
  296. package/package.json +12 -2
  297. package/php.js +4 -0
  298. package/php.mjs +6 -0
  299. package/python.js +4 -0
  300. package/python.mjs +6 -0
  301. package/core/workspace_comment.d.ts +0 -190
  302. package/core/workspace_comment_svg.d.ts +0 -360
  303. package/msg/yue.d.ts +0 -8
package/core/block.d.ts CHANGED
@@ -123,7 +123,7 @@ export declare class Block implements IASTNodeLocation {
123
123
  inputList: Input[];
124
124
  inputsInline?: boolean;
125
125
  icons: IIcon[];
126
- private disabled;
126
+ private disabledReasons;
127
127
  tooltip: Tooltip.TipInfo;
128
128
  contextMenu: boolean;
129
129
  protected parentBlock_: this | null;
@@ -320,6 +320,12 @@ export declare class Block implements IASTNodeLocation {
320
320
  * @internal
321
321
  */
322
322
  getTopStackBlock(): this;
323
+ /**
324
+ * Returns this block if it is a shadow block, or the first non-shadow parent.
325
+ *
326
+ * @internal
327
+ */
328
+ getFirstNonShadowBlock(): this;
323
329
  /**
324
330
  * Find all the blocks that are directly nested inside this one.
325
331
  * Includes value and statement inputs, as well as any following statement.
@@ -627,17 +633,44 @@ export declare class Block implements IASTNodeLocation {
627
633
  */
628
634
  getOutputShape(): number | null;
629
635
  /**
630
- * Get whether this block is enabled or not.
636
+ * Get whether this block is enabled or not. A block is considered enabled
637
+ * if there aren't any reasons why it would be disabled. A block may still
638
+ * be disabled for other reasons even if the user attempts to manually
639
+ * enable it, such as when the block is in an invalid location.
631
640
  *
632
641
  * @returns True if enabled.
633
642
  */
634
643
  isEnabled(): boolean;
635
- /**
636
- * Set whether the block is enabled or not.
644
+ /** @deprecated v11 - Get whether the block is manually disabled. */
645
+ private get disabled();
646
+ /** @deprecated v11 - Set whether the block is manually disabled. */
647
+ private set disabled(value);
648
+ /**
649
+ * @deprecated v11 - Set whether the block is manually enabled or disabled.
650
+ * The user can toggle whether a block is disabled from a context menu
651
+ * option. A block may still be disabled for other reasons even if the user
652
+ * attempts to manually enable it, such as when the block is in an invalid
653
+ * location. This method is deprecated and setDisabledReason should be used
654
+ * instead.
637
655
  *
638
656
  * @param enabled True if enabled.
639
657
  */
640
658
  setEnabled(enabled: boolean): void;
659
+ /**
660
+ * Add or remove a reason why the block might be disabled. If a block has
661
+ * any reasons to be disabled, then the block itself will be considered
662
+ * disabled. A block could be disabled for multiple independent reasons
663
+ * simultaneously, such as when the user manually disables it, or the block
664
+ * is invalid.
665
+ *
666
+ * @param disabled If true, then the block should be considered disabled for
667
+ * at least the provided reason, otherwise the block is no longer disabled
668
+ * for that reason.
669
+ * @param reason A language-neutral identifier for a reason why the block
670
+ * could be disabled. Call this method again with the same identifier to
671
+ * update whether the block is currently disabled for this reason.
672
+ */
673
+ setDisabledReason(disabled: boolean, reason: string): void;
641
674
  /**
642
675
  * Get whether the block is disabled or not due to parents.
643
676
  * The block's own disabled property is not considered.
@@ -645,6 +678,21 @@ export declare class Block implements IASTNodeLocation {
645
678
  * @returns True if disabled.
646
679
  */
647
680
  getInheritedDisabled(): boolean;
681
+ /**
682
+ * Get whether the block is currently disabled for the provided reason.
683
+ *
684
+ * @param reason A language-neutral identifier for a reason why the block
685
+ * could be disabled.
686
+ * @returns Whether the block is disabled for the provided reason.
687
+ */
688
+ hasDisabledReason(reason: string): boolean;
689
+ /**
690
+ * Get a set of reasons why the block is currently disabled, if any. If the
691
+ * block is enabled, this set will be empty.
692
+ *
693
+ * @returns The set of reasons why the block is disabled, if any.
694
+ */
695
+ getDisabledReasons(): ReadonlySet<string>;
648
696
  /**
649
697
  * Get whether the block is collapsed or not.
650
698
  *
@@ -238,7 +238,7 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
238
238
  * @param e Mouse event.
239
239
  * @internal
240
240
  */
241
- showContextMenu(e: Event): void;
241
+ showContextMenu(e: PointerEvent): void;
242
242
  /**
243
243
  * Updates the locations of any parts of the block that need to know where
244
244
  * they are (e.g. connections, icons).
@@ -356,11 +356,31 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
356
356
  private createIconPointerDownListener;
357
357
  removeIcon(type: IconType<IIcon>): boolean;
358
358
  /**
359
- * Set whether the block is enabled or not.
359
+ * @deprecated v11 - Set whether the block is manually enabled or disabled.
360
+ * The user can toggle whether a block is disabled from a context menu
361
+ * option. A block may still be disabled for other reasons even if the user
362
+ * attempts to manually enable it, such as when the block is in an invalid
363
+ * location. This method is deprecated and setDisabledReason should be used
364
+ * instead.
360
365
  *
361
366
  * @param enabled True if enabled.
362
367
  */
363
368
  setEnabled(enabled: boolean): void;
369
+ /**
370
+ * Add or remove a reason why the block might be disabled. If a block has
371
+ * any reasons to be disabled, then the block itself will be considered
372
+ * disabled. A block could be disabled for multiple independent reasons
373
+ * simultaneously, such as when the user manually disables it, or the block
374
+ * is invalid.
375
+ *
376
+ * @param disabled If true, then the block should be considered disabled for
377
+ * at least the provided reason, otherwise the block is no longer disabled
378
+ * for that reason.
379
+ * @param reason A language-neutral identifier for a reason why the block
380
+ * could be disabled. Call this method again with the same identifier to
381
+ * update whether the block is currently disabled for this reason.
382
+ */
383
+ setDisabledReason(disabled: boolean, reason: string): void;
364
384
  /**
365
385
  * Set whether the block is highlighted or not. Block highlighting is
366
386
  * often used to visually mark blocks currently being executed.
package/core/blockly.d.ts CHANGED
@@ -141,8 +141,6 @@ import * as VariablesDynamic from './variables_dynamic.js';
141
141
  import * as WidgetDiv from './widgetdiv.js';
142
142
  import { Workspace } from './workspace.js';
143
143
  import { WorkspaceAudio } from './workspace_audio.js';
144
- import { WorkspaceComment } from './workspace_comment.js';
145
- import { WorkspaceCommentSvg } from './workspace_comment_svg.js';
146
144
  import { WorkspaceDragger } from './workspace_dragger.js';
147
145
  import { WorkspaceSvg } from './workspace_svg.js';
148
146
  import * as Xml from './xml.js';
@@ -397,8 +395,6 @@ export { VariableModel };
397
395
  export { VerticalFlyout };
398
396
  export { Workspace };
399
397
  export { WorkspaceAudio };
400
- export { WorkspaceComment };
401
- export { WorkspaceCommentSvg };
402
398
  export { WorkspaceDragger };
403
399
  export { WorkspaceSvg };
404
400
  export { ZoomControls };
@@ -20,9 +20,11 @@ export declare class BlockPaster implements IPaster<BlockCopyData, BlockSvg> {
20
20
  * Exported for testing.
21
21
  *
22
22
  * @param block The block to move to an unambiguous location.
23
+ * @param originalPosition The initial coordinate to start searching from,
24
+ * likely the position of the copied block.
23
25
  * @internal
24
26
  */
25
- export declare function moveBlockToNotConflict(block: BlockSvg): void;
27
+ export declare function moveBlockToNotConflict(block: BlockSvg, originalPosition: Coordinate): void;
26
28
  export interface BlockCopyData extends ICopyData {
27
29
  blockState: State;
28
30
  typeCounts: {
@@ -7,12 +7,13 @@ import { IPaster } from '../interfaces/i_paster.js';
7
7
  import { ICopyData } from '../interfaces/i_copyable.js';
8
8
  import { Coordinate } from '../utils/coordinate.js';
9
9
  import { WorkspaceSvg } from '../workspace_svg.js';
10
- import { WorkspaceCommentSvg } from '../workspace_comment_svg.js';
11
- export declare class WorkspaceCommentPaster implements IPaster<WorkspaceCommentCopyData, WorkspaceCommentSvg> {
10
+ import * as commentSerialiation from '../serialization/workspace_comments.js';
11
+ import { RenderedWorkspaceComment } from '../comments/rendered_workspace_comment.js';
12
+ export declare class WorkspaceCommentPaster implements IPaster<WorkspaceCommentCopyData, RenderedWorkspaceComment> {
12
13
  static TYPE: string;
13
- paste(copyData: WorkspaceCommentCopyData, workspace: WorkspaceSvg, coordinate?: Coordinate): WorkspaceCommentSvg;
14
+ paste(copyData: WorkspaceCommentCopyData, workspace: WorkspaceSvg, coordinate?: Coordinate): RenderedWorkspaceComment | null;
14
15
  }
15
16
  export interface WorkspaceCommentCopyData extends ICopyData {
16
- commentState: Element;
17
+ commentState: commentSerialiation.State;
17
18
  }
18
19
  //# sourceMappingURL=workspace_comment_paster.d.ts.map
@@ -83,7 +83,10 @@ export declare class CommentView implements IRenderedElement {
83
83
  private createResizeHandle;
84
84
  /** Returns the root SVG group element of the comment view. */
85
85
  getSvgRoot(): SVGGElement;
86
- /** Returns the current size of the comment in workspace units. */
86
+ /**
87
+ * Returns the current size of the comment in workspace units.
88
+ * Respects collapsing.
89
+ */
87
90
  getSize(): Size;
88
91
  /**
89
92
  * Sets the size of the comment in workspace units, and updates the view
@@ -103,6 +106,8 @@ export declare class CommentView implements IRenderedElement {
103
106
  private calcDeleteMargin;
104
107
  /** Calculates the margin that should exist around the foldout icon. */
105
108
  private calcFoldoutMargin;
109
+ /** Updates the size of the highlight rect to reflect the new size. */
110
+ private updateHighlightRect;
106
111
  /** Updates the size of the top bar to reflect the new size. */
107
112
  private updateTopBarSize;
108
113
  /** Updates the size of the text area elements to reflect the new size. */
@@ -13,7 +13,10 @@ import { IRenderedElement } from '../interfaces/i_rendered_element.js';
13
13
  import { IDraggable } from '../interfaces/i_draggable.js';
14
14
  import { ISelectable } from '../interfaces/i_selectable.js';
15
15
  import { IDeletable } from '../interfaces/i_deletable.js';
16
- export declare class RenderedWorkspaceComment extends WorkspaceComment implements IBoundedElement, IRenderedElement, IDraggable, ISelectable, IDeletable {
16
+ import { ICopyable } from '../interfaces/i_copyable.js';
17
+ import { WorkspaceCommentCopyData } from '../clipboard/workspace_comment_paster.js';
18
+ import { IContextMenu } from '../interfaces/i_contextmenu.js';
19
+ export declare class RenderedWorkspaceComment extends WorkspaceComment implements IBoundedElement, IRenderedElement, IDraggable, ISelectable, IDeletable, ICopyable<WorkspaceCommentCopyData>, IContextMenu {
17
20
  /** The class encompassing the svg elements making up the workspace comment. */
18
21
  private view;
19
22
  readonly workspace: WorkspaceSvg;
@@ -35,7 +38,15 @@ export declare class RenderedWorkspaceComment extends WorkspaceComment implement
35
38
  setEditable(editable: boolean): void;
36
39
  /** Returns the root SVG element of this comment. */
37
40
  getSvgRoot(): SVGElement;
38
- /** Returns the bounding rectangle of this comment in workspace coordinates. */
41
+ /**
42
+ * Returns the comment's size in workspace units.
43
+ * Does not respect collapsing.
44
+ */
45
+ getSize(): Size;
46
+ /**
47
+ * Returns the bounding rectangle of this comment in workspace coordinates.
48
+ * Respects collapsing.
49
+ */
39
50
  getBoundingRectangle(): Rect;
40
51
  /** Move the comment by the given amounts in workspace coordinates. */
41
52
  moveBy(dx: number, dy: number, reason?: string[] | undefined): void;
@@ -60,8 +71,6 @@ export declare class RenderedWorkspaceComment extends WorkspaceComment implement
60
71
  * (that wasn't otherwise gobbled up, e.g. by resizing).
61
72
  */
62
73
  private startGesture;
63
- /** Returns whether this comment is deletable or not. */
64
- isDeletable(): boolean;
65
74
  /** Visually indicates that this comment would be deleted if dropped. */
66
75
  setDeleteStyle(wouldDelete: boolean): void;
67
76
  /** Returns whether this comment is movable or not. */
@@ -78,5 +87,14 @@ export declare class RenderedWorkspaceComment extends WorkspaceComment implement
78
87
  select(): void;
79
88
  /** Visually unhighlights the comment. */
80
89
  unselect(): void;
90
+ /**
91
+ * Returns a JSON serializable representation of this comment's state that
92
+ * can be used for pasting.
93
+ */
94
+ toCopyData(): WorkspaceCommentCopyData | null;
95
+ /** Show a context menu for this comment. */
96
+ showContextMenu(e: PointerEvent): void;
97
+ /** Snap this comment to the nearest grid point. */
98
+ snapToGrid(): void;
81
99
  }
82
100
  //# sourceMappingURL=rendered_workspace_comment.d.ts.map
@@ -11,4 +11,9 @@ export declare const COLLAPSED_INPUT_NAME = "_TEMP_COLLAPSED_INPUT";
11
11
  * The language-neutral ID given to the collapsed field.
12
12
  */
13
13
  export declare const COLLAPSED_FIELD_NAME = "_TEMP_COLLAPSED_FIELD";
14
+ /**
15
+ * The language-neutral ID for when the reason why a block is disabled is
16
+ * because the user manually disabled it, such as via the context menu.
17
+ */
18
+ export declare const MANUALLY_DISABLED = "MANUALLY_DISABLED";
14
19
  //# sourceMappingURL=constants.d.ts.map
@@ -7,8 +7,6 @@ import type { Block } from './block.js';
7
7
  import type { BlockSvg } from './block_svg.js';
8
8
  import type { ContextMenuOption, LegacyContextMenuOption } from './contextmenu_registry.js';
9
9
  import * as serializationBlocks from './serialization/blocks.js';
10
- import { WorkspaceCommentSvg } from './workspace_comment_svg.js';
11
- import type { WorkspaceSvg } from './workspace_svg.js';
12
10
  /**
13
11
  * Gets the block the context menu is currently attached to.
14
12
  *
@@ -28,7 +26,7 @@ export declare function setCurrentBlock(block: Block | null): void;
28
26
  * @param options Array of menu options.
29
27
  * @param rtl True if RTL, false if LTR.
30
28
  */
31
- export declare function show(e: Event, options: (ContextMenuOption | LegacyContextMenuOption)[], rtl: boolean): void;
29
+ export declare function show(e: PointerEvent, options: (ContextMenuOption | LegacyContextMenuOption)[], rtl: boolean): void;
32
30
  /**
33
31
  * Hide the context menu.
34
32
  */
@@ -46,35 +44,4 @@ export declare function dispose(): void;
46
44
  * @returns Function that creates a block.
47
45
  */
48
46
  export declare function callbackFactory(block: Block, state: Element | serializationBlocks.State): () => BlockSvg;
49
- /**
50
- * Make a context menu option for deleting the current workspace comment.
51
- *
52
- * @param comment The workspace comment where the
53
- * right-click originated.
54
- * @returns A menu option,
55
- * containing text, enabled, and a callback.
56
- * @internal
57
- */
58
- export declare function commentDeleteOption(comment: WorkspaceCommentSvg): LegacyContextMenuOption;
59
- /**
60
- * Make a context menu option for duplicating the current workspace comment.
61
- *
62
- * @param comment The workspace comment where the
63
- * right-click originated.
64
- * @returns A menu option,
65
- * containing text, enabled, and a callback.
66
- * @internal
67
- */
68
- export declare function commentDuplicateOption(comment: WorkspaceCommentSvg): LegacyContextMenuOption;
69
- /**
70
- * Make a context menu option for adding a comment on the workspace.
71
- *
72
- * @param ws The workspace where the right-click
73
- * originated.
74
- * @param e The right-click mouse event.
75
- * @returns A menu option, containing text, enabled, and a callback.
76
- * comments are not bundled in.
77
- * @internal
78
- */
79
- export declare function workspaceCommentOption(ws: WorkspaceSvg, e: Event): ContextMenuOption;
80
47
  //# sourceMappingURL=contextmenu.d.ts.map
@@ -55,6 +55,14 @@ export declare function registerDelete(): void;
55
55
  * Option to open help for a block.
56
56
  */
57
57
  export declare function registerHelp(): void;
58
+ /** Registers an option for deleting a workspace comment. */
59
+ export declare function registerCommentDelete(): void;
60
+ /** Registers an option for duplicating a workspace comment. */
61
+ export declare function registerCommentDuplicate(): void;
62
+ /** Registers an option for adding a workspace comment to the workspace. */
63
+ export declare function registerCommentCreate(): void;
64
+ /** Registers all workspace comment related menu items. */
65
+ export declare function registerCommentOptions(): void;
58
66
  /**
59
67
  * Registers all default context menu items. This should be called once per
60
68
  * instance of ContextMenuRegistry.
@@ -9,6 +9,7 @@
9
9
  * @class
10
10
  */
11
11
  import type { BlockSvg } from './block_svg.js';
12
+ import { RenderedWorkspaceComment } from './comments/rendered_workspace_comment.js';
12
13
  import type { WorkspaceSvg } from './workspace_svg.js';
13
14
  /**
14
15
  * Class for the registry of context menu items. This is intended to be a
@@ -63,7 +64,8 @@ export declare namespace ContextMenuRegistry {
63
64
  */
64
65
  enum ScopeType {
65
66
  BLOCK = "block",
66
- WORKSPACE = "workspace"
67
+ WORKSPACE = "workspace",
68
+ COMMENT = "comment"
67
69
  }
68
70
  /**
69
71
  * The actual workspace/block where the menu is being rendered. This is passed
@@ -72,12 +74,19 @@ export declare namespace ContextMenuRegistry {
72
74
  interface Scope {
73
75
  block?: BlockSvg;
74
76
  workspace?: WorkspaceSvg;
77
+ comment?: RenderedWorkspaceComment;
75
78
  }
76
79
  /**
77
80
  * A menu item as entered in the registry.
78
81
  */
79
82
  interface RegistryItem {
80
- callback: (p1: Scope) => void;
83
+ /**
84
+ * @param scope Object that provides a reference to the thing that had its
85
+ * context menu opened.
86
+ * @param e The original event that triggered the context menu to open. Not
87
+ * the event that triggered the click on the option.
88
+ */
89
+ callback: (scope: Scope, e: PointerEvent) => void;
81
90
  scopeType: ScopeType;
82
91
  displayText: ((p1: Scope) => string | HTMLElement) | string | HTMLElement;
83
92
  preconditionFn: (p1: Scope) => string;
@@ -90,7 +99,13 @@ export declare namespace ContextMenuRegistry {
90
99
  interface ContextMenuOption {
91
100
  text: string | HTMLElement;
92
101
  enabled: boolean;
93
- callback: (p1: Scope) => void;
102
+ /**
103
+ * @param scope Object that provides a reference to the thing that had its
104
+ * context menu opened.
105
+ * @param e The original event that triggered the context menu to open. Not
106
+ * the event that triggered the click on the option.
107
+ */
108
+ callback: (scope: Scope, e: PointerEvent) => void;
94
109
  scope: Scope;
95
110
  weight: number;
96
111
  }
@@ -20,11 +20,6 @@ export declare class BlockDragStrategy implements IDragStrategy {
20
20
  private connectionCandidate;
21
21
  private connectionPreviewer;
22
22
  private dragging;
23
- /**
24
- * If this is a shadow block, the offset between this block and the parent
25
- * block, to add to the drag location. In workspace units.
26
- */
27
- private dragOffset;
28
23
  constructor(block: BlockSvg);
29
24
  /** Returns true if the block is currently movable. False otherwise. */
30
25
  isMovable(): boolean;
@@ -33,8 +28,6 @@ export declare class BlockDragStrategy implements IDragStrategy {
33
28
  * from any parent blocks.
34
29
  */
35
30
  startDrag(e?: PointerEvent): void;
36
- /** Starts a drag on a shadow, recording the drag offset. */
37
- private startDraggingShadow;
38
31
  /**
39
32
  * Whether or not we should disconnect the block when a drag is started.
40
33
  *
@@ -93,7 +86,7 @@ export declare class BlockDragStrategy implements IDragStrategy {
93
86
  * Cleans up any state at the end of the drag. Applies any pending
94
87
  * connections.
95
88
  */
96
- endDrag(e?: PointerEvent): void;
89
+ endDrag(): void;
97
90
  /** Connects the given candidate connections. */
98
91
  private applyConnections;
99
92
  /**
@@ -15,6 +15,7 @@ export declare class CommentDragStrategy implements IDragStrategy {
15
15
  startDrag(): void;
16
16
  drag(newLoc: Coordinate): void;
17
17
  endDrag(): void;
18
+ private fireMoveEvent;
18
19
  revertDrag(): void;
19
20
  }
20
21
  //# sourceMappingURL=comment_drag_strategy.d.ts.map
@@ -29,6 +29,11 @@ export declare class BlockChange extends BlockBase {
29
29
  oldValue: unknown;
30
30
  /** The new value of the element. */
31
31
  newValue: unknown;
32
+ /**
33
+ * If element is 'disabled', this is the language-neutral identifier of the
34
+ * reason why the block was or was not disabled.
35
+ */
36
+ private disabledReason?;
32
37
  /**
33
38
  * @param opt_block The changed block. Undefined for a blank event.
34
39
  * @param opt_element One of 'field', 'comment', 'disabled', etc.
@@ -53,6 +58,15 @@ export declare class BlockChange extends BlockBase {
53
58
  * @internal
54
59
  */
55
60
  static fromJson(json: BlockChangeJson, workspace: Workspace, event?: any): BlockChange;
61
+ /**
62
+ * Set the language-neutral identifier for the reason why the block was or was
63
+ * not disabled. This is only valid for events where element is 'disabled'.
64
+ * Defaults to 'MANUALLY_DISABLED'.
65
+ *
66
+ * @param disabledReason The identifier of the reason why the block was or was
67
+ * not disabled.
68
+ */
69
+ setDisabledReason(disabledReason: string): void;
56
70
  /**
57
71
  * Does this event record any change of state?
58
72
  *
@@ -80,5 +94,6 @@ export interface BlockChangeJson extends BlockBaseJson {
80
94
  name?: string;
81
95
  newValue: unknown;
82
96
  oldValue: unknown;
97
+ disabledReason?: string;
83
98
  }
84
99
  //# sourceMappingURL=events_block_change.d.ts.map
@@ -231,10 +231,8 @@ export declare function fromJson(json: any, workspace: Workspace): Abstract;
231
231
  */
232
232
  export declare function get(eventType: string): new (...p1: any[]) => Abstract;
233
233
  /**
234
- * Enable/disable a block depending on whether it is properly connected.
234
+ * Set if a block is disabled depending on whether it is properly connected.
235
235
  * Use this on applications where all blocks should be connected to a top block.
236
- * Recommend setting the 'disable' option to 'false' in the config so that
237
- * users don't try to re-enable disabled orphan blocks.
238
236
  *
239
237
  * @param event Custom data for event.
240
238
  */
package/core/field.d.ts CHANGED
@@ -561,6 +561,7 @@ export declare abstract class Field<T = any> implements IASTNodeLocationSvg, IAS
561
561
  *
562
562
  * @param newValue New value.
563
563
  * @param validatedValue Validated value.
564
+ * @param fireChangeEvent Whether to fire a change event if the value changes.
564
565
  * @returns New value, or an Error object.
565
566
  */
566
567
  private processValidation_;
@@ -605,8 +606,9 @@ export declare abstract class Field<T = any> implements IASTNodeLocationSvg, IAS
605
606
  * No-op by default.
606
607
  *
607
608
  * @param _invalidValue The input value that was determined to be invalid.
609
+ * @param _fireChangeEvent Whether to fire a change event if the value changes.
608
610
  */
609
- protected doValueInvalid_(_invalidValue: any): void;
611
+ protected doValueInvalid_(_invalidValue: any, _fireChangeEvent?: boolean): void;
610
612
  /**
611
613
  * Handle a pointerdown event on a field.
612
614
  *
@@ -706,6 +708,17 @@ export declare abstract class Field<T = any> implements IASTNodeLocationSvg, IAS
706
708
  * @internal
707
709
  */
708
710
  updateMarkers_(): void;
711
+ /**
712
+ * Subclasses should reimplement this method to construct their Field
713
+ * subclass from a JSON arg object.
714
+ *
715
+ * It is an error to attempt to register a field subclass in the
716
+ * FieldRegistry if that subclass has not overridden this method.
717
+ *
718
+ * @param _options JSON configuration object with properties needed
719
+ * to configure a specific field.
720
+ */
721
+ static fromJson(_options: FieldConfig): Field;
709
722
  }
710
723
  /**
711
724
  * Extra configuration options for the base field.
@@ -714,12 +727,14 @@ export interface FieldConfig {
714
727
  tooltip?: string;
715
728
  }
716
729
  /**
717
- * For use by Field and descendants of Field. Constructors can change
730
+ * Represents an object that has all the prototype properties of the `Field`
731
+ * class. This is necessary because constructors can change
718
732
  * in descendants, though they should contain all of Field's prototype methods.
719
733
  *
720
- * @internal
734
+ * This type should only be used in places where we directly access the prototype
735
+ * of a Field class or subclass.
721
736
  */
722
- export type FieldProto = Pick<typeof Field, 'prototype'>;
737
+ type FieldProto = Pick<typeof Field, 'prototype'>;
723
738
  /**
724
739
  * Represents an error where the field is trying to access its block or
725
740
  * information about its block before it has actually been attached to said
@@ -729,4 +744,5 @@ export declare class UnattachedFieldError extends Error {
729
744
  /** @internal */
730
745
  constructor();
731
746
  }
747
+ export {};
732
748
  //# sourceMappingURL=field.d.ts.map
@@ -88,10 +88,11 @@ export declare abstract class FieldInput<T extends InputTypes> extends Field<str
88
88
  * value while allowing the display text to be handled by the htmlInput_.
89
89
  *
90
90
  * @param _invalidValue The input value that was determined to be invalid.
91
- * This is not used by the text input because its display value is stored
92
- * on the htmlInput_.
91
+ * This is not used by the text input because its display value is stored
92
+ * on the htmlInput_.
93
+ * @param fireChangeEvent Whether to fire a change event if the value changes.
93
94
  */
94
- protected doValueInvalid_(_invalidValue: any): void;
95
+ protected doValueInvalid_(_invalidValue: any, fireChangeEvent?: boolean): void;
95
96
  /**
96
97
  * Called by setValue if the text input is valid. Updates the value of the
97
98
  * field, and updates the text of the field if it is not currently being
@@ -3,10 +3,42 @@
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import type { Field, FieldProto } from './field.js';
7
- interface RegistryOptions {
6
+ import type { Field, FieldConfig } from './field.js';
7
+ /**
8
+ * When constructing a field from JSON using the registry, the
9
+ * `fromJson` method in this file is called with an options parameter
10
+ * object consisting of the "type" which is the name of the field, and
11
+ * other options that are part of the field's config object.
12
+ *
13
+ * These options are then passed to the field's static `fromJson`
14
+ * method. That method accepts an options parameter with a type that usually
15
+ * extends from FieldConfig, and may or may not have a "type" attribute (in
16
+ * fact, it shouldn't, because we'd overwrite it as described above!)
17
+ *
18
+ * Unfortunately the registry has no way of knowing the actual Field subclass
19
+ * that will be returned from passing in the name of the field. Therefore it
20
+ * also has no way of knowing that the options object not only implements
21
+ * `FieldConfig`, but it also should satisfy the Config that belongs to that
22
+ * specific class's `fromJson` method.
23
+ *
24
+ * Because of this uncertainty, we just give up on type checking the properties
25
+ * passed to the `fromJson` method, and allow arbitrary string keys with
26
+ * unknown types.
27
+ */
28
+ type RegistryOptions = FieldConfig & {
8
29
  type: string;
9
30
  [key: string]: unknown;
31
+ };
32
+ /**
33
+ * Represents the static methods that must be defined on any
34
+ * field that is registered, i.e. the constructor and fromJson methods.
35
+ *
36
+ * Because we don't know which Field subclass will be registered, we
37
+ * are unable to typecheck the parameters of the constructor.
38
+ */
39
+ export interface RegistrableField {
40
+ new (...args: any[]): Field;
41
+ fromJson(options: FieldConfig): Field;
10
42
  }
11
43
  /**
12
44
  * Registers a field type.
@@ -19,7 +51,7 @@ interface RegistryOptions {
19
51
  * @throws {Error} if the type name is empty, the field is already registered,
20
52
  * or the fieldClass is not an object containing a fromJson function.
21
53
  */
22
- export declare function register(type: string, fieldClass: FieldProto): void;
54
+ export declare function register(type: string, fieldClass: RegistrableField): void;
23
55
  /**
24
56
  * Unregisters the field registered with the given type.
25
57
  *
@@ -8,6 +8,7 @@ import { DeleteArea } from './delete_area.js';
8
8
  import { FlyoutButton } from './flyout_button.js';
9
9
  import type { IFlyout } from './interfaces/i_flyout.js';
10
10
  import type { Options } from './options.js';
11
+ import * as blocks from './serialization/blocks.js';
11
12
  import { Coordinate } from './utils/coordinate.js';
12
13
  import { Svg } from './utils/svg.js';
13
14
  import * as toolbox from './utils/toolbox.js';
@@ -505,6 +506,13 @@ export declare abstract class Flyout extends DeleteArea implements IAutoHideable
505
506
  * @returns The new block in the main workspace.
506
507
  */
507
508
  private placeNewBlock;
509
+ /**
510
+ * Serialize a block to JSON.
511
+ *
512
+ * @param block The block to serialize.
513
+ * @returns A serialized representation of the block.
514
+ */
515
+ protected serializeBlock(block: BlockSvg): blocks.State;
508
516
  /**
509
517
  * Positions a block on the target workspace.
510
518
  *
package/core/grid.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Copyright 2017 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { Coordinate } from './utils/coordinate.js';
6
7
  import { GridOptions } from './options.js';
7
8
  /**
8
9
  * Class for a workspace's grid.
@@ -92,6 +93,14 @@ export declare class Grid {
92
93
  * @internal
93
94
  */
94
95
  moveTo(x: number, y: number): void;
96
+ /**
97
+ * Given a coordinate, return the nearest coordinate aligned to the grid.
98
+ *
99
+ * @param xy A workspace coordinate.
100
+ * @returns Workspace coordinate of nearest grid point.
101
+ * If there's no change, return the same coordinate object.
102
+ */
103
+ alignXY(xy: Coordinate): Coordinate;
95
104
  /**
96
105
  * Create the DOM for the grid described by options.
97
106
  *