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

Commit

Permalink
feat: save resizable dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent 12d29a9 commit a8d9c62
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 144 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"mime-types": "2.1.18",
"mobx": "5.0.3",
"mobx-react": "5.2.3",
"monaco-editor": "0.13.1",
"node-fetch": "2.1.2",
"object-path": "0.11.4",
"query-string": "6.0.0",
Expand Down
58 changes: 58 additions & 0 deletions src/container/app-pane.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as MobxReact from 'mobx-react';
import * as React from 'react';
import { WithStore } from '../store';
import * as Types from '../types';

export interface AppPaneProps {
pane: Types.AppPane;
force?: boolean;
children: React.ReactNode;
defaultSize?: { width: number | string; height: number | string };
enable?: { top?: boolean; right?: boolean; bottom?: boolean; left?: boolean };
minWidth?: number;
minHeight?: number;
}

const Resizeable = require('re-resizable').default;

@MobxReact.inject('store')
@MobxReact.observer
export class AppPane extends React.Component<AppPaneProps> {
public render(): JSX.Element | null {
const props = this.props as AppPaneProps & WithStore;
const app = props.store.getApp();

if (!props.force && !app.isVisible(props.pane)) {
return null;
}

const paneSize = props.pane ? app.getPaneSize(props.pane) : undefined;

const defaultSize = paneSize
? { width: paneSize.width, height: paneSize.height }
: props.defaultSize;

return (
<Resizeable
handleStyles={{ right: { zIndex: 1 } }}
defaultSize={defaultSize}
enable={props.enable}
minWidth={props.minWidth}
minHeight={props.minHeight}
onResizeStop={(_, __, el: HTMLElement) => {
if (!props.pane) {
return;
}

app.setPaneSize({
pane: props.pane,
width: el.clientWidth,
height: el.clientHeight
});
}}
>
{this.props.children}
</Resizeable>
);
}
}
21 changes: 21 additions & 0 deletions src/container/app-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as MobxReact from 'mobx-react';
import * as React from 'react';
import { WithStore } from '../store';
import * as Types from '../types';

export interface AppViewProps {
view: Types.AlvaView;
}

@MobxReact.inject('store')
@MobxReact.observer
export class AppView extends React.Component<AppViewProps> {
public render(): JSX.Element | null {
const props = this.props as AppViewProps & WithStore;
if (props.store.getApp().getActiveView() !== props.view) {
return null;
}

return <>{this.props.children}</>;
}
}
138 changes: 9 additions & 129 deletions src/container/app.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { AppView } from './app-view';
import { ChromeContainer } from './chrome/chrome-container';
import * as Sender from '../sender/client';
import * as Components from '../components';
import { ConnectPaneContainer } from './connect-pane-container';
import { ElementList } from './element-list';
import { MessageType } from '../message';
import * as MobxReact from 'mobx-react';
import { PageListContainer } from './page-list/page-list-container';
import { PatternListContainer } from './pattern-list';
import { PreviewPaneWrapper } from './preview-pane-wrapper';
import { PropertyListContainer } from './property-list';
import { PropertiesSwitch } from './properties-switch';
import { ProjectSettingsContainer } from './project-settings-container';
import * as React from 'react';
import { SplashScreenContainer } from './splash-screen-container';
import { ViewDetails } from './view-details';
import { ViewStore } from '../store';
import { ViewSplashscreen } from './view-splashscreen';
import * as Types from '../types';
import * as uuid from 'uuid';

const Resizeable = require('re-resizable');

Components.globalStyles();

