style(vue-runtime-help): 更新ts定义

This commit is contained in:
roymondchen 2025-03-18 16:52:21 +08:00
parent f5742c107a
commit d53a479b21
2 changed files with 11 additions and 13 deletions

View File

@ -16,7 +16,7 @@
* limitations under the License.
*/
import { inject } from 'vue-demi';
import { ConcreteComponent, inject } from 'vue-demi';
import type TMagicApp from '@tmagic/core';
import { toLine } from '@tmagic/core';
@ -33,10 +33,12 @@ interface UseComponentOptions {
* @param options
* @returns magic-ui-
*/
export function useComponent<Component = any>(options: string | UseComponentOptions = '') {
export function useComponent<C extends ConcreteComponent = ConcreteComponent>(
options: string | UseComponentOptions = '',
) {
let componentType: string | undefined;
let app: TMagicApp | undefined;
let component: Component | undefined;
let component: C | undefined;
if (typeof options === 'string') {
componentType = options;
@ -47,21 +49,17 @@ export function useComponent<Component = any>(options: string | UseComponentOpti
if (!componentType || componentType === '') {
componentType = 'container';
}
if (!app) {
app = inject<TMagicApp>('app');
}
component = resolveComponent({ componentType, app });
component = app?.resolveComponent(componentType);
if (!component && !componentType.startsWith('magic-ui-')) {
componentType = `magic-ui-${toLine(componentType)}`;
component = resolveComponent({ componentType, app });
component = app?.resolveComponent(componentType);
}
return component ?? componentType;
}
type resolveComponentOptions = Required<Pick<UseComponentOptions, 'componentType'>> & UseComponentOptions;
function resolveComponent<Component = any>({ componentType, app }: resolveComponentOptions): Component | undefined {
return app?.resolveComponent(componentType);
}

View File

@ -9,10 +9,10 @@ export const useDsl = (app = inject<TMagicApp>('app')) => {
throw new Error('useDsl must be used after MagicApp is created');
}
const pageConfig = ref(app.page?.data || {});
const pageConfig = ref<MNode | undefined>(app.page?.data);
app.on('page-change', () => {
pageConfig.value = app.page?.data || {};
pageConfig.value = app.page?.data;
});
const updateDataHandler = (nodes: MNode[], sourceId: string, changeEvent: ChangeEvent) => {