🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

react-blockly-component

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-blockly-component - npm Package Compare versions

Comparing version
3.1.1
to
3.2.0
+4
-0
CHANGELOG.md

@@ -0,1 +1,5 @@

# Version 3.2.0 - January 17, 2019
* Support parsing nested blocks (thanks @YuliyaBolbot!)
# Version 3.1.1 - October 15, 2018

@@ -2,0 +6,0 @@

@@ -80,26 +80,88 @@ /**

cNew.custom = c.custom;
cNew.blocks = [];
const blocks = c.block;
if (blocks) {
if (!(blocks instanceof Array)) {
cNew.blocks[0] = blocks;
}
for (let j = 0; j < blocks.length; j++) {
const b = blocks[j];
const bNew = {};
bNew.type = b.type;
bNew.fields = {};
const fields = b.field;
if (fields) {
for (let k = 0; k < fields.length; k++) {
const f = fields[k];
bNew.fields[k] = f;
}
}
cNew.blocks[j] = bNew;
}
if (c.block) {
cNew.blocks = parseBlocks(c.block);
}
filteredResult.push(cNew);
}
return filteredResult;
}
function parseBlocks(blocks) {
let arr = ensureArray(blocks);
const res = [];
arr.forEach(block => {
let obj = parseObject(block);
obj.type = block.type;
res.push(obj);
});
return res;
}
function parseFields(fields) {
let arr = ensureArray(fields);
const res = {};
arr.forEach(field => {
res[field.name] = field.value;
});
return res;
}
function parseValues(values) {
let arr = ensureArray(values);
const res = {};
arr.forEach(value => {
res[value.name] = parseObject(value);
});
return res;
}
function ensureArray(obj) {
if (obj instanceof Array) {
return obj;
}
return [obj];
}
function parseObject(obj) {
let res = {};
if (obj.shadow) {
res = parseObject(obj.shadow);
res.type = obj.shadow.type;
res.shadow = true;
} else if (obj.block) {
res = parseObject(obj.block);
res.type = obj.block.type;
res.shadow = false;
}
if (obj.mutation) {
res.mutation = {
attributes: obj.mutation,
innerContent: obj.mutation.value
};
}
if (obj.field) {
res.fields = parseFields(obj.field);
}
if (obj.value) {
res.values = parseValues(obj.value);
}
if (obj.next) {
res.next = parseObject(obj.next);
}
if (obj.statement) {
res.statements = {
[obj.statement.name]: parseObject(obj.statement)
};
}
return res;
}
+4
-4
{
"name": "react-blockly-component",
"version": "3.1.1",
"version": "3.2.0",
"description": "A React wrapper for the Blockly visual programming editor",

@@ -38,7 +38,7 @@ "main": "dist-modules",

"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.5.1",
"expose-loader": "^0.7.3",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"webpack": "^3.0",

@@ -45,0 +45,0 @@ "webpack-dev-server": "^2.9"

@@ -5,3 +5,3 @@ /**

export default function parseWorkspaceXml(xml) {
const arrayTags = ['name', 'custom', 'colour','categories', 'blocks'];
const arrayTags = ['name', 'custom', 'colour', 'categories', 'blocks'];
let xmlDoc = null;

@@ -81,26 +81,88 @@ if (window.DOMParser) {

cNew.custom = c.custom;
cNew.blocks = [];
const blocks = c.block;
if (blocks) {
if(!(blocks instanceof Array)){
cNew.blocks[0] = blocks;
}
for (let j = 0; j < blocks.length; j++) {
const b = blocks[j];
const bNew = {};
bNew.type = b.type;
bNew.fields = {};
const fields = b.field;
if (fields) {
for (let k = 0; k < fields.length; k++) {
const f = fields[k];
bNew.fields[k] = f;
}
}
cNew.blocks[j] = bNew;
}
if (c.block) {
cNew.blocks = parseBlocks(c.block);
}
filteredResult.push(cNew);
}
return filteredResult;
}
function parseBlocks(blocks) {
let arr = ensureArray(blocks);
const res = [];
arr.forEach(block => {
let obj = parseObject(block);
obj.type = block.type;
res.push(obj);
});
return res;
}
function parseFields(fields) {
let arr = ensureArray(fields);
const res = {};
arr.forEach(field => {
res[field.name] = field.value;
});
return res;
}
function parseValues(values) {
let arr = ensureArray(values);
const res = {};
arr.forEach(value => {
res[value.name] = parseObject(value);
});
return res;
}
function ensureArray(obj) {
if (obj instanceof Array) {
return obj;
}
return [obj];
}
function parseObject(obj) {
let res = {};
if (obj.shadow) {
res = parseObject(obj.shadow);
res.type = obj.shadow.type;
res.shadow = true;
} else if (obj.block) {
res = parseObject(obj.block);
res.type = obj.block.type;
res.shadow = false;
}
if (obj.mutation) {
res.mutation = {
attributes: obj.mutation,
innerContent: obj.mutation.value,
};
}
if (obj.field) {
res.fields = parseFields(obj.field);
}
if (obj.value) {
res.values = parseValues(obj.value);
}
if (obj.next) {
res.next = parseObject(obj.next);
}
if (obj.statement) {
res.statements = {
[obj.statement.name]: parseObject(obj.statement),
};
}
return res;
}