From 92a11a1458feb649458f827455b6d951f474b487 Mon Sep 17 00:00:00 2001 From: Bowen Tan Date: Thu, 23 Sep 2021 15:49:19 +0800 Subject: [PATCH] support cross package import @mata-io/runtime --- packages/core/package.json | 4 ++-- packages/editor/src/main.tsx | 2 +- packages/editor/src/metaUI.ts | 7 +++++++ packages/runtime/package.json | 4 ++-- packages/runtime/src/index.ts | 14 +++++++++++--- packages/runtime/src/registry.tsx | 2 +- packages/runtime/src/utils/initStateAndMethod.ts | 2 +- 7 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 packages/editor/src/metaUI.ts diff --git a/packages/core/package.json b/packages/core/package.json index 7f8903f9..4d2c667f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/webzard-io/meta-ui#readme", "license": "MIT", "module": "lib/index.js", - "typings": "typings/index.d.ts", + "types": "lib/index.d.ts", "directories": { "lib": "lib", "test": "__tests__" @@ -20,7 +20,7 @@ }, "scripts": { "build": "tsc -b .", - "typings": "tsc -d --emitDeclarationOnly --declarationDir typings", + "typings": "tsc -d", "test": "jest", "lint": "eslint src --ext .ts", "prepublish": "npm run build && npm run typings" diff --git a/packages/editor/src/main.tsx b/packages/editor/src/main.tsx index 6b638b63..e39c7e17 100644 --- a/packages/editor/src/main.tsx +++ b/packages/editor/src/main.tsx @@ -1,6 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { App } from '@meta-ui/runtime'; +import { App } from './metaUI'; import { DialogFormSchema } from './constants'; export default function renderApp() { diff --git a/packages/editor/src/metaUI.ts b/packages/editor/src/metaUI.ts new file mode 100644 index 00000000..7f0adbeb --- /dev/null +++ b/packages/editor/src/metaUI.ts @@ -0,0 +1,7 @@ +import { InitMetaUI } from '@meta-ui/runtime'; + +const metaUI = InitMetaUI(); + +export const App = metaUI.App; +export const registry = metaUI.registry; +export const stateStore = metaUI.stateStore; diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 3e8d8113..3d04ca03 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -5,7 +5,7 @@ "dev": "vite", "test": "jest", "build": "tsc -b .", - "typings": "tsc -d --emitDeclarationOnly --declarationDir typings", + "typings": "tsc -d", "lint": "eslint src --ext .ts", "prepublish": "npm run build && npm run typings" }, @@ -13,7 +13,7 @@ "lib" ], "module": "lib/index.js", - "typings": "typings/index.d.ts", + "types": "lib/index.d.ts", "dependencies": { "@chakra-ui/react": "^1.6.5", "@emotion/react": "^11", diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 2877b48a..6f2d624a 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1,3 +1,11 @@ -export * from './App'; -export * from './api-service'; -export * from './store'; +import { stateStore } from './store'; +import { App } from './App'; +import { registry } from './registry'; + +export function InitMetaUI() { + return { + App, + stateStore, + registry, + }; +} diff --git a/packages/runtime/src/registry.tsx b/packages/runtime/src/registry.tsx index 3f8d4a1a..9959accd 100644 --- a/packages/runtime/src/registry.tsx +++ b/packages/runtime/src/registry.tsx @@ -97,7 +97,7 @@ export type TraitImplementation = ( } ) => TraitResult; -class Registry { +export class Registry { components: Map> = new Map(); traits: Map> = new Map(); diff --git a/packages/runtime/src/utils/initStateAndMethod.ts b/packages/runtime/src/utils/initStateAndMethod.ts index b9b12c6b..e92b41de 100644 --- a/packages/runtime/src/utils/initStateAndMethod.ts +++ b/packages/runtime/src/utils/initStateAndMethod.ts @@ -1,5 +1,5 @@ +import { RuntimeApplication } from '@meta-ui/core'; import { TSchema } from '@sinclair/typebox'; -import { RuntimeApplication } from '../../../core/typings'; import { registry } from '../registry'; import { stateStore } from '../store'; import { parseTypeBox } from './parseTypeBox';