Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ declare namespace pxt {
lightToc?: boolean; // if true: do NOT use inverted style in docs toc
// FIXME (riknoll): Can't use Blockly types here
blocklyOptions?: any; // Blockly options, see Configuration: https://developers.google.com/blockly/guides/get-started/web
blocklyKeyboardControlsByDefault?: boolean; // if true, keyboard controls will be enabled by default in the blockly editor
hideFlyoutHeadings?: boolean; // Hide the flyout headings at the top of the flyout when on a mobile device.
monacoColors?: pxt.Map<string>; // Monaco theme colors, see https://code.visualstudio.com/docs/getstarted/theme-color-reference
simAnimationEnter?: string; // Simulator enter animation
Expand Down
3 changes: 0 additions & 3 deletions localtypings/pxteditor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ declare namespace pxt.editor {
editorOffset?: string;
print?: boolean;
greenScreen?: boolean;
accessibleBlocks?: boolean;
home?: boolean;
hasError?: boolean;
cancelledDownload?: boolean;
Expand Down Expand Up @@ -1049,8 +1048,6 @@ declare namespace pxt.editor {
toggleHighContrast(): void;
setHighContrast(on: boolean): void;
toggleGreenScreen(): void;
toggleAccessibleBlocks(eventSource: string): void;
isAccessibleBlocks(): boolean;
launchFullEditor(): void;
resetWorkspace(): void;

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
},
"dependencies": {
"@blockly/field-grid-dropdown": "6.0.4",
"@blockly/keyboard-navigation": "3.0.3",
"@blockly/plugin-workspace-search": "10.1.2",
"@crowdin/crowdin-api-client": "^1.33.0",
"@fortawesome/fontawesome-free": "^5.15.4",
Expand All @@ -72,7 +71,7 @@
"@zip.js/zip.js": "2.4.20",
"adm-zip": "^0.5.12",
"axios": "^1.12.2",
"blockly": "12.3.1",
"blockly": "13.0.0-beta.5",
"browserify": "17.0.0",
"chai": "^3.5.0",
"chalk": "^4.1.2",
Expand Down Expand Up @@ -151,6 +150,12 @@
"yargs": "^17.7.2"
},
"overrides": {
"@blockly/field-grid-dropdown": {
"blockly": "13.0.0-beta.5"
},
"@blockly/plugin-workspace-search": {
"blockly": "13.0.0-beta.5"
},
"combine-source-map": {
"source-map": "0.4.4"
},
Expand Down
4 changes: 0 additions & 4 deletions pxtblocks/builtins/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as Blockly from "blockly";
import { createFlyoutGroupLabel, createFlyoutHeadingLabel, mkVariableFieldBlock } from "../toolbox";
import { installBuiltinHelpInfo, setBuiltinHelpInfo } from "../help";

export const CREATE_VAR_BTN_ID = 'create-variable-btn';

export function initVariables() {
let varname = lf("{id:var}item");
Blockly.Variables.flyoutCategory = flyoutCategory;
Expand Down Expand Up @@ -242,8 +240,6 @@ function flyoutCategory(workspace: Blockly.WorkspaceSvg, useXml: boolean): Eleme
const button = document.createElement('button') as HTMLElement;
button.setAttribute('text', lf("Make a Variable..."));
button.setAttribute('callbackKey', 'CREATE_VARIABLE');
// This id is used to re-focus the create variable button after the dialog is closed.
button.setAttribute('id', CREATE_VAR_BTN_ID);

workspace.registerButtonCallback('CREATE_VARIABLE', function (button) {
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace());
Expand Down
3 changes: 2 additions & 1 deletion pxtblocks/contextMenu/blockItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function registerDuplicate() {
scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK,
id: 'blockDuplicate',
weight: BlockContextWeight.Duplicate,
associatedKeyboardShortcut: Blockly.ShortcutItems.names.DUPLICATE,
};
Blockly.ContextMenuRegistry.registry.register(duplicateOption);
}
}
4 changes: 3 additions & 1 deletion pxtblocks/contextMenu/workspaceItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function registerFormatCode() {
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
id: 'pxtFormatCode',
weight: WorkspaceContextWeight.FormatCode,
// Re-registered with key F by webapp blocks.tsx initKeyboardControls.
associatedKeyboardShortcut: Blockly.ShortcutItems.names.CLEANUP,
};
Blockly.ContextMenuRegistry.registry.register(formatOption);
}
Expand Down Expand Up @@ -290,4 +292,4 @@ function registerFind() {
weight: WorkspaceContextWeight.Find,
};
Blockly.ContextMenuRegistry.registry.register(findOption);
}
}
74 changes: 10 additions & 64 deletions pxtblocks/copyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let oldCopy: Blockly.ShortcutRegistry.KeyboardShortcut;
let oldCut: Blockly.ShortcutRegistry.KeyboardShortcut;
let oldPaste: Blockly.ShortcutRegistry.KeyboardShortcut;

