Skip to content

Commit

Permalink
Merge pull request #76 from idyll-lang/dataset-initial-value
Browse files Browse the repository at this point in the history
Dataset initial value
  • Loading branch information
mathisonian authored Feb 11, 2021
2 parents adb1c2b + 758ae16 commit f048532
Show file tree
Hide file tree
Showing 19 changed files with 643 additions and 378 deletions.
15 changes: 9 additions & 6 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Main {
this.mainWindow.webContents.send('idyll:compile', {
ast: null
});
})
});

this.mainWindow.webContents.on('new-window', function(e, url) {
e.preventDefault();
Expand Down Expand Up @@ -76,10 +76,13 @@ class Main {
});
// import dataset
ipcMain.on('importDataset', (event, message) => {
fs.copyFileSync(message, `${this.workingDir}/data/${p.basename(message)}`);
const filePath = `${this.workingDir}/data/${p.basename(message)}`;

if (filePath !== message) {
fs.copyFileSync(message, filePath);
}
this.mainWindow.webContents.send('data:import');
});

}

async handleCreateProject(event, projectName) {
Expand All @@ -99,10 +102,10 @@ class Main {
const slugName = slugify(projectName);
await createProject({
'package-name': `${slugName}`,
'template': 'article',
template: 'article',
'post-dir': `${projectDir}/${slugName}`,
'installDependencies': true
})
installDependencies: true
});

this.executeOnProjectOpen(`${projectDir}/${slugName}/index.idyll`);
} catch (err) {
Expand Down
13 changes: 10 additions & 3 deletions src/render/idyll-display/components/author-tool-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class AuthorToolButtons extends React.PureComponent {
}
}


