Skip to content

Commit

Permalink
Merge pull request #50 from milafrerichs/feat/add-modes
Browse files Browse the repository at this point in the history
Feat/add modes
  • Loading branch information
milafrerichs authored Aug 28, 2019
2 parents 2a91329 + 947f0de commit 4f2d3b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.3.0
## Added
New `mode` prop
previous `viewOnly` can now be replicated using `view` mode

## Removed
- viewOnly prop is remove

# v0.0.10
## Added
- active state for the switcher
Expand Down
11 changes: 11 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ I tried observable which is great for d3 and you can for the code and try it out
That's why I built the prototype in a day to test it out.


## Usage outside a svelte app

```
new JavascriptRepl({
target: document.querySelector('#code-example'),
props: {
files: [{name: 'index.js', content: code, type: 'js' }]
}
});
```

### Example how it looks like
![](docs/example.png)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "javascript-repl",
"svelte": "src/Repl.svelte",
"module": "index.mjs",
"version": "0.2.5",
"version": "0.3.0",
"description": "",
"main": "index.js",
"author": "Mila Frerichs <[email protected]>",
Expand Down
44 changes: 26 additions & 18 deletions src/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let currentContent = '';
let code = '';
let html = '';
export let viewOnly = false;
export let mode = 'normal';
export let changedCode = () => {};
export let files = [];
export let injectedLibraries = [];
Expand Down Expand Up @@ -82,6 +82,10 @@
}
$: showEditor = (mode === 'normal' || mode === 'minimal')
$: showTabs = (mode === 'normal' || mode === 'view')
$: showFiles = (mode === 'normal' || mode === 'view')
$: currentFile = files[currentFileIndex]
$: if(editor && currentFile) {
Expand Down Expand Up @@ -129,27 +133,31 @@

<div class="{cssStyles.container}" >
<div class="result-container {cssStyles.resultContainer}">
{#if !viewOnly }
<div class:hidden="{viewOnly}" class="{cssStyles.editor}">
<div class="{cssStyles.editorActions.container}">
{#each files as { name }, i}
<div class="{cssStyles.editorActions.tabItem}">
<a class:active="{currentFileIndex == i}" class="{cssStyles.editorActions.link}" on:click="{() => showFile(i)}">{name}</a>
</div>
{/each}
</div>
{#if showEditor}
<div class:hidden="{!showEditor}" class="{cssStyles.editor}">
{#if showFiles}
<div class="{cssStyles.editorActions.container}">
{#each files as { name }, i}
<div class="{cssStyles.editorActions.tabItem}">
<a class:active="{currentFileIndex == i}" class="{cssStyles.editorActions.link}" on:click="{() => showFile(i)}">{name}</a>
</div>
{/each}
</div>
{/if}
<Editor bind:this={editor} on:change={debounceChangeCode}/>
</div>
{/if}
<div class:view-only="{viewOnly}" class="{cssStyles.viewerContainer}">
<div class="{cssStyles.viewerActions.container}">
<div class="{cssStyles.viewerActions.tabItem}">
<a class:active="{tab == 'viewer'}" class="{cssStyles.viewerActions.link}" on:click="{() => showResult()}">Result</a>
</div>
<div class="{cssStyles.viewerActions.tabItem}">
<a class:active="{tab == 'console'}" class="{cssStyles.viewerActions.link}" on:click="{() => showConsole()}">Console</a>
<div class:view-only="{!showEditor}" class="{cssStyles.viewerContainer}">
{#if showTabs}
<div class="{cssStyles.viewerActions.container}">
<div class="{cssStyles.viewerActions.tabItem}">
<a class:active="{tab == 'viewer'}" class="{cssStyles.viewerActions.link}" on:click="{() => showResult()}">Result</a>
</div>
<div class="{cssStyles.viewerActions.tabItem}">
<a class:active="{tab == 'console'}" class="{cssStyles.viewerActions.link}" on:click="{() => showConsole()}">Console</a>
</div>
</div>
</div>
{/if}
<div class="{cssStyles.viewerConsoleContainer}">
<div class:hidden="{tab != 'viewer'}" class="{cssStyles.viewer}">
<Viewer bind:ready={ready} {code} {injectedLibraries} {html} {injectedJS} />
Expand Down

0 comments on commit 4f2d3b1

Please sign in to comment.