Skip to content

Commit

Permalink
copyDoenetMLToClipboard action on all components (Doenet#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored Feb 28, 2023
1 parent 33083b9 commit c2e1815
Show file tree
Hide file tree
Showing 59 changed files with 604 additions and 335 deletions.
52 changes: 52 additions & 0 deletions src/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class Core {
this.attemptNumber = attemptNumber;
this.itemNumber = itemNumber;
this.activityVariantIndex = activityVariantIndex;
this.doenetML = doenetML;

this.serverSaveId = serverSaveId;
this.updateDataOnContentChange = updateDataOnContentChange;
Expand Down Expand Up @@ -71,6 +72,8 @@ export default class Core {
requestAnimationFrame: this.requestAnimationFrame.bind(this),
cancelAnimationFrame: this.cancelAnimationFrame.bind(this),
recordSolutionView: this.recordSolutionView.bind(this),
requestComponentDoenetML: this.requestComponentDoenetML.bind(this),
copyToClipboard: this.copyToClipboard.bind(this),
}

this.updateInfo = {
Expand Down Expand Up @@ -10355,6 +10358,55 @@ export default class Core {
}
}

requestComponentDoenetML(componentName) {

let component = this.components[componentName];

if (!component) {
return null;
}

let range = component.doenetMLrange;

if (!range) {
return null;
}

let startInd = range.openBegin !== undefined ? range.openBegin : range.selfCloseBegin;
let endInd = range.closeEnd !== undefined ? range.closeEnd : range.selfCloseEnd + 1;

let componentDoenetML = this.doenetML.slice(startInd - 1, endInd);

let lines = componentDoenetML.split("\n");

// min number of spaces that begin a line (ignoring first and any lines that are all whitespace)
let minSpaces = lines.slice(1).reduce((a, c) => Math.min(a, c.trim().length > 1 ? c.search(/\S|$/) : Infinity), Infinity)

if (Number.isFinite(minSpaces) && minSpaces > 0) {
lines = lines.map(s => {
let nStrip = Math.min(minSpaces, s.search(/\S|$/));
return s.slice(nStrip);
});
componentDoenetML = lines.join("\n");
}
componentDoenetML += "\n";

return componentDoenetML;


}

copyToClipboard(text, actionId) {
if (typeof text !== "string") {
this.resolveAction({ actionId });
} else {
postMessage({
messageType: "copyToClipboard",
coreId: this.coreId,
args: { text, actionId }
})
}
}
}


Expand Down
21 changes: 13 additions & 8 deletions src/Core/components/AnimateFromSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import me from 'math-expressions';
import { nanoid } from 'nanoid';

export default class AnimateFromSequence extends BaseComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
changedAnimationOn: this.changedAnimationOn.bind(this),
advanceAnimation: this.advanceAnimation.bind(this),
startAnimation: this.startAnimation.bind(this),
stopAnimation: this.stopAnimation.bind(this),
toggleAnimation: this.toggleAnimation.bind(this),
});

}

static componentType = "animateFromSequence";
static rendererType = undefined;

Expand Down Expand Up @@ -779,14 +792,6 @@ export default class AnimateFromSequence extends BaseComponent {
})
}

actions = {
changedAnimationOn: this.changedAnimationOn.bind(this),
advanceAnimation: this.advanceAnimation.bind(this),
startAnimation: this.startAnimation.bind(this),
stopAnimation: this.stopAnimation.bind(this),
toggleAnimation: this.toggleAnimation.bind(this),
};


async getUpdateInstructionsToSetTargetsToValue(value) {

Expand Down
12 changes: 8 additions & 4 deletions src/Core/components/Answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import stringify from 'json-stringify-deterministic';
import me from "math-expressions";

export default class Answer extends InlineComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
submitAnswer: this.submitAnswer.bind(this)
});

}
static componentType = "answer";

static renderChildren = true;
Expand Down Expand Up @@ -1722,10 +1730,6 @@ export default class Answer extends InlineComponent {
return stateVariableDefinitions;
}

actions = {
submitAnswer: this.submitAnswer.bind(this)
};


async submitAnswer({ actionId }) {

Expand Down
4 changes: 2 additions & 2 deletions src/Core/components/BooleanInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default class BooleanInput extends Input {
constructor(args) {
super(args);

this.actions = {
Object.assign(this.actions, {
updateBoolean: this.updateBoolean.bind(this)
};
});

this.externalActions = {};

Expand Down
14 changes: 9 additions & 5 deletions src/Core/components/CallAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { addStandardTriggeringStateVariableDefinitions, returnStandardTriggering
import InlineComponent from './abstract/InlineComponent';

export default class CallAction extends InlineComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
callAction: this.callAction.bind(this),
callActionIfTriggerNewlyTrue: this.callActionIfTriggerNewlyTrue.bind(this),
});

}
static componentType = "callAction";

static acceptTarget = true;
Expand Down Expand Up @@ -197,9 +206,4 @@ export default class CallAction extends InlineComponent {
this.coreFunctions.resolveAction({ actionId });
}
}

actions = {
callAction: this.callAction.bind(this),
callActionIfTriggerNewlyTrue: this.callActionIfTriggerNewlyTrue.bind(this),
};
}
12 changes: 8 additions & 4 deletions src/Core/components/Caption.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import BlockComponent from './abstract/BlockComponent';

