Skip to content

Commit

Permalink
labelIsName not copied with link=false, original name is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp committed Nov 14, 2024
1 parent e1d7e04 commit 0c6861f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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
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
18 changes: 18 additions & 0 deletions packages/doenetml-worker/src/utils/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export function returnLabelStateVariableDefinitions() {
dependencyType: "shadowSource",
variableNames: ["label", "labelHasLatex"],
},
unlinkedCopySource: {
dependencyType: "unlinkedCopySource",
variableNames: ["label", "labelHasLatex"],
},
}),
definition({ dependencyValues, essentialValues }) {
let labelChild =
Expand Down Expand Up @@ -315,6 +319,20 @@ export function returnLabelStateVariableDefinitions() {
),
},
};
} else if (
typeof dependencyValues.unlinkedCopySource?.stateValues
.label === "string"
) {
return {
setValue: {
label: dependencyValues.unlinkedCopySource.stateValues
.label,
labelHasLatex: Boolean(
dependencyValues.unlinkedCopySource.stateValues
.labelHasLatex,
),
},
};
} else {
return {
useEssentialOrDefaultValue: { label: true },
Expand Down

0 comments on commit 0c6861f

Please sign in to comment.