Skip to content

Commit

Permalink
fix: assetsNode clean imrprove & css update&preview
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Apr 18, 2020
1 parent bdfa90c commit eda6b7d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Visit: https://coldemo.github.io/
- [ ] antd4, safe js exec sandbox - see pureproxy
- [ ] lang ts/tsx/vue/py/rb/java
- [ ] storage list, reset btn, responsive, screenshot
- [ ] error-handling, sandboxNode
- [ ] error-handling, assetsNode
- [x] gh-pages, lang js/jsx, react/vue, umd-hack
- [x] code read from url, storybook cards
- [x] web worker for babel transform
Expand Down
10 changes: 4 additions & 6 deletions public/code/vue-at.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ await loadJsForceUmd({

appendCss(`
.container { padding: 20px }
.editor { padding:4px 8px; height:120px; border:solid 1px gray; white-space:pre-wrap }
.editor { margin-top:20px; padding:4px 8px; height:120px; border:solid 1px gray; white-space:pre-wrap }
`)

let App = {
components: { At: VueAt },
template: `
<div class="container">
<h1>Vue At</h1>
<div style="margin-top:20px">
<at :members="members" v-model="input">
<div class="editor" contenteditable></div>
</at>
</div>
<at :members="members" v-model="input">
<div class="editor" contenteditable></div>
</at>
</div>
`,
data() {
Expand Down
6 changes: 4 additions & 2 deletions src/gallery/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
height: 100%;
}

@media (max-width: 360px) {
/* @media (max-width: 360px) {
.page-gallery .ant-col-xs-12 {
width: 100% !important;
}
}
} */

@media (min-width: 640px) and (max-width: 899px) {
.page-gallery .ant-col-sm-12 {
Expand All @@ -42,9 +42,11 @@
.ant-card-body {
padding: 12px;
}

.ant-card-meta-title {
font-size: 12px;
}

.page-gallery .ant-card-cover {
height: 120px;
}
Expand Down
1 change: 1 addition & 0 deletions src/playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export let Playground: React.FC = () => {
<MainCol style={{ flex: 1, overflowX: 'auto' }}>
<GentleSpin spinning={previewLoading}>
<MountNode id="mountNode" />
<div id="assetsNode" />
</GentleSpin>
</MainCol>
<DragSizing
Expand Down
7 changes: 3 additions & 4 deletions src/playground/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
height: 100%;
}

.page-playground #mountNode {
min-height: 100px;
overflow-y: auto;
word-break: break-word;
.page-playground #assetsNode,
.page-playground #assetsNodeOutdated {
display: none;
}

.page-playground .ant-spin-nested-loading,
Expand Down
3 changes: 3 additions & 0 deletions src/playground/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export let MainCol = styled(Col)`

export let MountNode = styled.div`
height: 100%;
min-height: 100px;
overflow-y: auto;
word-break: break-word;
`;

export let ErrorInfo = styled.pre`
Expand Down
1 change: 1 addition & 0 deletions src/playground/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
interface Window {
assetsNode: HTMLDivElement;
mountNode: HTMLDivElement;
}
16 changes: 12 additions & 4 deletions src/playground/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export let loadJs = (url: string) => {
el.onerror = e => {
reject(new Error(`loadJs onerror - ${url}`));
};
window.mountNode.appendChild(el);
window.assetsNode.appendChild(el);
});
};

Expand All @@ -65,26 +65,33 @@ export let loadCss = (url: string) => {
el.onerror = e => {
reject(new Error(`loadCss onerror - ${url}`));
};
window.mountNode.appendChild(el);
window.assetsNode.appendChild(el);
});
};

export let appendJs = (code: string) => {
let el = document.createElement('script');
el.innerHTML = code;
window.mountNode.appendChild(el);
window.assetsNode.appendChild(el);
};

export let appendCss = (code: string) => {
let el = document.createElement('style');
el.innerHTML = code;
window.mountNode.appendChild(el);
window.assetsNode.appendChild(el);
};

export let wrapCode = (code: string) => {
return `
(async () => {
setRendering(true)
let a0 = assetsNode
a0.id = 'assetsNodeOutdated'
let a1 = document.createElement('div')
a1.id = 'assetsNode'
a0.parentNode.appendChild(a1)
// mountNode.innerHTML = '' // can cause error in react
ReactDOM.unmountComponentAtNode(mountNode)
try {
Expand All @@ -102,6 +109,7 @@ export let wrapCode = (code: string) => {
} else {
ReactDOM.render(React.createElement(App), mountNode)
}
a0.parentNode.removeChild(a0)
} catch (err) {
console.error(['displayError', err])
displayError(err)
Expand Down

0 comments on commit eda6b7d

Please sign in to comment.