Skip to content

Commit

Permalink
fix: 优化类型声明以支持 Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
knight.chen committed Oct 3, 2022
1 parent d517bb5 commit 5d02fda
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 225 deletions.
9 changes: 5 additions & 4 deletions packages/hooks/src/current-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Node } from '@alilc/lowcode-designer';
import { NodeSchema } from '@alilc/lowcode-types';
import { inject, InjectionKey } from 'vue';
import { DesignMode } from './renderer-context';
import type { Node } from '@alilc/lowcode-designer';
import type { InjectionKey } from 'vue';
import type { NodeSchema } from '@alilc/lowcode-types';
import type { DesignMode } from './renderer-context';
import { inject } from 'vue';

export interface EnvNode {
mode: DesignMode;
Expand Down
13 changes: 4 additions & 9 deletions packages/hooks/src/renderer-context.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
Component,
ComponentPublicInstance,
InjectionKey,
inject,
getCurrentInstance,
} from 'vue';
import { Node } from '@alilc/lowcode-designer';
import { NodeSchema } from '@alilc/lowcode-types';
import type { Component, ComponentPublicInstance, InjectionKey } from 'vue';
import type { Node } from '@alilc/lowcode-designer';
import type { NodeSchema } from '@alilc/lowcode-types';
import { inject, getCurrentInstance } from 'vue';

export type DesignMode = 'live' | 'design';

Expand Down
12 changes: 2 additions & 10 deletions packages/utils/src/asset.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* copy from https://github.com/alibaba/lowcode-engine/blob/main/packages/utils/src/asset.ts
*/

import {
Asset,
AssetBundle,
AssetItem,
AssetLevel,
AssetLevels,
AssetList,
AssetType,
} from '@alilc/lowcode-types';
import type { Asset, AssetBundle, AssetItem, AssetList } from '@alilc/lowcode-types';
import { AssetLevel, AssetLevels, AssetType } from '@alilc/lowcode-types';
import { isCSSUrl } from './check';
import { createDefer } from './create-defer';
import { evaluate, load } from './script';
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/src/build-components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, defineComponent, h } from 'vue';
import { isESModule, isFunction, isObject } from './check';
import type { Component } from 'vue';
import type { ComponentSchema, NpmInfo } from '@alilc/lowcode-types';
import { defineComponent, h } from 'vue';
import { isESModule, isFunction, isObject } from './check';

export function isVueComponent(val: unknown): val is Component {
if (isFunction(val)) return true;
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/build-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isJSFunction, JSFunction, NpmInfo } from '@alilc/lowcode-types';
import type { JSFunction, NpmInfo } from '@alilc/lowcode-types';
import { isJSFunction } from '@alilc/lowcode-types';
import { accessLibrary } from './build-components';

export interface UtilsNpmMetadata {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-renderer/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RendererComponent } from './core';
import type { RendererComponent } from './core';
import { RENDERER_COMPS } from './renderers';

export type RendererModules = Record<string, RendererComponent>;
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-renderer/src/core/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodeSchema, RootSchema } from '@alilc/lowcode-types';
import { Node } from '@alilc/lowcode-designer';
import { Component, ComponentPublicInstance, PropType, VNodeProps } from 'vue';
import { BlockScope, I18nMessages, RuntimeScope } from '../utils';
import type { NodeSchema, RootSchema } from '@alilc/lowcode-types';
import type { Node } from '@alilc/lowcode-designer';
import type { Component, ComponentPublicInstance, PropType, VNodeProps } from 'vue';
import type { BlockScope, I18nMessages, RuntimeScope } from '../utils';

