From 211263f6cf585ce22ef9e1a57d1e7a8dd7f5b1a7 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Thu, 1 Aug 2024 10:41:34 -0400 Subject: [PATCH 01/13] work in progress for charAt --- src/blocks2tree.js | 19 +++++++++- src/newBlocks.js | 86 ++++++++++++++++++++++++++++------------------ src/toolbox.js | 67 ++++++++++++++++++++++++++---------- src/tree2blocks.js | 10 ++++++ 4 files changed, 129 insertions(+), 53 deletions(-) diff --git a/src/blocks2tree.js b/src/blocks2tree.js index 71dec56..1ec403f 100644 --- a/src/blocks2tree.js +++ b/src/blocks2tree.js @@ -1,5 +1,5 @@ import Blockly from 'blockly'; -import { NODETYPES, TYPES } from './common'; +import { NODETYPES, StringFuncs, TYPES } from './common'; function containsOnlyNumbers(str) { return /^-?\d+$/.test(str); @@ -649,5 +649,22 @@ export const makeGenerator = () => { }) } + praxlyGenerator['praxly_charAt_block'] = (block) => { + const procedureName = StringFuncs.CHARAT; + const expression = block.getInputTargetBlock('EXPRESSION'); + const index = block.getInputTargetBlock('INDEX'); + return customizeMaybe(block, { + blockID: block.id, + name : procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: praxlyGenerator[index.type](index), + type: NODETYPES.FUNCCALL + } + }); + } + return praxlyGenerator; } diff --git a/src/newBlocks.js b/src/newBlocks.js index e38f8e6..3cd7a31 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -145,39 +145,6 @@ export function definePraxlyBlocks(workspace) { "tooltip": "Blank line in the code", "helpUrl": "" }, - { // common 6 - "type": "praxly_StringFunc_block", - "message0": "%1.%2(%3)", - "args0": [ - { - "type": "input_value", - "name": "EXPRESSION" - }, - { - "type": "field_dropdown", - "name": "FUNCTYPE", - "options": [ - ["charAt", StringFuncs.CHARAT], - ["contains", StringFuncs.CONTAINS], - ['indexOf', StringFuncs.INDEXOF], - ["length", StringFuncs.LENGTH], - ["substring", StringFuncs.SUBSTRING], - ["toLowerCase", StringFuncs.TOLOWERCSE], - ["toUpperCase", StringFuncs.TOUPPERCASE], - ] - }, - { - "type": "input_value", - "name": "PARAMS", - "text": "params" - }, - ], - "inputsInline": true, - "output": null, - "style": 'other_blocks', - "tooltip": "String methods:\ncharAt(i) - Returns the character at index i\ncontains(s) - Returns true if s is a substring\nindexOf(s) - Returns the first index of substring s, or -1 if not found\nlength() - Returns the length of the string\nsubstring(i, j) - Extracts characters from index i up to but not including index j\ntoLowerCase() - Converts the string to all lowercase\ntoUpperCase() - Converts the string to all uppercase", - "helpUrl": "" - }, { // variables 1 "type": "praxly_vardecl_block", "message0": "%1%2%3", @@ -614,6 +581,59 @@ export function definePraxlyBlocks(workspace) { "tooltip": "Calculates the square root", "helpURL": "" }, + { // text 1 + "type": "praxly_StringFunc_block", + "message0": "%1.%2(%3)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "field_dropdown", + "name": "FUNCTYPE", + "options": [ + ["charAt", StringFuncs.CHARAT], + ["contains", StringFuncs.CONTAINS], + ['indexOf', StringFuncs.INDEXOF], + ["length", StringFuncs.LENGTH], + ["substring", StringFuncs.SUBSTRING], + ["toLowerCase", StringFuncs.TOLOWERCSE], + ["toUpperCase", StringFuncs.TOUPPERCASE], + ] + }, + { + "type": "input_value", + "name": "PARAMS", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "String methods:\ncharAt(i) - Returns the character at index i\ncontains(s) - Returns true if s is a substring\nindexOf(s) - Returns the first index of substring s, or -1 if not found\nlength() - Returns the length of the string\nsubstring(i, j) - Extracts characters from index i up to but not including index j\ntoLowerCase() - Converts the string to all lowercase\ntoUpperCase() - Converts the string to all uppercase", + "helpUrl": "" + }, + { // text 1 + "type": "praxly_charAt_block", + "message0": "%1.charAt (%2)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "input_value", + "name": "INDEX", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the character at index i", + "helpUrl": "" + }, { // logic 1 "type": "praxly_true_block", "message0": "true", diff --git a/src/toolbox.js b/src/toolbox.js index 86b4759..cbd4784 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -39,25 +39,6 @@ export const toolbox = { 'kind': 'block', 'type': 'praxly_emptyline_block' }, - { - 'kind': 'block', - 'type': 'praxly_StringFunc_block', - 'inputs': { - 'EXPRESSION': { - 'shadow': { - 'type': 'praxly_literal_block', - 'fields': { - 'LITERAL': '\"hello, world\"', - } - }, - }, - 'PARAMS': { - 'block': { - 'type': 'praxly_parameter_block', - } - } - } - } ] }, { @@ -339,6 +320,54 @@ export const toolbox = { } ] }, + { + "kind": "category", + "name": "text", + "categorystyle": "class_blocks", + "contents": [ + { + 'kind': 'block', + 'type': 'praxly_StringFunc_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + }, + 'PARAMS': { + 'block': { + 'type': 'praxly_parameter_block', + } + } + } + }, + { + 'kind': 'block', + 'type': 'praxly_charAt_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'Literal': '\"hello, world\"', + } + }, + }, + 'INDEX': { + 'block': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 0 + } + } + } + } + } + ] + }, { "kind": "category", "name": "logic", diff --git a/src/tree2blocks.js b/src/tree2blocks.js index 2a5e597..42b899c 100644 --- a/src/tree2blocks.js +++ b/src/tree2blocks.js @@ -327,6 +327,16 @@ export const tree2blocks = (workspace, node) => { break; case NODETYPES.SPECIAL_STRING_FUNCCALL: + + if (node.name === 'charAt') { + result = workspace.newBlock('praxly_charAt_block'); + var recipient = tree2blocks(workspace, node.left); // left side + const child = tree2blocks(workspace, node?.args); + result.getInput('INDEX').connection.connect(child?.outputConnection); + result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + } + + var result = workspace.newBlock('praxly_StringFunc_block'); var params = workspace.newBlock('praxly_parameter_block'); var recipient = tree2blocks(workspace, node.left); From 9dcbba6314430d2e92cddf92c3e9797328a40607 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Thu, 1 Aug 2024 12:10:11 -0400 Subject: [PATCH 02/13] current charAt/contains block --- src/blocks2tree.js | 47 +++++++++++++++++++++++----------- src/newBlocks.js | 64 ++++++++++++++++++++++++++++++---------------- src/toolbox.js | 38 +++++++++++++++++++++------ src/tree2blocks.js | 32 +++++++++++++---------- 4 files changed, 123 insertions(+), 58 deletions(-) diff --git a/src/blocks2tree.js b/src/blocks2tree.js index 1ec403f..24de151 100644 --- a/src/blocks2tree.js +++ b/src/blocks2tree.js @@ -628,39 +628,56 @@ export const makeGenerator = () => { }) } - praxlyGenerator['praxly_StringFunc_block'] = (block) => { + // praxlyGenerator['praxly_StringFunc_block'] = (block) => { + // const expression = block.getInputTargetBlock('EXPRESSION'); + // var procedureName = block.getFieldValue('FUNCTYPE'); + // var args = block.getInputTargetBlock('PARAMS'); + // var argschildren = args.getChildren(true); + // var argsList = []; + // argschildren.forEach(element => { + // argsList.push(praxlyGenerator[element.type](element)); + // }); + // return customizeMaybe(block, { + // blockID: block.id, + // type: NODETYPES.SPECIAL_STRING_FUNCCALL, + // left: praxlyGenerator[expression.type](expression), + // right: { + // name: procedureName, + // args: argsList, + // type: NODETYPES.FUNCCALL + // } + // }); + // } + + praxlyGenerator['praxly_charAt_block'] = (block) => { + const procedureName = StringFuncs.CHARAT; const expression = block.getInputTargetBlock('EXPRESSION'); - var procedureName = block.getFieldValue('FUNCTYPE'); - var args = block.getInputTargetBlock('PARAMS'); - var argschildren = args.getChildren(true); - var argsList = []; - argschildren.forEach(element => { - argsList.push(praxlyGenerator[element.type](element)); - }); + const index = block.getInputTargetBlock('INDEX'); return customizeMaybe(block, { blockID: block.id, + name : procedureName, type: NODETYPES.SPECIAL_STRING_FUNCCALL, left: praxlyGenerator[expression.type](expression), right: { name: procedureName, - args: argsList, + args: [praxlyGenerator[index.type](index)], type: NODETYPES.FUNCCALL } - }) + }); } - praxlyGenerator['praxly_charAt_block'] = (block) => { - const procedureName = StringFuncs.CHARAT; + praxlyGenerator['praxly_contains_block'] = (block) => { + const procedureName = StringFuncs.CONTAINS; const expression = block.getInputTargetBlock('EXPRESSION'); - const index = block.getInputTargetBlock('INDEX'); + const param = block.getInputTargetBlock('PARAM'); return customizeMaybe(block, { blockID: block.id, - name : procedureName, + name: procedureName, type: NODETYPES.SPECIAL_STRING_FUNCCALL, left: praxlyGenerator[expression.type](expression), right: { name: procedureName, - args: praxlyGenerator[index.type](index), + args: [praxlyGenerator[param.type](param)], type: NODETYPES.FUNCCALL } }); diff --git a/src/newBlocks.js b/src/newBlocks.js index 3cd7a31..020c456 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -581,42 +581,62 @@ export function definePraxlyBlocks(workspace) { "tooltip": "Calculates the square root", "helpURL": "" }, + // { // text 1 + // "type": "praxly_StringFunc_block", + // "message0": "%1.%2(%3)", + // "args0": [ + // { + // "type": "input_value", + // "name": "EXPRESSION" + // }, + // { + // "type": "field_dropdown", + // "name": "FUNCTYPE", + // "options": [ + // ["charAt", StringFuncs.CHARAT], + // ["contains", StringFuncs.CONTAINS], + // ['indexOf', StringFuncs.INDEXOF], + // ["length", StringFuncs.LENGTH], + // ["substring", StringFuncs.SUBSTRING], + // ["toLowerCase", StringFuncs.TOLOWERCSE], + // ["toUpperCase", StringFuncs.TOUPPERCASE], + // ] + // }, + // { + // "type": "input_value", + // "name": "PARAMS", + // "text": "params" + // }, + // ], + // "inputsInline": true, + // "output": null, + // "style": 'other_blocks', + // "tooltip": "String methods:\ncharAt(i) - Returns the character at index i\ncontains(s) - Returns true if s is a substring\nindexOf(s) - Returns the first index of substring s, or -1 if not found\nlength() - Returns the length of the string\nsubstring(i, j) - Extracts characters from index i up to but not including index j\ntoLowerCase() - Converts the string to all lowercase\ntoUpperCase() - Converts the string to all uppercase", + // "helpUrl": "" + // }, { // text 1 - "type": "praxly_StringFunc_block", - "message0": "%1.%2(%3)", + "type": "praxly_charAt_block", + "message0": "%1.charAt (%2)", "args0": [ { "type": "input_value", "name": "EXPRESSION" }, - { - "type": "field_dropdown", - "name": "FUNCTYPE", - "options": [ - ["charAt", StringFuncs.CHARAT], - ["contains", StringFuncs.CONTAINS], - ['indexOf', StringFuncs.INDEXOF], - ["length", StringFuncs.LENGTH], - ["substring", StringFuncs.SUBSTRING], - ["toLowerCase", StringFuncs.TOLOWERCSE], - ["toUpperCase", StringFuncs.TOUPPERCASE], - ] - }, { "type": "input_value", - "name": "PARAMS", + "name": "INDEX", "text": "params" }, ], "inputsInline": true, "output": null, "style": 'other_blocks', - "tooltip": "String methods:\ncharAt(i) - Returns the character at index i\ncontains(s) - Returns true if s is a substring\nindexOf(s) - Returns the first index of substring s, or -1 if not found\nlength() - Returns the length of the string\nsubstring(i, j) - Extracts characters from index i up to but not including index j\ntoLowerCase() - Converts the string to all lowercase\ntoUpperCase() - Converts the string to all uppercase", + "tooltip": "Returns the character at index i", "helpUrl": "" }, - { // text 1 - "type": "praxly_charAt_block", - "message0": "%1.charAt (%2)", + { // text 2 + "type": "praxly_contains_block", + "message0": "%1.contains (%2)", "args0": [ { "type": "input_value", @@ -624,14 +644,14 @@ export function definePraxlyBlocks(workspace) { }, { "type": "input_value", - "name": "INDEX", + "name": "PARAM", "text": "params" }, ], "inputsInline": true, "output": null, "style": 'other_blocks', - "tooltip": "Returns the character at index i", + "tooltip": "Returns true if value is a substring", "helpUrl": "" }, { // logic 1 diff --git a/src/toolbox.js b/src/toolbox.js index cbd4784..8178fee 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -325,9 +325,28 @@ export const toolbox = { "name": "text", "categorystyle": "class_blocks", "contents": [ + // { + // 'kind': 'block', + // 'type': 'praxly_StringFunc_block', + // 'inputs': { + // 'EXPRESSION': { + // 'shadow': { + // 'type': 'praxly_literal_block', + // 'fields': { + // 'LITERAL': '\"hello, world\"', + // } + // }, + // }, + // 'PARAMS': { + // 'block': { + // 'type': 'praxly_parameter_block', + // } + // } + // } + // }, { 'kind': 'block', - 'type': 'praxly_StringFunc_block', + 'type': 'praxly_charAt_block', 'inputs': { 'EXPRESSION': { 'shadow': { @@ -337,35 +356,38 @@ export const toolbox = { } }, }, - 'PARAMS': { + 'INDEX': { 'block': { - 'type': 'praxly_parameter_block', + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 0 + } } } } }, { 'kind': 'block', - 'type': 'praxly_charAt_block', + 'type': 'praxly_contains_block', 'inputs': { 'EXPRESSION': { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'Literal': '\"hello, world\"', + 'LITERAL': '\"hello, world\"', } }, }, - 'INDEX': { + 'PARAM': { 'block': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 0 + 'LITERAL': 'value' } } } } - } + } ] }, { diff --git a/src/tree2blocks.js b/src/tree2blocks.js index 42b899c..4dd6ace 100644 --- a/src/tree2blocks.js +++ b/src/tree2blocks.js @@ -334,22 +334,28 @@ export const tree2blocks = (workspace, node) => { const child = tree2blocks(workspace, node?.args); result.getInput('INDEX').connection.connect(child?.outputConnection); result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + } else if (node.name === 'contains') { + result = workspace.newBlock('praxly_contains_block'); + var recipient = tree2blocks(workspace, node.left); // left side + const child = tree2blocks(workspace, node?.args); + result.getInput('PARAM').connection.connect(child?.outputConnection); + result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); } - var result = workspace.newBlock('praxly_StringFunc_block'); - var params = workspace.newBlock('praxly_parameter_block'); - var recipient = tree2blocks(workspace, node.left); - result.setFieldValue(node?.right?.name, 'FUNCTYPE'); - result.getInput('PARAMS').connection.connect(params?.outputConnection); - var argsList = node?.right?.args; - for (var i = 0; i < (argsList?.length ?? 0); i++) { - params.appendValueInput(`PARAM_${i}`); - var argument = tree2blocks(workspace, argsList[i]); - params.getInput(`PARAM_${i}`).connection.connect(argument?.outputConnection); - } - result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - params.initSvg(); + // var result = workspace.newBlock('praxly_StringFunc_block'); + // var params = workspace.newBlock('praxly_parameter_block'); + // var recipient = tree2blocks(workspace, node.left); + // result.setFieldValue(node?.right?.name, 'FUNCTYPE'); + // result.getInput('PARAMS').connection.connect(params?.outputConnection); + // var argsList = node?.right?.args; + // for (var i = 0; i < (argsList?.length ?? 0); i++) { + // params.appendValueInput(`PARAM_${i}`); + // var argument = tree2blocks(workspace, argsList[i]); + // params.getInput(`PARAM_${i}`).connection.connect(argument?.outputConnection); + // } + // result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + // params.initSvg(); break; From a867f9ddbfa2c229f32b6542392817dba6cc0e03 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Thu, 1 Aug 2024 15:52:51 -0400 Subject: [PATCH 03/13] consistency changes to variables, new numbers for builtins, no more empty spaces --- src/newBlocks.js | 6 ++-- src/toolbox.js | 73 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/newBlocks.js b/src/newBlocks.js index 020c456..0930a6b 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -165,7 +165,7 @@ export function definePraxlyBlocks(workspace) { { "type": "field_input", "name": "VARIABLENAME", - "text": "VariableName" + "text": "variableName" }, { "type": "input_dummy" @@ -198,7 +198,7 @@ export function definePraxlyBlocks(workspace) { { "type": "field_input", "name": "VARIABLENAME", - "text": "VariableName" + "text": "variableName" }, { "type": "input_value", @@ -222,7 +222,7 @@ export function definePraxlyBlocks(workspace) { { "type": "field_input", "name": "VARIABLENAME", - "text": "VariableName" + "text": "variableName" }, { "type": "input_value", diff --git a/src/toolbox.js b/src/toolbox.js index 8178fee..d4758c3 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -62,7 +62,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 0, + 'LITERAL': 'value', } }, }, @@ -74,9 +74,9 @@ export const toolbox = { 'inputs': { 'EXPRESSION': { 'shadow': { - 'type': 'praxly_literal_block', + 'type': 'praxly_variable_block', 'fields': { - 'LITERAL': 0, + 'LITERAL': 'value', } }, }, @@ -101,10 +101,18 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '0', + 'LITERAL': 'index', } }, }, + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 'value' + } + } + } } }, { @@ -115,7 +123,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '0', + 'LITERAL': 'index', } }, }, @@ -284,7 +292,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 1 + 'LITERAL': -5 } } } @@ -298,7 +306,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 1 + 'LITERAL': 2.718 } } } @@ -312,7 +320,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 1 + 'LITERAL': 25 } } } @@ -405,11 +413,25 @@ export const toolbox = { }, { 'kind': 'block', - 'type': 'praxly_if_block' + 'type': 'praxly_if_block', + 'inputs': { + 'CONDITION': { + 'shadow': { + 'type': 'praxly_true_block' + } + } + } }, { 'kind': 'block', - 'type': 'praxly_if_else_block' + 'type': 'praxly_if_else_block', + 'inputs': { + 'CONDITION': { + 'shadow': { + 'type': 'praxly_true_block' + } + } + } }, { 'kind': 'block', @@ -417,25 +439,26 @@ export const toolbox = { 'inputs': { 'A_OPERAND': { 'shadow': { - 'type': 'praxly_literal_block', - 'fields': { - 'LITERAL': true, - } + 'type': 'praxly_true_block', }, }, 'B_OPERAND': { 'shadow': { - 'type': 'praxly_literal_block', - 'fields': { - 'LITERAL': false, - } + 'type': 'praxly_false_block', }, } } }, { 'kind': 'block', - 'type': 'praxly_not_block' + 'type': 'praxly_not_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_true_block' + } + } + } }, { 'kind': 'block', @@ -706,7 +729,17 @@ export const toolbox = { }, { 'kind': 'block', - 'type': 'praxly_return_block' + 'type': 'praxly_return_block', + 'inputs': { + 'EXPRESSION': { + 'block': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': "value" + } + } + } + } }, { 'kind': 'block', From 711ac9cb56ccdc93daa8cce6c6688264428b6220 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Fri, 2 Aug 2024 10:10:48 -0400 Subject: [PATCH 04/13] adding more blocks for string functions --- src/blocks2tree.js | 28 ++++++++++++++ src/newBlocks.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++ src/toolbox.js | 36 ++++++++++++++++++ src/tree2blocks.js | 22 +++++++++-- 4 files changed, 178 insertions(+), 3 deletions(-) diff --git a/src/blocks2tree.js b/src/blocks2tree.js index 24de151..9f951e8 100644 --- a/src/blocks2tree.js +++ b/src/blocks2tree.js @@ -683,5 +683,33 @@ export const makeGenerator = () => { }); } + praxlyGenerator['praxly_indexOf_block'] = (block) => { + const procedureName = StringFuncs.INDEXOF; + const expression = block.getInputTargetBlock('EXPRESSION'); + const param = block.getInputTargetBlock('PARAM'); + return customizeMaybe(block, { + blockID: block.id, + name: procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: [[praxlyGenerator[param.type](param)]], + type: NODETYPES.FUNCCALL + } + }); + } + + praxlyGenerator['praxly_length_block'] = (block) => { + const procedureName = StringFuncs.LENGTH; + const expression = block.getInputTargetBlock('EXPRESSION'); + return customizeMaybe(block, { + blockID: block.id, + name: procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + }); + } + return praxlyGenerator; } diff --git a/src/newBlocks.js b/src/newBlocks.js index 0930a6b..3b3517a 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -654,6 +654,101 @@ export function definePraxlyBlocks(workspace) { "tooltip": "Returns true if value is a substring", "helpUrl": "" }, + { // text 3 + "type": "praxly_indexOf_block", + "message0": "%1.indexOf (%2)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "input_value", + "name": "PARAM", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the first index of substring value, or -1 if not found", + "helpUrl": "" + }, + { // text 4 + "type": "praxly_length_block", + "message0": "%1.length ( )", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the length of the string", + "helpUrl": "" + }, + { // text 5 + "type": "praxly_substring_block", + "message0": "%1.substringÍ (%2)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "input_value", + "name": "PARAM", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the first index of substring value, or -1 if not found", + "helpUrl": "" + }, + { // text 6 + "type": "praxly_toLowerCase_block", + "message0": "%1.toLowerCase (%2)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "input_value", + "name": "PARAM", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the first index of substring value, or -1 if not found", + "helpUrl": "" + }, + { // text 7 + "type": "praxly_toUpperCase_block", + "message0": "%1.toUpperCase (%2)", + "args0": [ + { + "type": "input_value", + "name": "EXPRESSION" + }, + { + "type": "input_value", + "name": "PARAM", + "text": "params" + }, + ], + "inputsInline": true, + "output": null, + "style": 'other_blocks', + "tooltip": "Returns the first index of substring value, or -1 if not found", + "helpUrl": "" + }, { // logic 1 "type": "praxly_true_block", "message0": "true", diff --git a/src/toolbox.js b/src/toolbox.js index d4758c3..64f2cf7 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -395,6 +395,42 @@ export const toolbox = { } } } + }, + { + 'kind': 'block', + 'type': 'praxly_indexOf_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + }, + 'PARAM': { + 'block': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 'value' + } + } + } + } + }, + { + 'kind': 'block', + 'type': 'praxly_length_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + } + } } ] }, diff --git a/src/tree2blocks.js b/src/tree2blocks.js index 4dd6ace..485630a 100644 --- a/src/tree2blocks.js +++ b/src/tree2blocks.js @@ -1,4 +1,4 @@ -import { NODETYPES, TYPES } from "./common"; +import { NODETYPES, StringFuncs, TYPES } from "./common"; function connectStatements(statements) { for (let i = 0; i < statements.length - 1; i++) { @@ -330,16 +330,32 @@ export const tree2blocks = (workspace, node) => { if (node.name === 'charAt') { result = workspace.newBlock('praxly_charAt_block'); - var recipient = tree2blocks(workspace, node.left); // left side + var recipient = tree2blocks(workspace, node.left); const child = tree2blocks(workspace, node?.args); result.getInput('INDEX').connection.connect(child?.outputConnection); result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); } else if (node.name === 'contains') { result = workspace.newBlock('praxly_contains_block'); - var recipient = tree2blocks(workspace, node.left); // left side + var recipient = tree2blocks(workspace, node.left); const child = tree2blocks(workspace, node?.args); result.getInput('PARAM').connection.connect(child?.outputConnection); result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + } else if (node.name === 'indexOf') { + result = workspace.newBlock('praxly_indexOf_block'); + var recipient = tree2blocks(workspace, node.left); + const child = tree2blocks(workspace, node?.args); + result.getInput('PARAM').connection.connect(child?.outputConnection); + result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + } else if (node.name === 'length') { + result = workspace.newBlock('praxly_indexOf_block'); + var recipient = tree2blocks(workspace, node.left); + result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); + } else if (node.name === 'substring') { + + } else if (node.name === StringFuncs.TOLOWERCSE) { + + } else if (node.name === StringFuncs.TOUPPERCASE) { + } From b3d461372082b0b10d1e10b6dab93a833782312f Mon Sep 17 00:00:00 2001 From: ellonamac Date: Fri, 2 Aug 2024 10:55:00 -0400 Subject: [PATCH 05/13] string functions fully split and working BUT dissapearing~ --- src/blocks2tree.js | 52 ++++++++++++++++++++++++++++++++++++++++ src/newBlocks.js | 33 +++++++++++-------------- src/toolbox.js | 60 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 125 insertions(+), 20 deletions(-) diff --git a/src/blocks2tree.js b/src/blocks2tree.js index 9f951e8..455c4d5 100644 --- a/src/blocks2tree.js +++ b/src/blocks2tree.js @@ -708,6 +708,58 @@ export const makeGenerator = () => { name: procedureName, type: NODETYPES.SPECIAL_STRING_FUNCCALL, left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: [] + } + }); + } + + praxlyGenerator['praxly_substring_block'] = (block) => { + const procedureName = StringFuncs.SUBSTRING; + const expression = block.getInputTargetBlock('EXPRESSION'); + const param1 = block.getInputTargetBlock('PARAM1'); + const param2 = block.getInputTargetBlock('PARAM2'); + return customizeMaybe(block, { + blockID: block.id, + name: procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: [praxlyGenerator[param1.type](param1), praxlyGenerator[param2.type](param2)], + type: NODETYPES.FUNCCALL + } + }); + } + + praxlyGenerator['praxly_toLowerCase_block'] = (block) => { + const procedureName = StringFuncs.TOLOWERCSE; + const expression = block.getInputTargetBlock('EXPRESSION'); + return customizeMaybe(block, { + blockID: block.id, + name: procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: [] + } + }); + } + + praxlyGenerator['praxly_toUpperCase_block'] = (block) => { + const procedureName = StringFuncs.TOUPPERCASE; + const expression = block.getInputTargetBlock('EXPRESSION'); + return customizeMaybe(block, { + blockID: block.id, + name: procedureName, + type: NODETYPES.SPECIAL_STRING_FUNCCALL, + left: praxlyGenerator[expression.type](expression), + right: { + name: procedureName, + args: [] + } }); } diff --git a/src/newBlocks.js b/src/newBlocks.js index 3b3517a..ed9a2fb 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -691,7 +691,7 @@ export function definePraxlyBlocks(workspace) { }, { // text 5 "type": "praxly_substring_block", - "message0": "%1.substringÍ (%2)", + "message0": "%1.substring (%2 , %3)", "args0": [ { "type": "input_value", @@ -699,54 +699,49 @@ export function definePraxlyBlocks(workspace) { }, { "type": "input_value", - "name": "PARAM", + "name": "PARAM1", "text": "params" }, + { + "type": "input_value", + "name": "PARAM2", + "text": "params" + } ], "inputsInline": true, "output": null, "style": 'other_blocks', - "tooltip": "Returns the first index of substring value, or -1 if not found", + "tooltip": "Extracts characters from the start index up to but not including the end index", "helpUrl": "" }, { // text 6 "type": "praxly_toLowerCase_block", - "message0": "%1.toLowerCase (%2)", + "message0": "%1.toLowerCase ( )", "args0": [ { "type": "input_value", "name": "EXPRESSION" - }, - { - "type": "input_value", - "name": "PARAM", - "text": "params" - }, + } ], "inputsInline": true, "output": null, "style": 'other_blocks', - "tooltip": "Returns the first index of substring value, or -1 if not found", + "tooltip": "Converts the string to all lowercase", "helpUrl": "" }, { // text 7 "type": "praxly_toUpperCase_block", - "message0": "%1.toUpperCase (%2)", + "message0": "%1.toUpperCase ( )", "args0": [ { "type": "input_value", "name": "EXPRESSION" - }, - { - "type": "input_value", - "name": "PARAM", - "text": "params" - }, + } ], "inputsInline": true, "output": null, "style": 'other_blocks', - "tooltip": "Returns the first index of substring value, or -1 if not found", + "tooltip": "Converts the string to all uppercase", "helpUrl": "" }, { // logic 1 diff --git a/src/toolbox.js b/src/toolbox.js index 64f2cf7..1419a24 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -431,7 +431,65 @@ export const toolbox = { }, } } - } + }, + { + 'kind': 'block', + 'type': 'praxly_substring_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + }, + 'PARAM1': { + 'block': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 'indexStart' + } + } + }, + 'PARAM2': { + 'block': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': 'indexEnd' + } + } + } + } + }, + { + 'kind': 'block', + 'type': 'praxly_toLowerCase_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + }, + } + }, + { + 'kind': 'block', + 'type': 'praxly_toUpperCase_block', + 'inputs': { + 'EXPRESSION': { + 'shadow': { + 'type': 'praxly_literal_block', + 'fields': { + 'LITERAL': '\"hello, world\"', + } + }, + }, + } + }, ] }, { From 7dd989996ec2cab77bf1d4e0a78f01c483f01163 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Fri, 2 Aug 2024 12:37:59 -0400 Subject: [PATCH 06/13] finished and tested string methods blocks --- src/ast.js | 8 ++-- src/blocks2tree.js | 2 +- src/text2tree.js | 2 +- src/toolbox.js | 16 ++++---- src/tree2blocks.js | 92 ++++++++++++++++++++++++---------------------- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/ast.js b/src/ast.js index 178298b..92ca86f 100644 --- a/src/ast.js +++ b/src/ast.js @@ -1693,12 +1693,12 @@ class Praxly_String_funccall { case StringFuncs.CONTAINS: var char = await this.args[0].evaluate(environment); this.typecheckhelper(char, [TYPES.STRING, TYPES.CHAR]); - result = str.includes(char.value) + result = str.value.includes(char.value); return new Praxly_boolean(result); case StringFuncs.INDEXOF: - var index = await this.args[0].evaluate(environment); - this.typecheckhelper(char, [TYPES.CHAR]); - result = str.value.indexOf(index.value); + var substr = await this.args[0].evaluate(environment); + this.typecheckhelper(substr, [TYPES.STRING, TYPES.CHAR]); + result = str.value.indexOf(substr.value); return new Praxly_int(result); case StringFuncs.LENGTH: return new Praxly_int(str.value.length); diff --git a/src/blocks2tree.js b/src/blocks2tree.js index 455c4d5..2faeafc 100644 --- a/src/blocks2tree.js +++ b/src/blocks2tree.js @@ -694,7 +694,7 @@ export const makeGenerator = () => { left: praxlyGenerator[expression.type](expression), right: { name: procedureName, - args: [[praxlyGenerator[param.type](param)]], + args: [praxlyGenerator[param.type](param)], type: NODETYPES.FUNCCALL } }); diff --git a/src/text2tree.js b/src/text2tree.js index 5e7714d..d052a86 100644 --- a/src/text2tree.js +++ b/src/text2tree.js @@ -566,7 +566,7 @@ class Parser { line = this.getCurrentToken().line; this.advance(); const r = this.parse_expression(precedence); - if (r.type != NODETYPES.FUNCCALL) { + if (r?.type != NODETYPES.FUNCCALL) { textError('parsing', "classes are not fully supported yet. the right side of the . operator must be a supported string function", line); } l = { diff --git a/src/toolbox.js b/src/toolbox.js index 1419a24..fe68f64 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -17,7 +17,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"Hello, World!\"', } }, }, @@ -360,7 +360,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, @@ -382,7 +382,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, @@ -404,7 +404,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, @@ -426,7 +426,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, } @@ -440,7 +440,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, @@ -470,7 +470,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, @@ -484,7 +484,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello, world\"', + 'LITERAL': '\"hello\"', } }, }, diff --git a/src/tree2blocks.js b/src/tree2blocks.js index 485630a..e76ffa5 100644 --- a/src/tree2blocks.js +++ b/src/tree2blocks.js @@ -327,54 +327,60 @@ export const tree2blocks = (workspace, node) => { break; case NODETYPES.SPECIAL_STRING_FUNCCALL: - - if (node.name === 'charAt') { - result = workspace.newBlock('praxly_charAt_block'); - var recipient = tree2blocks(workspace, node.left); - const child = tree2blocks(workspace, node?.args); - result.getInput('INDEX').connection.connect(child?.outputConnection); - result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - } else if (node.name === 'contains') { - result = workspace.newBlock('praxly_contains_block'); - var recipient = tree2blocks(workspace, node.left); - const child = tree2blocks(workspace, node?.args); - result.getInput('PARAM').connection.connect(child?.outputConnection); - result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - } else if (node.name === 'indexOf') { - result = workspace.newBlock('praxly_indexOf_block'); - var recipient = tree2blocks(workspace, node.left); - const child = tree2blocks(workspace, node?.args); - result.getInput('PARAM').connection.connect(child?.outputConnection); - result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - } else if (node.name === 'length') { + if (!node.right) { + break; // user still typing (nothing after the dot) + } + const name = node.right.name; + const args = node.right.args; + + // create applicable string method block and connect args + if (name === StringFuncs.CHARAT) { + var result = workspace.newBlock('praxly_charAt_block'); + if (args?.length == 1) { + const index = tree2blocks(workspace, args[0]); + result.getInput('INDEX').connection.connect(index?.outputConnection); + } + } + else if (name === StringFuncs.CONTAINS) { + var result = workspace.newBlock('praxly_contains_block'); + if (args?.length == 1) { + const param = tree2blocks(workspace, args[0]); + result.getInput('PARAM').connection.connect(param?.outputConnection); + } + } + else if (name === StringFuncs.INDEXOF) { result = workspace.newBlock('praxly_indexOf_block'); - var recipient = tree2blocks(workspace, node.left); - result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - } else if (node.name === 'substring') { - - } else if (node.name === StringFuncs.TOLOWERCSE) { - - } else if (node.name === StringFuncs.TOUPPERCASE) { - + if (args?.length == 1) { + const param = tree2blocks(workspace, args[0]); + result.getInput('PARAM').connection.connect(param?.outputConnection); + } + } + else if (name === StringFuncs.LENGTH) { + result = workspace.newBlock('praxly_length_block'); + } + else if (name === StringFuncs.SUBSTRING) { + result = workspace.newBlock('praxly_substring_block'); + if (args?.length == 2) { + const param1 = tree2blocks(workspace, args[0]); + const param2 = tree2blocks(workspace, args[1]); + result.getInput('PARAM1').connection.connect(param1?.outputConnection); + result.getInput('PARAM2').connection.connect(param2?.outputConnection); + } + } + else if (name === StringFuncs.TOLOWERCSE) { + result = workspace.newBlock('praxly_toLowerCase_block'); + } + else if (name === StringFuncs.TOUPPERCASE) { + result = workspace.newBlock('praxly_toUpperCase_block'); + } else { + break; // user still typing or misspelled name } - - // var result = workspace.newBlock('praxly_StringFunc_block'); - // var params = workspace.newBlock('praxly_parameter_block'); - // var recipient = tree2blocks(workspace, node.left); - // result.setFieldValue(node?.right?.name, 'FUNCTYPE'); - // result.getInput('PARAMS').connection.connect(params?.outputConnection); - // var argsList = node?.right?.args; - // for (var i = 0; i < (argsList?.length ?? 0); i++) { - // params.appendValueInput(`PARAM_${i}`); - // var argument = tree2blocks(workspace, argsList[i]); - // params.getInput(`PARAM_${i}`).connection.connect(argument?.outputConnection); - // } - // result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); - // params.initSvg(); + // connect the string on the left of the result block + var recipient = tree2blocks(workspace, node.left); + result.getInput("EXPRESSION").connection.connect(recipient.outputConnection); break; - case NODETYPES.FUNCDECL: var returnType = node?.returnType; var argsList = node?.params; From 48776bbf7c1752f8bebfaeaab3b01ee92802ae56 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Fri, 2 Aug 2024 12:39:41 -0400 Subject: [PATCH 07/13] temporary color changes --- src/newBlocks.js | 40 ++++++++++++++++++++-------------------- src/theme.js | 18 ++++++++++++------ src/toolbox.js | 20 ++++++++++---------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/newBlocks.js b/src/newBlocks.js index ed9a2fb..ed6fdd3 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -354,7 +354,7 @@ export function definePraxlyBlocks(workspace) { } ], "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "A literal value in the code", "helpUrl": "" }, @@ -408,7 +408,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Arithmetic operators:\n+ addition (and string concatenation)\n- subtraction\n* multiplication\n/ division (integer and floating-point)\n% remainder\n^ exponent", "helpUrl": "", }, @@ -425,7 +425,7 @@ export function definePraxlyBlocks(workspace) { } ], "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Negates a value", "helpUrl": "" }, @@ -434,7 +434,7 @@ export function definePraxlyBlocks(workspace) { "message0": "random ( )", "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Generates a random double greater than or equal to 0 and less than 1", "helpUrl": "" }, @@ -449,7 +449,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Generates a random integer greater than or equal to 0 and less than x", "helpUrl": "" }, @@ -464,7 +464,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Sets the seed of the random number generator", "helpUrl": "" }, @@ -479,7 +479,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Converts a String into an int", "helpURL": "" }, @@ -494,7 +494,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Converts a String into a float", "helpURL": "" }, @@ -513,7 +513,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Returns the lower value", "helpURL": "" }, @@ -532,7 +532,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Returns the higher value", "helpURL": "" }, @@ -547,7 +547,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Returns the absolute value", "helpURL": "" }, @@ -562,7 +562,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Calculates the natural logarithm", "helpURL": "" }, @@ -577,7 +577,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'expression_blocks', + "style": 'math_blocks', "tooltip": "Calculates the square root", "helpURL": "" }, @@ -630,7 +630,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Returns the character at index i", "helpUrl": "" }, @@ -650,7 +650,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Returns true if value is a substring", "helpUrl": "" }, @@ -670,7 +670,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Returns the first index of substring value, or -1 if not found", "helpUrl": "" }, @@ -685,7 +685,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Returns the length of the string", "helpUrl": "" }, @@ -710,7 +710,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Extracts characters from the start index up to but not including the end index", "helpUrl": "" }, @@ -725,7 +725,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Converts the string to all lowercase", "helpUrl": "" }, @@ -740,7 +740,7 @@ export function definePraxlyBlocks(workspace) { ], "inputsInline": true, "output": null, - "style": 'other_blocks', + "style": 'text_blocks', "tooltip": "Converts the string to all uppercase", "helpUrl": "" }, diff --git a/src/theme.js b/src/theme.js index a003568..7a7ae9d 100644 --- a/src/theme.js +++ b/src/theme.js @@ -69,7 +69,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#FA0000' }, 'logic_blocks': { - 'colourPrimary': '#00D084' + 'colourPrimary': '#3CB371' }, 'class_blocks': { 'colourPrimary': '#6381fe' @@ -83,14 +83,17 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'variable_blocks': { 'colourPrimary': '#f80069' }, - 'expression_blocks': { - 'colourPrimary': '#a7ca00' + 'math_blocks': { + 'colourPrimary': '#4B0082' }, 'parameter_blocks': { 'colourPrimary': '#8F48B7' }, 'other_blocks': { 'colourPrimary': '#00BFFF' + }, + 'text_blocks': { + 'colourPrimary': '#1E90FF' } }, 'categoryStyles': { @@ -101,7 +104,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#6381fe' }, 'logic_blocks': { - 'colour': '#00D084' + 'colour': '#3CB371' }, 'class_blocks': { 'colour': '#6381fe' @@ -115,8 +118,11 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'variable_blocks': { 'colour': '#f80069' }, - 'expression_blocks': { - 'colour': '#a7ca00' + 'math_blocks': { + 'colour': '#4B0082' + }, + 'text_blocks': { + 'colour': '#1E90FF' } }, 'componentStyles': { diff --git a/src/toolbox.js b/src/toolbox.js index 1419a24..f920e78 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -134,7 +134,7 @@ export const toolbox = { { "kind": "category", "name": "math", - "categorystyle": "expression_blocks", + "categorystyle": "math_blocks", "contents": [ { 'kind': 'block', @@ -331,7 +331,7 @@ export const toolbox = { { "kind": "category", "name": "text", - "categorystyle": "class_blocks", + "categorystyle": "text_blocks", "contents": [ // { // 'kind': 'block', @@ -497,14 +497,6 @@ export const toolbox = { "name": "logic", "categorystyle": "logic_blocks", "contents": [ - { - 'kind': 'block', - 'type': 'praxly_true_block' - }, - { - 'kind': 'block', - 'type': 'praxly_false_block' - }, { 'kind': 'block', 'type': 'praxly_if_block', @@ -575,6 +567,14 @@ export const toolbox = { }, } } + }, + { + 'kind': 'block', + 'type': 'praxly_true_block' + }, + { + 'kind': 'block', + 'type': 'praxly_false_block' } ] }, From 25b05494b14ed28dc242f4eee901eab0db1744e0 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Fri, 2 Aug 2024 13:46:05 -0400 Subject: [PATCH 08/13] text select works on variables and output, updated text function blocks and slight tooltip changes --- archive/style.css | 1 + public/themes.css | 1 + src/newBlocks.js | 4 ++-- src/toolbox.js | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/archive/style.css b/archive/style.css index 4fceb7a..8cf0c0d 100644 --- a/archive/style.css +++ b/archive/style.css @@ -430,6 +430,7 @@ main { display: flex; /* Add this */ flex-direction: row; /* Add this */ flex-basis: 25%; + user-select: all; } .output { diff --git a/public/themes.css b/public/themes.css index 0031732..c57af4f 100644 --- a/public/themes.css +++ b/public/themes.css @@ -531,6 +531,7 @@ body:not(.embed) #bottom-part { flex-direction: row-reverse; /* Add this */ flex-basis: 25%; + user-select: text; } .output { diff --git a/src/newBlocks.js b/src/newBlocks.js index ed6fdd3..bab3101 100644 --- a/src/newBlocks.js +++ b/src/newBlocks.js @@ -631,7 +631,7 @@ export function definePraxlyBlocks(workspace) { "inputsInline": true, "output": null, "style": 'text_blocks', - "tooltip": "Returns the character at index i", + "tooltip": "Returns the character at the index", "helpUrl": "" }, { // text 2 @@ -651,7 +651,7 @@ export function definePraxlyBlocks(workspace) { "inputsInline": true, "output": null, "style": 'text_blocks', - "tooltip": "Returns true if value is a substring", + "tooltip": "Returns true if string is a substring", "helpUrl": "" }, { // text 3 diff --git a/src/toolbox.js b/src/toolbox.js index a52b92a..787d569 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -368,7 +368,7 @@ export const toolbox = { 'block': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 0 + 'LITERAL': 'index' } } } @@ -390,7 +390,7 @@ export const toolbox = { 'block': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 'value' + 'LITERAL': '"string"' } } } @@ -412,7 +412,7 @@ export const toolbox = { 'block': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': 'value' + 'LITERAL': 'string' } } } From f1f6dfdcd3b3ad96108fdb9324ede2bd12e184c4 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Fri, 2 Aug 2024 14:37:05 -0400 Subject: [PATCH 09/13] new colors --- src/theme.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/theme.js b/src/theme.js index 7a7ae9d..a670ae2 100644 --- a/src/theme.js +++ b/src/theme.js @@ -78,13 +78,13 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#808080' }, 'procedure_blocks': { - 'colourPrimary': '#6381fe' + 'colourPrimary': '#4B0082' }, 'variable_blocks': { 'colourPrimary': '#f80069' }, 'math_blocks': { - 'colourPrimary': '#4B0082' + 'colourPrimary': '#DAA520' }, 'parameter_blocks': { 'colourPrimary': '#8F48B7' @@ -101,7 +101,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#395BBF' }, 'procedure_blocks': { - 'colour': '#6381fe' + 'colour': '#4B0082' }, 'logic_blocks': { 'colour': '#3CB371' @@ -119,7 +119,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#f80069' }, 'math_blocks': { - 'colour': '#4B0082' + 'colour': '#DAA520' }, 'text_blocks': { 'colour': '#1E90FF' From 4eb48cdad94c995f237338ed534a3de67492e0a3 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Mon, 5 Aug 2024 11:01:34 -0400 Subject: [PATCH 10/13] new procedure and text colors --- src/theme.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/theme.js b/src/theme.js index a670ae2..1b9936f 100644 --- a/src/theme.js +++ b/src/theme.js @@ -78,7 +78,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#808080' }, 'procedure_blocks': { - 'colourPrimary': '#4B0082' + 'colourPrimary': '#9370DB' }, 'variable_blocks': { 'colourPrimary': '#f80069' @@ -93,7 +93,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#00BFFF' }, 'text_blocks': { - 'colourPrimary': '#1E90FF' + 'colourPrimary': '#2F4F4F' } }, 'categoryStyles': { @@ -101,7 +101,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#395BBF' }, 'procedure_blocks': { - 'colour': '#4B0082' + 'colour': '#9370DB' }, 'logic_blocks': { 'colour': '#3CB371' @@ -122,7 +122,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#DAA520' }, 'text_blocks': { - 'colour': '#1E90FF' + 'colour': '#2F4F4F' } }, 'componentStyles': { From 2c43d11199bce8479eafb3f7014eed25b6dd0958 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Mon, 5 Aug 2024 17:57:55 -0400 Subject: [PATCH 11/13] new text color --- src/theme.js | 4 ++-- src/toolbox.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/theme.js b/src/theme.js index 1b9936f..4bee7f9 100644 --- a/src/theme.js +++ b/src/theme.js @@ -93,7 +93,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#00BFFF' }, 'text_blocks': { - 'colourPrimary': '#2F4F4F' + 'colourPrimary': '#cdd481' } }, 'categoryStyles': { @@ -122,7 +122,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#DAA520' }, 'text_blocks': { - 'colour': '#2F4F4F' + 'colour': '#cdd481' } }, 'componentStyles': { diff --git a/src/toolbox.js b/src/toolbox.js index 787d569..ecfb815 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -46,10 +46,6 @@ export const toolbox = { "name": "variables", "categorystyle": "variable_blocks", "contents": [ - { - 'kind': 'block', - 'type': 'praxly_variable_block' - }, { 'kind': 'block', 'type': 'praxly_vardecl_block', @@ -82,6 +78,10 @@ export const toolbox = { }, } }, + { + 'kind': 'block', + 'type': 'praxly_variable_block' + }, { 'kind': 'block', 'type': 'praxly_array_assignment_block', @@ -136,10 +136,6 @@ export const toolbox = { "name": "math", "categorystyle": "math_blocks", "contents": [ - { - 'kind': 'block', - 'type': 'praxly_literal_block' - }, // { // 'kind': 'block', // 'type': 'praxly_String_block' @@ -180,6 +176,10 @@ export const toolbox = { }, } }, + { + 'kind': 'block', + 'type': 'praxly_literal_block' + }, { 'kind': 'block', 'type': 'praxly_random_block' @@ -390,7 +390,7 @@ export const toolbox = { 'block': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '"string"' + 'LITERAL': 'string' } } } From 2acad72c2e79da7c8bb944ab4d3495052d84fba6 Mon Sep 17 00:00:00 2001 From: ellonamac Date: Mon, 5 Aug 2024 18:00:20 -0400 Subject: [PATCH 12/13] alternative text option --- src/theme.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/theme.js b/src/theme.js index 4bee7f9..82a2752 100644 --- a/src/theme.js +++ b/src/theme.js @@ -94,6 +94,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { }, 'text_blocks': { 'colourPrimary': '#cdd481' + // bec47e } }, 'categoryStyles': { @@ -123,6 +124,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { }, 'text_blocks': { 'colour': '#cdd481' + // bec47e } }, 'componentStyles': { From 707fd3eb07d03387fb4d8b3535772f77a7c40101 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Mon, 5 Aug 2024 20:19:07 -0400 Subject: [PATCH 13/13] tweak orange and yellow; capital Hello in blocks --- src/theme.js | 12 +++++------- src/toolbox.js | 14 +++++++------- test/colors.py | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 test/colors.py diff --git a/src/theme.js b/src/theme.js index 82a2752..92d7204 100644 --- a/src/theme.js +++ b/src/theme.js @@ -63,7 +63,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'base': Blockly.Themes.Classic, 'blockStyles': { 'loop_blocks': { - 'colourPrimary': '#0361FF' + 'colourPrimary': '#395BBF' }, 'array_blocks': { 'colourPrimary': '#FA0000' @@ -84,7 +84,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#f80069' }, 'math_blocks': { - 'colourPrimary': '#DAA520' + 'colourPrimary': '#FF9966' }, 'parameter_blocks': { 'colourPrimary': '#8F48B7' @@ -93,8 +93,7 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colourPrimary': '#00BFFF' }, 'text_blocks': { - 'colourPrimary': '#cdd481' - // bec47e + 'colourPrimary': '#FFC050', } }, 'categoryStyles': { @@ -120,11 +119,10 @@ export const PraxlyDark = Blockly.Theme.defineTheme('PraxlyDark', { 'colour': '#f80069' }, 'math_blocks': { - 'colour': '#DAA520' + 'colour': '#FF9966' }, 'text_blocks': { - 'colour': '#cdd481' - // bec47e + 'colour': '#FFC050' } }, 'componentStyles': { diff --git a/src/toolbox.js b/src/toolbox.js index ecfb815..7d78699 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -360,7 +360,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, @@ -382,7 +382,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, @@ -404,7 +404,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, @@ -426,7 +426,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, } @@ -440,7 +440,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, @@ -470,7 +470,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, @@ -484,7 +484,7 @@ export const toolbox = { 'shadow': { 'type': 'praxly_literal_block', 'fields': { - 'LITERAL': '\"hello\"', + 'LITERAL': '"Hello"', } }, }, diff --git a/test/colors.py b/test/colors.py new file mode 100644 index 0000000..7e7e239 --- /dev/null +++ b/test/colors.py @@ -0,0 +1,26 @@ +import matplotlib.pyplot as plt + +# Define the darker pastel colors +darker_colors = { + "Darker Pastel Violet": "#9966CC", + "Darker Pastel Blue": "#6699CC", + "Darker Pastel Green": "#66B266", + "Darker Pastel Yellow": "#FFCC66", + "Darker Pastel Orange": "#FF9966", + "Darker Pastel Red": "#FF6666", +} + +# Create a figure and axis +fig, ax = plt.subplots(figsize=(8, 6)) + +# Plot each darker color as a rectangle with white text on top +for i, (color_name, color_hex) in enumerate(darker_colors.items()): + ax.add_patch(plt.Rectangle((0, i), 1, 1, color=color_hex)) + ax.text(0.5, i + 0.5, color_name, ha='center', va='center', fontsize=14, color='white') + +# Remove axes +ax.set_xlim(0, 1) +ax.set_ylim(0, len(darker_colors)) +ax.axis('off') + +plt.show()