feat: 新增 globalLocale API

This commit is contained in:
lihao.ylh 2021-12-29 20:04:21 +08:00
parent 2eeafb1db1
commit 70a81d2a77
6 changed files with 37 additions and 32 deletions

View File

@ -29,7 +29,7 @@ const languageMap: { [key: string]: string } = {
const LowcodeConfigKey = 'ali-lowcode-config';
class AliGlobalLocale {
class GlobalLocale {
private emitter = new EventEmitter();
@obx.ref private _locale?: string;
@ -114,7 +114,7 @@ class AliGlobalLocale {
return this.locale;
}
onLocaleChange(fn: (locale: string) => void): () => void {
onChangeLocale(fn: (locale: string) => void): () => void {
this.emitter.on('localechange', fn);
return () => {
this.emitter.removeListener('localechange', fn);
@ -135,12 +135,13 @@ function hasLocalStorage(obj: any): obj is WindowLocalStorage {
return obj.localStorage;
}
let globalLocale: AliGlobalLocale;
if ((window as any).__aliGlobalLocale) {
globalLocale = (window as any).__aliGlobalLocale as any;
} else {
globalLocale = new AliGlobalLocale();
(window as any).__aliGlobalLocale = globalLocale;
}
let globalLocale = new GlobalLocale();
// let globalLocale: GlobalLocale;
// if ((window as any).__GlobalLocale) {
// globalLocale = (window as any).__GlobalLocale as any;
// } else {
// globalLocale = new GlobalLocale();
// (window as any).__GlobalLocale = globalLocale;
// }
export { globalLocale };

View File

@ -1,6 +1,6 @@
import { ReactNode, Component, createElement } from 'react';
import { IntlMessageFormat } from 'intl-messageformat';
import { globalLocale } from './ali-global-locale';
import { globalLocale } from './global-locale';
import { isI18nData } from '@ali/lowcode-types';
import { observer, computed } from '../utils';

View File

@ -21,4 +21,4 @@ export {
IReactionOptions,
} from 'mobx';
export * as mobx from 'mobx';
export { observer };
export { observer };

View File

@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/"],
"include": ["./src/"]
}

View File

@ -37,9 +37,9 @@ const editor = new Editor();
globalContext.register(editor, Editor);
globalContext.register(editor, 'editor');
const skeleton = new InnerSkeleton(editor);
editor.set(Skeleton, skeleton);
editor.set('skeleton' as any, skeleton);
const innerSkeleton = new InnerSkeleton(editor);
editor.set(Skeleton, innerSkeleton);
editor.set('skeleton' as any, innerSkeleton);
const designer = new Designer({ editor });
editor.set(Designer, designer);
@ -48,7 +48,7 @@ editor.set('designer' as any, designer);
const plugins = new LowCodePluginManager(editor).toProxy();
editor.set('plugins' as any, plugins);
const { project, currentSelection: selection } = designer;
const { project: innerProject, currentSelection: selection } = designer;
const { Workbench } = skeletonCabin;
// const setters: Setters = {
// getSetter,
@ -57,9 +57,9 @@ const { Workbench } = skeletonCabin;
// };
const hotkey = new Hotkey();
const project2 = new Project(project);
const skeleton2 = new Skeleton(skeleton);
const setters2 = new Setters();
const project = new Project(innerProject);
const skeleton = new Skeleton(innerSkeleton);
const setters = new Setters();
const material = new Material(editor);
const config = engineConfig;
const event = new Event(editor, { prefix: 'common' });
@ -67,13 +67,13 @@ const logger = getLogger({ level: 'warn', bizName: 'common' });
export {
// editor,
// editorCabin,
editorCabin,
// skeleton,
// skeletonCabin,
skeletonCabin,
// designer,
// designerCabin,
designerCabin,
plugins,
// setters,
setters,
project,
// selection,
/**
@ -84,8 +84,11 @@ export {
*
*/
// store,
// hotkey,
hotkey,
utils,
config,
event,
logger,
// engineConfig,
};
@ -95,18 +98,18 @@ const getSelection = () => designer.currentDocument?.selection;
/**
* start
*/
editor,
editorCabin,
skeletonCabin,
editor: event,
designer,
designerCabin,
/**
* end
*/
editorCabin,
skeletonCabin,
designerCabin,
plugins,
skeleton: skeleton2,
project: project2,
setters: setters2,
skeleton,
project,
setters,
material,
// get selection() {
// return getSelection();
@ -235,7 +238,7 @@ export async function init(container?: HTMLElement, options?: EngineOptions) {
await plugins.init();
render(
createElement(Workbench, {
skeleton,
skeleton: innerSkeleton,
className: 'engine-main',
topAreaItemClassName: 'engine-actionitem',
}),

View File

@ -9,4 +9,5 @@ export {
observer,
getSetter,
getSettersMap,
globalLocale,
} from '@ali/lowcode-editor-core';