export const rendererProps = {
__scope: {
Expand Down
15 changes: 5 additions & 10 deletions packages/vue-renderer/src/core/hoc.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import type { SlotNode } from '@alilc/lowcode-designer';
import type { ComponentPublicInstance } from 'vue';
import type { PropSchemaMap, SlotSchemaMap } from './use';
import { isNil } from 'lodash-es';
import { isJSSlot, TransformStage } from '@alilc/lowcode-types';
import { SlotNode } from '@alilc/lowcode-designer';
import {
ComponentPublicInstance,
h,
Fragment,
reactive,
onUnmounted,
defineComponent,
} from 'vue';
import { h, Fragment, reactive, onUnmounted, defineComponent } from 'vue';
import { leafProps } from './base';
import { useRendererContext } from '@knxcloud/lowcode-hooks';
import { ensureArray } from '../utils';
import { PropSchemaMap, SlotSchemaMap, useLeaf } from './use';
import { useLeaf } from './use';

export const Hoc = defineComponent({
name: 'Hoc',
Expand Down
27 changes: 12 additions & 15 deletions packages/vue-renderer/src/core/use.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Prop } from '@alilc/lowcode-designer';
import type { Prop } from '@alilc/lowcode-designer';
import type { Component, VNode, Ref, ComputedRef, Slot, Slots, InjectionKey } from 'vue';
import type {
NodeData,
SlotSchema,
NodeSchema,
JSFunction,
CompositeValue,
} from '@alilc/lowcode-types';
import type { LeafProps, RendererProps } from './base';
import type { MaybeArray, BlockScope, RuntimeScope } from '../utils';

import {
Component,
VNode,
Ref,
ComputedRef,
Slot,
Slots,
h,
createTextVNode,
computed,
Expand All @@ -24,14 +29,8 @@ import {
toRaw,
toDisplayString,
inject,
InjectionKey,
} from 'vue';
import {
NodeData,
SlotSchema,
NodeSchema,
JSFunction,
CompositeValue,
isJSSlot,
isJSFunction,
isDOMText,
Expand All @@ -45,7 +44,6 @@ import {
getRendererContextKey,
useRendererContext,
} from '@knxcloud/lowcode-hooks';
import { LeafProps, RendererProps } from './base';
import { Hoc } from './hoc';
import { Live } from './live';
import {
Expand All @@ -58,7 +56,6 @@ import {
parseExpression,
} from '../utils';
import { createDataSourceManager } from '../data-source';
import { MaybeArray, BlockScope, RuntimeScope } from '../utils';

const currentNodeKey = getCurrentNodeKey();

Expand Down
11 changes: 8 additions & 3 deletions packages/vue-renderer/src/data-source/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { InterpretDataSource, InterpretDataSourceConfig } from '@alilc/lowcode-types';
import type {
InterpretDataSource,
InterpretDataSourceConfig,
} from '@alilc/lowcode-types';
import type { RequestParams } from './interface';
import type { RuntimeScope } from '../utils';
import { computed, reactive, ref, shallowRef } from 'vue';
import { isBoolean, isFunction, isUndefined } from 'lodash-es';
import { request, Response } from './request';
import { DataSourceStatus, RequestParams } from './interface';
import { isPlainObject, parseSchema, RuntimeScope } from '../utils';
import { DataSourceStatus } from './interface';
import { isPlainObject, parseSchema } from '../utils';

const same = <T>(v: T) => v;
const noop = () => void 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-renderer/src/data-source/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RequestOptions, ResponseType } from './interface';
import { isPlainObject } from '../utils';
import { RequestOptions, ResponseType } from './interface';

function serializeParams(obj: Record<string, unknown>) {
const result: string[] = [];
Expand Down
17 changes: 6 additions & 11 deletions packages/vue-renderer/src/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { NodeSchema, RootSchema } from '@alilc/lowcode-types';
import type { NodeSchema, RootSchema } from '@alilc/lowcode-types';
import type { PropType, Component, ComponentPublicInstance } from 'vue';
import type { I18nMessages, BlockScope } from './utils';
import { Node } from '@alilc/lowcode-designer';
import {
PropType,
Component,
ComponentPublicInstance,
h,
computed,
defineComponent,
} from 'vue';
import { h, computed, defineComponent } from 'vue';
import config from './config';
import { RENDERER_COMPS } from './renderers';
import { I18nMessages, BlockScope } from './utils';

interface RendererProps {
scope?: BlockScope;
Expand Down Expand Up @@ -119,4 +113,5 @@ const Renderer = defineComponent({
},
}) as new (...args: any[]) => { $props: RendererProps };

export { RendererProps, Renderer, I18nMessages, BlockScope };
export { Renderer };
export type { RendererProps, I18nMessages, BlockScope };
2 changes: 1 addition & 1 deletion packages/vue-renderer/src/renderers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RendererComponent } from '../core';
import type { RendererComponent } from '../core';
import { PageRenderer } from './page';

export const RENDERER_COMPS: Record<string, RendererComponent> = {
Expand Down
12 changes: 3 additions & 9 deletions packages/vue-renderer/src/utils/parse.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import {
I18nData,
JSFunction,
JSExpression,
isI18nData,
isJSExpression,
isJSFunction,
} from '@alilc/lowcode-types';
import type { I18nData, JSFunction, JSExpression } from '@alilc/lowcode-types';
import type { BlockScope, RuntimeScope } from './scope';
import { isI18nData, isJSExpression, isJSFunction } from '@alilc/lowcode-types';
import { isFunction, isString } from 'lodash-es';
import { isPlainObject } from './object';
import { ensureArray } from './array';
import { BlockScope, RuntimeScope } from './scope';

export const EXPRESSION_TYPE = {
JSEXPRESSION: 'JSExpression',
Expand Down
7 changes: 4 additions & 3 deletions packages/vue-renderer/src/utils/scope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentPublicInstance, isProxy, reactive } from 'vue';
import type { ComponentPublicInstance } from 'vue';
import type { MaybeArray } from './array';
import type { DataSourceItem } from '../data-source';
import { isObject } from './object';
import { MaybeArray } from './array';
import { DataSourceItem } from '../data-source';
import { isProxy, reactive } from 'vue';

export interface BlockScope {
[x: string]: unknown;
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-simulator-renderer/src/host.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { BuiltinSimulatorHost } from '@alilc/lowcode-designer';
import type { BuiltinSimulatorHost } from '@alilc/lowcode-designer';

export const host: BuiltinSimulatorHost = (window as any).LCSimulatorHost;
14 changes: 9 additions & 5 deletions packages/vue-simulator-renderer/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Router } from 'vue-router';
import { Config, I18nMessages } from '@knxcloud/lowcode-vue-renderer';
import { Component, ComponentPublicInstance, App } from 'vue';
import { ComponentSchema, NpmInfo, RootSchema } from '@alilc/lowcode-types';
import { BuiltinSimulatorRenderer, DocumentModel, Node } from '@alilc/lowcode-designer';
import type { Router } from 'vue-router';
import type { Config, I18nMessages } from '@knxcloud/lowcode-vue-renderer';
import type { Component, ComponentPublicInstance, App } from 'vue';
import type { ComponentSchema, NpmInfo, RootSchema } from '@alilc/lowcode-types';
import type {
Node,
DocumentModel,
BuiltinSimulatorRenderer,
} from '@alilc/lowcode-designer';

export type MinxedComponent = NpmInfo | Component | ComponentSchema;

Expand Down
5 changes: 3 additions & 2 deletions packages/vue-simulator-renderer/src/simulator-view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineComponent, h, PropType, renderSlot } from 'vue';
import type { PropType } from 'vue';
import type { DocumentInstance, VueSimulatorRenderer } from './interface';
import { defineComponent, h, renderSlot } from 'vue';
import LowCodeRenderer from '@knxcloud/lowcode-vue-renderer';
import { DocumentInstance, VueSimulatorRenderer } from './interface';
import { RouterView } from 'vue-router';

export const Layout = defineComponent({
Expand Down
19 changes: 9 additions & 10 deletions packages/vue-simulator-renderer/src/simulator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { DocumentModel } from '@alilc/lowcode-designer';
import type { DocumentModel } from '@alilc/lowcode-designer';
import type { Ref, Component } from 'vue';
import type {
ComponentInstance,
DocumentInstance,
MinxedComponent,
SimulatorViewLayout,
VueSimulatorRenderer,
} from './interface';
import { TransformStage } from '@alilc/lowcode-types';
import {
Ref,
Component,
createApp,
ref,
shallowRef,
Expand All @@ -18,13 +24,6 @@ import {
buildComponents,
getSubComponent,
} from '@knxcloud/lowcode-utils';
import {
ComponentInstance,
DocumentInstance,
MinxedComponent,
SimulatorViewLayout,
VueSimulatorRenderer,
} from './interface';
import { Renderer, SimulatorRendererView } from './simulator-view';
import { Slot, Leaf, Page } from './buildin-components';
import { host } from './host';
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-simulator-renderer/src/utils/closest-node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NodeInstance } from '@alilc/lowcode-designer';
import { ComponentInternalInstance } from 'vue';
import type { NodeInstance } from '@alilc/lowcode-designer';
import type { ComponentInternalInstance } from 'vue';
import { isCommentNode } from './check-node';
import {
ComponentRecord,
Expand Down
5 changes: 3 additions & 2 deletions packages/vue-simulator-renderer/src/utils/comp-node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ComponentInternalInstance, VNode } from 'vue';
import type { ComponentInstance } from '../interface';
import { isNil } from '@knxcloud/lowcode-utils';
import { ComponentInternalInstance, isProxy, VNode } from 'vue';
import { ComponentInstance } from '../interface';
import { isProxy } from 'vue';
import { isObject } from './check';

const SYMBOL_VDID = Symbol('_LCDocId');
Expand Down
5 changes: 3 additions & 2 deletions packages/vue-simulator-renderer/src/utils/find-dom-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentInternalInstance, VNode, isVNode } from 'vue';
import { ComponentInstance } from '../interface';
import type { ComponentInternalInstance, VNode } from 'vue';
import type { ComponentInstance } from '../interface';
import { isVNode } from 'vue';
import { isVNodeHTMLElement } from './comp-node';
import { isDomNode, isEmptyNode } from './check-node';
import { getClientRects } from './get-client-rects';
Expand Down
Loading

0 comments on commit 5d02fda

Please sign in to comment.