onBlur(newMarkup) {
this.setState({
markup: newMarkup
Expand Down Expand Up @@ -54,8 +53,16 @@ class AuthorToolButtons extends React.PureComponent {
onClick={this.handleClickProps.bind(this)}
data-tip
data-for={props.uniqueKey}>
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 4.07099V5.90814L1.125 6.09604C1.20832 6.40919 1.33332 6.70148 1.47918 6.952L0.8125 7.87056L2.10418 9.1858L3.04168 8.53863C3.3125 8.68476 3.60418 8.81002 3.89582 8.89355L4.08332 10H5.91668L6.10418 8.87265C6.41668 8.78915 6.6875 8.66389 6.95832 8.51777L7.875 9.16494L9.1875 7.87056L8.52082 6.952C8.66664 6.68058 8.79164 6.38832 8.875 6.07517L10 5.90814V4.07099L8.875 3.8831C8.79168 3.56995 8.66668 3.29852 8.52082 3.02713L9.1875 2.08767L7.89582 0.793297L6.95832 1.46137C6.6875 1.31524 6.39582 1.18998 6.08332 1.10645L5.89582 0H4.0625L3.875 1.12735C3.58332 1.21085 3.29168 1.33611 3.02082 1.48223L2.08332 0.814198L0.791677 2.10854L1.45832 3.048C1.3125 3.31942 1.1875 3.59081 1.10418 3.90396L0 4.07099ZM5 3.0689C6.0625 3.0689 6.91668 3.92483 6.91668 4.98955C6.91668 6.05427 6.04168 6.91023 5 6.91023C3.95832 6.91023 3.08332 6.05427 3.08332 4.98955C3.08332 3.92483 3.9375 3.0689 5 3.0689Z" fill="white"/>
<svg
width='10'
height='10'
viewBox='0 0 10 10'
fill='none'
xmlns='http://www.w3.org/2000/svg'>
<path
d='M0 4.07099V5.90814L1.125 6.09604C1.20832 6.40919 1.33332 6.70148 1.47918 6.952L0.8125 7.87056L2.10418 9.1858L3.04168 8.53863C3.3125 8.68476 3.60418 8.81002 3.89582 8.89355L4.08332 10H5.91668L6.10418 8.87265C6.41668 8.78915 6.6875 8.66389 6.95832 8.51777L7.875 9.16494L9.1875 7.87056L8.52082 6.952C8.66664 6.68058 8.79164 6.38832 8.875 6.07517L10 5.90814V4.07099L8.875 3.8831C8.79168 3.56995 8.66668 3.29852 8.52082 3.02713L9.1875 2.08767L7.89582 0.793297L6.95832 1.46137C6.6875 1.31524 6.39582 1.18998 6.08332 1.10645L5.89582 0H4.0625L3.875 1.12735C3.58332 1.21085 3.29168 1.33611 3.02082 1.48223L2.08332 0.814198L0.791677 2.10854L1.45832 3.048C1.3125 3.31942 1.1875 3.59081 1.10418 3.90396L0 4.07099ZM5 3.0689C6.0625 3.0689 6.91668 3.92483 6.91668 4.98955C6.91668 6.05427 6.04168 6.91023 5 6.91023C3.95832 6.91023 3.08332 6.05427 3.08332 4.98955C3.08332 3.92483 3.9375 3.0689 5 3.0689Z'
fill='white'
/>
</svg>
</button>
</div>
Expand Down
54 changes: 43 additions & 11 deletions src/render/idyll-display/components/author-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export const WrappedAuthorView = withContext(
}

renderInner() {
switch(this.state.selectedView) {
switch (this.state.selectedView) {
case 'properties':
return <Properties />;
case 'code':
return <Code />;
case 'style':
return <Styles />;
default:
return null;
return null;
}
}

Expand All @@ -115,17 +115,49 @@ export const WrappedAuthorView = withContext(
top: dimensions.top + 30,
left: dimensions.left - 10
}}>
<div className="author-view-overlay-header">
<div style={{display: 'flex', justifyContent: 'space-between'}}>
<div className={'author-view-overlay-header-button author-view-overlay-header-close-button'} onClick={() => { this.close() }}>×</div>
<div className={`author-view-overlay-header-button ${selectedView === 'properties' ? 'selected' : ''}`} onClick={() => { this.setState({ selectedView: 'properties' }) }}>Properties</div>
<div className={`author-view-overlay-header-button ${selectedView === 'code' ? 'selected' : ''}`} onClick={() => { this.setState({ selectedView: 'code' }) }}>Markup</div>
<div className={`author-view-overlay-header-button ${selectedView === 'style' ? 'selected' : ''}`} onClick={() => { this.setState({ selectedView: 'style' }) }}>Styles</div>
<div className='author-view-overlay-header'>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div
className={
'author-view-overlay-header-button author-view-overlay-header-close-button'
}
onClick={() => {
this.close();
}}>
×
</div>
<div
className={`author-view-overlay-header-button ${
selectedView === 'properties' ? 'selected' : ''
}`}
onClick={() => {
this.setState({ selectedView: 'properties' });
}}>
Properties
</div>
<div
className={`author-view-overlay-header-button ${
selectedView === 'code' ? 'selected' : ''
}`}
onClick={() => {
this.setState({ selectedView: 'code' });
}}>
Markup
</div>
<div
className={`author-view-overlay-header-button ${
selectedView === 'style' ? 'selected' : ''
}`}
onClick={() => {
this.setState({ selectedView: 'style' });
}}>
Styles
</div>
</div>
<div style={{maxHeight: 200, overflowY: 'auto'}}>
{this.renderInner()}
</div>
</div>
<div style={{ maxHeight: 200, overflowY: 'auto' }}>
{this.renderInner()}
</div>
</div>
);
}
Expand Down
48 changes: 34 additions & 14 deletions src/render/idyll-display/components/component-editor/code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


import * as React from 'react';
import { getNodeById, getParentNodeById, getRandomId } from '../../utils/';
import { getNodeById, getParentNodeById, getRandomId } from '../../utils/';
import { withContext } from '../../../context/with-context';
import EditableCodeCell from './code-cell';

Expand Down Expand Up @@ -32,11 +30,12 @@ export default withContext(
this.updateAst(newMarkup);
}

onBlur(newMarkup) {
}
onBlur(newMarkup) {}

updateAst(newMarkup) {
const output = compile(newMarkup || this.getMarkup(this.props), { async: false });
const output = compile(newMarkup || this.getMarkup(this.props), {
async: false
});
let node = output.children[0];

while (node.type === 'component' && node.name === 'TextContainer') {
Expand Down Expand Up @@ -67,33 +66,54 @@ export default withContext(
return;
}

const childIdx = (parentNode.children || []).findIndex(c => c.id === this.props.context.activeComponent.id);
const childIdx = (parentNode.children || []).findIndex(
c => c.id === this.props.context.activeComponent.id
);

node.forEach((n) => {
node.forEach(n => {
n.id = getRandomId();
})
});

// parentNode.children.splice(childIdx, 0, ...node);
parentNode.children = parentNode.children.slice(0, childIdx).concat(node).concat(parentNode.children.slice(childIdx + 1));
parentNode.children = parentNode.children
.slice(0, childIdx)
.concat(node)
.concat(parentNode.children.slice(childIdx + 1));
}

this.props.context.setAst(this.props.context.ast);
}

render() {
return (
return (
<div className={'idyll-code-editor'}>
<EditableCodeCell
onExecute={this.onExecute.bind(this)}
onBlur={this.onBlur.bind(this)}
markup={this.getMarkup(this.props)}
/>
<div className={'code-instructions'} style={{color: '#ccc', fontSize: 10, fontStyle: 'italic', margin: '5px 16px', display: 'flex', justifyContent: 'space-between'}}>
<div
className={'code-instructions'}
style={{
color: '#ccc',
fontSize: 10,
fontStyle: 'italic',
margin: '5px 16px',
display: 'flex',
justifyContent: 'space-between'
}}>
<div>shift + enter to execute</div>
<div><a target="_blank" style={{color: '#ccc', textDecoration: 'underline'}} href={'https://idyll-lang.org/docs/syntax'}>Syntax Guide</a></div>
<div>
<a
target='_blank'
style={{ color: '#ccc', textDecoration: 'underline' }}
href={'https://idyll-lang.org/docs/syntax'}>
Syntax Guide
</a>
</div>
</div>
</div>
)
);
}
}
);
Loading

0 comments on commit f048532

Please sign in to comment.