mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-18 21:38:14 +00:00
refactor: 💡 处理以来冲突
This commit is contained in:
commit
3ca6830834
@ -352,6 +352,8 @@ const builtinComponentActions: ComponentAction[] = [
|
|||||||
title: intlNode('copy'),
|
title: intlNode('copy'),
|
||||||
action(node: Node) {
|
action(node: Node) {
|
||||||
// node.remove();
|
// node.remove();
|
||||||
|
const { document: doc, parent, schema, index } = node;
|
||||||
|
parent && doc.insertNode(parent, schema, index);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
important: true,
|
important: true,
|
||||||
|
|||||||
@ -174,6 +174,10 @@ export class History {
|
|||||||
this.emitter.removeAllListeners();
|
this.emitter.removeAllListeners();
|
||||||
this.records = [];
|
this.records = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isModified() {
|
||||||
|
return this.point !== this.session.cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
|
|||||||
@ -45,6 +45,8 @@ export default class Dock implements IWidget {
|
|||||||
} else {
|
} else {
|
||||||
this._body = createElement(DockView, props);
|
this._body = createElement(DockView, props);
|
||||||
}
|
}
|
||||||
|
this.inited = true;
|
||||||
|
|
||||||
return this._body;
|
return this._body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,11 @@ export default class Panel implements IWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
active(item?: Panel | string | null) {
|
active(item?: Panel | string | null) {
|
||||||
|
if (item) {
|
||||||
this.container?.active(item);
|
this.container?.active(item);
|
||||||
|
} else {
|
||||||
|
this.setActive(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getName() {
|
getName() {
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { observer } from '@recore/obx-react';
|
|||||||
import { SimulatorRenderer } from './renderer';
|
import { SimulatorRenderer } from './renderer';
|
||||||
import { host } from './host';
|
import { host } from './host';
|
||||||
import './renderer.less';
|
import './renderer.less';
|
||||||
import { toCss } from '@ali/vu-css-style';
|
|
||||||
|
|
||||||
// patch cloneElement avoid lost keyProps
|
// patch cloneElement avoid lost keyProps
|
||||||
const originCloneElement = window.React.cloneElement;
|
const originCloneElement = window.React.cloneElement;
|
||||||
@ -87,9 +86,6 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
|
|||||||
viewProps.componentId = __id;
|
viewProps.componentId = __id;
|
||||||
viewProps._leaf = host.document.getNode(__id);
|
viewProps._leaf = host.document.getNode(__id);
|
||||||
|
|
||||||
// FIXME: 此处未来使用propsReducer方式处理
|
|
||||||
this.createNodeStyleSheet(viewProps);
|
|
||||||
|
|
||||||
return createElement(
|
return createElement(
|
||||||
Component,
|
Component,
|
||||||
viewProps,
|
viewProps,
|
||||||
@ -105,28 +101,4 @@ class Renderer extends Component<{ renderer: SimulatorRenderer }> {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
createNodeStyleSheet(props: any) {
|
|
||||||
if (props && props.fieldId) {
|
|
||||||
let styleProp = props.__style__;
|
|
||||||
|
|
||||||
if (isObject(styleProp)) {
|
|
||||||
styleProp = toCss(styleProp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof styleProp === 'string') {
|
|
||||||
const s = document.createElement('style');
|
|
||||||
const cssId = '_style_pesudo_' + props.fieldId;
|
|
||||||
const cssClass = '_css_pesudo_' + props.fieldId;
|
|
||||||
|
|
||||||
props.className = cssClass;
|
|
||||||
s.setAttribute('type', 'text/css');
|
|
||||||
s.setAttribute('id', cssId);
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(s);
|
|
||||||
|
|
||||||
s.appendChild(document.createTextNode(styleProp.replace(/:root/g, '.' + cssClass)));
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { globalContext, Editor } from '@ali/lowcode-editor-core';
|
|||||||
import { Designer, TransformStage, addBuiltinComponentAction } from '@ali/lowcode-designer';
|
import { Designer, TransformStage, addBuiltinComponentAction } from '@ali/lowcode-designer';
|
||||||
// import { registerSetters } from '@ali/lowcode-setters';
|
// import { registerSetters } from '@ali/lowcode-setters';
|
||||||
import Outline from '@ali/lowcode-plugin-outline-pane';
|
import Outline from '@ali/lowcode-plugin-outline-pane';
|
||||||
|
import { toCss } from '@ali/vu-css-style';
|
||||||
|
|
||||||
import DesignerPlugin from '@ali/lowcode-plugin-designer';
|
import DesignerPlugin from '@ali/lowcode-plugin-designer';
|
||||||
import { Skeleton, SettingsPrimaryPane } from '@ali/lowcode-editor-skeleton';
|
import { Skeleton, SettingsPrimaryPane } from '@ali/lowcode-editor-skeleton';
|
||||||
@ -66,6 +67,37 @@ function upgradePropsReducer(props: any) {
|
|||||||
}
|
}
|
||||||
designer.addPropsReducer(upgradePropsReducer, TransformStage.Init);
|
designer.addPropsReducer(upgradePropsReducer, TransformStage.Init);
|
||||||
|
|
||||||
|
// 设计器组件样式处理
|
||||||
|
function stylePropsReducer(props: any, node: any) {
|
||||||
|
if (props && typeof props === 'object' && props.__style__) {
|
||||||
|
const doc = designer.currentDocument?.simulator?.contentDocument;
|
||||||
|
if (!doc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cssId = '_style_pesudo_' + node.id.replace(/\$/g, '_');
|
||||||
|
const cssClass = '_css_pesudo_' + node.id.replace(/\$/g, '_');
|
||||||
|
const dom = doc.getElementById(cssId);
|
||||||
|
if (dom) {
|
||||||
|
dom.parentNode?.removeChild(dom);
|
||||||
|
}
|
||||||
|
let styleProp = props.__style__;
|
||||||
|
if (typeof styleProp === 'object') {
|
||||||
|
styleProp = toCss(styleProp);
|
||||||
|
}
|
||||||
|
if (typeof styleProp === 'string') {
|
||||||
|
const s = doc.createElement('style');
|
||||||
|
props.className = cssClass;
|
||||||
|
s.setAttribute('type', 'text/css');
|
||||||
|
s.setAttribute('id', cssId);
|
||||||
|
doc.getElementsByTagName('head')[0].appendChild(s);
|
||||||
|
|
||||||
|
s.appendChild(doc.createTextNode(styleProp.replace(/:root/g, '.' + cssClass)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
designer.addPropsReducer(stylePropsReducer, TransformStage.Render);
|
||||||
|
|
||||||
skeleton.add({
|
skeleton.add({
|
||||||
area: 'mainArea',
|
area: 'mainArea',
|
||||||
name: 'designer',
|
name: 'designer',
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { ALI_SCHEMA_VERSION } from './base/const';
|
import { ALI_SCHEMA_VERSION } from './base/const';
|
||||||
|
import { obx } from '@ali/lowcode-editor-core';
|
||||||
|
|
||||||
interface ILiteralObject {
|
interface ILiteralObject {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Env {
|
export class Env {
|
||||||
|
@obx.val envs: ILiteralObject = {};
|
||||||
public envs: ILiteralObject;
|
|
||||||
|
|
||||||
private emitter: EventEmitter;
|
private emitter: EventEmitter;
|
||||||
private featureMap: ILiteralObject;
|
private featureMap: ILiteralObject;
|
||||||
@ -15,23 +15,22 @@ export class Env {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.emitter = new EventEmitter();
|
this.emitter = new EventEmitter();
|
||||||
this.emitter.setMaxListeners(0);
|
this.emitter.setMaxListeners(0);
|
||||||
this.envs = {};
|
|
||||||
this.featureMap = {};
|
this.featureMap = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(name: string): any {
|
get(name: string): any {
|
||||||
return this.getEnv(name);
|
return this.getEnv(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEnv(name: string): any {
|
getEnv(name: string): any {
|
||||||
return this.envs[name];
|
return this.envs[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public set(name: string, value: any) {
|
set(name: string, value: any) {
|
||||||
return this.setEnv(name, value);
|
return this.setEnv(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setEnv(name: string, value: any) {
|
setEnv(name: string, value: any) {
|
||||||
const orig = this.envs[name];
|
const orig = this.envs[name];
|
||||||
if (JSON.stringify(orig) === JSON.stringify(value)) {
|
if (JSON.stringify(orig) === JSON.stringify(value)) {
|
||||||
return;
|
return;
|
||||||
@ -40,47 +39,47 @@ export class Env {
|
|||||||
this.emitter.emit('envchange', this.envs, name, value);
|
this.emitter.emit('envchange', this.envs, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setEnvMap(envs: ILiteralObject): void {
|
setEnvMap(envs: ILiteralObject): void {
|
||||||
this.envs = Object.assign(this.envs, envs);
|
this.envs = Object.assign(this.envs, envs);
|
||||||
this.emitter.emit('envchange', this.envs);
|
this.emitter.emit('envchange', this.envs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLocale(): string {
|
getLocale(): string {
|
||||||
return this.getEnv('locale') || 'zh_CN';
|
return this.getEnv('locale') || 'zh_CN';
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLocale(locale: string) {
|
setLocale(locale: string) {
|
||||||
this.setEnv('locale', locale);
|
this.setEnv('locale', locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setExpertMode(flag: string) {
|
setExpertMode(flag: string) {
|
||||||
this.setEnv('expertMode', !!flag);
|
this.setEnv('expertMode', !!flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public isExpertMode() {
|
isExpertMode() {
|
||||||
return !!this.getEnv('expertMode');
|
return !!this.getEnv('expertMode');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSupportFeatures() {
|
getSupportFeatures() {
|
||||||
return Object.assign({}, this.featureMap);
|
return Object.assign({}, this.featureMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setSupportFeatures(features: ILiteralObject) {
|
setSupportFeatures(features: ILiteralObject) {
|
||||||
this.featureMap = Object.assign({}, this.featureMap, features);
|
this.featureMap = Object.assign({}, this.featureMap, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
public supports(name = 'supports') {
|
supports(name = 'supports') {
|
||||||
return !!this.featureMap[name];
|
return !!this.featureMap[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public onEnvChange(func: (envs: ILiteralObject, name: string, value: any) => any) {
|
onEnvChange(func: (envs: ILiteralObject, name: string, value: any) => any) {
|
||||||
this.emitter.on('envchange', func);
|
this.emitter.on('envchange', func);
|
||||||
return () => {
|
return () => {
|
||||||
this.emitter.removeListener('envchange', func);
|
this.emitter.removeListener('envchange', func);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAliSchemaVersion() {
|
getAliSchemaVersion() {
|
||||||
return ALI_SCHEMA_VERSION;
|
return ALI_SCHEMA_VERSION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const I18nUtil = require('@ali/ve-i18n-util');
|
|
||||||
import Env from './env';
|
import Env from './env';
|
||||||
|
const I18nUtil = require('@ali/ve-i18n-util');
|
||||||
|
|
||||||
interface I18nObject {
|
interface I18nObject {
|
||||||
type?: string;
|
type?: string;
|
||||||
@ -9,7 +9,9 @@ interface I18nObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function i18nReducer(obj?: any): any {
|
export function i18nReducer(obj?: any): any {
|
||||||
if (!obj) { return obj; }
|
if (!obj) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
return obj.map((item) => i18nReducer(item));
|
return obj.map((item) => i18nReducer(item));
|
||||||
}
|
}
|
||||||
@ -18,6 +20,7 @@ export function i18nReducer(obj?: any): any {
|
|||||||
// FIXME! use editor.get
|
// FIXME! use editor.get
|
||||||
let locale = Env.getLocale();
|
let locale = Env.getLocale();
|
||||||
if (obj.key) {
|
if (obj.key) {
|
||||||
|
// FIXME: 此处需要升级I18nUtil,改成响应式
|
||||||
return I18nUtil.get(obj.key, locale);
|
return I18nUtil.get(obj.key, locale);
|
||||||
}
|
}
|
||||||
if (locale !== 'zh_CN' && locale !== 'zh_TW' && !obj[locale]) {
|
if (locale !== 'zh_CN' && locale !== 'zh_TW' && !obj[locale]) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import DragEngine from './drag-engine';
|
|||||||
import Viewport from './viewport';
|
import Viewport from './viewport';
|
||||||
import Project from './project';
|
import Project from './project';
|
||||||
import { designer, editor } from './editor';
|
import { designer, editor } from './editor';
|
||||||
|
import Symbols from './symbols';
|
||||||
|
|
||||||
import './vision.less';
|
import './vision.less';
|
||||||
|
|
||||||
@ -109,6 +110,7 @@ const VisualEngine = {
|
|||||||
Version,
|
Version,
|
||||||
Project,
|
Project,
|
||||||
logger,
|
logger,
|
||||||
|
Symbols,
|
||||||
};
|
};
|
||||||
|
|
||||||
(window as any).VisualEngine = VisualEngine;
|
(window as any).VisualEngine = VisualEngine;
|
||||||
@ -156,6 +158,7 @@ export {
|
|||||||
Version,
|
Version,
|
||||||
Project,
|
Project,
|
||||||
logger,
|
logger,
|
||||||
|
Symbols,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,17 +6,23 @@ const { project } = designer;
|
|||||||
|
|
||||||
export interface OldPageData {
|
export interface OldPageData {
|
||||||
id: string;
|
id: string;
|
||||||
layout: RootSchema;
|
componentsTree: RootSchema[];
|
||||||
[dataAddon: string]: any;
|
[dataAddon: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pages = Object.assign(project, {
|
const pages = Object.assign(project, {
|
||||||
setPages(pages: OldPageData[]) {
|
setPages(pages: OldPageData[]) {
|
||||||
// FIXME: upgrade schema
|
if (!pages || !Array.isArray(pages) || pages.length === 0) {
|
||||||
pages[0].componentsTree.forEach((item: any) => {
|
throw new Error('pages schema 不合法');
|
||||||
item.lifeCycles = {};
|
}
|
||||||
item.methods = {};
|
|
||||||
});
|
if (pages[0].componentsTree[0]) {
|
||||||
|
pages[0].componentsTree[0].componentName = 'Page';
|
||||||
|
// FIXME
|
||||||
|
pages[0].componentsTree[0].lifeCycles = {};
|
||||||
|
pages[0].componentsTree[0].methods = {};
|
||||||
|
}
|
||||||
|
|
||||||
project.load({
|
project.load({
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
componentsMap: [],
|
componentsMap: [],
|
||||||
|
|||||||
@ -69,17 +69,7 @@ function upgradeConfig(config: OldPaneConfig): IWidgetBaseConfig & { area: strin
|
|||||||
newConfig.type = 'PanelDock';
|
newConfig.type = 'PanelDock';
|
||||||
newConfig.area = 'left';
|
newConfig.area = 'left';
|
||||||
newConfig.props.description = description || title;
|
newConfig.props.description = description || title;
|
||||||
const {
|
const { contents, hideTitleBar, tip, width, maxWidth, height, maxHeight, menu, isAction } = config;
|
||||||
contents,
|
|
||||||
hideTitleBar,
|
|
||||||
tip,
|
|
||||||
width,
|
|
||||||
maxWidth,
|
|
||||||
height,
|
|
||||||
maxHeight,
|
|
||||||
menu,
|
|
||||||
isAction
|
|
||||||
} = config;
|
|
||||||
if (menu) {
|
if (menu) {
|
||||||
newConfig.props.title = menu;
|
newConfig.props.title = menu;
|
||||||
}
|
}
|
||||||
@ -97,14 +87,14 @@ function upgradeConfig(config: OldPaneConfig): IWidgetBaseConfig & { area: strin
|
|||||||
if (contents && Array.isArray(contents)) {
|
if (contents && Array.isArray(contents)) {
|
||||||
newConfig.content = contents.map(({ title, content, tip }, index) => {
|
newConfig.content = contents.map(({ title, content, tip }, index) => {
|
||||||
return {
|
return {
|
||||||
type: "Panel",
|
type: 'Panel',
|
||||||
name: typeof title === 'string' ? title : `${name}:${index}`,
|
name: typeof title === 'string' ? title : `${name}:${index}`,
|
||||||
content,
|
content,
|
||||||
props: {
|
props: {
|
||||||
title,
|
title,
|
||||||
help: tip,
|
help: tip,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +153,11 @@ const dockPane = Object.assign(skeleton.leftArea, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const name = item.name || item;
|
const name = item.name || item;
|
||||||
skeleton.getPanel(name)?.active();
|
const pane = skeleton.getPanel(name);
|
||||||
|
if (!pane) {
|
||||||
|
console.warn(`Could not find pane with name ${name}`);
|
||||||
|
}
|
||||||
|
pane?.active();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
17
packages/vision-preset/src/symbols.ts
Normal file
17
packages/vision-preset/src/symbols.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export class SymbolManager {
|
||||||
|
private symbolMap: { [symbolName: string]: symbol } = {};
|
||||||
|
|
||||||
|
public create(name: string): symbol {
|
||||||
|
if (this.symbolMap[name]) {
|
||||||
|
return this.symbolMap[name];
|
||||||
|
}
|
||||||
|
this.symbolMap[name] = Symbol(name);
|
||||||
|
return this.symbolMap[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
public get(name: string) {
|
||||||
|
return this.symbolMap[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new SymbolManager();
|
||||||
@ -101,3 +101,9 @@ html.engine-blur #engine {
|
|||||||
.lc-left-float-pane {
|
.lc-left-float-pane {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.engine-preview-mode {
|
||||||
|
.lc-left-area, .lc-right-area {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user