How to use the blockly.Xml function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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_,
        originBlockXY.y + sourceXY.y + fieldRelativeXY.y + FieldTable.translateY_);
    Blockly.Events.enable();
    if (Blockly.Events.isEnabled()) {
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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_,
        originBlockXY.y + sourceXY.y + fieldRelativeXY.y + FieldTable.translateY_);
    Blockly.Events.enable();
github miguel76 / SparqlBlocks / src / core / jsonToBlocks.js View on Github external
valueBlock.showTooltip = function() {
      var xmlBlock = Blockly.Xml.blockToDom_(valueBlock);
      xmlBlock.removeAttribute("editable");
      xmlBlock.removeAttribute("movable");
      xmlBlock.removeAttribute("deletable");
      duplicateBlock = Blockly.Xml.domToBlock(xmlBlock, workspace);
      duplicateBlock.isInFlyout = true;
      duplicateBlock.hideTooltip = function() {
        if (duplicateBlock) {
          duplicateBlock.dispose();
        }
      };
      Blockly.Tooltip.poisonedElement_ = Blockly.Tooltip.element_ = duplicateBlock;
      var mousedownEvent = Blockly.bindEvent_(
          duplicateBlock.getSvgRoot(),
          'mousedown', null,
          function(e) {
            if (Blockly.isRightButton(e)) {
              // Right-click.  Don't create a block, let the context menu show.
              return;
            }
            if (duplicateBlock.disabled) {
github binary-com / binary-bot / src / cat / bot / view / index.js View on Github external
return function (e) {
			try {
				blockly.mainWorkspace.clear();
				var xml = blockly.Xml.textToDom(e.target.result);
				blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
				botUtils.addPurchaseOptions();
				var tokenList = storageManager.getTokenList();
				if (tokenList.length !== 0) {
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setValue(tokenList[0].token);
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setText(tokenList[0].account_name);
				}
				blockly.mainWorkspace.clearUndo();
				blockly.mainWorkspace.zoomToFit();
				botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
			} catch (err) {
				botUtils.showError(err);
			}
github binary-com / binary-bot / src / ui.js View on Github external
return function (e) {
			try {
				blockly.mainWorkspace.clear();
				var xml = blockly.Xml.textToDom(e.target.result);
				blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
				view.addPurchaseOptions();
				var tokenList = storageManager.getTokenList();
				if (tokenList.length !== 0) {
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setValue(tokenList[0].token);
					blockly.mainWorkspace.getBlockById('trade')
						.getField('ACCOUNT_LIST')
						.setText(tokenList[0].account_name);
				}
				blockly.mainWorkspace.clearUndo();
				blockly.mainWorkspace.zoomToFit();
				utils.log(i18n._('Blocks are loaded successfully'), 'success');
			} catch (err) {
				utils.showError(err);
			}
github miguel76 / SparqlBlocks / src / core / storage.js View on Github external
var linkGist = function(opt_workspace, callback) {
  MessageDisplay.alert("Saving Workspace as Gist on GitHub...");
  var workspace = opt_workspace || Blockly.getMainWorkspace();
  var xml = Blockly.Xml.workspaceToDom(workspace);
  var data = Blockly.Xml.domToPrettyText(xml);
  var testState = TestBlocks && TestBlocks.getState();
  var metaData = _.extend(
    {
      generator: "SparqlBlocks",
      version: packageJson.version,
      baseURI: location.href,
      timestamp: $.now(),
      workspaceXmlFile: "workspace.xml"
    },
    workspace.eventStack ? {
      eventHistoryFile: "eventHistory.json"
    } : {},
    testState ? {
      testStateFile: "testState.json"
    } : {},
github miguel76 / SparqlBlocks / src / core / storage.js View on Github external
var bindData = workspace.addChangeListener( function (event) {
      var xmlDom = Blockly.Xml.workspaceToDom(workspace);
      var xmlText = Blockly.Xml.domToText(xmlDom);
      if (startXmlText != xmlText) {
        window.location.hash = '';
        $('#copy-button').prop('disabled', true);
        $('#save-button').prop('disabled', false);
        setTimeout( function() { workspace.removeChangeListener(bindData); });
      }
    });
  } );
github miguel76 / SparqlBlocks / src / blocks / resources.js View on Github external
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;
        changePrefixEvent.group = e.group;
        changeLocalEvent.group = e.group;
        Blockly.Events.fire(mutationEvent);
github Paol-imi / blockly-gamepad / src / gamepad.js View on Github external
save(name) {
        if (typeof (Storage) !== "undefined") {
            let xml = Blockly.Xml.workspaceToDom(this.workspace);
            localStorage.setItem(name, Blockly.Xml.domToText(xml));
        }
    }