Skip to content

Commit

Permalink
Merge pull request #170 from duenyang/feature/react
Browse files Browse the repository at this point in the history
feat(react): 优化react适配逻辑
  • Loading branch information
duenyang authored Nov 28, 2024
2 parents c7fc2d9 + aa0a0ac commit aa18c2f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
6 changes: 3 additions & 3 deletions script/plugin-tdoc/md-to-wc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function getGitTimestamp(file) {
});
}

export default async function mdToReact(options) {
export default async function mdToWebC(options) {
const mdSegment = await customRender(options);
const { demoDefsStr, demoCodesDefsStr, components } = options;

const reactSource = `
const webCSource = `
import { h, define } from 'omi';
import { signal, effect } from 'reactive-signal'
import Prismjs from 'prismjs';
Expand Down Expand Up @@ -137,7 +137,7 @@ export default async function mdToReact(options) {
}
`;

const result = esbuild.transformSync(reactSource, {
const result = esbuild.transformSync(webCSource, {
loader: 'tsx',
jsxFactory: 'h',
jsxFragment: 'h.f',
Expand Down
22 changes: 21 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VNode, WeElement } from 'omi';
import { Component, VNode, WeElement } from 'omi';

export type TElement<T = undefined> = T extends undefined ? WeElement : (props: T) => WeElement;
export type TNode<T = any> = VNode<T> | ((props: T) => VNode) | object | string | number | boolean | null;
Expand Down Expand Up @@ -119,3 +119,23 @@ export interface ScrollToElementParams {
export interface ComponentScrollToElementParams extends ScrollToElementParams {
key?: string | number;
}

export type ExtendedElement = (HTMLElement | SVGAElement | HTMLInputElement) & {
receiveProps: Function;
update: Function;
queuedUpdate: Function;
store?: unknown;
className?: string;
props: Record<string, unknown>;
splitText?: Function;
prevProps?: Record<string, unknown> & {
ref?:
| {
current?: unknown;
}
| Function;
};
attributes: NamedNodeMap;
_component?: Component;
_listeners: Record<string, Function>;
} & Record<string, unknown>;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export * from './tag-input';
export * from './textarea';
export * from './tooltip';
export * from './upload';
export * from './vue';
export * from './watermark';
22 changes: 2 additions & 20 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@
* 在React环境中使用的兼容方法
*/

import { Component, render } from 'omi';
import { render } from 'omi';

export type ExtendedElement = (HTMLElement | SVGAElement | HTMLInputElement) & {
receiveProps: Function;
update: Function;
queuedUpdate: Function;
store?: unknown;
className?: string;
props: Record<string, unknown>;
splitText?: Function;
prevProps?: Record<string, unknown> & {
ref?:
| {
current?: unknown;
}
| Function;
};
attributes: NamedNodeMap;
_component?: Component;
_listeners: Record<string, Function>;
} & Record<string, unknown>;
import { ExtendedElement } from './common';

const convertReactToOmi = (r: any): Omi.ComponentChild => {
if (!r) return r;
Expand Down

0 comments on commit aa18c2f

Please sign in to comment.