-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
554 additions
and
2,702 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
packages/doenetml-prototype/src/renderers/pretext/choice-input.css
This file was deleted.
Oops, something went wrong.
35 changes: 1 addition & 34 deletions
35
packages/doenetml-prototype/src/renderers/pretext/choice-input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,6 @@ | ||
import React from "react"; | ||
import { BasicComponent } from "../types"; | ||
import { useAppSelector } from "../../state/hooks"; | ||
import { renderingOnServerSelector } from "../../state/redux-slices/global"; | ||
import "./choice-input.css"; | ||
import { elementsArraySelector } from "../../state/redux-slices/dast"; | ||
import { Radio, RadioGroup, RadioProvider } from "@ariakit/react"; | ||
import { flatDastChildrenToReactChildren } from "../element"; | ||
|
||
export const ChoiceInput: BasicComponent = ({ node }) => { | ||
const childrenIds = React.useMemo( | ||
() => | ||
node.children.filter( | ||
(n) => typeof n === "number", | ||
) as unknown[] as number[], | ||
[node.children], | ||
); | ||
const elements = useAppSelector(elementsArraySelector); | ||
|
||
const choiceChildren = childrenIds.flatMap((id) => { | ||
const choice = elements[id]; | ||
return choice.type === "element" && choice.name === "choice" | ||
? choice | ||
: []; | ||
}); | ||
|
||
return ( | ||
<RadioProvider> | ||
<RadioGroup className="choice-input"> | ||
{choiceChildren.map((child, i) => ( | ||
<label key={child.data.id}> | ||
<Radio value={child.data.id} /> | ||
{flatDastChildrenToReactChildren(child.children)} | ||
</label> | ||
))} | ||
</RadioGroup> | ||
</RadioProvider> | ||
); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
packages/doenetml-prototype/src/renderers/pretext/graph.css
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 2 additions & 13 deletions
15
packages/doenetml-prototype/src/renderers/pretext/math.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
import React from "react"; | ||
import { MathJax } from "better-react-mathjax"; | ||
import { BasicComponent } from "../types"; | ||
import { useAppSelector } from "../../state/hooks"; | ||
import { renderingOnServerSelector } from "../../state/redux-slices/global"; | ||
|
||
type MathData = { props: { latex: string } }; | ||
|
||
export const Math: BasicComponent<MathData> = ({ node }) => { | ||
const onServer = useAppSelector(renderingOnServerSelector); | ||
if (onServer) { | ||
return <span className="process-math">{node.data.props.latex}</span>; | ||
} | ||
// better-react-mathjax cannot handle multiple children (it will not update when they change) | ||
// so create a single string. | ||
const latexString = `\\(${node.data.props.latex}\\)`; | ||
return ( | ||
<MathJax inline dynamic> | ||
{latexString} | ||
</MathJax> | ||
); | ||
const latexString = node.data.props.latex; | ||
return React.createElement("m", {}, latexString); | ||
}; |
10 changes: 0 additions & 10 deletions
10
packages/doenetml-prototype/src/renderers/pretext/text-input.css
This file was deleted.
Oops, something went wrong.
54 changes: 2 additions & 52 deletions
54
packages/doenetml-prototype/src/renderers/pretext/text-input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,11 @@ | ||
import React from "react"; | ||
import type { Action, TextInputProps } from "@doenet/doenetml-worker-rust"; | ||
import type { TextInputProps } from "@doenet/doenetml-worker-rust"; | ||
import { BasicComponent } from "../types"; | ||
import { useAppDispatch, useAppSelector } from "../../state/hooks"; | ||
import { renderingOnServerSelector } from "../../state/redux-slices/global"; | ||
import "./text-input.css"; | ||
import { coreActions } from "../../state/redux-slices/core"; | ||
|
||
type TextInputData = { props: TextInputProps }; | ||
|
||
export const TextInput: BasicComponent<TextInputData> = ({ node }) => { | ||
const onServer = useAppSelector(renderingOnServerSelector); | ||
const id = node.data.id; | ||
const value = node.data.props.immediateValue; | ||
//const disabled = node.data.props.disabled; | ||
const dispatch = useAppDispatch(); | ||
|
||
const updateValue = React.useCallback(() => { | ||
let action: Action = { | ||
component: "textInput", | ||
actionName: "updateValue", | ||
componentIdx: id, | ||
}; | ||
dispatch(coreActions.dispatchAction(action)); | ||
}, [dispatch, value]); | ||
|
||
if (onServer) { | ||
return <span className="text-input">{value}</span>; | ||
} | ||
|
||
// TODO: change style to gray out when disabled | ||
|
||
return ( | ||
<span className="text-input"> | ||
<label> | ||
<input | ||
type="text" | ||
value={value} | ||
disabled={ | ||
false //disabled | ||
} | ||
onChange={(e) => { | ||
const action: Action = { | ||
component: "textInput", | ||
componentIdx: id, | ||
actionName: "updateImmediateValue", | ||
args: { text: e.target.value }, | ||
}; | ||
dispatch(coreActions.dispatchAction(action)); | ||
}} | ||
onBlur={updateValue} | ||
onKeyUp={(e) => { | ||
if (e.key === "Enter") { | ||
updateValue(); | ||
} | ||
}} | ||
/> | ||
</label> | ||
</span> | ||
); | ||
return <em>{value}</em>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.