Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Set whether this block is a shadow block or not.
* @param {boolean} shadow True if a shadow.
*/
Blockly.Block.prototype.setShadow = function(shadow) {
if (this.isShadow_ != shadow) {
Blockly.Events.fire(new Blockly.Events.Change(
this, 'shadow', null, this.isShadow_, shadow));
this.isShadow_ = shadow;
}
};
/**
* Run a change event.
* @param {boolean} forward True if run forward, false if run backward (undo).
*/
Blockly.Events.Change.prototype.run = function(forward) {
var workspace = Blockly.Workspace.getById(this.workspaceId);
var block = workspace.getBlockById(this.blockId);
if (!block) {
console.warn("Can't change non-existant block: " + this.blockId);
return;
}
if (block.mutator) {
// Close the mutator (if open) since we don't want to update it.
block.mutator.setVisible(false);
}
var value = forward ? this.newValue : this.oldValue;
switch (this.element) {
case 'field':
var field = block.getField(this.name);
if (field) {
// Run the validator for any side-effects it may have.
this.workspace.addChangeListener((event) => {
if (event.type == Blockly.Events.BLOCK_MOVE) {
// update codinge state and remove block highlight
if (!this.isCoding) this.removeHighlight();
this.isCoding = true;
}
});
return function(e) {
if (Blockly.isRightButton(e)) {
// Right-click. Don't create a block, let the context menu show.
return;
}
if (originBlock.disabled) {
// Beyond capacity.
return;
}
Blockly.Events.disable();
// Create the new block by cloning the block in the flyout (via XML).
var xml = Blockly.Xml.blockToDom(originBlock);
var block = Blockly.Xml.domToBlock(xml, workspace);
block.setEditable(true);
block.setCollapsed(false);
// Place it in the same spot as the flyout copy.
var svgRootOld = originBlock.getSvgRoot();
if (!svgRootOld) {
throw 'originBlock is not rendered.';
}
var sourceXY = sourceBlock.getRelativeToSurfaceXY();
var fieldRelativeXY = Blockly.getRelativeXY_(svgRoot);
var originBlockXY = originBlock.getRelativeToSurfaceXY();
block.moveBy(
originBlockXY.x + sourceXY.x + fieldRelativeXY.x + FieldTable.translateX_,
// Place it in the same spot as the flyout copy.
var svgRootOld = originBlock.getSvgRoot();
if (!svgRootOld) {
throw 'originBlock is not rendered.';
}
var sourceXY = sourceBlock.getRelativeToSurfaceXY();
var fieldRelativeXY = Blockly.getRelativeXY_(svgRoot);
var originBlockXY = originBlock.getRelativeToSurfaceXY();
block.moveBy(
originBlockXY.x + sourceXY.x + fieldRelativeXY.x + FieldTable.translateX_,
originBlockXY.y + sourceXY.y + fieldRelativeXY.y + FieldTable.translateY_);
Blockly.Events.enable();
if (Blockly.Events.isEnabled()) {
Blockly.Events.setGroup(true);
Blockly.Events.fire(new Blockly.Events.Create(block));
}
if (flyout.autoClose) {
flyout.hide();
} else {
flyout.filterForCapacity_();
}
// Start a dragging operation on the new block.
block.onMouseDown_(e);
Blockly.dragMode_ = Blockly.DRAG_FREE;
block.setDragging_(true);
};
};
if (e.blockId == this.id && !this.usesPrefix_() && e.recordUndo
&& e.type == Blockly.Events.CHANGE && e.element == 'field') {
var luRes = Prefixes.lookForIri(e.newValue);
if (luRes) {
var oldMutation = Blockly.Xml.domToText(this.mutationToDom());
this.removeInput('RESOURCE');
this.appendDummyInput('RESOURCE')
.appendField(new Blockly.FieldTextInput(luRes.prefix), "PREFIX")
.appendField(":")
.appendField(new Blockly.FieldTextInput(luRes.localPart), "LOCAL_NAME");
var newMutation = Blockly.Xml.domToText(this.mutationToDom());
var mutationEvent = new Blockly.Events.Change(
this, 'mutation', null, oldMutation, newMutation);
var changePrefixEvent = new Blockly.Events.Change(
this, 'field', 'PREFIX', '', luRes.prefix);
var changeLocalEvent = new Blockly.Events.Change(
this, 'field', 'LOCAL_NAME', '', luRes.localPart);
mutationEvent.group = e.group;
changePrefixEvent.group = e.group;
changeLocalEvent.group = e.group;
Blockly.Events.fire(mutationEvent);
Blockly.Events.fire(changePrefixEvent);
Blockly.Events.fire(changeLocalEvent);
}
}
Resources.saveResource(this);
},
/**
onchange: function(e) {
if (e.blockId == this.id && !this.usesPrefix_() && e.recordUndo
&& e.type == Blockly.Events.CHANGE && e.element == 'field') {
var luRes = Prefixes.lookForIri(e.newValue);
if (luRes) {
var oldMutation = Blockly.Xml.domToText(this.mutationToDom());
this.removeInput('RESOURCE');
this.appendDummyInput('RESOURCE')
.appendField(new Blockly.FieldTextInput(luRes.prefix), "PREFIX")
.appendField(":")
.appendField(new Blockly.FieldTextInput(luRes.localPart), "LOCAL_NAME");
var newMutation = Blockly.Xml.domToText(this.mutationToDom());
var mutationEvent = new Blockly.Events.Change(
this, 'mutation', null, oldMutation, newMutation);
var changePrefixEvent = new Blockly.Events.Change(
this, 'field', 'PREFIX', '', luRes.prefix);
var changeLocalEvent = new Blockly.Events.Change(
this, 'field', 'LOCAL_NAME', '', luRes.localPart);
mutationEvent.group = e.group;
Blockly.Block.prototype.blockIsTargetOfConnection = function(childBlock, manageEvent) {
var noGroup = false;
if (Blockly.Events.recordUndo) {
if (Blockly.Events.isEnabled()) {
noGroup = true; //!Blockly.Events.getGroup();
Blockly.Events.setGroup(true);
}
morphShadowRec(this);
}
manageEvent();
if (noGroup) {
Blockly.Events.setGroup(false);
}
};
success: function(data) {
if (!data.length) {
MessageDisplay.alert(HASH_ERROR.replace('%1', window.location.hash), 'error');
if (_.isFunction(callback))
callback('Unknown error');
} else {
if (Blockly.Events.isEnabled()) {
Blockly.Events.setGroup(true);
var loadEvent = new Blockly.Events.Abstract(null);
loadEvent.type = "load-snapshot";
loadEvent.workspaceId = workspace.id;
loadEvent.value = key;
Blockly.Events.fire(loadEvent);
}
loadXml_(data, workspace);
MessageDisplay.alert("Workspace Loaded", "info");
if (Blockly.Events.isEnabled()) {
Blockly.Events.setGroup(false);
}
monitorChanges_(workspace);
if (_.isFunction(callback))
callback();
}
if (localStorage && !localStorage.clientId) {
localStorage.clientId = uuid.v4();
if (Blockly.Events.isEnabled()) {
var newClientEvent = new Blockly.Events.Abstract(null);
newClientEvent.type = "new-client";
newClientEvent.workspaceId = workspace.id;
Blockly.Events.fire(newClientEvent);
}
}
if (sessionStorage && !sessionStorage.sessionId) {
sessionStorage.sessionId = uuid.v4();
if (Blockly.Events.isEnabled()) {
var newSessionEvent = new Blockly.Events.Abstract(null);
newSessionEvent.type = "new-session";
newSessionEvent.workspaceId = workspace.id;
Blockly.Events.fire(newSessionEvent);
}
}
if (mode === "eval") {
var check = function(data) {
var block = SparqlBlocks.Guide.check(workspace, data.check);
if (block) {
if (block.getSvgRoot) {
data.focus = block.getSvgRoot();
} else if (block[0] && block[0].getSvgRoot) {
data.focus = block[0].getSvgRoot();
}
return true;
} else {
return false;
}
};
Blockly.Block.prototype.blockIsTargetOfConnection = function(childBlock, manageEvent) {
var noGroup = false;
if (Blockly.Events.recordUndo) {
if (Blockly.Events.isEnabled()) {
noGroup = true; //!Blockly.Events.getGroup();
Blockly.Events.setGroup(true);
}
morphShadowRec(this);
}
manageEvent();
if (noGroup) {
Blockly.Events.setGroup(false);
}
};