Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LabelIsName tweaks #257

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/doenetml-worker/src/components/BooleanInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
returnAnchorStateVariableDefinition,
} from "../utils/graphical";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
returnWrapNonLabelsSugarFunction,
} from "../utils/label";
Expand Down Expand Up @@ -48,12 +49,6 @@ export default class BooleanInput extends Input {
defaultValue: false,
public: true,
};
attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};
attributes.asToggleButton = {
createComponentOfType: "boolean",
createStateVariable: "asToggleButton",
Expand All @@ -73,6 +68,8 @@ export default class BooleanInput extends Input {
forRenderer: true,
};

Object.assign(attributes, returnLabelAttributes());

Object.assign(attributes, returnAnchorAttributes());

return attributes;
Expand Down
14 changes: 6 additions & 8 deletions packages/doenetml-worker/src/components/CallAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
returnAnchorAttributes,
returnAnchorStateVariableDefinition,
} from "../utils/graphical";
import { returnLabelStateVariableDefinitions } from "../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../utils/label";
import {
addStandardTriggeringStateVariableDefinitions,
returnStandardTriggeringAttributes,
Expand Down Expand Up @@ -56,13 +59,6 @@ export default class CallAction extends InlineComponent {
// attributes.width = {default: 300};
// attributes.height = {default: 50};

attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};

attributes.actionName = {
createComponentOfType: "text",
createStateVariable: "actionName",
Expand All @@ -78,6 +74,8 @@ export default class CallAction extends InlineComponent {
forRenderer: true,
};

Object.assign(attributes, returnLabelAttributes());

Object.assign(attributes, returnAnchorAttributes());

let triggerAttributes = returnStandardTriggeringAttributes(
Expand Down
12 changes: 5 additions & 7 deletions packages/doenetml-worker/src/components/ChoiceInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import Input from "./abstract/Input";
import me from "math-expressions";
import { enumerateCombinations, enumeratePermutations } from "@doenet/utils";
import { setUpVariantSeedAndRng } from "../utils/variants";
import { returnLabelStateVariableDefinitions } from "../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../utils/label";

export default class Choiceinput extends Input {
constructor(args) {
Expand Down Expand Up @@ -102,12 +105,7 @@ export default class Choiceinput extends Input {
fallBackToParentStateVariable: "submitLabelNoCorrectness",
};

attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};
Object.assign(attributes, returnLabelAttributes());

return attributes;
}
Expand Down
1 change: 1 addition & 0 deletions packages/doenetml-worker/src/components/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ export default class Copy extends CompositeComponent {
serializedReplacements = [
await replacementSourceComponent.serialize({
copyAll: !link,
componentSourceAttributesToIgnore: ["labelIsName"],
copyVariants: !link,
primitiveSourceAttributesToIgnore: sourceAttributesToIgnore,
copyPrimaryEssential,
Expand Down
13 changes: 6 additions & 7 deletions packages/doenetml-worker/src/components/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
returnRoundingAttributes,
returnRoundingStateVariableDefinitions,
} from "../utils/rounding";
import { returnWrapNonLabelsSugarFunction } from "../utils/label";
import {
returnLabelAttributes,
returnWrapNonLabelsSugarFunction,
} from "../utils/label";
import {
find_local_global_maxima,
find_local_global_minima,
Expand Down Expand Up @@ -79,12 +82,8 @@ export default class Function extends InlineComponent {
// include attributes of graphical components
// for case when function is adapted into a curve

attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};
Object.assign(attributes, returnLabelAttributes());

attributes.applyStyleToLabel = {
createComponentOfType: "boolean",
createStateVariable: "applyStyleToLabel",
Expand Down
10 changes: 4 additions & 6 deletions packages/doenetml-worker/src/components/MathInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
returnRoundingStateVariableDefinitions,
} from "../utils/rounding";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
returnWrapNonLabelsSugarFunction,
} from "../utils/label";
Expand Down Expand Up @@ -130,12 +131,9 @@ export default class MathInput extends Input {
public: true,
forRenderer: true,
};
attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};

Object.assign(attributes, returnLabelAttributes());

return attributes;
}

Expand Down
13 changes: 6 additions & 7 deletions packages/doenetml-worker/src/components/Slider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { roundForDisplay } from "../utils/math";
import BaseComponent from "./abstract/BaseComponent";
import me from "math-expressions";
import { returnLabelStateVariableDefinitions } from "../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../utils/label";
import {
returnRoundingAttributeComponentShadowing,
returnRoundingAttributes,
Expand Down Expand Up @@ -50,12 +53,6 @@ export default class Slider extends BaseComponent {
createStateVariable: "initialValue",
defaultValue: null,
};
attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};
attributes.showControls = {
createComponentOfType: "boolean",
createStateVariable: "showControls",
Expand Down Expand Up @@ -99,6 +96,8 @@ export default class Slider extends BaseComponent {
forRenderer: true,
};

Object.assign(attributes, returnLabelAttributes());

Object.assign(attributes, returnRoundingAttributes());

attributes.bindValueTo = {
Expand Down
9 changes: 3 additions & 6 deletions packages/doenetml-worker/src/components/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
returnAnchorStateVariableDefinition,
} from "../utils/graphical";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
returnWrapNonLabelsSugarFunction,
} from "../utils/label";
Expand Down Expand Up @@ -73,12 +74,6 @@ export default class Textinput extends Input {
forRenderer: true,
public: true,
};
attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};
attributes.draggable = {
createComponentOfType: "boolean",
createStateVariable: "draggable",
Expand All @@ -89,6 +84,8 @@ export default class Textinput extends Input {

Object.assign(attributes, returnAnchorAttributes());

Object.assign(attributes, returnLabelAttributes());

return attributes;
}

Expand Down
14 changes: 6 additions & 8 deletions packages/doenetml-worker/src/components/TriggerSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
returnAnchorAttributes,
returnAnchorStateVariableDefinition,
} from "../utils/graphical";
import { returnLabelStateVariableDefinitions } from "../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../utils/label";
import {
addStandardTriggeringStateVariableDefinitions,
returnStandardTriggeringAttributes,
Expand All @@ -30,13 +33,6 @@ export default class triggerSet extends InlineComponent {
// attributes.width = {default: 300};
// attributes.height = {default: 50};

attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};

attributes.draggable = {
createComponentOfType: "boolean",
createStateVariable: "draggable",
Expand All @@ -47,6 +43,8 @@ export default class triggerSet extends InlineComponent {

Object.assign(attributes, returnAnchorAttributes());

Object.assign(attributes, returnLabelAttributes());

let triggerAttributes = returnStandardTriggeringAttributes(
"triggerActionsIfTriggerNewlyTrue",
);
Expand Down
14 changes: 6 additions & 8 deletions packages/doenetml-worker/src/components/UpdateValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
returnAnchorAttributes,
returnAnchorStateVariableDefinition,
} from "../utils/graphical";
import { returnLabelStateVariableDefinitions } from "../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../utils/label";
import { normalizeMathExpression } from "@doenet/utils";
import {
addStandardTriggeringStateVariableDefinitions,
Expand Down Expand Up @@ -33,13 +36,6 @@ export default class UpdateValue extends InlineComponent {
// attributes.width = {default: 300};
// attributes.height = {default: 50};

attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};

attributes.type = {
createPrimitiveOfType: "string",
createStateVariable: "type",
Expand Down Expand Up @@ -98,6 +94,8 @@ export default class UpdateValue extends InlineComponent {

Object.assign(attributes, returnAnchorAttributes());

Object.assign(attributes, returnLabelAttributes());

let triggerAttributes = returnStandardTriggeringAttributes(
"updateValueIfTriggerNewlyTrue",
);
Expand Down
19 changes: 17 additions & 2 deletions packages/doenetml-worker/src/components/abstract/BaseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,14 @@ export default class BaseComponent {
primitiveSourceAttributesToIgnore = [];
}

let componentSourceAttributesToIgnore;
if (parameters.componentSourceAttributesToIgnore) {
componentSourceAttributesToIgnore =
parameters.componentSourceAttributesToIgnore;
} else {
componentSourceAttributesToIgnore = [];
}

if (includeDefiningChildren) {
if (
this.constructor.serializeReplacementsForChildren &&
Expand Down Expand Up @@ -1246,8 +1254,15 @@ export default class BaseComponent {
for (let attrName in this.attributes) {
let attribute = this.attributes[attrName];
if (attribute.component) {
// only copy attribute components if copy all
if (parameters.copyAll) {
// only copy attribute components if copy all and not set to be ignored
// Note that, unlike for the primitive case, below,
// attributeToIgnore supersedes copyAll.
// As of Nov 2024, the only componentSourceAttributesToIgnore
// is labelIsName when copying without link.
if (
parameters.copyAll &&
!componentSourceAttributesToIgnore.includes(attrName)
) {
serializedComponent.attributes[attrName] = {
component: await attribute.component.serialize(
parametersForChildren,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import BaseComponent from "./BaseComponent";
import { returnSelectedStyleStateVariableDefinition } from "@doenet/utils";
import { returnLabelStateVariableDefinitions } from "../../utils/label";
import {
returnLabelAttributes,
returnLabelStateVariableDefinitions,
} from "../../utils/label";

export default class GraphicalComponent extends BaseComponent {
static componentType = "_graphical";

static createAttributesObject() {
let attributes = super.createAttributesObject();
attributes.labelIsName = {
createComponentOfType: "boolean",
createStateVariable: "labelIsName",
defaultValue: false,
public: true,
};

Object.assign(attributes, returnLabelAttributes());

attributes.applyStyleToLabel = {
createComponentOfType: "boolean",
createStateVariable: "applyStyleToLabel",
Expand Down
Loading
Loading