Skip to content

Commit bcdb65c

Browse files
committed
release: Merge branch 'develop' into rc/v12.0.0
2 parents 75efba9 + 0c20129 commit bcdb65c

20 files changed

Lines changed: 473 additions & 341 deletions

blocks/lists.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,22 +1046,19 @@ blocks['lists_split'] = {
10461046

10471047
/**
10481048
* Returns the state of this block as a JSON serializable object.
1049-
* This block does not need to serialize any specific state as it is already
1050-
* encoded in the dropdown values, but must have an implementation to avoid
1051-
* the backward compatible XML mutations being serialized.
10521049
*
10531050
* @returns The state of this block.
10541051
*/
1055-
saveExtraState: function (this: SplitBlock): null {
1056-
return null;
1052+
saveExtraState: function (this: SplitBlock): {mode: string} {
1053+
return {'mode': this.getFieldValue('MODE')};
10571054
},
10581055

10591056
/**
10601057
* Applies the given state to this block.
1061-
* No extra state is needed or expected as it is already encoded in the
1062-
* dropdown values.
10631058
*/
1064-
loadExtraState: function (this: SplitBlock) {},
1059+
loadExtraState: function (this: SplitBlock, state: {mode: string}) {
1060+
this.updateType_(state['mode']);
1061+
},
10651062
};
10661063

10671064
// Register provided blocks.

core/block_svg.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class BlockSvg
246246
*
247247
* @returns #RRGGBB string.
248248
*/
249-
getColourSecondary(): string | undefined {
249+
getColourSecondary(): string {
250250
return this.style.colourSecondary;
251251
}
252252

@@ -255,7 +255,7 @@ export class BlockSvg
255255
*
256256
* @returns #RRGGBB string.
257257
*/
258-
getColourTertiary(): string | undefined {
258+
getColourTertiary(): string {
259259
return this.style.colourTertiary;
260260
}
261261

@@ -1221,6 +1221,15 @@ export class BlockSvg
12211221
}
12221222
}
12231223

1224+
/**
1225+
* Returns the BlockStyle object used to style this block.
1226+
*
1227+
* @returns This block's style object.
1228+
*/
1229+
getStyle(): BlockStyle {
1230+
return this.style;
1231+
}
1232+
12241233
/**
12251234
* Move this block to the front of the visible workspace.
12261235
* <g> tags do not respect z-index so SVG renders them in the

core/clipboard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ function pasteFromData<T extends ICopyData>(
8383
workspace: WorkspaceSvg,
8484
coordinate?: Coordinate,
8585
): ICopyable<T> | null {
86-
workspace = workspace.getRootWorkspace() ?? workspace;
86+
workspace = workspace.isMutator
87+
? workspace
88+
: (workspace.getRootWorkspace() ?? workspace);
8789
return (globalRegistry
8890
.getObject(globalRegistry.Type.PASTER, copyData.paster, false)
8991
?.paste(copyData, workspace, coordinate) ?? null) as ICopyable<T> | null;

core/contextmenu_items.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ export function registerCommentDuplicate() {
611611
export function registerCommentCreate() {
612612
const createOption: RegistryItem = {
613613
displayText: () => Msg['ADD_COMMENT'],
614-
preconditionFn: () => 'enabled',
614+
preconditionFn: (scope: Scope) => {
615+
return scope.workspace?.isMutator ? 'hidden' : 'enabled';
616+
},
615617
callback: (scope: Scope, e: PointerEvent) => {
616618
const workspace = scope.workspace;
617619
if (!workspace) return;

core/field_dropdown.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {Coordinate} from './utils/coordinate.js';
2929
import * as dom from './utils/dom.js';
3030
import * as parsing from './utils/parsing.js';
3131
import * as utilsString from './utils/string.js';
32-
import * as style from './utils/style.js';
3332
import {Svg} from './utils/svg.js';
3433

3534
/**
@@ -293,7 +292,7 @@ export class FieldDropdown extends Field<string> {
293292

294293
if (this.getConstants()!.FIELD_DROPDOWN_COLOURED_DIV) {
295294
const primaryColour = block.getColour();
296-
const borderColour = (this.sourceBlock_ as BlockSvg).style.colourTertiary;
295+
const borderColour = (this.sourceBlock_ as BlockSvg).getColourTertiary();
297296
dropDownDiv.setColour(primaryColour, borderColour);
298297
}
299298

@@ -306,11 +305,6 @@ export class FieldDropdown extends Field<string> {
306305

307306
if (this.selectedMenuItem) {
308307
this.menu_!.setHighlighted(this.selectedMenuItem);
309-
style.scrollIntoContainerView(
310-
this.selectedMenuItem.getElement()!,
311-
dropDownDiv.getContentDiv(),
312-
true,
313-
);
314308
}
315309

316310
this.applyColour();
@@ -469,21 +463,21 @@ export class FieldDropdown extends Field<string> {
469463
* Updates the dropdown arrow to match the colour/style of the block.
470464
*/
471465
override applyColour() {
472-
const style = (this.sourceBlock_ as BlockSvg).style;
466+
const sourceBlock = this.sourceBlock_ as BlockSvg;
473467
if (this.borderRect_) {
474-
this.borderRect_.setAttribute('stroke', style.colourTertiary);
468+
this.borderRect_.setAttribute('stroke', sourceBlock.getColourTertiary());
475469
if (this.menu_) {
476-
this.borderRect_.setAttribute('fill', style.colourTertiary);
470+
this.borderRect_.setAttribute('fill', sourceBlock.getColourTertiary());
477471
} else {
478472
this.borderRect_.setAttribute('fill', 'transparent');
479473
}
480474
}
481475
// Update arrow's colour.
482-
if (this.sourceBlock_ && this.arrow) {
483-
if (this.sourceBlock_.isShadow()) {
484-
this.arrow.style.fill = style.colourSecondary;
476+
if (sourceBlock && this.arrow) {
477+
if (sourceBlock.isShadow()) {
478+
this.arrow.style.fill = sourceBlock.getColourSecondary();
485479
} else {
486-
this.arrow.style.fill = style.colourPrimary;
480+
this.arrow.style.fill = sourceBlock.getColour();
487481
}
488482
}
489483
}

core/field_input.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
227227

228228
if (!this.isFullBlockField() && this.borderRect_) {
229229
this.borderRect_!.style.display = 'block';
230-
this.borderRect_.setAttribute('stroke', block.style.colourTertiary);
230+
this.borderRect_.setAttribute('stroke', block.getColourTertiary());
231231
} else {
232232
this.borderRect_!.style.display = 'none';
233233
// In general, do *not* let fields control the color of blocks. Having the
@@ -430,8 +430,8 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
430430
borderRadius = (bBox.bottom - bBox.top) / 2 + 'px';
431431
// Pull stroke colour from the existing shadow block
432432
const strokeColour = block.getParent()
433-
? (block.getParent() as BlockSvg).style.colourTertiary
434-
: (this.sourceBlock_ as BlockSvg).style.colourTertiary;
433+
? (block.getParent() as BlockSvg).getColourTertiary()
434+
: (this.sourceBlock_ as BlockSvg).getColourTertiary();
435435
htmlInput.style.border = 1 * scale + 'px solid ' + strokeColour;
436436
div!.style.borderRadius = borderRadius;
437437
div!.style.transition = 'box-shadow 0.25s ease 0s';

core/icons/comment_icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
129129

130130
override applyColour(): void {
131131
super.applyColour();
132-
const colour = (this.sourceBlock as BlockSvg).style.colourPrimary;
132+
const colour = (this.sourceBlock as BlockSvg).getColour();
133133
this.textInputBubble?.setColour(colour);
134134
}
135135

core/icons/mutator_icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class MutatorIcon extends Icon implements IHasBubble {
136136

137137
override applyColour(): void {
138138
super.applyColour();
139-
this.miniWorkspaceBubble?.setColour(this.sourceBlock.style.colourPrimary);
139+
this.miniWorkspaceBubble?.setColour(this.sourceBlock.getColour());
140140
this.miniWorkspaceBubble?.updateBlockStyles();
141141
}
142142

core/icons/warning_icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class WarningIcon extends Icon implements IHasBubble {
108108

109109
override applyColour(): void {
110110
super.applyColour();
111-
this.textBubble?.setColour(this.sourceBlock.style.colourPrimary);
111+
this.textBubble?.setColour(this.sourceBlock.getColour());
112112
}
113113

114114
override updateCollapsed(): void {

core/menu.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ export class Menu {
255255
this.highlightedItem = item;
256256
// Bring the highlighted item into view. This has no effect if the menu is
257257
// not scrollable.
258-
const el = this.getElement() as Element;
259-
style.scrollIntoContainerView(item.getElement() as Element, el);
260-
261-
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
258+
const el = this.getElement();
259+
if (el) {
260+
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
261+
}
262+
item.getElement()?.scrollIntoView();
262263
}
263264
}
264265

0 commit comments

Comments
 (0)