Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: add ability to define a custom preview frame html wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Küchler authored and lkuechler committed Jan 20, 2018
1 parent a8cd86e commit 47e1f4d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/component/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class App extends React.Component<AppProps> {
// Todo: project and page don't update on page change
const project = this.props.store.getCurrentProject();
const title = `${project && project.getName()}`;
const previewFrame = project && project.getPreviewFrame();
const previewFramePath =
previewFrame && PathUtils.join(this.props.store.getStyleGuidePath(), 'alva', previewFrame);

const DevTools = getDevTools();

Expand All @@ -101,7 +104,7 @@ class App extends React.Component<AppProps> {
<PatternListContainer store={this.props.store} />
</PatternsPane>
</SideBar>,
<PreviewPane key="center" />,
<PreviewPane key="center" previewFrame={previewFramePath} />,
<SideBar key="right" directionVertical hasPaddings>
<PropertyPane>
<PropertyList store={this.props.store} />
Expand Down
4 changes: 3 additions & 1 deletion src/component/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ ipcRenderer.on('open-styleguide', (event: {}, message: JsonObject) => {
store.openStyleguide(message.styleGuidePath as string);
});

ReactDom.render(<PreviewApp store={store} />, document.getElementById('app'));
window.onload = () => {
ReactDom.render(<PreviewApp store={store} />, document.getElementById('app'));
};
3 changes: 1 addition & 2 deletions src/electron/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<body>
<div id="app" style="position: absolute; top:0; bottom:0; left:0; right:0;"></div>
<script>require('../../build/component/preview.js')</script>
</body>

</html>
</html>
30 changes: 21 additions & 9 deletions src/lsg/patterns/panes/preview-pane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { colors } from '../../colors';
import * as React from 'react';
import styled from 'styled-components';

export interface PreviewPaneProps {
previewFrame?: string;
}

const StyledPreviewPane = styled.div`
flex-grow: 1;
flex-shrink: 0;
Expand All @@ -11,13 +15,21 @@ const StyledPreviewPane = styled.div`
overflow: hidden;
`;

const PreviewPane: React.StatelessComponent = props => (
<StyledPreviewPane
dangerouslySetInnerHTML={{
__html:
'<webview id="preview" style="height: 100%; border-radius: 6px 6px 0 0; overflow: hidden;" src="./preview.html" partition="electron" nodeintegration />'
}}
/>
);
export default class PreviewPane extends React.Component<PreviewPaneProps> {
public constructor(props: PreviewPaneProps) {
super(props);
}

public render(): JSX.Element {
const { previewFrame } = this.props;

export default PreviewPane;
return (
<StyledPreviewPane
dangerouslySetInnerHTML={{
__html: `<webview id="preview" style="height: 100%; border-radius: 6px 6px 0 0; overflow: hidden;" src="${previewFrame ||
'./preview.html'}" preload="../../build/component/preview.js" partition="electron" nodeintegration />`
}}
/>
);
}
}
24 changes: 22 additions & 2 deletions src/store/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ export class Project {
*/
@MobX.observable private pages: PageRef[] = [];

/**
* Path to the preview frame, relative to the projects.yaml file.
*/
@MobX.observable private previewFrame: string;

/**
* Creates a new project.
* @param id The technical (internal) ID of the project.
* @param name The human-friendly name of the project.
* @param previewFrame Path to the preview frame, relative to the projects.yaml file.
*/
public constructor(id: string, name: string) {
public constructor(id: string, name: string, previewFrame: string) {
this.id = id;
this.name = name;
this.previewFrame = previewFrame;
}

/**
Expand All @@ -46,7 +53,11 @@ export class Project {
* @return A new project object containing the loaded data.
*/
public static fromJsonObject(json: JsonObject, store: Store): Project {
const project: Project = new Project(json.id as string, json.name as string);
const project: Project = new Project(
json.id as string,
json.name as string,
json.previewFrame as string
);

const pages: PageRef[] = [];
(json.pages as JsonArray).forEach((pageJson: JsonObject) => {
Expand Down Expand Up @@ -91,6 +102,14 @@ export class Project {
return this.pages as MobX.IObservableArray<PageRef>;
}

/**
* Returns the configured path to the preview frame, relative to the projects.yaml file.
* @return Path to the configured preview frame
*/
public getPreviewFrame(): string {
return this.previewFrame;
}

/**
* Serializes the project into a JSON object for persistence.
* @return The JSON object to be persisted.
Expand All @@ -104,6 +123,7 @@ export class Project {
return {
id: this.id,
name: this.name,
previewFrame: this.previewFrame,
pages: pagesJsonObject
};
}
Expand Down

0 comments on commit 47e1f4d

Please sign in to comment.