Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rupato/bot 1987 update blockly to the latest version #45

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
3,350 changes: 1,725 additions & 1,625 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"postcss": "^8.4.38",
"prettier": "^3.1.0",
"raw-loader": "^4.0.2",
"rimraf": "^6.0.1",
"sass": "^1.77.6",
"sass-loader": "^14.2.1",
"sass-resources-loader": "^2.2.5",
Expand All @@ -140,4 +141,4 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
}
}
2 changes: 2 additions & 0 deletions src/components/blockly-loading/blockly-loading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
z-index: 99999;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: var(--overlay-outside-dialog);
pointer-events: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/flyout/help-contents/flyout-help-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const HelpBase = observer(() => {
className='flyout__button-add'
has_effect
id={`db-flyout-help__add--${block_type}`}
onClick={() => Blockly.derivWorkspace.addBlockNode(block_node)}
onClick={() => window.Blockly.derivWorkspace.addBlockNode(block_node)}
primary
text={localize('Add')}
type='button'
Expand Down
5 changes: 4 additions & 1 deletion src/components/layout/header/Notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const Notifications = () => {
const [isOpen, setIsOpen] = useState(false);
const { localize } = useTranslations();
const { isMobile } = useDevice();

return (
<div className='notifications__wrapper'>
<Tooltip
Expand All @@ -24,7 +25,6 @@ export const Notifications = () => {
'notifications__wrapper--mobile': isMobile,
'notifications__wrapper--desktop': !isMobile,
})}
clearNotificationsCallback={() => {}}
componentConfig={{
clearButtonText: localize('Clear all'),
modalTitle: localize('Notifications'),
Expand All @@ -34,6 +34,9 @@ export const Notifications = () => {
isOpen={isOpen}
notifications={[]}
setIsOpen={setIsOpen}
clearNotificationsCallback={() => {}}
loadMoreFunction={() => {}}
isLoading={false}
/>
</div>
);
Expand Down
53 changes: 16 additions & 37 deletions src/external/bot-skeleton/scratch/backward-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ export default class BlockConversion {

// eslint-disable-next-line class-methods-use-this
createWorkspace() {
const options = new window.window.window.Blockly.Options({
media: `${window.__webpack_public_path__}assets/media/`,
});
const options = new window.Blockly.Options({ media: `assets/images` });
const el_injection_div = new DocumentFragment();
const workspace = window.window.window.Blockly.createVirtualWorkspace_(el_injection_div, options, false, false);
const workspace = window.Blockly.createVirtualWorkspace_(el_injection_div, options, false, false);

return workspace;
}
Expand Down Expand Up @@ -358,8 +356,8 @@ export default class BlockConversion {
// For old "market" blocks, move everything in "Trade options" except "DURATION"
// to "Run once at start". Legacy "market" blocks had no such thing as "Run once at start"
// not moving everything would kill Martingale strategies as they'd be reinitialised each run.
const trade_definition_block = this.workspace.getTradeDefinitionBlock();
const has_initialization_block = trade_definition_block.getBlocksInStatement('INITIALIZATION').length > 0;
const trade_definition_block = this.workspace?.getTradeDefinitionBlock();
const has_initialization_block = trade_definition_block?.getBlocksInStatement('INITIALIZATION').length > 0;
if (trade_definition_block) {
trade_definition_block.getBlocksInStatement('SUBMARKET').forEach(block => {
if (
Expand All @@ -384,27 +382,22 @@ export default class BlockConversion {
current_name = variable_name + counter;
}

const ws_variable = window.window.window.Blockly.Variables.getOrCreateVariablePackage(
this.workspace,
'',
current_name,
''
);
const ws_variable = window.Blockly.Variables.getOrCreateVariablePackage(this.workspace, '', current_name, '');
this.workspace_variables[ws_variable.id_] = current_name; // eslint-disable-line

return ws_variable;
}

convertStrategy(strategy_node, showIncompatibleStrategyDialog) {
// Disable events (globally) to suppress block onchange listeners from firing.
window.window.window.Blockly.Events.disable();
window.Blockly.Events.disable();

// We only want to update renamed fields for modern strategies.
const xml = this.updateRenamedFields(strategy_node);

// Don't convert already compatible strategies.
if (strategy_node.hasAttribute('is_dbot') && strategy_node.getAttribute('is_dbot') === 'true') {
window.window.window.Blockly.Events.enable();
window.Blockly.Events.enable();
return xml;
}

Expand All @@ -418,8 +411,8 @@ export default class BlockConversion {
if (showIncompatibleStrategyDialog) {
showIncompatibleStrategyDialog();
}
window.window.window.Blockly.Events.enable();
return window.window.window.Blockly.utils.xml.textToDom('<xml />');
window.Blockly.Events.enable();
return window.Blockly.utils.xml.textToDom('<xml />');
}

const variable_nodes = [];
Expand Down Expand Up @@ -449,7 +442,7 @@ export default class BlockConversion {
const variable_name = el_variable.textContent;

if (!this.workspace_variables[variable_id]) {
const variable = window.window.window.Blockly.Variables.getOrCreateVariablePackage(
const variable = window.Blockly.Variables.getOrCreateVariablePackage(
this.workspace,
variable_id,
variable_name,
Expand Down Expand Up @@ -512,12 +505,12 @@ export default class BlockConversion {

this.workspace.getAllBlocks(true).forEach(block => {
block.initSvg();
// block.render();
block.renderEfficiently();
});

this.workspace.cleanUp();

const converted_xml = window.window.window.Blockly.Xml.workspaceToDom(this.workspace);
const converted_xml = window.Blockly.Xml.workspaceToDom(this.workspace);

if (strategy_node.hasAttribute('collection') && strategy_node.getAttribute('collection') === 'true') {
converted_xml.setAttribute('collection', 'true');
Expand All @@ -527,7 +520,7 @@ export default class BlockConversion {

this.workspace = null;

window.window.window.Blockly.Events.enable();
window.Blockly.Events.enable();

return converted_xml;
}
Expand Down Expand Up @@ -580,7 +573,7 @@ export default class BlockConversion {
});
}
} else {
const is_legal_block = Object.keys(window.window.window.Blockly.Blocks).includes(block_type);
const is_legal_block = Object.keys(window.Blockly.Blocks).includes(block_type);

if (is_legal_block) {
block = this.workspace.newBlock(block_type);
Expand Down Expand Up @@ -621,10 +614,10 @@ export default class BlockConversion {
const field = block.getField(field_name);

if (field) {
if (field instanceof window.window.window.Blockly.FieldVariable) {
if (field instanceof window.Blockly.FieldVariable) {
const variable_id = el_block_child.getAttribute('id');
const variable_name = el_block_child.innerText.trim();
const variable = window.window.window.Blockly.Variables.getOrCreateVariablePackage(
const variable = window.Blockly.Variables.getOrCreateVariablePackage(
this.workspace,
variable_id,
variable_name,
Expand Down Expand Up @@ -661,20 +654,6 @@ export default class BlockConversion {
}
break;
}
case 'comment': {
const is_minimised = el_block_child.getAttribute('pinned') !== 'true';
const comment_text = el_block_child.innerText;

block.comment = new window.window.window.Blockly.WorkspaceComment(
this.workspace,
comment_text,
0,
0,
is_minimised
);
block.comment.iconXY_ = { x: 0, y: 0 };
break;
}
default:
break;
}
Expand Down
29 changes: 26 additions & 3 deletions src/external/bot-skeleton/scratch/blockly.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import * as BlocklyJavaScript from 'blockly/javascript';
import goog from '@/utils/tmp/goog-helper';
import { setColors } from './hooks/colours';
import { localize } from '@/utils/tmp/dummy';
import { setColors } from './hooks/colours.js';
import goog from './goog.js';

window.goog = goog;

const modifyBlocklyWorkSpaceContextMenu = () => {
const exclude_item = ['blockInline'];
exclude_item.forEach(item_id => {
const option = window.Blockly.ContextMenuRegistry.registry.getItem(item_id);
option.preconditionFn = () => 'hidden';
});

const items_to_localize = {
undoWorkspace: localize('Undo'),
redoWorkspace: localize('Redo'),
cleanWorkspace: localize('Clean up Blocks'),
collapseWorkspace: localize('Collapse Blocks'),
expandWorkspace: localize('Expand Blocks'),
};

Object.keys(items_to_localize).forEach(item_id => {
const option = window.Blockly.ContextMenuRegistry.registry.getItem(item_id);
option.displayText = localize(items_to_localize[item_id]);
});
};

export const loadBlockly = async isDarkMode => {
const BlocklyModule = await import('blockly');
window.Blockly = BlocklyModule.default;
Expand All @@ -18,7 +40,8 @@ export const loadBlockly = async isDarkMode => {
base: window.Blockly.Themes.Zelos,
componentStyles: {},
});
modifyBlocklyWorkSpaceContextMenu();
setColors(isDarkMode);
await import('./hooks/index.js');
await import('./blocks');
await import('./hooks');
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { localize } from '@deriv-com/translations';
import { localize } from '@/utils/tmp/dummy';
import { modifyContextMenu } from '../../../utils';

window.Blockly.Blocks.procedures_callnoreturn = {
init() {
Expand Down Expand Up @@ -55,7 +56,7 @@ window.Blockly.Blocks.procedures_callnoreturn = {
* @this window.Blockly.Block
*/
onchange(event) {
if (!this.workspace || window.Blockly.derivWorkspace.isFlyout_) {
if (!this.workspace || window.Blockly.derivWorkspace.isFlyoutVisible) {
// Block is deleted or is in a flyout.
return;
}
Expand Down Expand Up @@ -315,6 +316,7 @@ window.Blockly.Blocks.procedures_callnoreturn = {
* @this window.Blockly.Block
*/
customContextMenu(options) {
modifyContextMenu(options);
const name = this.getProcedureCall();
const { workspace } = this;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localize } from '@deriv-com/translations';
import { removeExtraInput } from '../../../utils';
import { localize } from '@/utils/tmp/dummy';
import { modifyContextMenu, removeExtraInput } from '../../../utils';
import { plusIconLight } from '../../images';

window.Blockly.Blocks.procedures_defnoreturn = {
Expand All @@ -10,6 +10,10 @@ window.Blockly.Blocks.procedures_defnoreturn = {
this.timeout_id;
this.jsonInit(this.definition());

if (window.Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT) {
this.setCommentText(window.Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT);
}

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(window.Blockly.Procedures.rename);
Expand Down Expand Up @@ -80,10 +84,10 @@ window.Blockly.Blocks.procedures_defnoreturn = {
window.Blockly.Events.BLOCK_CHANGE,
];

if (!this.workspace || window.Blockly.derivWorkspace.isFlyout_ || !allowedEvents.includes(event.type)) {
if (!this.workspace || window.Blockly.derivWorkspace.isFlyoutVisible || !allowedEvents.includes(event.type)) {
return;
}
if (event.type === window.Blockly.Events.BLOCK_CHANGE) {
if (event.type === window.Blockly.Events.BLOCK_CREATE || window.Blockly.Events.BLOCK_CHANGE) {
// Sync names between definition- and execution-block
if (event.blockId === this.id && event.name === 'NAME') {
this.getProcedureCallers().forEach(block => {
Expand All @@ -98,7 +102,7 @@ window.Blockly.Blocks.procedures_defnoreturn = {
* @this window.Blockly.Block
*/
onAddClick() {
if (this.is_adding || this.workspace.options.readOnly || window.Blockly.derivWorkspace.isFlyout_) {
if (this.is_adding || this.workspace.options.readOnly || window.Blockly.derivWorkspace.isFlyoutVisible) {
return;
}

Expand Down Expand Up @@ -287,7 +291,8 @@ window.Blockly.Blocks.procedures_defnoreturn = {
* @this window.Blockly.Block
*/
customContextMenu(options) {
if (window.Blockly.derivWorkspace.isFlyout_) {
modifyContextMenu(options);
if (window.Blockly.derivWorkspace.isFlyoutVisible) {
return;
}
// Add option to create caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ window.Blockly.Blocks.procedures_defreturn = {
this.argument_var_models = [];

this.jsonInit(this.definition());

if (window.Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT) {
this.setCommentText(window.Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT);
}

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(window.Blockly.Procedures.rename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ window.Blockly.Blocks.procedures_ifreturn = {
this.hasReturnValue = true;
}

if (!window.Blockly.derivWorkspace.isFlyout_) {
if (!window.Blockly.derivWorkspace.isFlyoutVisible) {
this.setDisabled(false);
}
} else if (!window.Blockly.derivWorkspace.isFlyout_ && !this.getInheritedDisabled()) {
} else if (!window.Blockly.derivWorkspace.isFlyoutVisible && !this.getInheritedDisabled()) {
this.setDisabled(true);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localize } from '@deriv-com/translations';
import { runGroupedEvents, runIrreversibleEvents } from '../../../utils';
import { localize } from '@/utils/tmp/dummy';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
import { plusIconDark } from '../../images';

window.Blockly.Blocks.lists_create_with = {
Expand Down Expand Up @@ -45,7 +45,7 @@ window.Blockly.Blocks.lists_create_with = {
};
},
onIconClick() {
if (this.workspace.options.readOnly || window.Blockly.derivWorkspace.isFlyout_) {
if (this.workspace.options.readOnly || window.Blockly.derivWorkspace.isFlyoutVisible) {
return;
}

Expand All @@ -61,7 +61,7 @@ window.Blockly.Blocks.lists_create_with = {
});
},
onchange(event) {
if (!this.workspace || window.Blockly.derivWorkspace.isFlyout_ || this.workspace.isDragging()) {
if (!this.workspace || window.Blockly.derivWorkspace.isFlyoutVisible || this.workspace.isDragging()) {
return;
}

Expand All @@ -77,6 +77,9 @@ window.Blockly.Blocks.lists_create_with = {
});
}
},
customContextMenu(menu) {
modifyContextMenu(menu);
},
};

// Head's up! This is also the code generation for the "text_join" block.
Expand Down
Loading
Loading