diff --git a/packages/canvas/common/src/utils.js b/packages/canvas/common/src/utils.js index ae1f9d23e..16e1177b7 100644 --- a/packages/canvas/common/src/utils.js +++ b/packages/canvas/common/src/utils.js @@ -91,7 +91,8 @@ const dynamicImportComponentLib = async ({ pkg, script }) => { try { // 优先从importmap导入,兼容npm.script字段定义的cdn地址 - if (getImportMapKeys().includes(pkg)) { + const importMapKeys = getImportMapKeys() + if (importMapKeys.includes(pkg)) { modules = await import(/* @vite-ignore */ pkg) } else if (script) { modules = await import(/* @vite-ignore */ script) @@ -121,19 +122,3 @@ export const getComponents = async ({ package: pkg, script, components }) => { } }) } - -/** - * 更新区块/组件依赖 - * @param {object} param0 依赖的CDN信息 - */ -export const updateDependencies = ({ detail }) => { - const { scripts = [], styles = [] } = detail || {} - const { styles: canvasStyles } = window.componentsDepsMap - const newStyles = [...styles].filter((item) => !canvasStyles.has(item)) - - newStyles.forEach((item) => canvasStyles.add(item)) - - const promises = [...newStyles].map((src) => addStyle(src)).concat(scripts.map(getComponents)) - - Promise.allSettled(promises) -} diff --git a/packages/canvas/render/src/runner.js b/packages/canvas/render/src/runner.js index ec3c66d79..ea2084c95 100644 --- a/packages/canvas/render/src/runner.js +++ b/packages/canvas/render/src/runner.js @@ -11,7 +11,7 @@ */ import { createApp } from 'vue' -import { addScript, addStyle, getComponents, updateDependencies } from '../../common' +import { addScript, addStyle, getComponents } from '../../common' import TinyI18nHost, { I18nInjectionKey } from '@opentiny/tiny-engine-common/js/i18n' import Main, { api } from './RenderMain' import lowcode from './lowcode' @@ -27,8 +27,6 @@ const initRenderContext = () => { window.TinyLowcodeComponent = {} window.TinyComponentLibs = {} - - document.addEventListener('updateDependencies', updateDependencies) } let App = null diff --git a/packages/plugins/materials/src/composable/useMaterial.js b/packages/plugins/materials/src/composable/useMaterial.js index f85c94189..a7ec30f23 100644 --- a/packages/plugins/materials/src/composable/useMaterial.js +++ b/packages/plugins/materials/src/composable/useMaterial.js @@ -478,20 +478,6 @@ const getBlockDeps = (dependencies = {}) => { styles?.forEach((item) => materialState.componentsDepsMap.styles.add(item)) } -/** - * 获取新增区块的依赖,更新画布中的组件依赖 - * @param {array} blocks 新增的区块列表 - */ -const updateCanvasDependencies = (blocks) => { - blocks.forEach((block) => { - if (!block.content.dependencies) return - - getBlockDeps(block.content.dependencies) - }) - - useCanvas().canvasApi.value?.canvasDispatch('updateDependencies', { detail: materialState.componentsDepsMap }) -} - const initBuiltinMaterial = () => { const { Builtin } = useCanvas().canvasApi.value // 添加画布物料 @@ -535,7 +521,6 @@ export default function () { setMaterial, // 设置单个物料 (property) setMaterial: (name: string, data: Material) => void addMaterials, // 添加多个物料 registerBlock, // 注册新的区块 - updateCanvasDependencies, //传入新的区块,获取新增区块的依赖,更新画布中的组件依赖 getCanvasDeps, // 组装画布依赖,包含物料和工具类的依赖。 updateCanvasDeps, // 通知画布更新依赖 getConfigureMap, // 获取物料组件的配置信息