mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-27 02:43:04 +01:00
implementing generic way to extend UI through 'sockets'
This commit is contained in:
parent
aaa6bd6690
commit
1aae2e1b73
7 changed files with 72 additions and 10 deletions
|
|
@ -4,11 +4,15 @@ import cx from 'classnames';
|
|||
import ls from './AuxWidget.less';
|
||||
import AdjustableAbs from './AdjustableAbs';
|
||||
|
||||
export default function AuxWidget({flatTop, flatBottom, flatRight, flatLeft, children, className, ...props}) {
|
||||
return <AdjustableAbs className={cx(ls.root,
|
||||
flatTop && ls.flatTop, flatBottom && ls.flatBottom,
|
||||
flatRight && ls.flatRight, flatLeft && ls.flatLeft,
|
||||
className)} {...props}>
|
||||
export default function AuxWidget(props) {
|
||||
return <AuxWidgetLook {...props} Component={AdjustableAbs}/>
|
||||
}
|
||||
|
||||
export function AuxWidgetLook({flatTop, flatBottom, flatRight, flatLeft, children, className, Component, ...props}) {
|
||||
return <Component className={cx(ls.root,
|
||||
flatTop && ls.flatTop, flatBottom && ls.flatBottom,
|
||||
flatRight && ls.flatRight, flatLeft && ls.flatLeft,
|
||||
className)} {...props}>
|
||||
{children}
|
||||
</AdjustableAbs>;
|
||||
</Component>;
|
||||
}
|
||||
13
web/app/cad/dom/components/HeadsUpHelper.jsx
Normal file
13
web/app/cad/dom/components/HeadsUpHelper.jsx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import React from 'react';
|
||||
import ls from './HeadsUpHelper.less';
|
||||
|
||||
import Socket from './Socket';
|
||||
import {AuxWidgetLook} from 'ui/components/AuxWidget';
|
||||
|
||||
export default function HeadsUpHelper() {
|
||||
return <AuxWidgetLook Component={Div} className={ls.root} flatTop>
|
||||
<Socket entry='headsUpHelper'/>
|
||||
</AuxWidgetLook>
|
||||
}
|
||||
|
||||
const Div = props => <div {...props} />;
|
||||
4
web/app/cad/dom/components/HeadsUpHelper.less
Normal file
4
web/app/cad/dom/components/HeadsUpHelper.less
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.root {
|
||||
margin: 0 auto;
|
||||
z-index: 100;
|
||||
}
|
||||
29
web/app/cad/dom/components/Socket.jsx
Normal file
29
web/app/cad/dom/components/Socket.jsx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import React from 'react';
|
||||
import connect from 'ui/connect';
|
||||
import mapContext from 'ui/mapContext';
|
||||
import {state} from 'lstream';
|
||||
|
||||
@mapContext(ctx => ({
|
||||
getComponent: ctx.services.ui.getComponent
|
||||
}))
|
||||
@connect((streams, props) => {
|
||||
let stream = streams.ui.sockets[props.entry];
|
||||
if (!stream) {
|
||||
stream= state();
|
||||
streams.ui.sockets[props.entry] = stream;
|
||||
}
|
||||
return stream.map(componentId => ({componentId}));
|
||||
})
|
||||
export default class Socket extends React.Component {
|
||||
render() {
|
||||
let {getComponent, componentId, ...props} = this.props;
|
||||
if (!componentId) {
|
||||
return null;
|
||||
}
|
||||
let Component = getComponent(componentId);
|
||||
if (!Component) {
|
||||
return null;
|
||||
}
|
||||
return <Component {...props} />;
|
||||
}
|
||||
};
|
||||
|
|
@ -11,6 +11,7 @@ import SelectedModificationInfo from '../../craft/ui/SelectedModificationInfo';
|
|||
import BottomStack from './BottomStack';
|
||||
import SketcherToolbars from './SketcherToolbars';
|
||||
import CameraControl from './CameraControl';
|
||||
import HeadsUpHelper from './HeadsUpHelper';
|
||||
|
||||
|
||||
export default class View3d extends React.Component {
|
||||
|
|
@ -32,6 +33,7 @@ export default class View3d extends React.Component {
|
|||
<AuxiliaryToolbar small vertical/>
|
||||
</Abs>
|
||||
</Abs>
|
||||
<HeadsUpHelper/>
|
||||
<BottomStack>
|
||||
<CameraControl />
|
||||
<HistoryTimeline />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {state} from 'lstream';
|
||||
|
||||
export function activate({streams}) {
|
||||
export function defineStreams({streams}) {
|
||||
|
||||
streams.ui = {
|
||||
controlBars: {
|
||||
|
|
@ -15,8 +15,18 @@ export function activate({streams}) {
|
|||
sketcherControl: state([]),
|
||||
sketcherToolbarsVisible: state(false)
|
||||
},
|
||||
sockets: {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function activate({services}) {
|
||||
|
||||
let components = new Map();
|
||||
const registerComponent = (id, Component) => components.set(id, Component);
|
||||
const getComponent = id => components.get(id);
|
||||
|
||||
services.ui = {
|
||||
registerComponent, getComponent
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import * as MouseEventSystemPlugin from '../scene/controls/mouseEventSystemPlugi
|
|||
import * as ScenePlugin from '../scene/scenePlugin';
|
||||
import * as SelectionMarkerPlugin from '../scene/selectionMarker/selectionMarkerPlugin';
|
||||
import * as ActionSystemPlugin from '../actions/actionSystemPlugin';
|
||||
import * as UiEntryPointsPlugin from '../dom/uiEntryPointsPlugin';
|
||||
import * as UiPlugin from '../dom/uiPlugin';
|
||||
import * as MenuPlugin from '../dom/menu/menuPlugin';
|
||||
import * as KeyboardPlugin from '../keyboard/keyboardPlugin';
|
||||
import * as WizardPlugin from '../craft/wizard/wizardPlugin';
|
||||
|
|
@ -39,7 +39,7 @@ export default function startApplication(callback) {
|
|||
StoragePlugin,
|
||||
AppTabsPlugin,
|
||||
ActionSystemPlugin,
|
||||
UiEntryPointsPlugin,
|
||||
UiPlugin,
|
||||
MenuPlugin,
|
||||
KeyboardPlugin,
|
||||
OperationPlugin,
|
||||
|
|
|
|||
Loading…
Reference in a new issue