Skip to content

Commit 967030b

Browse files
committed
Add Item Preview and Question Extras editors
1 parent 3879b6a commit 967030b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/perseus-editor/src/__stories__/editor-with-layout.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export const Controlled: Story = {
102102
<Section title="Hints Editor">
103103
{items.hintsEditor}
104104
</Section>
105+
106+
<Section title="Question Extras">
107+
{items.questionExtras}
108+
</Section>
105109
</View>
106110
)}
107111
</EditorWithLayout>

packages/perseus-editor/src/editor-with-layout.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import {Checkbox} from "@khanacademy/wonder-blocks-form";
33
import * as React from "react";
44
import _ from "underscore";
55

6+
import DeviceFramer from "./components/device-framer";
67
import JsonEditor from "./components/json-editor";
78
import ViewportResizer from "./components/viewport-resizer";
9+
import ContentPreview from "./content-preview";
810
import CombinedHintsEditor from "./hint-editor";
11+
import IframeContentRenderer from "./iframe-content-renderer";
912
import ItemEditor from "./item-editor";
13+
import ItemExtrasEditor from "./item-extras-editor";
1014

1115
import type {
1216
APIOptions,
@@ -88,12 +92,26 @@ type Props = {
8892
*/
8993
itemEditor: React.ReactNode;
9094

95+
/**
96+
* A rendered component that previews the current item. It is updated
97+
* any time the question, hints, or answerArea changes. It is also
98+
* updaed when the `jsonModeEditor` is toggled on and the `JsonEditor`
99+
* is changed.
100+
*/
101+
itemPreview: React.ReactNode;
102+
91103
/**
92104
* A rendered component that provides the hints editing experience.
93105
* TODO: Inline this component into EditorWithLayout for more layout
94106
* control.
95107
*/
96108
hintsEditor: React.ReactNode;
109+
110+
/**
111+
* A rendered component that provides an editor to toggle question
112+
* extras for this item (such as calculator, periodic table, etc).
113+
*/
114+
questionExtras: React.ReactNode;
97115
}) => React.ReactNode;
98116
};
99117

@@ -115,6 +133,8 @@ class EditorWithLayout extends React.Component<Props, State> {
115133

116134
itemEditor = React.createRef<ItemEditor>();
117135
hintsEditor = React.createRef<CombinedHintsEditor>();
136+
itemExtrasEditor = React.createRef<ItemExtrasEditor>();
137+
previewRenderer = React.createRef<IframeContentRenderer>();
118138

119139
static defaultProps: {
120140
developerMode: boolean;
@@ -340,6 +360,21 @@ class EditorWithLayout extends React.Component<Props, State> {
340360
previewURL={this.props.previewURL}
341361
/>
342362
),
363+
itemPreview: (
364+
<DeviceFramer
365+
deviceType={this.props.previewDevice}
366+
nochrome={true}
367+
>
368+
<IframeContentRenderer
369+
ref={this.previewRenderer}
370+
key={this.props.previewDevice}
371+
datasetKey="mobile"
372+
datasetValue={touch}
373+
seamless={true}
374+
url={this.props.previewURL}
375+
/>
376+
</DeviceFramer>
377+
),
343378
hintsEditor: !this.props.jsonMode && (
344379
<CombinedHintsEditor
345380
ref={this.hintsEditor}
@@ -353,6 +388,21 @@ class EditorWithLayout extends React.Component<Props, State> {
353388
highlightLint={this.state.highlightLint}
354389
/>
355390
),
391+
questionExtras: (
392+
<ItemExtrasEditor
393+
ref={this.itemExtrasEditor}
394+
onChange={(answerArea) =>
395+
this.handleChange({
396+
// @ts-expect-error - TS2322 - Types of property 'calculator' are incompatible.
397+
answerArea: {
398+
...this.props.answerArea,
399+
...answerArea,
400+
},
401+
})
402+
}
403+
{...this.props.answerArea}
404+
/>
405+
),
356406
})}
357407
</div>
358408
);

0 commit comments

Comments
 (0)