fix: 解决 device 变化后不刷新视图的 bug

This commit is contained in:
力皓 2020-11-05 17:09:05 +08:00
parent 0e7268fae3
commit 11e8e02f70
17 changed files with 1238 additions and 15 deletions

View File

@ -4,8 +4,9 @@
"private": true,
"description": "低代码引擎 DEMO",
"scripts": {
"cloud-build": "build-scripts build --config cloud-build.json",
"start": "build-scripts start"
"start": "build-scripts start",
"build": "build-scripts build",
"cloud-build": "build-scripts build --config cloud-build.json"
},
"config": {},
"dependencies": {

View File

@ -14,5 +14,6 @@ module.exports = {
'no-useless-constructor': 1,
'no-empty-function': 1,
'@typescript-eslint/member-ordering': 0,
'lines-between-class-members': 0
}
}

View File

@ -1,5 +1,6 @@
{
"plugins": [
"build-plugin-component",
"@ali/lowcode-test-mate/plugin/index.ts"
]
}

View File

@ -10,7 +10,7 @@
],
"scripts": {
"build": "build-scripts build --skip-demo",
"test": "build-scripts --config build.test.json test"
"test": "build-scripts test --config build.test.json"
},
"license": "MIT",
"dependencies": {

View File

@ -0,0 +1,12 @@
module.exports = ({ onGetJestConfig, onGetWebpackConfig }) => {
console.log('111111111111xxxxxxxxxxxx')
onGetWebpackConfig((config) => {
console.log('111111111111')
config.browserslist('last 2 versions, Firefox ESR, > 1%, ie >= 9, iOS >= 8, Android >= 4');
});
onGetJestConfig((jestConfig) => {
console.log('11111111111122222222')
return jestConfig;
});
};

View File

@ -9,7 +9,7 @@ export interface Serialization<T = any> {
unserialize(data: T): NodeSchema;
}
let currentSerializion: Serialization<any> = {
let currentSerialization: Serialization<any> = {
serialize(data: NodeSchema): string {
return JSON.stringify(data);
},
@ -18,8 +18,8 @@ let currentSerializion: Serialization<any> = {
},
};
export function setSerialization(serializion: Serialization) {
currentSerializion = serializion;
export function setSerialization(serialization: Serialization) {
currentSerialization = serialization;
}
export class History {
@ -46,7 +46,7 @@ export class History {
return;
}
untracked(() => {
const log = currentSerializion.serialize(data);
const log = currentSerialization.serialize(data);
if (this.session.cursor === 0 && this.session.isActive()) {
// first log
this.session.log(log);
@ -98,7 +98,7 @@ export class History {
this.obx.sleep();
try {
this.redoer(currentSerializion.unserialize(hotData));
this.redoer(currentSerialization.unserialize(hotData));
this.emitter.emit('cursor', hotData);
} catch (e) {
//

View File

@ -0,0 +1,19 @@
{
"plugins": [
[
"build-plugin-component",
{
"filename": "editor-preset-vision",
"library": "LowcodeEditor",
"libraryTarget": "umd",
"externals": {
"react": "var window.React",
"react-dom": "var window.ReactDOM",
"prop-types": "var window.PropTypes",
"rax": "var window.Rax"
}
}
],
"@ali/lowcode-test-mate/plugin/index.ts"
]
}

View File

@ -0,0 +1,23 @@
const esModules = [
'@recore/obx-react',
'@ali/lowcode-editor-core',
].join('|');
module.exports = {
// transform: {
// '^.+\\.[jt]sx?$': 'babel-jest',
// // '^.+\\.(ts|tsx)$': 'ts-jest',
// // '^.+\\.(js|jsx)$': 'babel-jest',
// },
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
transformIgnorePatterns: [
`/node_modules/(?!${esModules})/`,
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
collectCoverage: false,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!**/node_modules/**',
'!**/vendor/**',
],
};

View File

@ -11,7 +11,8 @@
],
"scripts": {
"build": "build-scripts build --skip-demo",
"cloud-build": "build-scripts build --skip-demo"
"cloud-build": "build-scripts build --skip-demo",
"test": "build-scripts test --config build.test.json"
},
"license": "MIT",
"dependencies": {
@ -37,6 +38,7 @@
"react-dom": "^16.8.1"
},
"devDependencies": {
"@ali/lowcode-test-mate": "^1.0.0",
"@alib/build-scripts": "^0.1.18",
"@types/domready": "^1.0.0",
"@types/events": "^3.0.0",
@ -45,6 +47,7 @@
"build-plugin-fusion": "^0.1.0",
"build-plugin-moment-locales": "^0.1.0",
"build-plugin-react-app": "^1.1.2",
"prop-types": "^15.7.2",
"tsconfig-paths-webpack-plugin": "^3.2.0"
},
"publishConfig": {

View File

@ -316,7 +316,7 @@ designer.addPropsReducer(deepValueParser, TransformStage.Render);
// 清除空的 props value
function removeEmptyProps(props: any, node: Node) {
if (node.isRoot() && props.dataSource) {
if (node.isRoot() && props.dataSource && Array.isArray(props.dataSource.online)) {
const online = cloneDeep(props.dataSource.online);
online.forEach((item: any) => {
const newParam: any = {};

View File

@ -166,6 +166,6 @@ const version = '6.0.0(LowcodeEngine 0.9.3)';
console.log(
`%c VisionEngine %c v${version} `,
'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060;font-weight:bold;',
'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e;font-weight:bold;',
'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;',
'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;',
);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
React.PropTypes = PropTypes;
window.React = React;

View File

@ -0,0 +1,46 @@
import set from 'lodash/set';
import cloneDeep from 'lodash/clonedeep';
import '../fixtures/window';
// import { Project } from '../../src/project/project';
// import { Node } from '../../src/document/node/node';
// import { Designer } from '../../src/designer/designer';
import formSchema from '../fixtures/schema/form';
import VisualEngine from '../../src';
// import { getIdsFromSchema, getNodeFromSchemaById } from '../utils';
// const mockCreateSettingEntry = jest.fn();
// jest.mock('../../src/designer/designer', () => {
// return {
// Designer: jest.fn().mockImplementation(() => {
// return {
// getComponentMeta() {
// return {
// getMetadata() {
// return { experimental: null };
// },
// };
// },
// transformProps(props) { return props; },
// createSettingEntry: mockCreateSettingEntry,
// postEvent() {},
// };
// }),
// };
// });
// let designer = null;
// beforeAll(() => {
// designer = new Designer({});
// });
describe('schema 生成节点模型测试', () => {
describe('block ❌ | component ❌ | slot ❌', () => {
it('基本的节点模型初始化,模型导出,初始化传入 schema', () => {
console.log(VisualEngine);
console.log(VisualEngine.Pages.addPage(formSchema));
});
});
});

View File

@ -54,5 +54,5 @@
"publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com"
},
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.13.1-10/build/index.html"
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.13.1-11/build/index.html"
}

View File

@ -339,7 +339,7 @@ export default class BaseRender extends PureComponent {
if (refProps && typeof refProps === 'string') {
this[refProps] = ref;
}
engine && engine.props.onCompGetRef(schema, ref);
ref && engine && engine.props.onCompGetRef(schema, ref);
};
}
// scope需要传入到组件上

View File

@ -187,7 +187,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
this._componentsMap = host.designer.componentsMap;
// 需要注意的是autorun 依赖收集的是同步执行的代码,所以 await / promise / callback 里的变量不会被收集依赖
// 此例中host.designer.componentsMap 是需要被收集依赖的,否则无法响应式
await host.waitForCurrentDocument();
// await host.waitForCurrentDocument();
this.buildComponents();
}
@ -540,6 +540,7 @@ function getComponentController(schema: NodeSchema, componentsMap: any) {
constructor(props: any) {
super(props);
console.log('>>> current');
const node = host.currentDocument?.createNode(schema);
this.renderSchema = node?.export(TransformStage.Render) || {};
}