Skip to content

Commit

Permalink
inverse definition of text will attempt to update a composite-generat…
Browse files Browse the repository at this point in the history
…ed list
  • Loading branch information
dqnykamp committed Oct 30, 2024
1 parent 6622d00 commit 6f3df30
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 72 deletions.
1 change: 1 addition & 0 deletions packages/doenetml-worker/src/components/MathInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default class MathInput extends Input {
sugarInstructions.push({
replacementFunction: returnWrapNonLabelsSugarFunction({
wrappingComponentType: "math",
wrapSingleIfNotWrappingComponentType: true,
}),
});

Expand Down
1 change: 0 additions & 1 deletion packages/doenetml-worker/src/components/MathList.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export default class MathList extends CompositeComponent {
};

stateVariableDefinitions.maths = {
public: true,
shadowingInstructions: {
createComponentOfType: "math",
},
Expand Down
39 changes: 39 additions & 0 deletions packages/doenetml-worker/src/components/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,48 @@ export default class Text extends InlineComponent {
dependencyValues,
}) {
let numChildren = dependencyValues.textLikeChildren.length;

if (numChildren > 1) {
// if have multiple children, then we could still update them if
// 1. all children come from a single composite with asList set to true, and
// 2. the desired value is a comma-separated list with the number of entries
// matching the number of children.
// In that case, we will attempt to update each child to the corresponding entry
// from the desired value.

// Check if all text children are from a composite with asList set to true
let foundAllFromListComposite = false;
for (let range of dependencyValues.textLikeChildren
.compositeReplacementRange) {
if (
range.asList &&
range.firstInd === 0 &&
range.lastInd === numChildren - 1
) {
foundAllFromListComposite = true;
}
}

if (foundAllFromListComposite) {
// Check if desired value is a comma-separated list with the same number of entries as children
let splitValues = desiredStateVariableValues.value
.split(",")
.map((v) => v.trim());

if (splitValues.length === numChildren) {
// All conditions are met, so we attempt to update the children
let instructions = splitValues.map((v, i) => ({
setDependency: "textLikeChildren",
desiredValue: v,
childIndex: i,
variableIndex: 0,
}));
return { success: true, instructions };
}
}
return { success: false };
}

if (numChildren === 1) {
return {
success: true,
Expand Down
1 change: 1 addition & 0 deletions packages/doenetml-worker/src/components/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default class Textinput extends Input {
sugarInstructions.push({
replacementFunction: returnWrapNonLabelsSugarFunction({
wrappingComponentType: "text",
wrapSingleIfNotWrappingComponentType: true,
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ describe("Boolean tag tests", async () => {
isSupersetCaseInsensitive: false,
},
{
set1: "<extract prop='listItems'><text>a, c</text></extract>",
set1: "<extract prop='list'><text>a, c</text></extract>",
set2: "<sequence type='letters' from='a' to='e' step='2' />",
isSubset: true,
isSubsetCaseInsensitive: true,
Expand Down
Loading

0 comments on commit 6f3df30

Please sign in to comment.