export function initCopyPaste(accessibleBlocksEnabled: boolean, forceRefresh: boolean = false) {
export function initCopyPaste(forceRefresh: boolean = false) {
if (!getCopyPasteHandlers()) return;

if (oldCopy && !forceRefresh) return;
Expand All @@ -27,65 +27,8 @@ export function initCopyPaste(accessibleBlocksEnabled: boolean, forceRefresh: bo
registerCut();
registerPaste();

if (!accessibleBlocksEnabled) {
registerCopyContextMenu();
registerPasteContextMenu();
}
}

export function initAccessibleBlocksCopyPasteContextMenu() {
overridePasteContextMenuItem();
overrideCutContextMenuItem();
}

function overridePasteContextMenuItem() {
const oldPasteOption = Blockly.ContextMenuRegistry.registry.getItem("blockPasteFromContextMenu");

if ("separator" in oldPasteOption) {
throw new Error(`RegistryItem ${oldPasteOption.id} is not of type ActionRegistryItem`);
};

const pasteOption: Blockly.ContextMenuRegistry.RegistryItem = {
...oldPasteOption,
preconditionFn: pasteContextMenuPreconditionFn,
};

Blockly.ContextMenuRegistry.registry.unregister("blockPasteFromContextMenu");
Blockly.ContextMenuRegistry.registry.register(pasteOption);
}

function overrideCutContextMenuItem() {
const oldCutOption = Blockly.ContextMenuRegistry.registry.getItem("blockCutFromContextMenu");

if ("separator" in oldCutOption) {
throw new Error(`RegistryItem ${oldCutOption.id} is not of type ActionRegistryItem`);
};

const cutOption: Blockly.ContextMenuRegistry.RegistryItem = {
...oldCutOption,
preconditionFn: (scope: Blockly.ContextMenuRegistry.Scope) => {
const focused = scope.focusedNode;
if (!focused || !Blockly.isCopyable(focused)) return "hidden";

const workspace = focused.workspace;

if (focused.workspace.isFlyout)
return "hidden";

if (!(workspace instanceof Blockly.WorkspaceSvg)) return 'hidden';

if (
oldCut.preconditionFn(workspace, scope)
) {
return 'enabled';
}

return "hidden";
},
};

Blockly.ContextMenuRegistry.registry.unregister("blockCutFromContextMenu");
Blockly.ContextMenuRegistry.registry.register(cutOption);
registerCopyContextMenu();
registerPasteContextMenu();
}

function registerCopy() {
Expand Down Expand Up @@ -167,7 +110,8 @@ function registerCopyContextMenu() {
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK,
weight: BlockContextWeight.Copy,
id: "makecode-copy-block"
id: "makecode-copy-block",
associatedKeyboardShortcut: Blockly.ShortcutItems.names.COPY,
};

const copyCommentOption: Blockly.ContextMenuRegistry.RegistryItem = {
Expand Down Expand Up @@ -196,7 +140,8 @@ function registerCopyContextMenu() {
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.COMMENT,
weight: BlockContextWeight.Copy,
id: "makecode-copy-comment"
id: "makecode-copy-comment",
associatedKeyboardShortcut: Blockly.ShortcutItems.names.COPY,
};

if (Blockly.ContextMenuRegistry.registry.getItem(copyOption.id)) {
Expand All @@ -222,7 +167,8 @@ function registerPasteContextMenu() {
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
weight: WorkspaceContextWeight.Paste,
id: "makecode-paste"
id: "makecode-paste",
associatedKeyboardShortcut: Blockly.ShortcutItems.names.PASTE,
};

if (Blockly.ContextMenuRegistry.registry.getItem(pasteOption.id)) {
Expand Down Expand Up @@ -286,4 +232,4 @@ function runCopyPreconditionFunction(

updateDuplicateOnDragState(toCopy as Blockly.BlockSvg);
return result;
}
}
7 changes: 3 additions & 4 deletions pxtblocks/fields/field_asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
}

const toolboxWidth = block.workspace.getToolbox().getWidth();
const workspaceLeft = injectDivBounds.left + toolboxWidth;

if (divBounds.width > injectDivBounds.width - toolboxWidth) {
widgetDiv.style.width = "";
Expand All @@ -256,16 +255,16 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
const blockLeft = workspaceToScreenCoordinates(block.workspace as Blockly.WorkspaceSvg,
new Blockly.utils.Coordinate(bounds.left, bounds.top));

if (blockLeft.x - divBounds.width - 20 > workspaceLeft) {
if (blockLeft.x - divBounds.width - 20 > toolboxWidth) {
widgetDiv.style.left = (blockLeft.x - divBounds.width - 20) + "px"
}
else {
// As a last resort, just center on the inject div
widgetDiv.style.left = (workspaceLeft + ((injectDivBounds.width - toolboxWidth) / 2) - divBounds.width / 2) + "px";
widgetDiv.style.left = (toolboxWidth + ((injectDivBounds.width - toolboxWidth) / 2) - divBounds.width / 2) + "px";
}
}
else if (divBounds.left < injectDivBounds.left) {
widgetDiv.style.left = workspaceLeft + "px"
widgetDiv.style.left = toolboxWidth + "px"
}
}

Expand Down
7 changes: 4 additions & 3 deletions pxtblocks/fields/field_ledmatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ export class FieldLedMatrix extends FieldMatrix implements FieldCustom {
this.selected = [0, 0];

const matrixRect = this.matrixSvg.getBoundingClientRect();
const injectDivBounds = (this.getSourceBlock().workspace as Blockly.WorkspaceSvg).getInjectionDiv().getBoundingClientRect();

const widgetDiv = Blockly.WidgetDiv.getDiv();
widgetDiv.append(this.matrixSvg);
this.addKeyboardFocusHandlers();

widgetDiv.style.left = matrixRect.left + "px";
widgetDiv.style.top = matrixRect.top + "px";
widgetDiv.style.left = matrixRect.left - injectDivBounds.left + "px";
widgetDiv.style.top = matrixRect.top - injectDivBounds.top + "px";
widgetDiv.style.transform = `scale(${(Blockly.getMainWorkspace() as Blockly.WorkspaceSvg).getScale()})`;
widgetDiv.style.transformOrigin = "0 0";

Expand Down Expand Up @@ -486,4 +487,4 @@ Blockly.Css.register(`
}
.blocklyFieldLedMatrixGroup > .blocklyFieldRect {
fill: none !important;
}`);
}`);
7 changes: 3 additions & 4 deletions pxtblocks/fields/field_sound_effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,13 @@ export class FieldSoundEffect extends FieldBase<FieldSoundEffectParams> {
const blockLeft = workspaceToScreenCoordinates(block.workspace as Blockly.WorkspaceSvg,
new Blockly.utils.Coordinate(bounds.left, bounds.top));

const workspaceLeft = injectDivBounds.left + toolboxWidth;

if (blockLeft.x - divBounds.width - 20 > workspaceLeft) {
if (blockLeft.x - divBounds.width - 20 > toolboxWidth) {
widgetDiv.style.left = (blockLeft.x - divBounds.width - 20) + "px"
}
else {
// As a last resort, just center on the inject div
widgetDiv.style.left = (workspaceLeft + ((injectDivBounds.width - toolboxWidth) / 2) - divBounds.width / 2) + "px";
widgetDiv.style.left = (toolboxWidth + ((injectDivBounds.width - toolboxWidth) / 2) - divBounds.width / 2) + "px";
}
}
}
Expand Down Expand Up @@ -442,4 +441,4 @@ function isTrue(value: any) {
}

return !!value;
}
}
14 changes: 3 additions & 11 deletions pxtblocks/fields/field_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,8 @@ export function workspaceToScreenCoordinates(ws: Blockly.WorkspaceSvg, wsCoordin
const clientOffsetPixels = Blockly.utils.Coordinate.sum(
scaledWS, mainOffsetPixels);


const injectionDiv = ws.getInjectionDiv();

// Bounding rect coordinates are in client coordinates, meaning that they
// are in pixels relative to the upper left corner of the visible browser
// window. These coordinates change when you scroll the browser window.
const boundingRect = injectionDiv.getBoundingClientRect();

return new Blockly.utils.Coordinate(clientOffsetPixels.x + boundingRect.left,
clientOffsetPixels.y + boundingRect.top)
return new Blockly.utils.Coordinate(clientOffsetPixels.x,
clientOffsetPixels.y)
}

export function getBlockData(block: Blockly.Block): PXTBlockData {
Expand Down Expand Up @@ -720,4 +712,4 @@ export function isImageProperties(obj: any): obj is Blockly.ImageProperties {
'height' in obj &&
typeof obj.height === 'number'
);
}
}
Loading
Loading