diff --git a/.npmrc b/.npmrc index 44a619f9..e69de29b 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +0,0 @@ -link-workspace-packages = false \ No newline at end of file diff --git a/packages/inula-router/babel.config.cjs b/packages/inula-router/babel.config.cjs index a7d35e56..d21c7300 100644 --- a/packages/inula-router/babel.config.cjs +++ b/packages/inula-router/babel.config.cjs @@ -13,7 +13,7 @@ * See the Mulan PSL v2 for more details. */ -module.exports = { +module.exports = { presets: ['@babel/preset-typescript', ['@babel/preset-env', { targets: { node: 'current' } }]], plugins: [ '@babel/plugin-syntax-jsx', diff --git a/packages/inula-router/src/router/Link.tsx b/packages/inula-router/src/router/Link.tsx index 926826bf..a9a9bcf8 100644 --- a/packages/inula-router/src/router/Link.tsx +++ b/packages/inula-router/src/router/Link.tsx @@ -13,7 +13,7 @@ * See the Mulan PSL v2 for more details. */ -import Inula from 'openinula'; +import Inula, { InulaElement } from 'openinula'; import { useContext, MouseEvent, ComponentType, Ref } from 'openinula'; import RouterContext from './context'; import { Location } from './index'; @@ -36,7 +36,7 @@ const checkTarget = (target?: any) => { return !target || target === '_self'; }; -function Link
(props: P) { +function Link
(props: P): InulaElement { const { to, replace, component, onClick, target, ...other } = props; const tag = props.tag || 'a'; diff --git a/packages/inula/package.json b/packages/inula/package.json index 43b55067..a9a6b8f6 100644 --- a/packages/inula/package.json +++ b/packages/inula/package.json @@ -8,11 +8,14 @@ "homepage": "", "bugs": "", "license": "MulanPSL2", - "main": "index.js", + "main": "./build/inula/index.js", "repository": {}, "engines": { "node": ">=0.10.0" }, + "publishConfig": { + "directory": "./build/inula" + }, "scripts": { "build": "npm run build-types && rollup --config ./scripts/rollup/rollup.config.js", "build-types": "tsc -p tsconfig.build.json || echo \"WARNING: TSC exited with status $?\" && rollup -c ./scripts/rollup/build-types.js", @@ -23,14 +26,14 @@ "test": "jest --config=jest.config.js", "watch-test": "yarn test --watch --dev" }, - "types": "@types/index.d.ts", + "types": "./build/inula/@types/index.d.ts", "exports": { ".": { - "types": "./@types/index.d.ts", - "default": "./index.js" + "types": "./build/inula/@types/index.d.ts", + "default": "./build/inula/index.js" }, "./package.json": "./package.json", - "./jsx-runtime": "./jsx-runtime.js", - "./jsx-dev-runtime": "./jsx-dev-runtime.js" + "./jsx-runtime": "./build/inula/jsx-runtime.js", + "./jsx-dev-runtime": "./build/inula/jsx-dev-runtime.js" } } diff --git a/packages/inula/src/external/JSXElement.ts b/packages/inula/src/external/JSXElement.ts index 5f55e6b0..de9c2e09 100644 --- a/packages/inula/src/external/JSXElement.ts +++ b/packages/inula/src/external/JSXElement.ts @@ -25,6 +25,7 @@ import { ClassicComponentClass, ComponentClass, ComponentState, + FunctionComponent, FunctionComponentElement, InulaCElement, InulaElement, @@ -156,17 +157,30 @@ export function createElement
, T extends Element>( ...children: InulaNode[] ): DOMElement
; +export function createElement
( + type: FunctionComponent
, + props?: (Attributes & P) | null, + ...children: InulaNode[] +): FunctionComponentElement
; + export function createElement
( type: ClassType
, ClassicComponentClass
>,
props?: (ClassAttributes >;
+
export function createElement , C extends ComponentClass >(
type: ClassType ,
props?: (ClassAttributes ;
+export function createElement (
+ type: FunctionComponent | ComponentClass | string,
+ props?: (Attributes & P) | null,
+ ...children: InulaNode[]
+): InulaElement ;
+
// 创建Element结构体,供JSX编译时调用
export function createElement(type, setting, ...children) {
return buildElement(false, type, setting, children);
@@ -213,8 +227,8 @@ export function cloneElement(element, setting, ...children) {
}
// 检测结构体是否为合法的Element
-export function isValidElement (element: KVObject | null | undefined): element is InulaElement {
- return !!(element && element.vtype === TYPE_COMMON_ELEMENT);
+export function isValidElement (element: {} | null | undefined): element is InulaElement {
+ return typeof element === 'object' && element !== null && 'vtype' in element && element.vtype === TYPE_COMMON_ELEMENT;
}
// 兼容高版本的babel编译方式
diff --git a/packages/inula/src/types.ts b/packages/inula/src/types.ts
index 5be48899..04955c3c 100644
--- a/packages/inula/src/types.ts
+++ b/packages/inula/src/types.ts
@@ -55,7 +55,7 @@ export interface ExoticComponent {
(props: P): InulaElement | null;
}
-interface ProviderProps