1
0
mirror of synced 2025-12-11 12:17:56 +08:00

Compare commits

..

9 Commits

Author SHA1 Message Date
roymondchen
38ea57c6cb chore: update lockfile v1.5.12 2025-03-27 16:32:44 +08:00
roymondchen
c8fc2f7bfb chore: release v1.5.12 2025-03-27 16:30:51 +08:00
roymondchen
b715a87f40 feat(cli): 如果识别不要组件文件,则默认从npm包的default导入 2025-03-27 16:25:58 +08:00
roymondchen
f17ef325b1 chore: update vite 2025-03-27 11:29:18 +08:00
roymondchen
4ddc55aa6d fix(design): card没有slots时隐藏对应slot 2025-03-27 11:12:27 +08:00
roymondchen
2a714ae9cc fix(vue-components): button删除调试代码,text支持富文本 2025-03-18 16:54:55 +08:00
roymondchen
d53a479b21 style(vue-runtime-help): 更新ts定义 2025-03-18 16:52:21 +08:00
roymondchen
f5742c107a fix(editor): 获取关联组件的方法默认值 2025-03-13 14:30:28 +08:00
roymondchen
9c7d711c16 fix(editor): 数据源修改后,依赖重新收集不准确 2025-03-12 14:22:33 +08:00
37 changed files with 561 additions and 400 deletions

View File

