blockly 10.1.2 → 10.2.0-beta.1

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.
package/core/block.d.ts CHANGED
@@ -76,8 +76,14 @@ export declare class Block implements IASTNodeLocation, IDeletable {
76
76
  * An optional serialization method for defining how to serialize the
77
77
  * block's extra state (eg mutation state) to something JSON compatible.
78
78
  * This must be coupled with defining `loadExtraState`.
79
+ *
80
+ * @param doFullSerialization Whether or not to serialize the full state of
81
+ * the extra state (rather than possibly saving a reference to some
82
+ * state). This is used during copy-paste. See the
83
+ * {@link https://developers.devsite.google.com/blockly/guides/create-custom-blocks/extensions#full_serialization_and_backing_data | block serialization docs}
84
+ * for more information.
79
85
  */
80
- saveExtraState?: () => any;
86
+ saveExtraState?: (doFullSerialization?: boolean) => any;
81
87
  /**
82
88
  * An optional serialization method for defining how to deserialize the
83
89
  * block's extra state (eg mutation state) from something JSON compatible.
@@ -674,6 +680,14 @@ export declare class Block implements IASTNodeLocation, IDeletable {
674
680
  * @returns The input object created.
675
681
  */
676
682
  appendDummyInput(name?: string): Input;
683
+ /**
684
+ * Appends an input that ends the row.
685
+ *
686
+ * @param name Optional language-neutral identifier which may used to find
687
+ * this input again. Should be unique to this block.
688
+ * @returns The input object created.
689
+ */
690
+ appendEndRowInput(name?: string): Input;
677
691
  /**
678
692
  * Appends the given input row.
679
693
  *
@@ -728,8 +742,8 @@ export declare class Block implements IASTNodeLocation, IDeletable {
728
742
  * @param message Text contains interpolation tokens (%1, %2, ...) that match
729
743
  * with fields or inputs defined in the args array.
730
744
  * @param args Array of arguments to be interpolated.
731
- * @param lastDummyAlign If a dummy input is added at the end, how should it
732
- * be aligned?
745
+ * @param implicitAlign If an implicit input is added at the end or in place
746
+ * of newline tokens, how should it be aligned?
733
747
  * @param warningPrefix Warning prefix string identifying block.
734
748
  */
735
749
  private interpolate_;
@@ -744,13 +758,14 @@ export declare class Block implements IASTNodeLocation, IDeletable {
744
758
  private validateTokens_;
745
759
  /**
746
760
  * Inserts args in place of numerical tokens. String args are converted to
747
- * JSON that defines a label field. If necessary an extra dummy input is added
748
- * to the end of the elements.
761
+ * JSON that defines a label field. Newline characters are converted to
762
+ * end-row inputs, and if necessary an extra dummy input is added to the end
763
+ * of the elements.
749
764
  *
750
765
  * @param tokens The tokens to interpolate
751
766
  * @param args The arguments to insert.
752
- * @param lastDummyAlign The alignment the added dummy input should have, if
753
- * we are required to add one.
767
+ * @param implicitAlign The alignment to use for any implicitly added end-row
768
+ * or dummy inputs, if necessary.
754
769
  * @returns The JSON definitions of field and inputs to add to the block.
755
770
  */
756
771
  private interpolateArguments_;
@@ -13,7 +13,7 @@ import type { Field } from './field.js';
13
13
  import type { Input } from './inputs/input.js';
14
14
  import type { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js';
15
15
  import type { IBoundedElement } from './interfaces/i_bounded_element.js';
16
- import type { CopyData, ICopyable } from './interfaces/i_copyable.js';
16
+ import type { ICopyable } from './interfaces/i_copyable.js';
17
17
  import type { IDraggable } from './interfaces/i_draggable.js';
18
18
  import { IIcon } from './interfaces/i_icon.js';
19
19
  import { MutatorIcon } from './icons/mutator_icon.js';
@@ -26,11 +26,12 @@ import { WarningIcon } from './icons/warning_icon.js';
26
26
  import type { Workspace } from './workspace.js';
27
27
  import type { WorkspaceSvg } from './workspace_svg.js';
28
28
  import { IconType } from './icons/icon_types.js';
29
+ import { BlockCopyData } from './clipboard/block_paster.js';
29
30
  /**
30
31
  * Class for a block's SVG representation.
31
32
  * Not normally called directly, workspace.newBlock() is preferred.
32
33
  */
33
- export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, ICopyable, IDraggable {
34
+ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBoundedElement, ICopyable<BlockCopyData>, IDraggable {
34
35
  /**
35
36
  * Constant for identifying rows that are to be rendered inline.
36
37
  * Don't collide with Blockly.inputTypes.
@@ -322,9 +323,8 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
322
323
  * Encode a block for copying.
323
324
  *
324
325
  * @returns Copy metadata, or null if the block is an insertion marker.
325
- * @internal
326
326
  */
327
- toCopyData(): CopyData | null;
327
+ toCopyData(): BlockCopyData | null;
328
328
  /**
329
329
  * Updates the colour of the block to match the block's state.
330
330
  *
@@ -350,10 +350,10 @@ export declare class BlockSvg extends Block implements IASTNodeLocationSvg, IBou
350
350
  * Set this block's warning text.
351
351
  *
352
352
  * @param text The text, or null to delete.
353
- * @param opt_id An optional ID for the warning text to be able to maintain
353
+ * @param id An optional ID for the warning text to be able to maintain
354
354
  * multiple warnings.
355
355
  */
356
- setWarningText(text: string | null, opt_id?: string): void;
356
+ setWarningText(text: string | null, id?: string): void;
357
357
  /**
358
358
  * Give this block a mutator dialog.
359
359
  *
package/core/blockly.d.ts CHANGED
@@ -75,7 +75,7 @@ import { ICollapsibleToolboxItem } from './interfaces/i_collapsible_toolbox_item
75
75
  import { IComponent } from './interfaces/i_component.js';
76
76
  import { IConnectionChecker } from './interfaces/i_connection_checker.js';
77
77
  import { IContextMenu } from './interfaces/i_contextmenu.js';
78
- import { ICopyable } from './interfaces/i_copyable.js';
78
+ import { ICopyable, isCopyable } from './interfaces/i_copyable.js';
79
79
  import { IDeletable } from './interfaces/i_deletable.js';
80
80
  import { IDeleteArea } from './interfaces/i_delete_area.js';
81
81
  import { IDragTarget } from './interfaces/i_drag_target.js';
@@ -87,6 +87,7 @@ import { IKeyboardAccessible } from './interfaces/i_keyboard_accessible.js';
87
87
  import { IMetricsManager } from './interfaces/i_metrics_manager.js';
88
88
  import { IMovable } from './interfaces/i_movable.js';
89
89
  import { IObservable, isObservable } from './interfaces/i_observable.js';
90
+ import { IPaster, isPaster } from './interfaces/i_paster.js';
90
91
  import { IPositionable } from './interfaces/i_positionable.js';
91
92
  import { IRegistrable } from './interfaces/i_registrable.js';
92
93
  import { ISelectable } from './interfaces/i_selectable.js';
@@ -371,7 +372,7 @@ export { IComponent };
371
372
  export { IConnectionChecker };
372
373
  export { IContextMenu };
373
374
  export { icons };
374
- export { ICopyable };
375
+ export { ICopyable, isCopyable };
375
376
  export { IDeletable };
376
377
  export { IDeleteArea };
377
378
  export { IDragTarget };
@@ -386,6 +387,7 @@ export { Input };
386
387
  export { inputs };
387
388
  export { InsertionMarkerManager };
388
389
  export { IObservable, isObservable };
390
+ export { IPaster, isPaster };
389
391
  export { IPositionable };
390
392
  export { IRegistrable };
391
393
  export { ISelectable };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BlockSvg } from '../block_svg.js';
7
+ import { ICopyData } from '../interfaces/i_copyable.js';
8
+ import { IPaster } from '../interfaces/i_paster.js';
9
+ import { State } from '../serialization/blocks.js';
10
+ import { Coordinate } from '../utils/coordinate.js';
11
+ import { WorkspaceSvg } from '../workspace_svg.js';
12
+ export declare class BlockPaster implements IPaster<BlockCopyData, BlockSvg> {
13
+ static TYPE: string;
14
+ paste(copyData: BlockCopyData, workspace: WorkspaceSvg, coordinate?: Coordinate): BlockSvg | null;
15
+ }
16
+ /**
17
+ * Moves the given block to a location where it does not: (1) overlap exactly
18
+ * with any other blocks, or (2) look like it is connected to any other blocks.
19
+ *
20
+ * Exported for testing.
21
+ *
22
+ * @param block The block to move to an unambiguous location.
23
+ * @internal
24
+ */
25
+ export declare function moveBlockToNotConflict(block: BlockSvg): void;
26
+ export interface BlockCopyData extends ICopyData {
27
+ blockState: State;
28
+ typeCounts: {
29
+ [key: string]: number;
30
+ };
31
+ }
32
+ //# sourceMappingURL=block_paster.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { ICopyable, ICopyData } from '../interfaces/i_copyable.js';
7
+ import type { IPaster } from '../interfaces/i_paster.js';
8
+ /**
9
+ * Registers the given paster so that it cna be used for pasting.
10
+ *
11
+ * @param type The type of the paster to register, e.g. 'block', 'comment', etc.
12
+ * @param paster The paster to register.
13
+ */
14
+ export declare function register<U extends ICopyData, T extends ICopyable<U>>(type: string, paster: IPaster<U, T>): void;
15
+ /**
16
+ * Unregisters the paster associated with the given type.
17
+ *
18
+ * @param type The type of the paster to unregister.
19
+ */
20
+ export declare function unregister(type: string): void;
21
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { IPaster } from '../interfaces/i_paster.js';
7
+ import { ICopyData } from '../interfaces/i_copyable.js';
8
+ import { Coordinate } from '../utils/coordinate.js';
9
+ import { WorkspaceSvg } from '../workspace_svg.js';
10
+ import { WorkspaceCommentSvg } from '../workspace_comment_svg.js';
11
+ export declare class WorkspaceCommentPaster implements IPaster<WorkspaceCommentCopyData, WorkspaceCommentSvg> {
12
+ static TYPE: string;
13
+ paste(copyData: WorkspaceCommentCopyData, workspace: WorkspaceSvg, coordinate?: Coordinate): WorkspaceCommentSvg;
14
+ }
15
+ export interface WorkspaceCommentCopyData extends ICopyData {
16
+ commentState: Element;
17
+ }
18
+ //# sourceMappingURL=workspace_comment_paster.d.ts.map
@@ -3,41 +3,59 @@
3
3
  * Copyright 2021 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import type { ICopyable } from './interfaces/i_copyable.js';
6
+ import type { ICopyData, ICopyable } from './interfaces/i_copyable.js';
7
+ import { BlockPaster } from './clipboard/block_paster.js';
8
+ import { WorkspaceSvg } from './workspace_svg.js';
9
+ import * as registry from './clipboard/registry.js';
10
+ import { Coordinate } from './utils/coordinate.js';
7
11
  /**
8
- * Copy a block or workspace comment onto the local clipboard.
12
+ * Copy a copyable element onto the local clipboard.
9
13
  *
10
- * @param toCopy Block or Workspace Comment to be copied.
14
+ * @param toCopy The copyable element to be copied.
15
+ * @deprecated v11. Use `myCopyable.toCopyData()` instead. To be removed v12.
11
16
  * @internal
12
17
  */
13
- export declare function copy(toCopy: ICopyable): void;
18
+ export declare function copy<T extends ICopyData>(toCopy: ICopyable<T>): T | null;
14
19
  /**
15
20
  * Private version of copy for stubbing in tests.
16
21
  */
17
- declare function copyInternal(toCopy: ICopyable): void;
22
+ declare function copyInternal<T extends ICopyData>(toCopy: ICopyable<T>): T | null;
18
23
  /**
19
- * Paste a block or workspace comment on to the main workspace.
24
+ * Paste a pasteable element into the workspace.
20
25
  *
26
+ * @param copyData The data to paste into the workspace.
27
+ * @param workspace The workspace to paste the data into.
28
+ * @param coordinate The location to paste the thing at.
21
29
  * @returns The pasted thing if the paste was successful, null otherwise.
22
- * @internal
23
30
  */
24
- export declare function paste(): ICopyable | null;
31
+ export declare function paste<T extends ICopyData>(copyData: T, workspace: WorkspaceSvg, coordinate?: Coordinate): ICopyable<T> | null;
32
+ /**
33
+ * Pastes the last copied ICopyable into the workspace.
34
+ *
35
+ * @returns the pasted thing if the paste was successful, null otherwise.
36
+ */
37
+ export declare function paste(): ICopyable<ICopyData> | null;
25
38
  /**
26
- * Duplicate this block and its children, or a workspace comment.
39
+ * Duplicate this copy-paste-able element.
27
40
  *
28
- * @param toDuplicate Block or Workspace Comment to be duplicated.
29
- * @returns The block or workspace comment that was duplicated, or null if the
30
- * duplication failed.
41
+ * @param toDuplicate The element to be duplicated.
42
+ * @returns The element that was duplicated, or null if the duplication failed.
43
+ * @deprecated v11. Use
44
+ * `Blockly.clipboard.paste(myCopyable.toCopyData(), myWorkspace)` instead.
45
+ * To be removed v12.
31
46
  * @internal
32
47
  */
33
- export declare function duplicate(toDuplicate: ICopyable): ICopyable | null;
48
+ export declare function duplicate<U extends ICopyData, T extends ICopyable<U> & IHasWorkspace>(toDuplicate: T): T | null;
34
49
  /**
35
50
  * Private version of duplicate for stubbing in tests.
36
51
  */
37
- declare function duplicateInternal(toDuplicate: ICopyable): ICopyable | null;
52
+ declare function duplicateInternal<U extends ICopyData, T extends ICopyable<U> & IHasWorkspace>(toDuplicate: T): T | null;
53
+ interface IHasWorkspace {
54
+ workspace: WorkspaceSvg;
55
+ }
38
56
  export declare const TEST_ONLY: {
39
57
  duplicateInternal: typeof duplicateInternal;
40
58
  copyInternal: typeof copyInternal;
41
59
  };
42
- export {};
60
+ export { BlockPaster, registry };
43
61
  //# sourceMappingURL=clipboard.d.ts.map
package/core/common.d.ts CHANGED
@@ -4,9 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import type { Block } from './block.js';
7
+ import { ISelectable } from './blockly.js';
7
8
  import { BlockDefinition } from './blocks.js';
8
9
  import type { Connection } from './connection.js';
9
- import type { ICopyable } from './interfaces/i_copyable.js';
10
10
  import type { Workspace } from './workspace.js';
11
11
  import type { WorkspaceSvg } from './workspace_svg.js';
12
12
  /**
@@ -51,7 +51,7 @@ export declare function setMainWorkspace(workspace: Workspace): void;
51
51
  /**
52
52
  * Returns the currently selected copyable object.
53
53
  */
54
- export declare function getSelected(): ICopyable | null;
54
+ export declare function getSelected(): ISelectable | null;
55
55
  /**
56
56
  * Sets the currently selected block. This function does not visually mark the
57
57
  * block as selected or fire the required events. If you wish to
@@ -60,7 +60,7 @@ export declare function getSelected(): ICopyable | null;
60
60
  * @param newSelection The newly selected block.
61
61
  * @internal
62
62
  */
63
- export declare function setSelected(newSelection: ICopyable | null): void;
63
+ export declare function setSelected(newSelection: ISelectable | null): void;
64
64
  /**
65
65
  * Get the container element in which to render the WidgetDiv, DropDownDiv and
66
66
  * Tooltip.
package/core/field.d.ts CHANGED
@@ -236,6 +236,9 @@ export declare abstract class Field<T = any> implements IASTNodeLocationSvg, IAS
236
236
  * @param _doFullSerialization If true, this signals to the field that if it
237
237
  * normally just saves a reference to some state (eg variable fields) it
238
238
  * should instead serialize the full state of the thing being referenced.
239
+ * See the
240
+ * {@link https://developers.devsite.google.com/blockly/guides/create-custom-blocks/fields/customizing-fields/creating#full_serialization_and_backing_data | field serialization docs}
241
+ * for more information.
239
242
  * @returns JSON serializable state.
240
243
  * @internal
241
244
  */
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Block } from '../block.js';
7
+ import { Input } from './input.js';
8
+ import { inputTypes } from './input_types.js';
9
+ /**
10
+ * Represents an input on a block that is always the last input in the row. Any
11
+ * following input will be rendered on the next row even if the block has inline
12
+ * inputs. Any newline character in a JSON block definition's message will
13
+ * automatically be parsed as an end-row input.
14
+ */
15
+ export declare class EndRowInput extends Input {
16
+ name: string;
17
+ readonly type = inputTypes.END_ROW;
18
+ /**
19
+ * @param name Language-neutral identifier which may used to find this input
20
+ * again.
21
+ * @param block The block containing this input.
22
+ */
23
+ constructor(name: string, block: Block);
24
+ }
25
+ //# sourceMappingURL=end_row_input.d.ts.map
@@ -10,6 +10,7 @@ export declare enum inputTypes {
10
10
  VALUE = 1,
11
11
  STATEMENT = 3,
12
12
  DUMMY = 5,
13
- CUSTOM = 6
13
+ CUSTOM = 6,
14
+ END_ROW = 7
14
15
  }
15
16
  //# sourceMappingURL=input_types.d.ts.map
package/core/inputs.d.ts CHANGED
@@ -6,8 +6,9 @@
6
6
  import { Align } from './inputs/align.js';
7
7
  import { Input } from './inputs/input.js';
8
8
  import { DummyInput } from './inputs/dummy_input.js';
9
+ import { EndRowInput } from './inputs/end_row_input.js';
9
10
  import { StatementInput } from './inputs/statement_input.js';
10
11
  import { ValueInput } from './inputs/value_input.js';
11
12
  import { inputTypes } from './inputs/input_types.js';
12
- export { Align, Input, DummyInput, StatementInput, ValueInput, inputTypes };
13
+ export { Align, Input, DummyInput, EndRowInput, StatementInput, ValueInput, inputTypes, };
13
14
  //# sourceMappingURL=inputs.d.ts.map
@@ -3,25 +3,21 @@
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import type { WorkspaceSvg } from '../workspace_svg.js';
7
6
  import type { ISelectable } from './i_selectable.js';
8
- export interface ICopyable extends ISelectable {
7
+ export interface ICopyable<T extends ICopyData> extends ISelectable {
9
8
  /**
10
9
  * Encode for copying.
11
10
  *
12
11
  * @returns Copy metadata.
13
- * @internal
14
12
  */
15
- toCopyData(): CopyData | null;
13
+ toCopyData(): T | null;
16
14
  }
17
15
  export declare namespace ICopyable {
18
- interface CopyData {
19
- saveInfo: Object | Element;
20
- source: WorkspaceSvg;
21
- typeCounts: {
22
- [key: string]: number;
23
- } | null;
16
+ interface ICopyData {
17
+ paster: string;
24
18
  }
25
19
  }
26
- export type CopyData = ICopyable.CopyData;
20
+ export type ICopyData = ICopyable.ICopyData;
21
+ /** @returns true if the given object is copyable. */
22
+ export declare function isCopyable(obj: any): obj is ICopyable<ICopyData>;
27
23
  //# sourceMappingURL=i_copyable.d.ts.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Coordinate } from '../utils/coordinate.js';
7
+ import { WorkspaceSvg } from '../workspace_svg.js';
8
+ import { ICopyable, ICopyData } from './i_copyable.js';
9
+ /** An object that can paste data into a workspace. */
10
+ export interface IPaster<U extends ICopyData, T extends ICopyable<U>> {
11
+ paste(copyData: U, workspace: WorkspaceSvg, coordinate?: Coordinate): T | null;
12
+ }
13
+ /** @returns True if the given object is a paster. */
14
+ export declare function isPaster(obj: any): obj is IPaster<ICopyData, ICopyable<ICopyData>>;
15
+ //# sourceMappingURL=i_paster.d.ts.map
@@ -18,6 +18,8 @@ import type { Options } from './options.js';
18
18
  import type { Renderer } from './renderers/common/renderer.js';
19
19
  import type { Theme } from './theme.js';
20
20
  import type { ToolboxItem } from './toolbox/toolbox_item.js';
21
+ import { IPaster } from './interfaces/i_paster.js';
22
+ import { ICopyable } from './interfaces/i_copyable.js';
21
23
  export declare const TEST_ONLY: {
22
24
  typeMap: {
23
25
  [key: string]: {
@@ -59,6 +61,8 @@ export declare class Type<_T> {
59
61
  static SERIALIZER: Type<ISerializer>;
60
62
  /** @internal */
61
63
  static ICON: Type<IIcon>;
64
+ /** @internal */
65
+ static PASTER: Type<IPaster<ICopyable.ICopyData, ICopyable<ICopyable.ICopyData>>>;
62
66
  }
63
67
  /**
64
68
  * Registers a class based on a type and name.
@@ -26,7 +26,6 @@ import { SquareCorner } from '../measurables/square_corner.js';
26
26
  import { StatementInput } from '../measurables/statement_input.js';
27
27
  import { TopRow } from '../measurables/top_row.js';
28
28
  import { Types } from '../measurables/types.js';
29
- import { ConstantProvider } from './constants.js';
30
29
  import { Drawer } from './drawer.js';
31
30
  import type { IPathObject } from './i_path_object.js';
32
31
  import { RenderInfo } from './info.js';
@@ -62,7 +61,6 @@ export declare function init(name: string, theme: Theme, opt_rendererOverrides?:
62
61
  }): Renderer;
63
62
  export { BottomRow };
64
63
  export { Connection };
65
- export { ConstantProvider };
66
64
  export { Drawer };
67
65
  export { ExternalValueInput };
68
66
  export { Field };
@@ -89,4 +87,5 @@ export { SquareCorner };
89
87
  export { StatementInput };
90
88
  export { TopRow };
91
89
  export { Types };
90
+ export { OutsideCorners, InsideCorners, StartHat, Notch, PuzzleTab, JaggedTeeth, BaseShape, DynamicShape, ConstantProvider, } from './constants.js';
92
91
  //# sourceMappingURL=block_rendering.d.ts.map
@@ -69,7 +69,7 @@ export declare class Row {
69
69
  */
70
70
  hasInlineInput: boolean;
71
71
  /**
72
- * Whether the row has any dummy inputs.
72
+ * Whether the row has any dummy inputs or end-row inputs.
73
73
  */
74
74
  hasDummyInput: boolean;
75
75
  /**
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { KeyCodes } from './utils/keycodes.js';
7
- import type { Workspace } from './workspace.js';
7
+ import { WorkspaceSvg } from './workspace_svg.js';
8
8
  /**
9
9
  * Class for the registry of keyboard shortcuts. This is intended to be a
10
10
  * singleton. You should not create a new instance, and only access this class
@@ -103,7 +103,7 @@ export declare class ShortcutRegistry {
103
103
  * @param e The key down event.
104
104
  * @returns True if the event was handled, false otherwise.
105
105
  */
106
- onKeyDown(workspace: Workspace, e: KeyboardEvent): boolean;
106
+ onKeyDown(workspace: WorkspaceSvg, e: KeyboardEvent): boolean;
107
107
  /**
108
108
  * Gets the shortcuts registered to the given key code.
109
109
  *
@@ -146,9 +146,9 @@ export declare class ShortcutRegistry {
146
146
  }
147
147
  export declare namespace ShortcutRegistry {
148
148
  interface KeyboardShortcut {
149
- callback?: (p1: Workspace, p2: Event, p3: KeyboardShortcut) => boolean;
149
+ callback?: (p1: WorkspaceSvg, p2: Event, p3: KeyboardShortcut) => boolean;
150
150
  name: string;
151
- preconditionFn?: (p1: Workspace) => boolean;
151
+ preconditionFn?: (p1: WorkspaceSvg) => boolean;
152
152
  metadata?: object;
153
153
  keyCodes?: (number | string)[];
154
154
  allowCollision?: boolean;
@@ -8,7 +8,8 @@
8
8
  * It will also replace string table references (e.g., %{bky_my_msg} and
9
9
  * %{BKY_MY_MSG} will both be replaced with the value in
10
10
  * Msg['MY_MSG']). Percentage sign characters '%' may be self-escaped
11
- * (e.g., '%%').
11
+ * (e.g., '%%'). Newline characters will also be output as string tokens
12
+ * containing a single newline character.
12
13
  *
13
14
  * @param message Text which might contain string table references and
14
15
  * interpolation tokens.
@@ -6,15 +6,16 @@
6
6
  import './events/events_selected.js';
7
7
  import type { IBoundedElement } from './interfaces/i_bounded_element.js';
8
8
  import type { IBubble } from './interfaces/i_bubble.js';
9
- import type { CopyData, ICopyable } from './interfaces/i_copyable.js';
9
+ import type { ICopyable } from './interfaces/i_copyable.js';
10
10
  import { Coordinate } from './utils/coordinate.js';
11
11
  import { Rect } from './utils/rect.js';
12
12
  import { WorkspaceComment } from './workspace_comment.js';
13
13
  import type { WorkspaceSvg } from './workspace_svg.js';
14
+ import { WorkspaceCommentCopyData } from './clipboard/workspace_comment_paster.js';
14
15
  /**
15
16
  * Class for a workspace comment's SVG representation.
16
17
  */
17
- export declare class WorkspaceCommentSvg extends WorkspaceComment implements IBoundedElement, IBubble, ICopyable {
18
+ export declare class WorkspaceCommentSvg extends WorkspaceComment implements IBoundedElement, IBubble, ICopyable<WorkspaceCommentCopyData> {
18
19
  /**
19
20
  * The width and height to use to size a workspace comment when it is first
20
21
  * added, before it has been edited by the user.
@@ -249,9 +250,8 @@ export declare class WorkspaceCommentSvg extends WorkspaceComment implements IBo
249
250
  * Encode a comment for copying.
250
251
  *
251
252
  * @returns Copy metadata.
252
- * @internal
253
253
  */
254
- toCopyData(): CopyData;
254
+ toCopyData(): WorkspaceCommentCopyData;
255
255
  /**
256
256
  * Returns a bounding box describing the dimensions of this comment.
257
257
  *
@@ -15,7 +15,7 @@ import { Gesture } from './gesture.js';
15
15
  import { Grid } from './grid.js';
16
16
  import type { IASTNodeLocationSvg } from './interfaces/i_ast_node_location_svg.js';
17
17
  import type { IBoundedElement } from './interfaces/i_bounded_element.js';
18
- import type { ICopyable } from './interfaces/i_copyable.js';
18
+ import type { ICopyData, ICopyable } from './interfaces/i_copyable.js';
19
19
  import type { IDragTarget } from './interfaces/i_drag_target.js';
20
20
  import type { IFlyout } from './interfaces/i_flyout.js';
21
21
  import type { IMetricsManager } from './interfaces/i_metrics_manager.js';
@@ -559,8 +559,10 @@ export declare class WorkspaceSvg extends Workspace implements IASTNodeLocationS
559
559
  *
560
560
  * @param state The representation of the thing to paste.
561
561
  * @returns The pasted thing, or null if the paste was not successful.
562
+ * @deprecated v10. Use `Blockly.clipboard.paste` instead. To be removed in
563
+ * v11.
562
564
  */
563
- paste(state: any | Element | DocumentFragment): ICopyable | null;
565
+ paste(state: any | Element | DocumentFragment): ICopyable<ICopyData> | null;
564
566
  /**
565
567
  * Paste the provided block onto the workspace.
566
568
  *
@@ -276,7 +276,7 @@ int ${b.FUNCTION_NAME_PLACEHOLDER_}(num a, num b) {
276
276
  }
277
277
  `)+"("+c+", "+a+")",Order$$module$build$src$generators$dart$dart_generator.UNARY_POSTFIX]},math_random_float$$module$build$src$generators$dart$math=function(a,b){b.definitions_.import_dart_math="import 'dart:math' as Math;";return["new Math.Random().nextDouble()",Order$$module$build$src$generators$dart$dart_generator.UNARY_POSTFIX]},math_atan2$$module$build$src$generators$dart$math=function(a,b){b.definitions_.import_dart_math="import 'dart:math' as Math;";const c=b.valueToCode(a,"X",Order$$module$build$src$generators$dart$dart_generator.NONE)||
278
278
  "0";return["Math.atan2("+(b.valueToCode(a,"Y",Order$$module$build$src$generators$dart$dart_generator.NONE)||"0")+", "+c+") / Math.pi * 180",Order$$module$build$src$generators$dart$dart_generator.MULTIPLICATIVE]},procedures_defreturn$$module$build$src$generators$dart$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE);var d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(d+=b.injectId(b.STATEMENT_SUFFIX,
279
- a));d&&(d=b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));const f=b.statementToCode(a,"STACK");let g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$dart$dart_generator.NONE)||"",h="";f&&g&&(h=d);g&&(g=b.INDENT+"return "+g+";\n");const k=g?"dynamic":"void",l=[],n=a.getVars();for(let m=0;m<n.length;m++)l[m]=b.nameDB_.getName(n[m],$.NameType$$module$build$src$core$names.VARIABLE);d=k+" "+c+"("+l.join(", ")+") {\n"+
279
+ a));d&&(d=b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));const f=b.statementToCode(a,"STACK");let g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$dart$dart_generator.NONE)||"",h="";f&&g&&(h=d);g&&(g=b.INDENT+"return "+g+";\n");const k=g?"dynamic":"void",l=[],m=a.getVars();for(let n=0;n<m.length;n++)l[n]=b.nameDB_.getName(m[n],$.NameType$$module$build$src$core$names.VARIABLE);d=k+" "+c+"("+l.join(", ")+") {\n"+
280
280
  d+e+f+h+g+"}";d=b.scrub_(a,d);b.definitions_["%"+c]=d;return null},procedures_callreturn$$module$build$src$generators$dart$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE),d=[],e=a.getVars();for(let f=0;f<e.length;f++)d[f]=b.valueToCode(a,"ARG"+f,Order$$module$build$src$generators$dart$dart_generator.NONE)||"null";return[c+"("+d.join(", ")+")",Order$$module$build$src$generators$dart$dart_generator.UNARY_POSTFIX]},procedures_callnoreturn$$module$build$src$generators$dart$procedures=
281
281
  function(a,b){return b.forBlock.procedures_callreturn(a,b)[0]+";\n"},procedures_ifreturn$$module$build$src$generators$dart$procedures=function(a,b){let c="if ("+(b.valueToCode(a,"CONDITION",Order$$module$build$src$generators$dart$dart_generator.NONE)||"false")+") {\n";b.STATEMENT_SUFFIX&&(c+=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT));a.hasReturnValue_?(a=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$dart$dart_generator.NONE)||"null",c+=b.INDENT+"return "+a+";\n"):c+=b.INDENT+
282
282
  "return;\n";return c+"}\n"},text$$module$build$src$generators$dart$text=function(a,b){return[b.quote_(a.getFieldValue("TEXT")),Order$$module$build$src$generators$dart$dart_generator.ATOMIC]},text_multiline$$module$build$src$generators$dart$text=function(a,b){a=b.multiline_quote_(a.getFieldValue("TEXT"));b=-1!==a.indexOf("+")?Order$$module$build$src$generators$dart$dart_generator.ADDITIVE:Order$$module$build$src$generators$dart$dart_generator.ATOMIC;return[a,b]},text_join$$module$build$src$generators$dart$text=
@@ -213,7 +213,7 @@ function ${b.FUNCTION_NAME_PLACEHOLDER_}(a, b) {
213
213
  }
214
214
  `)+"("+c+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_random_float$$module$build$src$generators$javascript$math=function(a,b){return["Math.random()",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_atan2$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"X",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";return["Math.atan2("+(b.valueToCode(a,"Y",
215
215
  Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0")+", "+c+") / Math.PI * 180",Order$$module$build$src$generators$javascript$javascript_generator.DIVISION]},procedures_defreturn$$module$build$src$generators$javascript$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE);var d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(d+=b.injectId(b.STATEMENT_SUFFIX,a));d&&(d=
216
- b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));const f=b.statementToCode(a,"STACK");let g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"",h="";f&&g&&(h=d);g&&(g=b.INDENT+"return "+g+";\n");const k=[],l=a.getVars();for(let n=0;n<l.length;n++)k[n]=b.nameDB_.getName(l[n],$.NameType$$module$build$src$core$names.VARIABLE);d="function "+c+"("+k.join(", ")+") {\n"+d+e+f+h+g+"}";
216
+ b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));const f=b.statementToCode(a,"STACK");let g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"",h="";f&&g&&(h=d);g&&(g=b.INDENT+"return "+g+";\n");const k=[],l=a.getVars();for(let m=0;m<l.length;m++)k[m]=b.nameDB_.getName(l[m],$.NameType$$module$build$src$core$names.VARIABLE);d="function "+c+"("+k.join(", ")+") {\n"+d+e+f+h+g+"}";
217
217
  d=b.scrub_(a,d);b.definitions_["%"+c]=d;return null},procedures_callreturn$$module$build$src$generators$javascript$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE),d=[],e=a.getVars();for(let f=0;f<e.length;f++)d[f]=b.valueToCode(a,"ARG"+f,Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"null";return[c+"("+d.join(", ")+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},
218
218
  procedures_callnoreturn$$module$build$src$generators$javascript$procedures=function(a,b){return b.forBlock.procedures_callreturn(a,b)[0]+";\n"},procedures_ifreturn$$module$build$src$generators$javascript$procedures=function(a,b){let c="if ("+(b.valueToCode(a,"CONDITION",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"false")+") {\n";b.STATEMENT_SUFFIX&&(c+=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT));a.hasReturnValue_?(a=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||
219
219
  "null",c+=b.INDENT+"return "+a+";\n"):c+=b.INDENT+"return;\n";return c+"}\n"},text$$module$build$src$generators$javascript$text=function(a,b){return[b.quote_(a.getFieldValue("TEXT")),Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},text_multiline$$module$build$src$generators$javascript$text=function(a,b){a=b.multiline_quote_(a.getFieldValue("TEXT"));b=-1!==a.indexOf("+")?Order$$module$build$src$generators$javascript$javascript_generator.ADDITION:Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC;
package/lua_compressed.js CHANGED
@@ -275,7 +275,7 @@ end
275
275
  function(a,b){const c=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$lua$lua_generator.NONE)||"0",d=b.valueToCode(a,"LOW",Order$$module$build$src$generators$lua$lua_generator.NONE)||"-math.huge";a=b.valueToCode(a,"HIGH",Order$$module$build$src$generators$lua$lua_generator.NONE)||"math.huge";return["math.min(math.max("+c+", "+d+"), "+a+")",Order$$module$build$src$generators$lua$lua_generator.HIGH]},math_random_int$$module$build$src$generators$lua$math=function(a,b){const c=b.valueToCode(a,
276
276
  "FROM",Order$$module$build$src$generators$lua$lua_generator.NONE)||"0";a=b.valueToCode(a,"TO",Order$$module$build$src$generators$lua$lua_generator.NONE)||"0";return["math.random("+c+", "+a+")",Order$$module$build$src$generators$lua$lua_generator.HIGH]},math_random_float$$module$build$src$generators$lua$math=function(a,b){return["math.random()",Order$$module$build$src$generators$lua$lua_generator.HIGH]},math_atan2$$module$build$src$generators$lua$math=function(a,b){const c=b.valueToCode(a,"X",Order$$module$build$src$generators$lua$lua_generator.NONE)||
277
277
  "0";return["math.deg(math.atan2("+(b.valueToCode(a,"Y",Order$$module$build$src$generators$lua$lua_generator.NONE)||"0")+", "+c+"))",Order$$module$build$src$generators$lua$lua_generator.HIGH]},procedures_defreturn$$module$build$src$generators$lua$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE);var d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(d+=b.injectId(b.STATEMENT_SUFFIX,a));d&&(d=
278
- b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));let f=b.statementToCode(a,"STACK"),g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$lua$lua_generator.NONE)||"",h="";f&&g&&(h=d);g?g=b.INDENT+"return "+g+"\n":f||(f="");const k=[],l=a.getVars();for(let n=0;n<l.length;n++)k[n]=b.nameDB_.getName(l[n],$.NameType$$module$build$src$core$names.VARIABLE);d="function "+c+"("+k.join(", ")+")\n"+d+e+f+h+g+"end\n";d=b.scrub_(a,
278
+ b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));let f=b.statementToCode(a,"STACK"),g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$lua$lua_generator.NONE)||"",h="";f&&g&&(h=d);g?g=b.INDENT+"return "+g+"\n":f||(f="");const k=[],l=a.getVars();for(let m=0;m<l.length;m++)k[m]=b.nameDB_.getName(l[m],$.NameType$$module$build$src$core$names.VARIABLE);d="function "+c+"("+k.join(", ")+")\n"+d+e+f+h+g+"end\n";d=b.scrub_(a,
279
279
  d);b.definitions_["%"+c]=d;return null},procedures_callreturn$$module$build$src$generators$lua$procedures=function(a,b){const c=b.nameDB_.getName(a.getFieldValue("NAME"),$.NameType$$module$build$src$core$names.PROCEDURE),d=[],e=a.getVars();for(let f=0;f<e.length;f++)d[f]=b.valueToCode(a,"ARG"+f,Order$$module$build$src$generators$lua$lua_generator.NONE)||"nil";return[c+"("+d.join(", ")+")",Order$$module$build$src$generators$lua$lua_generator.HIGH]},procedures_callnoreturn$$module$build$src$generators$lua$procedures=
280
280
  function(a,b){return b.forBlock.procedures_callreturn(a,b)[0]+"\n"},procedures_ifreturn$$module$build$src$generators$lua$procedures=function(a,b){let c="if "+(b.valueToCode(a,"CONDITION",Order$$module$build$src$generators$lua$lua_generator.NONE)||"false")+" then\n";b.STATEMENT_SUFFIX&&(c+=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT));a.hasReturnValue_?(a=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$lua$lua_generator.NONE)||"nil",c+=b.INDENT+"return "+a+"\n"):c+=b.INDENT+
281
281
  "return\n";return c+"end\n"},text$$module$build$src$generators$lua$text=function(a,b){return[b.quote_(a.getFieldValue("TEXT")),Order$$module$build$src$generators$lua$lua_generator.ATOMIC]},text_multiline$$module$build$src$generators$lua$text=function(a,b){a=b.multiline_quote_(a.getFieldValue("TEXT"));b=-1!==a.indexOf("..")?Order$$module$build$src$generators$lua$lua_generator.CONCATENATION:Order$$module$build$src$generators$lua$lua_generator.ATOMIC;return[a,b]},text_join$$module$build$src$generators$lua$text=