diff --git a/HISTORY.md b/HISTORY.md index c7e7cb6a..20866d45 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -45,6 +45,9 @@ * **Translation Updates:** * German +### 2022-05-01 +* byob: programmatically reduce the number of inputs in a custom block + ### 2022-04-28 * threads, byob: programmatically re-define custom blocks, experimental, under construction * threads: programmatically re-categorize custom blocks diff --git a/snap.html b/snap.html index 3cf5e862..7bfa5597 100755 --- a/snap.html +++ b/snap.html @@ -23,7 +23,7 @@ - + diff --git a/src/byob.js b/src/byob.js index eaaf544e..908212a4 100644 --- a/src/byob.js +++ b/src/byob.js @@ -111,7 +111,7 @@ ArgLabelMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2022-April-28'; +modules.byob = '2022-May-01'; // Declarations @@ -569,7 +569,10 @@ CustomBlockDefinition.prototype.setBlockDefinition = function (aContext) { declarations = this.declarations, parts = []; - if (oldInputs.length !== newInputs.length) { + if (oldInputs.length > newInputs.length) { + this.removeInputs(oldInputs.length - newInputs.length); + spec = this.abstractBlockSpec(); + } else if (oldInputs.length !== newInputs.length) { throw new Error('expecting the number of inputs to match'); } @@ -601,6 +604,31 @@ CustomBlockDefinition.prototype.setBlockDefinition = function (aContext) { this.body = aContext; }; +CustomBlockDefinition.prototype.removeInputs = function (count) { + // private - only to be called from a Process that also does housekeeping + var surplus = this.inputNames().slice(-count); + + // remove the surplus input names from the spec + this.spec = this.parseSpec(this.spec).filter(str => + !(str.length > 1 && (str[0]) === '%' && surplus.includes(str.slice(1))) + ).join(' ').trim(); + + // remove the surplus input names from the slot declarations + surplus.forEach(name => this.declarations.delete(name)); +}; + +CustomBlockDefinition.prototype.addInputs = function (count) { + // private +}; + +CustomBlockDefinition.prototype.gensym = function (existing) { + var count = 1; + while (contains(existing, '#' + count)) { + count += 1; + } + return '#' + count; +}; + // CustomBlockDefinition picturing CustomBlockDefinition.prototype.scriptsPicture = function () {