Expand All @@ -42,121 +31,12 @@ export class App extends React.Component {
<ChromeContainer />
</Components.FixedArea>
<Components.MainArea>
{props.store.getActiveAppView() === Types.AlvaView.SplashScreen && (
<SplashScreenContainer
onPrimaryButtonClick={() => {
Sender.send({
type: MessageType.CreateNewFileRequest,
id: uuid.v4(),
payload: undefined
});
}}
onSecondaryButtonClick={() => {
Sender.send({
type: MessageType.OpenFileRequest,
id: uuid.v4(),
payload: undefined
});
}}
/>
)}
{props.store.getActiveAppView() === Types.AlvaView.PageDetail && (
<React.Fragment>
{app.getPanes().has(Types.AppPane.PagesPane) && (
<Resizeable
handleStyles={{ right: { zIndex: 1 } }}
defaultSize={{ width: 140, height: '100%' }}
enable={{ right: true }}
minWidth={140}
>
<Components.SideBar
side={Components.LayoutSide.Left}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<PageListContainer />
</Components.SideBar>
</Resizeable>
)}
{app.getPanes().has(Types.AppPane.ElementsPane) && (
<Resizeable
handleStyles={{ right: { zIndex: 1 } }}
defaultSize={{ width: 240, height: '100%' }}
enable={{ right: true }}
minWidth={240}
>
<Components.SideBar
side={Components.LayoutSide.Left}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<Components.ElementPane>
<ElementList />
</Components.ElementPane>

<Resizeable
handleStyles={{ top: { zIndex: 1 } }}
defaultSize={{ height: 500, width: '100%' }}
enable={{ top: true }}
minHeight={240}
>
<Components.PatternsPane>
<PatternListContainer />
</Components.PatternsPane>
</Resizeable>
</Components.SideBar>
</Resizeable>
)}
<PreviewPaneWrapper
isDragging={props.store.getDragging()}
key="center"
previewFrame={`http://localhost:${props.store.getServerPort()}/preview.html`}
/>

{app.getPanes().has(Types.AppPane.PropertiesPane) && (
<Resizeable
handleStyles={{ left: { zIndex: 1 } }}
defaultSize={{ width: 240, height: '100%' }}
enable={{ left: true }}
minWidth={240}
>
<Components.SideBar
side={Components.LayoutSide.Right}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<div style={{ flexShrink: 0, height: 40 }}>
<PropertiesSwitch />
</div>
{props.store
.getPatternLibraries()
.every(
lib => lib.getOrigin() === Types.PatternLibraryOrigin.BuiltIn
) && (
<ConnectPaneContainer
onPrimaryButtonClick={() => props.store.connectPatternLibrary()}
onSecondaryButtonClick={() =>
Sender.send({
type: MessageType.OpenExternalURL,
id: uuid.v4(),
payload: 'http://meetalva.github.io/example/example.alva'
})
}
/>
)}
<Components.PropertyPane>
{props.store.getApp().getRightSidebarTab() ===
Types.RightSidebarTab.Properties && <PropertyListContainer />}
{props.store.getApp().getRightSidebarTab() ===
Types.RightSidebarTab.ProjectSettings && (
<ProjectSettingsContainer />
)}
</Components.PropertyPane>
</Components.SideBar>
</Resizeable>
)}
</React.Fragment>
)}
<AppView view={Types.AlvaView.SplashScreen}>
<ViewSplashscreen />
</AppView>
<AppView view={Types.AlvaView.PageDetail}>
<ViewDetails />
</AppView>
</Components.MainArea>
<Components.IconRegistry />
</Components.Layout>
Expand Down
124 changes: 124 additions & 0 deletions src/container/view-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { AppPane } from './app-pane';

import * as Sender from '../sender/client';
import * as Components from '../components';
import { ConnectPaneContainer } from './connect-pane-container';
import { ElementList } from './element-list';
import { MessageType } from '../message';
import * as MobxReact from 'mobx-react';
import { PageListContainer } from './page-list/page-list-container';
import { PatternListContainer } from './pattern-list';
import { PreviewPaneWrapper } from './preview-pane-wrapper';
import { PropertyListContainer } from './property-list';
import { PropertiesSwitch } from './properties-switch';
import { ProjectSettingsContainer } from './project-settings-container';
import * as React from 'react';
import * as Types from '../types';
import * as uuid from 'uuid';
import { ViewStore } from '../store';

@MobxReact.inject('store')
@MobxReact.observer
export class ViewDetails extends React.Component {
public render(): JSX.Element {
const props = this.props as { store: ViewStore };

return (
<React.Fragment>
<AppPane
pane={Types.AppPane.PagesPane}
defaultSize={{ width: 140, height: '100%' }}
enable={{ right: true }}
minWidth={140}
>
<Components.SideBar
side={Components.LayoutSide.Left}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<PageListContainer />
</Components.SideBar>
</AppPane>
<AppPane
pane={Types.AppPane.ElementsPane}
defaultSize={{ width: 240, height: '100%' }}
enable={{ right: true }}
minWidth={240}
>
<Components.SideBar
side={Components.LayoutSide.Left}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<Components.ElementPane>
<ElementList />
</Components.ElementPane>

<AppPane
force
pane={Types.AppPane.PatternsPane}
defaultSize={{ height: 500, width: '100%' }}
enable={{ top: true }}
minHeight={240}
>
<Components.PatternsPane>
<PatternListContainer />
</Components.PatternsPane>
</AppPane>
</Components.SideBar>
</AppPane>
<div style={{ display: 'flex', flexGrow: 1, flexDirection: 'column' }}>
<PreviewPaneWrapper
isDragging={props.store.getDragging()}
key="center"
previewFrame={`http://localhost:${props.store.getServerPort()}/preview.html`}
/>
<AppPane
pane={Types.AppPane.DevelopmentPane}
defaultSize={{ width: '100%', height: 500 }}
enable={{ top: true }}
minHeight={240}
>
<div style={{ borderTop: `1px solid ${Components.Color.Grey90}` }} />
</AppPane>
</div>
<AppPane
pane={Types.AppPane.PropertiesPane}
defaultSize={{ width: 240, height: '100%' }}
enable={{ left: true }}
minWidth={240}
>
<Components.SideBar
side={Components.LayoutSide.Right}
direction={Components.LayoutDirection.Column}
border={Components.LayoutBorder.Side}
>
<div style={{ flexShrink: 0, height: 40 }}>
<PropertiesSwitch />
</div>
{props.store
.getPatternLibraries()
.every(lib => lib.getOrigin() === Types.PatternLibraryOrigin.BuiltIn) && (
<ConnectPaneContainer
onPrimaryButtonClick={() => props.store.connectPatternLibrary()}
onSecondaryButtonClick={() =>
Sender.send({
type: MessageType.OpenExternalURL,
id: uuid.v4(),
payload: 'http://meetalva.github.io/example/example.alva'
})
}
/>
)}
<Components.PropertyPane>
{props.store.getApp().getRightSidebarTab() ===
Types.RightSidebarTab.Properties && <PropertyListContainer />}
{props.store.getApp().getRightSidebarTab() ===
Types.RightSidebarTab.ProjectSettings && <ProjectSettingsContainer />}
</Components.PropertyPane>
</Components.SideBar>
</AppPane>
</React.Fragment>
);
}
}
Loading

0 comments on commit a8d9c62

Please sign in to comment.