fix: codes refactor
This commit is contained in:
parent
006b9b615e
commit
a02b19e6e3
|
@ -64,5 +64,6 @@ export default tseslint.config({
|
|||
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies
|
||||
|
||||
'no-inner-declarations': 'off',
|
||||
'no-constant-condition': 'off',
|
||||
},
|
||||
});
|
||||
|
|
38
package.json
38
package.json
|
@ -20,27 +20,27 @@
|
|||
"prepare": "husky"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
"@commitlint/cli": "^19.2.1",
|
||||
"@commitlint/config-conventional": "^19.1.0",
|
||||
"@changesets/cli": "^2.27.7",
|
||||
"@commitlint/cli": "^19.3.0",
|
||||
"@commitlint/config-conventional": "^19.2.2",
|
||||
"@eslint/js": "^8.57.0",
|
||||
"@microsoft/api-extractor": "^7.43.0",
|
||||
"@stylistic/eslint-plugin": "^1.7.0",
|
||||
"@types/node": "^20.11.30",
|
||||
"@vanilla-extract/vite-plugin": "^4.0.7",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"@microsoft/api-extractor": "^7.47.4",
|
||||
"@stylistic/eslint-plugin": "^1.8.1",
|
||||
"@types/node": "^22.0.0",
|
||||
"@vanilla-extract/vite-plugin": "^4.0.13",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-react": "^7.34.1",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"globals": "^15.0.0",
|
||||
"husky": "^9.0.11",
|
||||
"jsdom": "^24.1.0",
|
||||
"lint-staged": "^15.2.2",
|
||||
"prettier": "^3.2.5",
|
||||
"rimraf": "^5.0.2",
|
||||
"typescript": "^5.4.2",
|
||||
"typescript-eslint": "^7.5.0",
|
||||
"vite": "^5.2.9",
|
||||
"eslint-plugin-react": "^7.35.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"globals": "^15.8.0",
|
||||
"husky": "^9.1.3",
|
||||
"jsdom": "^24.1.1",
|
||||
"lint-staged": "^15.2.7",
|
||||
"prettier": "^3.3.3",
|
||||
"rimraf": "^6.0.1",
|
||||
"typescript": "^5.5.4",
|
||||
"typescript-eslint": "^7.17.0",
|
||||
"vite": "^5.3.5",
|
||||
"vitest": "^1.6.0"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
||||
import { type Root, createRoot } from 'react-dom/client';
|
||||
import { RendererContext, getRenderInstancesByAccessor } from './context';
|
||||
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
|
||||
import { ApplicationView, boosts } from '../app';
|
||||
import { type ReactAppOptions } from './types';
|
||||
|
||||
export const createApp = async (options: ReactAppOptions) => {
|
||||
return createRenderer(async (accessor) => {
|
||||
const instances = getRenderInstancesByAccessor(accessor);
|
||||
return createRenderer(async (service) => {
|
||||
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
|
||||
return {
|
||||
options,
|
||||
...getRenderInstancesByAccessor(accessor),
|
||||
};
|
||||
});
|
||||
|
||||
instances.boostsManager.extend(boosts.toExpose());
|
||||
contextValue.boostsManager.extend(boosts.toExpose());
|
||||
|
||||
let root: Root | undefined;
|
||||
|
||||
|
@ -16,9 +21,8 @@ export const createApp = async (options: ReactAppOptions) => {
|
|||
async mount(containerOrId) {
|
||||
if (root) return;
|
||||
|
||||
const defaultId = instances.schema.get('config')?.targetRootID ?? 'app';
|
||||
const defaultId = contextValue.schema.get<string>('config.targetRootID', 'app');
|
||||
const rootElement = normalizeContainer(containerOrId, defaultId);
|
||||
const contextValue = { ...instances, options };
|
||||
|
||||
root = createRoot(rootElement);
|
||||
root.render(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { createRenderer } from '@alilc/lowcode-renderer-core';
|
||||
import { FunctionComponent } from 'react';
|
||||
import { type ComponentTreeRoot } from '@alilc/lowcode-shared';
|
||||
import { type FunctionComponent } from 'react';
|
||||
import {
|
||||
type LowCodeComponentProps,
|
||||
createComponent as createSchemaComponent,
|
||||
} from '../runtime/createComponent';
|
||||
import { RendererContext, getRenderInstancesByAccessor } from './context';
|
||||
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
|
||||
import { type ReactAppOptions } from './types';
|
||||
|
||||
interface Render {
|
||||
|
@ -12,17 +13,25 @@ interface Render {
|
|||
}
|
||||
|
||||
export async function createComponent(options: ReactAppOptions) {
|
||||
const creator = createRenderer<Render>((accessor) => {
|
||||
const instances = getRenderInstancesByAccessor(accessor);
|
||||
const componentsTree = instances.schema.get('componentsTree')[0];
|
||||
const creator = createRenderer<Render>((service) => {
|
||||
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
|
||||
return {
|
||||
options,
|
||||
...getRenderInstancesByAccessor(accessor),
|
||||
};
|
||||
});
|
||||
|
||||
const componentsTree = contextValue.schema.get<ComponentTreeRoot>('componentsTree.0');
|
||||
|
||||
if (!componentsTree) {
|
||||
throw new Error('componentsTree is required');
|
||||
}
|
||||
|
||||
const LowCodeComponent = createSchemaComponent(componentsTree, {
|
||||
displayName: componentsTree.componentName,
|
||||
...options.component,
|
||||
});
|
||||
|
||||
const contextValue = { ...instances, options };
|
||||
|
||||
function Component(props: LowCodeComponentProps) {
|
||||
return (
|
||||
<RendererContext.Provider value={contextValue}>
|
||||
|
|
|
@ -12,15 +12,14 @@ const buildTypes = args['types'] || args['t'];
|
|||
async function run() {
|
||||
const packages = await findWorkspacePackages(cwd());
|
||||
const targetPackageName = `@alilc/lowcode-${targets[0]}`;
|
||||
const finalName = packages
|
||||
.filter((item) => item.manifest.name === targetPackageName)
|
||||
.map(item => item.manifest.name);
|
||||
const manifest = packages.filter((item) => item.manifest.name === targetPackageName)[0].manifest;
|
||||
|
||||
await execa('pnpm', ['--filter', finalName[0], 'build:target'], {
|
||||
await execa('pnpm', ['--filter', manifest.name, 'build:target'], {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
PROD: prod,
|
||||
FORMATS: formatArgs ? formatArgs : !prod ? 'es' : undefined,
|
||||
VERSION: manifest.version,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
"importHelpers": false,
|
||||
// Enables experimental support for ES7 decorators.
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
// Generates corresponding .map file.
|
||||
"sourceMap": true,
|
||||
// Disallow inconsistently-cased references to the same file.
|
||||
|
@ -37,7 +36,7 @@
|
|||
"paths": {
|
||||
"@alilc/lowcode-*": ["packages/*/src"]
|
||||
},
|
||||
"types": ["vite/client", "vitest/globals", "node"]
|
||||
"types": ["vitest/globals", "node"]
|
||||
},
|
||||
"include": [
|
||||
"packages/global.d.ts",
|
||||
|
|
|
@ -32,6 +32,10 @@ export default async ({
|
|||
}
|
||||
|
||||
return defineConfig({
|
||||
define: {
|
||||
__DEV__: JSON.stringify(!isProduction),
|
||||
__VERSION__: JSON.stringify(env['VERSION']),
|
||||
},
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolvePath(entry),
|
||||
|
|
Loading…
Reference in New Issue