export default class Caption extends BlockComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
recordVisibilityChange: this.recordVisibilityChange.bind(this),
});

}
static componentType = "caption";
static rendererType = "containerInline";

Expand Down Expand Up @@ -69,8 +77,4 @@ export default class Caption extends BlockComponent {
this.coreFunctions.resolveAction({ actionId });
}

actions = {
recordVisibilityChange: this.recordVisibilityChange.bind(this),
}

}
27 changes: 9 additions & 18 deletions src/Core/components/Chart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import BlockComponent from './abstract/BlockComponent';

export default class Chart extends BlockComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
changeAxisLimits: this.changeAxisLimits.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
});

}
static componentType = "chart";

static acceptTarget = true;
Expand Down Expand Up @@ -737,22 +746,4 @@ export default class Chart extends BlockComponent {
this.coreFunctions.resolveAction({ actionId });
}

recordVisibilityChange({ isVisible, actionId }) {
this.coreFunctions.requestRecordEvent({
verb: "visibilityChanged",
object: {
componentName: this.componentName,
componentType: this.componentType,
},
result: { isVisible }
})
this.coreFunctions.resolveAction({ actionId });
}

actions = {
changeAxisLimits: this.changeAxisLimits.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
}

}
5 changes: 2 additions & 3 deletions src/Core/components/ChoiceInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export default class Choiceinput extends Input {
constructor(args) {
super(args);


this.actions = {
Object.assign(this.actions, {
updateSelectedIndices: this.updateSelectedIndices.bind(this),
}
});

this.externalActions = {};

Expand Down
16 changes: 10 additions & 6 deletions src/Core/components/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import GraphicalComponent from './abstract/GraphicalComponent';
import me from 'math-expressions';

export default class Circle extends Curve {
constructor(args) {
super(args);

Object.assign(this.actions, {
moveCircle: this.moveCircle.bind(this),
circleClicked: this.circleClicked.bind(this),
mouseDownOnCircle: this.mouseDownOnCircle.bind(this),
});

}
static componentType = "circle";
static rendererType = "circle";
static representsClosedPath = true;

actions = {
moveCircle: this.moveCircle.bind(this),
circleClicked: this.circleClicked.bind(this),
mouseDownOnCircle: this.mouseDownOnCircle.bind(this),
};


static createAttributesObject() {
let attributes = super.createAttributesObject();
Expand Down
18 changes: 11 additions & 7 deletions src/Core/components/CodeEditor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import BlockComponent from './abstract/BlockComponent';

export default class CodeEditor extends BlockComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
updateImmediateValue: this.updateImmediateValue.bind(this),
updateValue: this.updateValue.bind(this),
updateComponents: this.updateComponents.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
});

}
static componentType = "codeEditor";

static variableForPlainMacro = "value";
Expand Down Expand Up @@ -430,11 +441,4 @@ export default class CodeEditor extends BlockComponent {
this.coreFunctions.resolveAction({ actionId });
}

actions = {
updateImmediateValue: this.updateImmediateValue.bind(this),
updateValue: this.updateValue.bind(this),
updateComponents: this.updateComponents.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
};

}
15 changes: 9 additions & 6 deletions src/Core/components/CodeViewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import BlockComponent from './abstract/BlockComponent';

export default class CodeViewer extends BlockComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
updateComponents: this.updateComponents.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
});

}
static componentType = "codeViewer";
static renderChildren = true;

Expand Down Expand Up @@ -254,10 +263,4 @@ export default class CodeViewer extends BlockComponent {
this.coreFunctions.resolveAction({ actionId });
}


actions = {
updateComponents: this.updateComponents.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
};

}
23 changes: 13 additions & 10 deletions src/Core/components/Curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import me from 'math-expressions';
import { returnBezierFunctions } from '../utils/function';

export default class Curve extends GraphicalComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
moveControlVector: this.moveControlVector.bind(this),
moveThroughPoint: this.moveThroughPoint.bind(this),
changeVectorControlDirection: this.changeVectorControlDirection.bind(this),
switchCurve: this.switchCurve.bind(this),
curveClicked: this.curveClicked.bind(this),
mouseDownOnCurve: this.mouseDownOnCurve.bind(this),
});

}
static componentType = "curve";
static rendererType = "curve";


actions = {
moveControlVector: this.moveControlVector.bind(this),
moveThroughPoint: this.moveThroughPoint.bind(this),
changeVectorControlDirection: this.changeVectorControlDirection.bind(this),
switchCurve: this.switchCurve.bind(this),
curveClicked: this.curveClicked.bind(this),
mouseDownOnCurve: this.mouseDownOnCurve.bind(this),
};

static primaryStateVariableForDefinition = "fShadow";


Expand Down
14 changes: 9 additions & 5 deletions src/Core/components/DiscreteSimulationResultList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import BlockComponent from './abstract/BlockComponent';


export default class DiscreteSimulationResultList extends BlockComponent {
constructor(args) {
super(args);

Object.assign(this.actions, {
onChange: this.onChange.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
});

}
static componentType = "DiscreteSimulationResultList";
static rendererType = "spreadsheet";

Expand Down Expand Up @@ -387,11 +396,6 @@ export default class DiscreteSimulationResultList extends BlockComponent {
this.coreFunctions.resolveAction({ actionId });
}

actions = {
onChange: this.onChange.bind(this),
recordVisibilityChange: this.recordVisibilityChange.bind(this),
};


}

Loading

0 comments on commit c2e1815

Please sign in to comment.