@@ -1,3 +1,20 @@
## [1.5.12](https://github.com/Tencent/tmagic-editor/compare/v1.5.11...v1.5.12) (2025-03-27)
### Bug Fixes
* **design:** card没有slots时隐藏对应slot ([4ddc55a](https://github.com/Tencent/tmagic-editor/commit/4ddc55aa6de4bafb978a621ab9b69af1e0c36d78))
* **editor:** 数据源修改后,依赖重新收集不准确 ([9c7d711](https://github.com/Tencent/tmagic-editor/commit/9c7d711c167c5e8ee1e9d8a8e89d66d245070dee))
* **editor:** 获取关联组件的方法默认值 ([f5742c1](https://github.com/Tencent/tmagic-editor/commit/f5742c107a68389c0828de991e7f5e9745e20d67))
* **vue-components:** button删除调试代码text支持富文本 ([2a714ae](https://github.com/Tencent/tmagic-editor/commit/2a714ae9cc89b7c88528c8afe9270ad774d7755d))
### Features
* **cli:** 如果识别不要组件文件则默认从npm包的default导入 ([b715a87](https://github.com/Tencent/tmagic-editor/commit/b715a87f409856ed396b3e35eb4102776329531e))
## [1.5.11](https://github.com/Tencent/tmagic-editor/compare/v1.5.10...v1.5.11) (2025-03-11)

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "tmagic",
"private": true,
"type": "module",
@@ -81,7 +81,7 @@
"serialize-javascript": "^6.0.2",
"shx": "^0.3.4",
"typescript": "^5.7.3",
"vite": "^6.0.10",
"vite": "^6.2.3",
"vitepress": "^1.6.1",
"vitest": "^3.0.2",
"vue": "^3.5.13",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/cli",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@@ -11,11 +11,14 @@ export default class Core {
public options: UserConfig;
public moduleMainFilePath: ModuleMainFilePath = {
componentPackage: {},
componentMap: {},
pluginPakcage: {},
pluginMap: {},
configMap: {},
valueMap: {},
eventMap: {},
datasourcePackage: {},
datasourceMap: {},
dsConfigMap: {},
dsValueMap: {},

View File

@@ -54,11 +54,14 @@ export interface NpmConfig {
}
export interface ModuleMainFilePath {
componentPackage: Record<string, string>;
componentMap: Record<string, string>;
pluginPakcage: Record<string, string>;
pluginMap: Record<string, string>;
configMap: Record<string, string>;
valueMap: Record<string, string>;
eventMap: Record<string, string>;
datasourcePackage: Record<string, string>;
datasourceMap: Record<string, string>;
dsConfigMap: Record<string, string>;
dsValueMap: Record<string, string>;

View File

@@ -5,33 +5,84 @@ import { EntryType } from '../types';
export const prepareEntryFile = async (app: App) => {
const { moduleMainFilePath, options } = app;
const { componentFileAffix, dynamicImport, hooks, useTs = true } = options;
const { dynamicImport, hooks, useTs = true } = options;
let contentMap: Record<string, string> = {
'comp-entry': generateContent(useTs, EntryType.COMPONENT, moduleMainFilePath.componentMap, componentFileAffix),
'comp-entry': generateContent(
useTs,
EntryType.COMPONENT,
moduleMainFilePath.componentPackage,
moduleMainFilePath.componentMap,
),
'async-comp-entry': generateContent(
useTs,
EntryType.COMPONENT,
moduleMainFilePath.componentPackage,
moduleMainFilePath.componentMap,
componentFileAffix,
dynamicImport,
),
'plugin-entry': generateContent(useTs, EntryType.PLUGIN, moduleMainFilePath.pluginMap),
'async-plugin-entry': generateContent(useTs, EntryType.PLUGIN, moduleMainFilePath.pluginMap, '', dynamicImport),
'config-entry': generateContent(useTs, EntryType.CONFIG, moduleMainFilePath.configMap),
'value-entry': generateContent(useTs, EntryType.VALUE, moduleMainFilePath.valueMap),
'event-entry': generateContent(useTs, EntryType.EVENT, moduleMainFilePath.eventMap),
'datasource-entry': generateContent(useTs, EntryType.DATASOURCE, moduleMainFilePath.datasourceMap),
'plugin-entry': generateContent(
useTs,
EntryType.PLUGIN,
moduleMainFilePath.pluginPakcage,
moduleMainFilePath.pluginMap,
),
'async-plugin-entry': generateContent(
useTs,
EntryType.PLUGIN,
moduleMainFilePath.pluginPakcage,
moduleMainFilePath.pluginMap,
dynamicImport,
),
'config-entry': generateContent(
useTs,
EntryType.CONFIG,
moduleMainFilePath.componentPackage,
moduleMainFilePath.configMap,
),
'value-entry': generateContent(
useTs,
EntryType.VALUE,
moduleMainFilePath.componentPackage,
moduleMainFilePath.valueMap,
),
'event-entry': generateContent(
useTs,
EntryType.EVENT,
moduleMainFilePath.componentPackage,
moduleMainFilePath.eventMap,
),
'datasource-entry': generateContent(
useTs,
EntryType.DATASOURCE,
moduleMainFilePath.datasourcePackage,
moduleMainFilePath.datasourceMap,
),
'async-datasource-entry': generateContent(
useTs,
EntryType.DATASOURCE,
moduleMainFilePath.datasourcePackage,
moduleMainFilePath.datasourceMap,
'',
dynamicImport,
),
'ds-config-entry': generateContent(useTs, EntryType.DS_CONFIG, moduleMainFilePath.dsConfigMap),
'ds-value-entry': generateContent(useTs, EntryType.DS_VALUE, moduleMainFilePath.dsValueMap),
'ds-event-entry': generateContent(useTs, EntryType.DS_EVENT, moduleMainFilePath.dsEventMap),
'ds-config-entry': generateContent(
useTs,
EntryType.DS_CONFIG,
moduleMainFilePath.datasourcePackage,
moduleMainFilePath.dsConfigMap,
),
'ds-value-entry': generateContent(
useTs,
EntryType.DS_VALUE,
moduleMainFilePath.datasourcePackage,
moduleMainFilePath.dsValueMap,
),
'ds-event-entry': generateContent(
useTs,
EntryType.DS_EVENT,
moduleMainFilePath.datasourcePackage,
moduleMainFilePath.dsEventMap,
),
};
if (typeof hooks?.beforeWriteEntry === 'function') {
@@ -53,8 +104,8 @@ export const prepareEntryFile = async (app: App) => {
export const generateContent = (
useTs: boolean,
type: EntryType,
packageMap: Record<string, string> = {},
map: Record<string, string> = {},
componentFileAffix = '',
dynamicImport = false,
) => {
const list: string[] = [];
@@ -62,14 +113,14 @@ export const generateContent = (
Object.entries(map).forEach(([key, packagePath]) => {
const name = makeCamelCase(key);
if (dynamicImport) {
list.push(
`'${key}': () => import('${packagePath}${packagePath.endsWith(componentFileAffix) ? '' : componentFileAffix}')`,
);
if ([EntryType.CONFIG, EntryType.EVENT, EntryType.VALUE].includes(type) && packagePath === packageMap[key]) {
importDeclarations.push(`import { ${type} as ${name} } from '${packageMap[key]}'`);
list.push(`'${key}': ${name}`);
} else if (dynamicImport) {
list.push(`'${key}': () => import('${packagePath}')`);
} else {
importDeclarations.push(
`import ${name} from '${packagePath}${packagePath.endsWith(componentFileAffix) ? '' : componentFileAffix}'`,
);
importDeclarations.push(`import ${name} from '${packagePath}'`);
list.push(`'${key}': ${name}`);
}
});

View File

@@ -38,20 +38,37 @@ const getRelativePath = (str: string, base: string) => (path.isAbsolute(str) ? p
const npmInstall = function (dependencies: Record<string, string>, cwd: string, npmConfig: NpmConfig = {}) {
try {
const { client = 'npm', registry, installArgs = '' } = npmConfig;
const { client = 'npm', registry, installArgs = '', keepPackageJsonClean } = npmConfig;
const install = {
npm: 'install',
yarn: 'add',
pnpm: 'add',
}[client];
const packages = Object.entries(dependencies)
.map(([name, version]) => (version ? `${name}@${version}` : name))
.join(' ');
let packages = Object.entries(dependencies);
const newPackages = Object.entries(dependencies).filter(([name]) => {
if (fs.existsSync(path.resolve(cwd, 'node_modules', name))) {
return false;
}
return true;
});
// keepPackageJsonClean会保留原始的package.json这样配置的packages就不会被写入dependencies中
// install 时会删除不在dependencies中的依赖所以需要install packages中配置的所有包
if (!keepPackageJsonClean || !newPackages.length) {
packages = newPackages;
}
if (!packages.length) {
return;
}
const packageNames = packages.map(([name, version]) => (version ? `${name}@${version}` : name)).join(' ');
const installArgsString = `${installArgs ? ` ${installArgs}` : ''}`;
const registryString = `${registry ? ` --registry ${registry}` : ''}`;
const command = `${client} ${install}${installArgsString} ${packages}${registryString}`;
const command = `${client} ${install}${installArgsString} ${packageNames}${registryString}`;
execInfo(cwd);
execInfo(command);
@@ -318,25 +335,30 @@ const parseEntry = function ({ ast, package: module, indexPath }: ParseEntryOpti
const tokens = getASTTokenByTraverse({ ast, indexPath });
let { config, value, event, component } = tokens;
if (!config) {
if (typeof config === 'undefined') {
info(`${module} 表单配置文件声明缺失`);
}
if (!value) {
if (typeof value === 'undefined') {
info(`${module} 初始化数据文件声明缺失`);
}
if (!event) {
if (typeof event === 'undefined') {
info(`${module} 事件声明文件声明缺失`);
}
if (!component) {
info(`${module} 组件或数据源文件声明不合法`);
exit(1);
}
const reg = /^.*[/\\]node_modules[/\\](.*)/;
[, config] = config.match(reg) || [, config];
[, value] = value.match(reg) || [, value];
[, component] = component.match(reg) || [, component];
[, event] = event.match(reg) || [, event];
if (config) {
[, config] = config.match(reg) || [, config];
}
if (value) {
[, value] = value.match(reg) || [, value];
}
if (component) {
[, component] = component.match(reg) || [, component];
}
if (event) {
[, event] = event.match(reg) || [, event];
}
return {
config,
@@ -347,10 +369,10 @@ const parseEntry = function ({ ast, package: module, indexPath }: ParseEntryOpti
};
const getASTTokenByTraverse = ({ ast, indexPath }: { ast: any; indexPath: string }) => {
let config = '';
let value = '';
let event = '';
let component = '';
let config: string | undefined;
let value: string | undefined;
let event: string | undefined;
let component: string | undefined;
const importSpecifiersMap: { [key: string]: string } = {};
const exportSpecifiersMap: { [key: string]: string | undefined } = {};
@@ -396,7 +418,11 @@ const getASTTokenByTraverse = ({ ast, indexPath }: { ast: any; indexPath: string
visitExportDefaultDeclaration(p) {
const { node } = p;
const { declaration } = node as any;
component = path.resolve(path.dirname(indexPath), importSpecifiersMap[declaration.name]);
if (importSpecifiersMap[declaration.name]) {
component = path.resolve(path.dirname(indexPath), importSpecifiersMap[declaration.name]);
}
this.traverse(p);
},
});
@@ -405,7 +431,10 @@ const getASTTokenByTraverse = ({ ast, indexPath }: { ast: any; indexPath: string
const exportValue = exportSpecifiersMap[exportName];
const importValue = importSpecifiersMap[exportName];
const connectValue = exportValue ? importSpecifiersMap[exportValue] : '';
const filePath = path.resolve(path.dirname(indexPath), connectValue || importValue || exportValue || '');
const fileName = connectValue || importValue || exportValue || '';
const filePath = fileName ? path.resolve(path.dirname(indexPath), fileName) : '';
if (exportName === EntryType.VALUE) {
value = filePath;
@@ -463,7 +492,7 @@ const getDependencies = (dependencies: Record<string, string>, packagePath: stri
const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string, cwd: string, key?: string) => {
const { options } = app;
const { temp, componentFileAffix, datasoucreSuperClass } = options;
const { temp, componentFileAffix = '', datasoucreSuperClass } = options;
let { name: moduleName } = splitNameVersion(packagePath);
@@ -513,15 +542,45 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string
if (!key) return;
if (result.type === PackageType.COMPONENT) {
if (result.type === PackageType.COMPONENT || !result.type) {
packages.componentPackage[key] = moduleName;
// 组件
const entry = parseEntry({ ast, package: moduleName, indexPath });
if (entry.component) packages.componentMap[key] = getRelativePath(entry.component, temp);
if (entry.config) packages.configMap[key] = getRelativePath(entry.config, temp);
if (entry.event) packages.eventMap[key] = getRelativePath(entry.event, temp);
if (entry.value) packages.valueMap[key] = getRelativePath(entry.value, temp);
if (entry.component) {
const packagePath = getRelativePath(entry.component, temp);
packages.componentMap[key] = `${packagePath}${
packagePath.endsWith(componentFileAffix) ? '' : componentFileAffix
}`;
} else {
packages.componentMap[key] = moduleName;
}
if (typeof entry.config === 'string') {
if (entry.config) {
packages.configMap[key] = getRelativePath(entry.config, temp);
} else {
packages.configMap[key] = moduleName;
}
}
if (typeof entry.event === 'string') {
if (entry.event) {
packages.eventMap[key] = getRelativePath(entry.event, temp);
} else {
packages.eventMap[key] = moduleName;
}
}
if (typeof entry.value === 'string') {
if (entry.value) {
packages.valueMap[key] = getRelativePath(entry.value, temp);
} else {
packages.valueMap[key] = moduleName;
}
}
} else if (result.type === PackageType.DATASOURCE) {
packages.datasourcePackage[key] = moduleName;
// 数据源
const entry = parseEntry({ ast, package: moduleName, indexPath });
@@ -530,6 +589,7 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string
if (entry.event) packages.dsEventMap[key] = getRelativePath(entry.event, temp);
if (entry.value) packages.dsValueMap[key] = getRelativePath(entry.value, temp);
} else if (result.type === PackageType.PLUGIN) {
packages.pluginPakcage[key] = moduleName;
// 插件
packages.pluginMap[key] = getRelativePath(moduleName, temp);
}
@@ -573,11 +633,14 @@ export const resolveAppPackages = (app: App): ModuleMainFilePath => {
}
const packagesMap: ModuleMainFilePath = {
componentPackage: {},
componentMap: {},
configMap: {},
eventMap: {},
valueMap: {},
pluginPakcage: {},
pluginMap: {},
datasourcePackage: {},
datasourceMap: {},
dsConfigMap: {},
dsEventMap: {},

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/core",
"type": "module",
"main": "dist/tmagic-core.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/data-source",
"type": "module",
"main": "dist/tmagic-data-source.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/dep",
"type": "module",
"main": "dist/tmagic-dep.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/design",
"type": "module",
"sideEffects": [

View File

@@ -1,10 +1,10 @@
<template>
<component class="tmagic-design-card" :is="uiComponent" v-bind="uiProps">
<template #header>
<template #header v-if="$slots.header">
<slot name="header" class="header"></slot>
</template>
<template #default>
<template #default v-if="$slots.default">
<slot name="default"></slot>
</template>
</component>

View File

@@ -6,7 +6,7 @@
@update:modelValue="updateModelValue"
@change="changeHandler"
>
<template #default>
<template #default v-if="$slots.default">
<slot></slot>
</template>
</component>

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/editor",
"type": "module",
"sideEffects": [

View File

@@ -502,6 +502,7 @@ export const initServiceEvents = (
isModifyField =
changeRecord.propPath === 'fields' ||
/fields.(\d)+.name/.test(changeRecord.propPath) ||
/fields.(\d)+.defaultValue/.test(changeRecord.propPath) ||
/fields.(\d)+$/.test(changeRecord.propPath);
isModifyMock = changeRecord.propPath === 'mocks';
@@ -523,25 +524,35 @@ export const initServiceEvents = (
if (Array.isArray(root?.items)) {
depService.clearIdleTasks();
removeDataSourceTarget(config.id);
initDataSourceDepTarget(config);
let collectIdlePromises: Promise<void[]>[] = [];
if (isModifyField) {
depService.removeTarget(config.id, DepTargetType.DATA_SOURCE);
depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_COND);
depService.addTarget(createDataSourceTarget(config, reactive({})));
depService.addTarget(createDataSourceCondTarget(config, reactive({})));
collectIdlePromises = [
collectIdle(root.items, true, DepTargetType.DATA_SOURCE),
collectIdle(root.items, true, DepTargetType.DATA_SOURCE_COND),
];
} else if (isModifyMock) {
depService.removeTarget(config.id, DepTargetType.DATA_SOURCE);
depService.addTarget(createDataSourceTarget(config, reactive({})));
collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE)];
} else if (isModifyMethod) {
depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_METHOD);
depService.addTarget(createDataSourceMethodTarget(config, reactive({})));
collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE_METHOD)];
}
Promise.all(collectIdlePromises).then(() => {
updateDataSourceSchema();
updateDsData();
updateStageNodes(root.items);
});
Promise.all(collectIdlePromises)
.then(() => updateDataSourceSchema())
.then(() => updateDsData())
.then(() => updateStageNodes(root.items));
}
} else if (root?.dataSources) {
updateDsData();
@@ -616,20 +627,31 @@ export const initServiceEvents = (
}
root.dataSourceCondDeps[target.id] = target.deps;
}
if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
if (!root.dataSourceMethodDeps) {
root.dataSourceMethodDeps = {};
}
root.dataSourceMethodDeps[target.id] = target.deps;
}
};
const targetRemoveHandler = (id: string | number) => {
const targetRemoveHandler = (id: string | number, type: DepTargetType) => {
const root = editorService.get('root');
if (!root) return;
if (root.dataSourceDeps) {
if (root.dataSourceDeps && type === DepTargetType.DATA_SOURCE) {
delete root.dataSourceDeps[id];
}
if (root.dataSourceCondDeps) {
if (root.dataSourceCondDeps && type === DepTargetType.DATA_SOURCE_COND) {
delete root.dataSourceCondDeps[id];
}
if (root.dataSourceMethodDeps && type === DepTargetType.DATA_SOURCE_METHOD) {
delete root.dataSourceMethodDeps[id];
}
};
depService.on('add-target', targetAddHandler);

View File

@@ -28,7 +28,7 @@ import BaseService from './BaseService';
export interface DepEvents {
'add-target': [target: Target];
'remove-target': [id: string | number];
'remove-target': [id: string | number, type: string | DepTargetType];
collected: [nodes: MNode[], deep: boolean];
'ds-collected': [nodes: MNode[], deep: boolean];
}
@@ -77,7 +77,7 @@ class Dep extends BaseService {
if (!targets) return;
for (const target of Object.values(targets)) {
this.emit('remove-target', target.id);
this.emit('remove-target', target.id, type);
}
}
@@ -96,7 +96,7 @@ class Dep extends BaseService {
public removeTarget(id: Id, type: string = DepTargetType.DEFAULT) {
this.watcher.removeTarget(id, type);
this.emit('remove-target', id);
this.emit('remove-target', id, type);
}
public clearTargets() {

View File

@@ -57,7 +57,7 @@ class Events extends BaseService {
}
public getMethod(type: string) {
return cloneDeep(methodMap[toLine(type)]);
return cloneDeep(methodMap[toLine(type)]) || [];
}
public resetState() {

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/element-plus-adapter",
"type": "module",
"main": "dist/tmagic-element-plus-adapter.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/form",
"type": "module",
"sideEffects": [

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/schema",
"type": "module",
"main": "dist/tmagic-schema.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/stage",
"type": "module",
"main": "dist/tmagic-stage.umd.cjs",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/table",
"type": "module",
"sideEffects": [

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/tdesign-vue-next-adapter",
"type": "module",
"main": "dist/tmagic-tdesign-vue-next-adapter.umd.cjs",

View File

@@ -1,6 +1,6 @@
{
"name": "@tmagic/ui-react",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"main": "dist/tmagic-ui-react.js",
"types": "types/index.d.ts",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/ui",
"type": "module",
"main": "dist/tmagic-ui.js",

View File

@@ -1,5 +1,5 @@
{
"version": "1.5.11",
"version": "1.5.12",
"name": "@tmagic/utils",
"type": "module",
"main": "dist/tmagic-utils.umd.cjs",

View File

@@ -1,6 +1,6 @@
{
"name": "tmagic-playground",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"private": true,
"scripts": {
@@ -13,9 +13,9 @@
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@tmagic/core": "1.5.11",
"@tmagic/editor": "1.5.11",
"@tmagic/element-plus-adapter": "1.5.11",
"@tmagic/core": "1.5.12",
"@tmagic/editor": "1.5.12",
"@tmagic/element-plus-adapter": "1.5.12",
"@tmagic/tmagic-form-runtime": "1.1.3",
"element-plus": "^2.9.3",
"lodash-es": "^4.17.21",
@@ -37,6 +37,6 @@
"typescript": "^5.7.3",
"unplugin-auto-import": "^0.12.0",
"unplugin-vue-components": "^0.22.11",
"vite": "^6.0.10"
"vite": "^6.2.3"
}
}

554
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "runtime-react",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"private": true,
"scripts": {
@@ -19,21 +19,21 @@
"build:ds:event": "vite build --config build.vite.config.ts --mode ds:event"
},
"dependencies": {
"@tmagic/core": "1.5.11",
"@tmagic/core": "1.5.12",
"@tmagic/react-runtime-help": "0.1.0",
"@tmagic/stage": "1.5.11",
"@tmagic/stage": "1.5.12",
"axios": "^0.25.0",
"terser": "^5.31.6",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@tmagic/cli": "1.5.11",
"@tmagic/cli": "1.5.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-legacy": "^6.0.0",
"@vitejs/plugin-react-refresh": "^1.3.1",
"typescript": "^5.7.3",
"vite": "^6.0.10"
"vite": "^6.2.3"
}
}

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) => {

View File

@@ -1,6 +1,6 @@
{
"name": "runtime-vue2",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"private": true,
"scripts": {
@@ -19,21 +19,21 @@
"build:ds:event": "vite build --config build.vite.config.ts --mode ds:event"
},
"dependencies": {
"@tmagic/core": "1.5.11",
"@tmagic/stage": "1.5.11",
"@tmagic/core": "1.5.12",
"@tmagic/stage": "1.5.12",
"@tmagic/vue-runtime-help": "^1.1.0",
"axios": "^0.25.0",
"terser": "^5.31.6",
"vue": "^2.7.16"
},
"devDependencies": {
"@tmagic/cli": "1.5.11",
"@tmagic/cli": "1.5.12",
"@types/events": "^3.0.0",
"axios": "^0.27.2",
"rollup": "^4.31.0",
"rollup-plugin-external-globals": "^0.10.0",
"sass": "^1.83.0",
"vite": "^6.0.10",
"vite": "^6.2.3",
"@vitejs/plugin-legacy": "^6.0.0",
"@vitejs/plugin-vue2": "^2.3.1",
"vue-template-compiler": "^2.7.4"

View File

@@ -1,6 +1,6 @@
{
"name": "runtime-vue3",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"private": true,
"scripts": {
@@ -19,14 +19,14 @@
"build:ds:event": "vite build --config build.vite.config.ts --mode ds:event"
},
"dependencies": {
"@tmagic/core": "1.5.11",
"@tmagic/stage": "1.5.11",
"@tmagic/core": "1.5.12",
"@tmagic/stage": "1.5.12",
"@tmagic/vue-runtime-help": "^1.1.0",
"axios": "^0.25.0",
"vue": "^3.5.0"
},
"devDependencies": {
"@tmagic/cli": "1.5.11",
"@tmagic/cli": "1.5.12",
"@types/node": "^18.19.0",
"@vitejs/plugin-legacy": "^6.0.0",
"@vitejs/plugin-vue": "5.2.1",
@@ -37,6 +37,6 @@
"sass": "^1.83.0",
"terser": "^5.31.6",
"typescript": "^5.7.3",
"vite": "^6.0.10"
"vite": "^6.2.3"
}
}

View File

@@ -1,5 +1,5 @@
{
"version": "0.1.1",
"version": "0.1.2",
"name": "@tmagic/vue-button",
"type": "module",
"main": "src/index.ts",

View File

@@ -7,10 +7,10 @@
</template>
<script lang="ts">
import { defineComponent, inject, type PropType } from 'vue-demi';
import { defineComponent, type PropType } from 'vue-demi';
import { COMMON_EVENT_PREFIX, type Id, type MComponent } from '@tmagic/core';
import { useApp, useComponentStatus } from '@tmagic/vue-runtime-help';
import { useApp } from '@tmagic/vue-runtime-help';
interface ButtonSchema extends Omit<MComponent, 'id'> {
id?: Id;
@@ -36,10 +36,6 @@ export default defineComponent({
},
setup(props) {
const { setStatus } = inject<ReturnType<typeof useComponentStatus>>('componentStatusStore')!;
setStatus('disabled');
const { app, node } = useApp(props);
const clickHandler = () => {

View File

@@ -1,5 +1,5 @@
{
"version": "0.1.0",
"version": "0.1.1",
"name": "@tmagic/vue-text",
"type": "module",
"main": "src/index.ts",

View File

@@ -1,7 +1,5 @@
<template>
<p @click="clickHandler">
<slot>{{ config.text }}</slot>
</p>
<p @click="clickHandler" v-html="config.text"></p>
</template>
<script lang="ts">