@vtj/coder 0.17.8 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.17.8",
4
+ "version": "0.18.0",
5
5
  "type": "module",
6
6
  "keywords": [
7
+ "AI低代码",
8
+ "AI编程",
7
9
  "低代码引擎",
8
10
  "LowCode Engine",
9
11
  "Vue3低代码",
@@ -12,7 +14,7 @@
12
14
  "代码生成器",
13
15
  "代码可视化"
14
16
  ],
15
- "description": "VTJ 是一款基于 Vue3 + Typescript 的低代码页面可视化设计器。内置低代码引擎、渲染器和代码生成器,面向前端开发者,开箱即用。 无缝嵌入本地开发工程,不改变前端开发流程和编码习惯。",
17
+ "description": "VVTJ.PRO 是一个开源的、AI 驱动的 Vue3 企业级应用开发平台,通过 AI 智能体与可视化编排实现高效开发,并支持导出标准 Vue 代码以避免平台锁定。",
16
18
  "repository": {
17
19
  "type": "git",
18
20
  "url": "https://gitee.com/newgateway/vtj.git"
@@ -22,11 +24,11 @@
22
24
  "license": "MIT",
23
25
  "dependencies": {
24
26
  "prettier": "~3.7.0",
25
- "@vtj/core": "~0.17.8",
26
- "@vtj/base": "~0.12.4"
27
+ "@vtj/base": "~0.13.0",
28
+ "@vtj/core": "~0.18.0"
27
29
  },
28
30
  "devDependencies": {
29
- "@vtj/cli": "~0.12.20"
31
+ "@vtj/cli": "~0.13.0"
30
32
  },
31
33
  "exports": {
32
34
  ".": {
@@ -11,8 +11,11 @@ export declare class Collecter {
11
11
  members: string[];
12
12
  urlSchemas: Record<string, NodeFromUrlSchema>;
13
13
  blockPlugins: Record<string, NodeFromPlugin>;
14
+ /** 配置了 easycom 的依赖包名集合,出码时不需要 import */
15
+ easycomPackages: Set<string>;
14
16
  private libraryRegex;
15
17
  constructor(dsl: BlockSchema, dependencies: Dependencie[]);
18
+ private collectEasycom;
16
19
  private collectLibrary;
17
20
  /**
18
21
  * 收集 import 信息
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { version as VTJ_CODER_VERSION } from './version';
2
2
  export * from './generator';
3
3
  export { tsFormatter, cssFormatter, vueFormatter } from './formatters';
4
+ export { GLOBAL_API_MAP, UI_GLOBAL_API_MAPS, UI_PACKAGES, detectUIPackage, buildEffectiveApiMap, type GlobalApiConfig } from './parser/composition/globalApi';
@@ -0,0 +1,18 @@
1
+ import { BlockComposable } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ export interface ComposableResult {
4
+ /** 顶层声明语句 */
5
+ statements: string[];
6
+ /** 需要 import 的标识符:{ from: [composable, ...] } */
7
+ imports: Record<string, string[]>;
8
+ }
9
+ /**
10
+ * 解析 composables:
11
+ * - { name: 'router', composable: { type: 'JSExpression', value: 'this.$libs.VueRouter.useRouter' } }
12
+ * → const router = this.$libs.VueRouter.useRouter();
13
+ * - { composable: { type: 'JSExpression', value: 'useUserStore' }, destructure: ['user', 'login'] }
14
+ * → const { user, login } = useUserStore();
15
+ * - { name: 'data', composable: { type: 'JSExpression', value: 'useFetch' }, args: ['/api'] }
16
+ * → const data = useFetch('/api');
17
+ */
18
+ export declare function parseComposables(composables: BlockComposable[] | undefined, symbols: SymbolTable): ComposableResult;
@@ -0,0 +1,8 @@
1
+ import { JSExpression, JSFunction } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 computed 为 Composition 顶层声明:
5
+ * { total: { value: '() => this.count * 2' } }
6
+ * → const total = computed(() => count.value * 2);
7
+ */
8
+ export declare function parseComputed(computed: Record<string, JSFunction | JSExpression> | undefined, symbols: SymbolTable): string[];
@@ -0,0 +1,49 @@
1
+ import { BlockSchema, MaterialDescription } from '@vtj/core';
2
+ /**
3
+ * 全局 API 配置:DSL 中 this.$xxx 形式 → Composition API 等价物
4
+ */
5
+ export interface GlobalApiConfig {
6
+ /** 需要 import 的标识符(如 useAttrs),无则为 null */
7
+ composable: string | null;
8
+ /** composable 的来源包(如 'vue'、'vue-router') */
9
+ from: string;
10
+ /** 顶层声明语句(无则不生成) */
11
+ declare: string | null;
12
+ /** 替换后的名称(this.$attrs → attrs) */
13
+ replace: string;
14
+ }
15
+ /**
16
+ * 框架无关的基础全局 API 映射表
17
+ * 包含 Vue 原生、vue-router、vue-i18n、@vtj/renderer
18
+ * 不含任何 UI 库(element-plus / ant-design-vue 等)
19
+ */
20
+ export declare const GLOBAL_API_MAP: Record<string, GlobalApiConfig>;
21
+ /**
22
+ * UI 库专属全局 API 映射(按包名分组)
23
+ * 同名 key 会在运行时覆盖 GLOBAL_API_MAP 中的同名条目
24
+ */
25
+ export declare const UI_GLOBAL_API_MAPS: Record<string, Record<string, GlobalApiConfig>>;
26
+ /** 已知 UI 库包名列表 */
27
+ export declare const UI_PACKAGES: string[];
28
+ /**
29
+ * 从 componentMap 探测当前激活的 UI 库包名
30
+ */
31
+ export declare function detectUIPackage(componentMap: Map<string, MaterialDescription>): string | null;
32
+ /**
33
+ * 构建有效 API 映射:基础 Map + 当前 UI 库 Map(UI 库覆盖同名 key)
34
+ */
35
+ export declare function buildEffectiveApiMap(uiPackage: string | null): Record<string, GlobalApiConfig>;
36
+ /**
37
+ * 全局 API 检测器
38
+ * 走读 DSL 中所有 JSExpression / JSFunction 的 value 字符串
39
+ * 识别使用到的 this.$xxx,返回出现的 API 名集合
40
+ */
41
+ export declare function detectGlobalApis(dsl: BlockSchema, effectiveMap?: Record<string, GlobalApiConfig>): Set<string>;
42
+ /**
43
+ * 根据检测到的全局 API 生成顶层声明语句
44
+ */
45
+ export declare function generateGlobalApiDeclares(apis: Set<string>, effectiveMap?: Record<string, GlobalApiConfig>): string[];
46
+ /**
47
+ * 收集全局 API 需要导入的标识符,按来源包分组
48
+ */
49
+ export declare function collectGlobalApiImports(apis: Set<string>, effectiveMap?: Record<string, GlobalApiConfig>): Record<string, string[]>;
@@ -0,0 +1,31 @@
1
+ import { MaterialDescription, PlatformType } from '@vtj/core';
2
+ export interface CompositionImportsInput {
3
+ /** 物料组件映射 */
4
+ componentMap: Map<string, MaterialDescription>;
5
+ /** template 中使用到的组件名 */
6
+ components: string[];
7
+ /** 区块导入语句(已为完整字符串) */
8
+ importBlocks: string[];
9
+ /** collecter 收集到的 imports(this.$libs.X.Y)*/
10
+ collectImports: Record<string, Set<string>>;
11
+ /** 平台 */
12
+ platform: PlatformType;
13
+ /** Vue 需要导入的 Composition API */
14
+ vueImports: string[];
15
+ /** composables 引入:{ from: [composable, ...] } */
16
+ composableImports: Record<string, string[]>;
17
+ /** 全局 API 引入(按来源包分组):{ 'vue': ['useAttrs'], 'vue-router': ['useRouter'] } */
18
+ globalApiImports: Record<string, string[]>;
19
+ /** Uniapp 专用生命周期钩子(如 onLoad),需从 @dcloudio/uni-app 导入 */
20
+ uniHookImports: string[];
21
+ /** 配置了 easycom 的依赖包名集合,出码时不需要 import */
22
+ easycomPackages: Set<string>;
23
+ }
24
+ /**
25
+ * 解析 Composition 模式的所有 import
26
+ */
27
+ export declare function parseImports(input: CompositionImportsInput): {
28
+ imports: string[];
29
+ uniComponents: string[];
30
+ componentDeclarations: string[];
31
+ };
@@ -0,0 +1,63 @@
1
+ import { MaterialDescription, PlatformType } from '@vtj/core';
2
+ import { Collecter } from '../../collecter';
3
+ export interface TokenComposition {
4
+ id: string;
5
+ version: string;
6
+ name: string;
7
+ /** 顶层 imports(全部完整 import 语句) */
8
+ imports: string;
9
+ /** defineProps 内容 */
10
+ props: string;
11
+ /** defineEmits 列表(已带引号的字符串) */
12
+ emits: string;
13
+ /** 是否需要生成 defineProps(DSL 中使用了 this.$props) */
14
+ needsProps: boolean;
15
+ /** 是否需要生成 defineEmits(DSL 中使用了 this.$emit) */
16
+ needsEmit: boolean;
17
+ /** defineExpose 参数 */
18
+ expose: string;
19
+ /** 全局 API 顶层声明(const router = useRouter() 等) */
20
+ globalApiDeclares: string;
21
+ /** inject 顶层声明 */
22
+ injects: string;
23
+ /** composables 顶层声明 */
24
+ composables: string;
25
+ /** state(作为 reactive) */
26
+ state: string;
27
+ /** refs 顶层声明 */
28
+ refs: string;
29
+ /** reactives 顶层声明 */
30
+ reactives: string;
31
+ /** computed 顶层声明 */
32
+ computed: string;
33
+ /** methods 顶层声明 */
34
+ methods: string;
35
+ /** dataSources 顶层声明 */
36
+ dataSources: string;
37
+ /** watch 顶层调用 */
38
+ watch: string;
39
+ /** provide 顶层调用 */
40
+ provide: string;
41
+ /** created/beforeCreate 顶层立即执行 */
42
+ createdStatements: string;
43
+ /** setup 字段顶层立即执行 */
44
+ setupStatements: string;
45
+ /** onXxx 生命周期顶层调用 */
46
+ lifeCycles: string;
47
+ /** 模板部分 */
48
+ template: string;
49
+ css: string;
50
+ style: string;
51
+ urlSchemas: string;
52
+ blockPlugins: string;
53
+ uniComponents: string[];
54
+ renderer: string;
55
+ /** renderer 包导入的标识符(useProvider + 可能的 useStore 等) */
56
+ rendererImports: string;
57
+ /** parent 类型组件的 const 声明(如 const AButtonGroup = AButton.Group;) */
58
+ componentDeclarations: string;
59
+ }
60
+ /**
61
+ * Composition 模式 parser
62
+ */
63
+ export declare function parserComposition(collecter: Collecter, componentMap: Map<string, MaterialDescription>, platform?: PlatformType): TokenComposition;
@@ -0,0 +1,8 @@
1
+ import { BlockInject } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 inject 为 Composition 顶层声明:
5
+ * { name: 'theme', from: 'theme', default: 'light' }
6
+ * → const theme = inject('theme', 'light');
7
+ */
8
+ export declare function parseInject(injects: BlockInject[] | undefined, symbols: SymbolTable): string[];
@@ -0,0 +1,23 @@
1
+ import { JSFunction } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * Uniapp 专用生命周期钩子
5
+ */
6
+ export declare const UNI_HOOKS: Set<string>;
7
+ export interface LifeCyclesResult {
8
+ /** 顶层 onXxx() 调用语句 */
9
+ statements: string[];
10
+ /** 实际使用到的 Vue Composition 钩子(用于 vue import 收集) */
11
+ usedHooks: Set<string>;
12
+ /** 实际使用到的 Uniapp 专用钩子(用于 @dcloudio/uni-app import 收集) */
13
+ usedUniHooks: Set<string>;
14
+ }
15
+ /**
16
+ * 解析 lifeCycles 为 Composition 顶层 onXxx() 调用
17
+ *
18
+ * 注意:
19
+ * - created / beforeCreate 不在此处理(由 setupStatements 处理)
20
+ * - mounted 等 Options 命名自动映射为 onMounted
21
+ * - 已是 onXxx 的直接使用
22
+ */
23
+ export declare function parseLifeCycles(lifeCycles: Record<string, JSFunction> | undefined, symbols: SymbolTable): LifeCyclesResult;
@@ -0,0 +1,18 @@
1
+ import { JSFunction } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 methods 为 Composition 顶层 const 函数声明:
5
+ *
6
+ * { handleClick: { value: 'function() { this.count++ }' } }
7
+ * → const handleClick = function() { count.value++ };
8
+ *
9
+ * { fetch: { value: 'async function() { ... }' } }
10
+ * → const fetch = async function() { ... };
11
+ *
12
+ * 兼容箭头函数:{ fn: { value: '() => {}' } } → const fn = () => {};
13
+ */
14
+ export declare function parseMethods(methods: Record<string, JSFunction> | undefined, symbols: SymbolTable): string[];
15
+ /**
16
+ * 解析 dataSources 为 Composition 顶层 async 函数声明
17
+ */
18
+ export declare function parseDataSources(dataSources?: Record<string, any>, symbols?: SymbolTable): string[];
@@ -0,0 +1,9 @@
1
+ import { JSExpression, JSFunction, JSONValue } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 provide 为 Composition provide() 调用:
5
+ * { theme: 'light', count: { type: 'JSExpression', value: 'this.count' } }
6
+ * → provide('theme', 'light');
7
+ * provide('count', count);
8
+ */
9
+ export declare function parseProvide(provide: Record<string, JSONValue | JSExpression | JSFunction> | undefined, symbols: SymbolTable): string[];
@@ -0,0 +1,11 @@
1
+ import { JSExpression, JSFunction, JSONValue } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 reactives 声明:
5
+ * { form: { name: '' } } → ['const form = reactive({ "name": "" });']
6
+ */
7
+ export declare function parseReactives(reactives: Record<string, JSONValue | JSExpression> | undefined, symbols: SymbolTable): string[];
8
+ /**
9
+ * state 作为一个 reactive 输出(如果非空)
10
+ */
11
+ export declare function parseStateAsReactive(state: Record<string, JSONValue | JSExpression | JSFunction> | undefined, symbols: SymbolTable): string;
@@ -0,0 +1,8 @@
1
+ import { JSExpression, JSONValue } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 refs 声明:
5
+ * { count: 0, list: { type: 'JSExpression', value: 'this.props.items' } }
6
+ * → ['const count = ref(0);', 'const list = ref(props.items);']
7
+ */
8
+ export declare function parseRefs(refs: Record<string, JSONValue | JSExpression> | undefined, symbols: SymbolTable): string[];
@@ -0,0 +1,24 @@
1
+ import { JSFunction } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 提取函数体内容(用于 setup 顶层执行场景)
5
+ *
6
+ * 输入: 'async function() { console.log("init"); await foo(); }'
7
+ * 输出: 'console.log("init"); await foo();'
8
+ *
9
+ * 输入: '() => doSomething()'
10
+ * 输出: 'doSomething();'
11
+ *
12
+ * 输入: '() => { return foo(); }'
13
+ * 输出: 'return foo();' (由调用方决定是否需要包装)
14
+ */
15
+ export declare function extractFunctionBody(code: string): string;
16
+ /**
17
+ * 解析 setup 字段为顶层语句
18
+ */
19
+ export declare function parseSetupStatements(setup: JSFunction | undefined, symbols: SymbolTable): string;
20
+ /**
21
+ * 解析 created/beforeCreate 为顶层立即执行语句
22
+ * 二者均映射为 setup 阶段同步执行
23
+ */
24
+ export declare function parseCreatedStatements(lifeCycles: Record<string, JSFunction> | undefined, symbols: SymbolTable): string;
@@ -0,0 +1,32 @@
1
+ import { BlockSchema } from '@vtj/core';
2
+ import { GlobalApiConfig } from './globalApi';
3
+ /**
4
+ * 符号表:标识 DSL 中可识别的 this.xxx 引用属于哪一类
5
+ * Composition 模式出码时根据符号类别决定如何转换
6
+ */
7
+ export interface SymbolTable {
8
+ /** ref 声明集(需要 .value 解包)*/
9
+ refs: Set<string>;
10
+ /** reactive 声明集 + state(直接使用) */
11
+ reactives: Set<string>;
12
+ /** computed 声明集(需要 .value 解包) */
13
+ computed: Set<string>;
14
+ /** methods 声明集(顶层函数) */
15
+ methods: Set<string>;
16
+ /** props 名集(通过 props.xxx 访问) */
17
+ props: Set<string>;
18
+ /** composables 暴露的名集(包含 destructure) */
19
+ composables: Set<string>;
20
+ /** inject 名集(顶层变量) */
21
+ injects: Set<string>;
22
+ /** dataSources 名集(顶层函数) */
23
+ dataSources: Set<string>;
24
+ /** 是否生成 state reactive 声明 */
25
+ hasState: boolean;
26
+ /** 有效的全局 API 映射表(基础 Map + 当前 UI 库 Map) */
27
+ effectiveApiMap: Record<string, GlobalApiConfig>;
28
+ }
29
+ /**
30
+ * 构建符号表
31
+ */
32
+ export declare function buildSymbolTable(dsl: BlockSchema, effectiveApiMap?: Record<string, GlobalApiConfig>): SymbolTable;
@@ -0,0 +1,17 @@
1
+ import { NodeSchema, MaterialDescription, JSFunction } from '@vtj/core';
2
+ import { GlobalApiConfig } from './globalApi';
3
+ /**
4
+ * Composition 模式模板解析:
5
+ * - 预处理 nodes:替换全局 API、ref/computed 的 .value 解包
6
+ * - 委托给原 parseTemplate(this. 前缀剥离已能正确处理)
7
+ */
8
+ export declare function parseTemplateComposition(children: NodeSchema[], componentMap: Map<string, MaterialDescription>, computedKeys?: string[], context?: Record<string, Set<string>>, parent?: NodeSchema, effectiveMap?: Record<string, GlobalApiConfig>, refs?: Set<string>, computed?: Set<string>): {
9
+ nodes: string[];
10
+ methods: Record<string, JSFunction>;
11
+ directives: string[];
12
+ components: string[];
13
+ importBlocks: {
14
+ id: string;
15
+ name: string;
16
+ }[];
17
+ };
@@ -0,0 +1,38 @@
1
+ import { JSExpression, JSFunction } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 转换上下文:影响 ref/computed 的 .value 解包行为
5
+ * - script: 解包,输出 xxx.value
6
+ * - template: 不解包,Vue 模板自动解包
7
+ */
8
+ export type TransformContext = 'script' | 'template';
9
+ /**
10
+ * 转换 DSL 中的 this.xxx 引用为 Composition API 顶层标识符
11
+ *
12
+ * 转换规则:
13
+ * - this.$router 等 globalApi → 替换为 router 等
14
+ * - this.refsName → script: refsName.value, template: refsName
15
+ * - this.reactiveName → reactiveName(包含 state)
16
+ * - this.computedName → script: computedName.value, template: computedName
17
+ * - this.methodName → methodName
18
+ * - this.propName (props) → script: props.propName, template: propName
19
+ * - this.composableName → composableName
20
+ * - this.injectName → injectName
21
+ * - this.dataSourceName → dataSourceName
22
+ * - 未识别的 this.xxx → 保持原样(可能是动态属性 / 测试用例)
23
+ */
24
+ export declare function transformExpression(code: string, symbols: SymbolTable, context?: TransformContext): string;
25
+ /**
26
+ * 转换 JSExpression / JSFunction,返回纯字符串
27
+ */
28
+ export declare function transformCode(code: JSExpression | JSFunction | undefined, symbols: SymbolTable, context?: TransformContext): string;
29
+ /**
30
+ * 仅替换 this 前缀,不依赖符号表(兜底转换)
31
+ * 用于无法识别的场景:直接去掉 this. 前缀
32
+ */
33
+ export declare function stripThisPrefix(code: string): string;
34
+ /**
35
+ * 移除外层括号包装:( fn ) → fn
36
+ * 与 utils.ts 的 replaceFunctionTag 类似但更宽松
37
+ */
38
+ export declare function unwrapFunction(code: string): string;
@@ -0,0 +1,9 @@
1
+ import { BlockWatch } from '@vtj/core';
2
+ import { SymbolTable } from './symbolTable';
3
+ /**
4
+ * 解析 watch 为 Composition watch() 调用:
5
+ *
6
+ * { source: '() => this.count', handler: 'function(val) {...}', deep: true }
7
+ * → watch(() => count.value, function(val) {...}, { deep: true });
8
+ */
9
+ export declare function parseWatch(watches: BlockWatch[] | undefined, symbols: SymbolTable): string[];
@@ -1,2 +1,2 @@
1
- import { JSFunction } from '@vtj/core';
2
- export declare function parseFunctionMap(map?: Record<string, JSFunction>, computedKeys?: string[]): (string | null)[];
1
+ import { JSExpression, JSFunction } from '@vtj/core';
2
+ export declare function parseFunctionMap(map?: Record<string, JSFunction | JSExpression>, computedKeys?: string[]): (string | null)[];
@@ -1,5 +1,5 @@
1
1
  import { MaterialDescription, PlatformType } from '@vtj/core';
2
- export declare function parseImports(componentMap: Map<string, MaterialDescription>, components?: string[], importBlocks?: string[], collectImports?: Record<string, Set<string>>, platform?: PlatformType): {
2
+ export declare function parseImports(componentMap: Map<string, MaterialDescription>, components?: string[], importBlocks?: string[], collectImports?: Record<string, Set<string>>, platform?: PlatformType, easycomPackages?: Set<string>): {
3
3
  imports: string[];
4
4
  uniComponents: string[];
5
5
  };
@@ -1,3 +1,4 @@
1
1
  import { TemplateExecutor } from 'lodash';
2
2
  export declare const scriptCompiled: TemplateExecutor;
3
+ export declare const scriptSetupCompiled: TemplateExecutor;
3
4
  export declare const vueCompiled: TemplateExecutor;
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2026, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/coder
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.17.7
5
+ * @version 0.17.8
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.17.7";
8
+ export declare const version = "0.17.8";