Skip to content

Commit 0157bbd

Browse files
committed
fix: fix some bugs
1 parent f1711e0 commit 0157bbd

File tree

28 files changed

+270
-290
lines changed

28 files changed

+270
-290
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"playground": "pnpm --filter playground dev",
76
"build": "node ./scripts/build.js",
87
"test": "vitest",
98
"clean": "rimraf ./packages/*/dist",
@@ -35,6 +34,7 @@
3534
"eslint-plugin-react-hooks": "^4.6.0",
3635
"globals": "^15.0.0",
3736
"husky": "^9.0.11",
37+
"jsdom": "^24.1.0",
3838
"lint-staged": "^15.2.2",
3939
"prettier": "^3.2.5",
4040
"rimraf": "^5.0.2",

packages/react-renderer/src/components/route.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ function RouteOutlet({ pageConfig }: OutletProps) {
2626
const context = useRenderContext();
2727
const { schema, packageManager } = context;
2828
const { type = 'lowCode', mappingId } = pageConfig;
29+
console.log(
30+
'%c [ pageConfig ]-29',
31+
'font-size:13px; background:pink; color:#bf2c9f;',
32+
pageConfig,
33+
);
2934

3035
if (type === 'lowCode') {
3136
// 在页面渲染时重新获取 componentsMap

packages/react-renderer/src/components/routerView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export const createRouterProvider = (router: Router) => {
1313
return () => remove();
1414
}, []);
1515

16-
const pageSchema = useMemo(() => {
16+
const pageConfig = useMemo(() => {
1717
const pages = schema.get('pages') ?? [];
1818
const matched = location.matched[location.matched.length - 1];
1919

2020
if (matched) {
21-
const page = pages.find((item) => matched.page === item.id);
21+
const page = pages.find((item) => matched.page === item.mappingId);
2222
return page;
2323
}
2424

@@ -28,7 +28,7 @@ export const createRouterProvider = (router: Router) => {
2828
return (
2929
<RouterContext.Provider value={router}>
3030
<RouteLocationContext.Provider value={location}>
31-
<PageConfigContext.Provider value={pageSchema}>{children}</PageConfigContext.Provider>
31+
<PageConfigContext.Provider value={pageConfig}>{children}</PageConfigContext.Provider>
3232
</RouteLocationContext.Provider>
3333
</RouterContext.Provider>
3434
);
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export const dataSourceCreator = () => ({}) as any;
1+
export const dataSourceCreator = () =>
2+
({
3+
dataSourceMap: {},
4+
reloadDataSource: () => {},
5+
}) as any;

packages/react-renderer/src/runtime/index.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { processValue, someValue } from '@alilc/lowcode-renderer-core';
22
import {
3-
watch,
43
isJSExpression,
54
isJSFunction,
65
isJSSlot,
76
invariant,
8-
isLowCodeComponentSchema,
7+
isLowCodeComponentPackage,
98
isJSI18nNode,
109
} from '@alilc/lowcode-shared';
1110
import { forwardRef, useRef, useEffect, createElement, memo } from 'react';
12-
import { appendExternalStyle } from '../utils/element';
11+
import { appendExternalStyle } from '../../../../playground/renderer/src/plugin/remote/element';
1312
import { reactive } from '../utils/reactive';
1413
import { useRenderContext } from '../context/render';
1514
import { reactiveStateCreator } from './reactiveState';
@@ -63,7 +62,7 @@ export function getComponentByName(
6362

6463
invariant(result, `${name} component not found in componentsRecord`);
6564

66-
if (isLowCodeComponentSchema(result)) {
65+
if (isLowCodeComponentPackage(result)) {
6766
const { componentsMap, componentsTree, utils, i18n } = result.schema;
6867

6968
if (componentsMap.length > 0) {
@@ -120,6 +119,7 @@ export function createComponentBySchema(
120119
}
121120

122121
const model = modelRef.current;
122+
console.log('%c [ model ]-123', 'font-size:13px; background:pink; color:#bf2c9f;', model);
123123

124124
const isConstructed = useRef(false);
125125
const isMounted = useRef(false);
@@ -133,7 +133,7 @@ export function createComponentBySchema(
133133
const scopeValue = model.codeScope.value;
134134

135135
// init dataSource
136-
scopeValue.reloadDataSource();
136+
scopeValue.reloadDataSource?.();
137137

138138
let styleEl: HTMLElement | undefined;
139139
const cssText = model.getCssText();
@@ -148,19 +148,19 @@ export function createComponentBySchema(
148148
model.triggerLifeCycle('componentDidMount');
149149

150150
// 当 state 改变之后调用
151-
const unwatch = watch(scopeValue.state, (_, oldVal) => {
152-
if (isMounted.current) {
153-
model.triggerLifeCycle('componentDidUpdate', props, oldVal);
154-
}
155-
});
151+
// const unwatch = watch(scopeValue.state, (_, oldVal) => {
152+
// if (isMounted.current) {
153+
// model.triggerLifeCycle('componentDidUpdate', props, oldVal);
154+
// }
155+
// });
156156

157157
isMounted.current = true;
158158

159159
return () => {
160160
// componentWillUnmount?.();
161161
model.triggerLifeCycle('componentWillUnmount');
162162
styleEl?.parentNode?.removeChild(styleEl);
163-
unwatch();
163+
// unwatch();
164164
isMounted.current = false;
165165
};
166166
}, []);
@@ -247,7 +247,7 @@ function createElementByWidget(
247247
};
248248

249249
// 先将 jsslot, jsFunction 对象转换
250-
const finalProps = processValue(
250+
let finalProps = processValue(
251251
componentProps,
252252
(node) => isJSFunction(node) || isJSSlot(node),
253253
(node: Spec.JSSlot | Spec.JSFunction) => {
@@ -288,6 +288,17 @@ function createElementByWidget(
288288
},
289289
);
290290

291+
finalProps = processValue(
292+
finalProps,
293+
(value) => {
294+
return value.type === 'JSSlot' && !value.value;
295+
},
296+
(node) => {
297+
console.log('%c [ node ]-303', 'font-size:13px; background:pink; color:#bf2c9f;', node);
298+
return null;
299+
},
300+
);
301+
291302
const childElements = children?.map((child) =>
292303
createElementByWidget(child, codeScope, renderContext, componentRefAttached),
293304
);

packages/react-renderer/src/utils/element.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

packages/react-renderer/src/utils/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export function normalizeComponentNode(node: Spec.ComponentNode): NormalizedComp
1010
...node,
1111
loopArgs: node.loopArgs ?? ['item', 'index'],
1212
props: node.props ?? {},
13+
condition: node.condition || node.condition === false ? node.condition : true,
1314
};
1415
}

packages/react-renderer/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"compilerOptions": {
44
"outDir": "dist"
55
},
6-
"include": ["src"]
6+
"include": ["src", "../../playground/renderer/src/plugin/remote/element.ts"]
77
}

packages/renderer-core/__tests__/boosts.spec.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/renderer-core/__tests__/code-runtime.spec.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)