workflow底层UI库整合至项目,优化构建逻辑

This commit is contained in:
2026-02-24 11:20:18 +08:00
parent 094b185c49
commit 12accb2575
91 changed files with 6820 additions and 115 deletions

View File

@@ -0,0 +1,78 @@
<template>
<div ref="divRef" :class="['tinyflow', className]" :style="style" />
</template>
<script setup lang="ts">
import {Tinyflow as TinyflowNative, TinyflowOptions} from '@tinyflow-ai/ui';
import '@tinyflow-ai/ui/dist/index.css';
import {onMounted, onUnmounted, ref} from 'vue';
const props = defineProps<
{
className?: string;
style?: Record<string, string>;
} & Omit<TinyflowOptions, 'element'>
>();
const divRef = ref<HTMLDivElement | null>(null);
let tinyflow: TinyflowNative | null = null;
// 安全深拷贝工具函数
function safeDeepClone<T>(obj: T): T {
if (obj === null || typeof obj !== 'object') return obj;
try {
return structuredClone(obj);
} catch {
try {
return JSON.parse(JSON.stringify(obj));
} catch {
console.warn('Failed to clone object, returning original (may cause issues)', obj);
return obj;
}
}
}
onMounted(() => {
if (divRef.value) {
// 净化 props.data避免响应式对象或函数污染
const cleanedProps = { ...props } as any;
if ('data' in cleanedProps && cleanedProps.data != null) {
cleanedProps.data = safeDeepClone(cleanedProps.data);
}
tinyflow = new TinyflowNative({
...cleanedProps,
element: divRef.value
});
}
});
onUnmounted(() => {
if (tinyflow) {
tinyflow.destroy();
tinyflow = null;
}
});
const getData = () => {
if (tinyflow) {
return tinyflow.getData();
}
console.warn('Tinyflow instance is not initialized');
return null;
};
const getInstance = () => {
if (tinyflow) {
return tinyflow;
}
console.warn('Tinyflow instance is not initialized');
return null;
};
defineExpose({
getData,
getInstance
});
</script>