mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 02:38:16 +00:00
Merge branch 'polyfill/vision' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into polyfill/vision
This commit is contained in:
commit
e5b7390dde
@ -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,
|
||||||
|
|||||||
@ -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]) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user