Merge branch 'fix/rax-miniapp' into 'release/0.9.19'

fix: 1.修复 rax 路由问题 2.切换 designMode 重新 setupSelection 3.settingpane add state shouldIgnoreRoot

1.修复 rax 路由问题
2.切换 designMode 重新 setupSelection
3.settingpane add state shouldIgnoreRoot

See merge request !984258
This commit is contained in:
力皓 2020-09-17 15:38:01 +08:00
commit 0a6e0eb354
4 changed files with 66 additions and 27 deletions

View File

@ -171,27 +171,6 @@ export class Designer {
node.document.simulator?.scrollToNode(node, detail);
});
let selectionDispose: undefined | (() => void);
const setupSelection = () => {
if (selectionDispose) {
selectionDispose();
selectionDispose = undefined;
}
const currentSelection = this.currentSelection;
// TODO: 避免选中 Page 组件,默认选中第一个子节点;新增规则 或 判断 Live 模式
if (currentSelection && currentSelection.selected.length === 0 && this.simulatorProps?.designMode === 'live') {
const rootNodeChildrens = this.currentDocument.getRoot().getChildren().children;
if (rootNodeChildrens.length > 0) {
currentSelection.select(rootNodeChildrens[0].id);
}
}
this.postEvent('selection.change', currentSelection);
if (currentSelection) {
selectionDispose = currentSelection.onSelectionChange(() => {
this.postEvent('selection.change', currentSelection);
});
}
};
let historyDispose: undefined | (() => void);
const setupHistory = () => {
if (historyDispose) {
@ -210,17 +189,39 @@ export class Designer {
this.postEvent('current-document.change', this.currentDocument);
this.postEvent('selection.change', this.currentSelection);
this.postEvent('history.change', this.currentHistory);
setupSelection();
this.setupSelection();
setupHistory();
});
this.postEvent('designer.init', this);
setupSelection();
this.setupSelection();
setupHistory();
// TODO: 先简单实现,后期通过焦点赋值
focusing.focusDesigner = this;
}
setupSelection = () => {
let selectionDispose: undefined | (() => void);
if (selectionDispose) {
selectionDispose();
selectionDispose = undefined;
}
const currentSelection = this.currentSelection;
// TODO: 避免选中 Page 组件,默认选中第一个子节点;新增规则 或 判断 Live 模式
if (currentSelection && currentSelection.selected.length === 0 && this.simulatorProps?.designMode === 'live') {
const rootNodeChildrens = this.currentDocument.getRoot().getChildren().children;
if (rootNodeChildrens.length > 0) {
currentSelection.select(rootNodeChildrens[0].id);
}
}
this.postEvent('selection.change', currentSelection);
if (currentSelection) {
selectionDispose = currentSelection.onSelectionChange(() => {
this.postEvent('selection.change', currentSelection);
});
}
};
postEvent(event: string, ...args: any[]) {
this.editor.emit(`designer.${event}`, ...args);
}
@ -329,6 +330,10 @@ export class Designer {
}
if (props.simulatorProps !== this.props.simulatorProps) {
this._simulatorProps = props.simulatorProps;
// 重新 setupSelection
if (props.simulatorProps?.designMode !== this.props.simulatorProps?.designMode) {
this.setupSelection();
}
}
if (props.suspensed !== this.props.suspensed && props.suspensed != null) {
this.suspensed = props.suspensed;

View File

@ -9,7 +9,10 @@ import { SkeletonContext } from '../../context';
import { createIcon } from '@ali/lowcode-utils';
@observer
export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any }> {
export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any }, { shouldIgnoreRoot: boolean }> {
state = {
shouldIgnoreRoot: false,
};
private main = new SettingsMain(this.props.editor);
@obx.ref private _activeKey?: any;
@ -18,6 +21,17 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
return false;
}
componentDidMount() {
this.setShouldIgnoreRoot();
}
async setShouldIgnoreRoot() {
let designMode = await this.props.editor.get('designMode');
this.setState({
shouldIgnoreRoot: designMode === 'live',
})
}
componentWillUnmount() {
this.main.purge();
}
@ -25,7 +39,8 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
renderBreadcrumb() {
const { settings } = this.main;
const { config } = this.props;
const shouldIgnoreRoot = config.props?.ignoreRoot;
// const shouldIgnoreRoot = config.props?.ignoreRoot;
const { shouldIgnoreRoot } = this.state;
if (!settings) {
return null;
}

View File

@ -209,15 +209,28 @@ function getInitialComponent(routerConfig) {
let unlisten = null;
let handleId = null;
let pathes = '';
export function useRouter(routerConfig) {
const [component, setComponent] = useState(getInitialComponent(routerConfig));
let newPathes = '';
if (routerConfig) {
_routerConfig = routerConfig;
const routes = _routerConfig.routes;
router.root = Array.isArray(routes) ? { routes } : routes;
if (Array.isArray(routes)) {
newPathes = routes.map(it => it.path).join(',');
} else {
newPathes = routes.path;
}
}
if (_initialized && _routerConfig.history) {
if (newPathes !== pathes) {
matchLocation(_routerConfig.history.location);
pathes = newPathes;
}
}
useLayoutEffect(() => {
if (unlisten) {
unlisten();
@ -241,15 +254,18 @@ export function useRouter(routerConfig) {
// Init path match
if (_initialized || !_routerConfig.InitialComponent) {
matchLocation(history.location);
pathes = newPathes;
}
unlisten = history.listen(({ location }) => {
matchLocation(location);
pathes = newPathes;
});
_initialized = true;
return () => {
pathes = '';
router.removeHandle(handleId);
handleId = null;
unlisten();

View File

@ -273,7 +273,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
return inst;
});
this.emitter.emit('layoutChange');
const path = host.project.currentDocument ? documentInstanceMap.get(host.project.currentDocument.id)!.path : '/';
if (firstRun) {
initialEntry = path;
@ -281,6 +280,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
if (this.history.location.pathname !== path) {
this.history.replace(path);
}
this.emitter.emit('layoutChange');
}
});
const history = createMemoryHistory({
@ -305,6 +305,9 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
replace(path: string, params?: object) {
history.replace(withQueryParams(path, params));
},
back() {
history.back();
}
},
legaoBuiltins: {
getUrlParams() {