Skip to content

Commit 89a96d7

Browse files
committed
Add itemEditor and hintsEditor to EditorWithLayout
1 parent 8e1db2e commit 89a96d7

File tree

2 files changed

+73
-45
lines changed

2 files changed

+73
-45
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,38 @@ export const Controlled: Story = {
6969
>
7070
{(items) => (
7171
<View style={{gap: spacing.xSmall_8}}>
72-
<Section title="JSON Mode Editor">
73-
{items.jsonModeEditor}
72+
<View
73+
style={{
74+
flexDirection: "row",
75+
gap: spacing.xSmall_8,
76+
}}
77+
>
78+
<Section title="Viewport Resizer">
79+
{items.viewportResizerElement}
80+
</Section>
81+
82+
<Section title="Heads-up Display (HUD)">
83+
{items.hudElement}
84+
</Section>
85+
86+
<Section title="JSON Mode Editor">
87+
{items.jsonModeEditor}
88+
</Section>
89+
</View>
90+
91+
<Section title="Item Editor">
92+
{items.itemEditor}
7493
</Section>
7594

7695
<Section
7796
title="JSON Editor"
78-
style={{width: 50, height: 300}}
97+
style={{width: "100%", height: 300}}
7998
>
8099
<items.JsonEditor style={{height: 100}} />
81100
</Section>
82101

83-
<Section title="Heads-up Display (HUD)">
84-
{items.hudElement}
102+
<Section title="Hints Editor">
103+
{items.hintsEditor}
85104
</Section>
86105
</View>
87106
)}

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

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import _ from "underscore";
55

66
import JsonEditor from "./components/json-editor";
77
import ViewportResizer from "./components/viewport-resizer";
8+
import CombinedHintsEditor from "./hint-editor";
9+
import ItemEditor from "./item-editor";
810

9-
import type CombinedHintsEditor from "./hint-editor";
10-
import type ItemEditor from "./item-editor";
1111
import type {
1212
APIOptions,
1313
APIOptionsWithDefaults,
@@ -55,31 +55,45 @@ type Props = {
5555

5656
children: (components: {
5757
/**
58-
* Provides a rendered component that allows users to flip between the
58+
* A rendered component that allows users to flip between the
5959
* standard content editors or the raw JSON view. This view should be
6060
* gated behind a permission check and only "Developer" level folks
6161
* should be able to access this mode.
6262
*/
6363
jsonModeEditor: React.ReactNode;
6464

6565
/**
66-
* Provides a React Component that renders the JSON view of the current
66+
* A React Component that renders the JSON view of the current
6767
* item being edited. Note that this is a "Power User" editor and can
6868
* easily break an item if not used carefully.
6969
*/
7070
JsonEditor: React.ComponentType<{style: StyleType}>;
7171

7272
/**
73-
* Provides a rendered component that flips the preview component
73+
* A rendered component that flips the preview component
7474
* between different viewport sizes (ie. phone, tablet, desktop).
7575
*/
7676
viewportResizerElement: React.ReactNode;
7777

7878
/**
79-
* Provides a rendered component that provides a button to toggle lint
79+
* A rendered component of a button to toggle lint
8080
* warnings on and off in the other editors.
8181
*/
8282
hudElement: React.ReactNode;
83+
84+
/**
85+
* A rendered component that provides the item editing experience.
86+
* TODO: Inline this component into EditorWithLayout for more layout
87+
* control.
88+
*/
89+
itemEditor: React.ReactNode;
90+
91+
/**
92+
* A rendered component that provides the hints editing experience.
93+
* TODO: Inline this component into EditorWithLayout for more layout
94+
* control.
95+
*/
96+
hintsEditor: React.ReactNode;
8397
}) => React.ReactNode;
8498
};
8599

@@ -285,8 +299,6 @@ class EditorWithLayout extends React.Component<Props, State> {
285299
{this.props.children({
286300
jsonModeEditor: jsonModeEditor,
287301
JsonEditor: ({style}: {style: StyleType}) => (
288-
// I suspect this will need some way to pass styles in
289-
// so the host can define its size.
290302
<JsonEditor
291303
value={this.state.json}
292304
onChange={this.changeJSON}
@@ -313,41 +325,38 @@ class EditorWithLayout extends React.Component<Props, State> {
313325
}}
314326
/>
315327
),
328+
itemEditor: !this.props.jsonMode && (
329+
<ItemEditor
330+
ref={this.itemEditor}
331+
itemId={this.props.itemId}
332+
question={this.props.question}
333+
answerArea={this.props.answerArea}
334+
imageUploader={this.props.imageUploader}
335+
onChange={this.handleChange}
336+
wasAnswered={this.state.wasAnswered}
337+
gradeMessage={this.state.gradeMessage}
338+
deviceType={this.props.previewDevice}
339+
apiOptions={deviceBasedApiOptions}
340+
previewURL={this.props.previewURL}
341+
/>
342+
),
343+
hintsEditor: !this.props.jsonMode && (
344+
<CombinedHintsEditor
345+
ref={this.hintsEditor}
346+
itemId={this.props.itemId}
347+
hints={this.props.hints}
348+
imageUploader={this.props.imageUploader}
349+
onChange={this.handleChange}
350+
deviceType={this.props.previewDevice}
351+
apiOptions={deviceBasedApiOptions}
352+
previewURL={this.props.previewURL}
353+
highlightLint={this.state.highlightLint}
354+
/>
355+
),
316356
})}
317357
</div>
318358
);
319359
}
320360
}
321-
/*
322-
323-
{(!this.props.developerMode || !this.props.jsonMode) && (
324-
<ItemEditor
325-
ref={this.itemEditor}
326-
itemId={this.props.itemId}
327-
question={this.props.question}
328-
answerArea={this.props.answerArea}
329-
imageUploader={this.props.imageUploader}
330-
onChange={this.handleChange}
331-
wasAnswered={this.state.wasAnswered}
332-
gradeMessage={this.state.gradeMessage}
333-
deviceType={this.props.previewDevice}
334-
apiOptions={deviceBasedApiOptions}
335-
previewURL={this.props.previewURL}
336-
/>
337-
)}
338-
339-
{(!this.props.developerMode || !this.props.jsonMode) && (
340-
<CombinedHintsEditor
341-
ref={this.hintsEditor}
342-
itemId={this.props.itemId}
343-
hints={this.props.hints}
344-
imageUploader={this.props.imageUploader}
345-
onChange={this.handleChange}
346-
deviceType={this.props.previewDevice}
347-
apiOptions={deviceBasedApiOptions}
348-
previewURL={this.props.previewURL}
349-
highlightLint={this.state.highlightLint}
350-
/>
351-
)}
352-
*/
361+
353362
export default EditorWithLayout;

0 commit comments

Comments
 (0)