Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/WebComponent.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ The `set menuItems(newValue)` method shows how data could be set dynamically fro

The `mountReactApp()` method creates a dom element attaches a shadow dom to it and then mounts the React application in it.

The `static get observedAttributes()` method returns an array of attributes that are allowed to be set on the web component. At present it returns `['code']` meaning you can add the code attribute:
The `static get observedAttributes()` method returns an array of attributes that are allowed to be set on the web component. At present it returns `['code', 'visualOutput]` meaning you can add these attributes:

`<editor-wc code="print('Hello component')"></editor-wc>`
`<editor-wc code="print('Hello component')" visualOutput="1"></editor-wc>`

* `code` is the prepopulated code
* `visualOutput` if truthy will show the visual output tab, else it'll show the text output tab

Any other attributes set will not be available in the component and would need to be added to the observedAttributes to make them so.

Expand Down
4 changes: 3 additions & 1 deletion src/components/Editor/Runners/PythonRunner/PythonRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ const PythonRunner = () => {
}
}

let tabIndex = projectCode[0] && projectCode[0].visualoutput ? 0 : 1;

return (
<div className="pythonrunner-container">
<Tabs forceRenderTabPanel={true} defaultIndex={1}>
<Tabs forceRenderTabPanel={true} defaultIndex={tabIndex}>
<TabList>
<Tab key={0}>Visual Output</Tab>
<Tab key={1}>Text Output</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import WebComponentProject from '../Project/WebComponentProject';

const ProjectComponentLoader = (props) => {
const projectLoaded = useSelector((state) => state.editor.projectLoaded);
const { code } = props;
const { code, visualoutput } = props;
const dispatch = useDispatch()

useEffect(() => {
const proj = {
type: 'python',
components: [{ name: 'main', extension: 'py', content: code }]
components: [{ name: 'main', extension: 'py', content: code, visualoutput: visualoutput}]
}
dispatch(setProject(proj))
dispatch(setProjectLoaded(true))
Expand Down
2 changes: 1 addition & 1 deletion src/web-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Editor Web component</title>
</head>
<body>
<editor-wc code=""></editor-wc>
<editor-wc code="" visualOutput="1"></editor-wc>
<p id="results"></p>
</body>

Expand Down
2 changes: 1 addition & 1 deletion src/web-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebComponent extends HTMLElement {
}

static get observedAttributes() {
return ['code'];
return ['code', 'visualoutput'];
}

attributeChangedCallback(name, _oldVal, newVal) {
Expand Down