From 2efda617ba4e6313f24278ded6b7d12cb47e12e2 Mon Sep 17 00:00:00 2001 From: Hoikan <408255371@qq.com> Date: Mon, 17 Mar 2025 19:15:31 +0800 Subject: [PATCH 1/4] chore: remove useless blank space --- packages/inula-router/babel.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inula-router/babel.config.cjs b/packages/inula-router/babel.config.cjs index a7d35e56f..d21c73000 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', From cc248682b639b8929782f8be7b8065f951c53637 Mon Sep 17 00:00:00 2001 From: Hoikan <408255371@qq.com> Date: Tue, 18 Mar 2025 14:44:33 +0800 Subject: [PATCH 2/4] chore: use workspace --- .npmrc | 1 - packages/inula-router/src/router/Link.tsx | 2 +- packages/inula/package.json | 15 +++++++++------ packages/inula/src/external/JSXElement.ts | 20 ++++++++++++++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.npmrc b/.npmrc index 44a619f9e..e69de29bb 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +0,0 @@ -link-workspace-packages = false \ No newline at end of file diff --git a/packages/inula-router/src/router/Link.tsx b/packages/inula-router/src/router/Link.tsx index 926826bf5..18247d1b6 100644 --- a/packages/inula-router/src/router/Link.tsx +++ b/packages/inula-router/src/router/Link.tsx @@ -36,7 +36,7 @@ const checkTarget = (target?: any) => { return !target || target === '_self'; }; -function Link

(props: P) { +function Link

(props: P): JSX.Element { 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 43b550674..a9a6b8f62 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 5f55e6b06..087bf1e3d 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,11 +157,18 @@ 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> & P) | null, ...children: InulaNode[] ): InulaCElement>; + export function createElement

, C extends ComponentClass

>( type: ClassType, props?: (ClassAttributes & P) | null, @@ -168,8 +176,12 @@ export function createElement

; // 创建Element结构体,供JSX编译时调用 -export function createElement(type, setting, ...children) { - return buildElement(false, type, setting, children); +export function createElement

( + type: FunctionComponent

| ComponentClass

| string, + props?: (Attributes & P) | null, + ...children: InulaNode[] +): InulaElement

{ + return buildElement(false, type, props, children); } export function cloneElement

, T extends HTMLElement>( @@ -213,8 +225,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编译方式 From f0b2f18ccfc6f8d8d98febb12b72a4a91ee6f98a Mon Sep 17 00:00:00 2001 From: Hoikan <408255371@qq.com> Date: Tue, 18 Mar 2025 15:12:47 +0800 Subject: [PATCH 3/4] fix: type error --- packages/inula/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inula/src/types.ts b/packages/inula/src/types.ts index 5be488998..04955c3c3 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 { +export interface ProviderProps { value: T; children?: InulaNode | undefined; } From 8873d89112f6c4f5032075ea5bb1944664796d98 Mon Sep 17 00:00:00 2001 From: Hoikan <408255371@qq.com> Date: Tue, 18 Mar 2025 15:29:16 +0800 Subject: [PATCH 4/4] fix: type error --- packages/inula-router/src/router/Link.tsx | 4 ++-- packages/inula/src/external/JSXElement.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/inula-router/src/router/Link.tsx b/packages/inula-router/src/router/Link.tsx index 18247d1b6..a9a9bcf8e 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): JSX.Element { +function Link

(props: P): InulaElement { const { to, replace, component, onClick, target, ...other } = props; const tag = props.tag || 'a'; diff --git a/packages/inula/src/external/JSXElement.ts b/packages/inula/src/external/JSXElement.ts index 087bf1e3d..de9c2e098 100644 --- a/packages/inula/src/external/JSXElement.ts +++ b/packages/inula/src/external/JSXElement.ts @@ -175,13 +175,15 @@ export function createElement

; -// 创建Element结构体,供JSX编译时调用 -export function createElement

( +export function createElement

( type: FunctionComponent

| ComponentClass

| string, props?: (Attributes & P) | null, ...children: InulaNode[] -): InulaElement

{ - return buildElement(false, type, props, children); +): InulaElement

; + +// 创建Element结构体,供JSX编译时调用 +export function createElement(type, setting, ...children) { + return buildElement(false, type, setting, children); } export function cloneElement

, T extends HTMLElement>(