From 0c6861fbb8c60cd201c154b701cdc4049983f9b2 Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Thu, 14 Nov 2024 14:59:30 -0600 Subject: [PATCH] labelIsName not copied with link=false, original name is preserved --- .../doenetml-worker/src/components/Copy.js | 1 + .../src/components/abstract/BaseComponent.js | 19 +++++++++++++++++-- packages/doenetml-worker/src/utils/label.js | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/doenetml-worker/src/components/Copy.js b/packages/doenetml-worker/src/components/Copy.js index 6dec195c6..fc6ade24c 100644 --- a/packages/doenetml-worker/src/components/Copy.js +++ b/packages/doenetml-worker/src/components/Copy.js @@ -1830,6 +1830,7 @@ export default class Copy extends CompositeComponent { serializedReplacements = [ await replacementSourceComponent.serialize({ copyAll: !link, + componentSourceAttributesToIgnore: ["labelIsName"], copyVariants: !link, primitiveSourceAttributesToIgnore: sourceAttributesToIgnore, copyPrimaryEssential, diff --git a/packages/doenetml-worker/src/components/abstract/BaseComponent.js b/packages/doenetml-worker/src/components/abstract/BaseComponent.js index 1f0e8860c..d057e0408 100644 --- a/packages/doenetml-worker/src/components/abstract/BaseComponent.js +++ b/packages/doenetml-worker/src/components/abstract/BaseComponent.js @@ -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 && @@ -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, diff --git a/packages/doenetml-worker/src/utils/label.js b/packages/doenetml-worker/src/utils/label.js index 09302b55f..e24ca2785 100644 --- a/packages/doenetml-worker/src/utils/label.js +++ b/packages/doenetml-worker/src/utils/label.js @@ -214,6 +214,10 @@ export function returnLabelStateVariableDefinitions() { dependencyType: "shadowSource", variableNames: ["label", "labelHasLatex"], }, + unlinkedCopySource: { + dependencyType: "unlinkedCopySource", + variableNames: ["label", "labelHasLatex"], + }, }), definition({ dependencyValues, essentialValues }) { let labelChild = @@ -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 },