Skip to content

Commit

Permalink
labelIsName does not use auto-generated names
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp committed Nov 15, 2024
1 parent 0c6861f commit 808f885
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions packages/doenetml-worker/src/utils/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,22 @@ export function returnLabelStateVariableDefinitions() {
// find a valid name for a label from the component name
// or the name of one of its shadow targets,

let label = "__";
let label = "_";
let cNames = dependencyValues.componentNameAndShadowSourceNames;

for (let cN of cNames) {
let lastSlash = cN.lastIndexOf("/");
label = cN.substring(lastSlash + 1);
if (label.slice(0, 2) !== "__") {
let lastSlashInd = cN.lastIndexOf("/");
label = cN.substring(lastSlashInd + 1);
if (label[0] !== "_") {
break;
}
}
if (label.slice(0, 2) === "__") {
if (label[0] === "_") {
// if label from componentName starts with two underscores,
// it is an automatically generated component name that has random characters in it
// Don't display name, as they are for internal use only (and the user cannot refer to them)
// (Nov 2024) Also now that are phasing out automatically generated names with single _,
// don't display those either.
return {
setValue: {
label: "",
Expand All @@ -277,26 +279,22 @@ export function returnLabelStateVariableDefinitions() {
};
}

if (label[0] !== "_") {
// we have a user supplied name
// we have a user supplied name

if (label.includes("_") || label.includes("-")) {
label = label.replace(/[_\-]/g, " ");
} else if (label.match(/^[a-z]/)) {
if (label.match(/[A-Z]/)) {
// label starts with a lower case letter and has an upper case letter
// treat as camel case and add spaces and lowercase letters
label = label
.replace(/([A-Z])/g, " $1")
.toLowerCase();
}
} else if (label.match(/^[A-Z]/)) {
if (label.match(/[a-z]/)) {
// label starts with a upper case letter and has an lower case letter
// treat as pascal case and add spaces
label = label.replace(/([A-Z])/g, " $1");
label = label.slice(1); // delete extra space at beginning
}
if (label.includes("_") || label.includes("-")) {
label = label.replace(/[_\-]/g, " ");
} else if (label.match(/^[a-z]/)) {
if (label.match(/[A-Z]/)) {
// label starts with a lower case letter and has an upper case letter
// treat as camel case and add spaces and lowercase letters
label = label.replace(/([A-Z])/g, " $1").toLowerCase();
}
} else if (label.match(/^[A-Z]/)) {
if (label.match(/[a-z]/)) {
// label starts with a upper case letter and has an lower case letter
// treat as pascal case and add spaces
label = label.replace(/([A-Z])/g, " $1");
label = label.slice(1); // delete extra space at beginning
}
}

Expand Down

0 comments on commit 808f885

Please sign in to comment.