chore: clear old block compile code (#1450)

This commit is contained in:
chilingling 2025-06-23 22:43:22 +08:00 committed by GitHub
parent 9e26abb971
commit cb5856e75b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 1 additions and 95 deletions

View File

@ -129,9 +129,6 @@ const material = useMaterial().getMaterial('ComponentName')
// 生成组件节点
const node = useMaterial().generateNode({ type: 'component', component: 'Button' })
// 注册新区块
await useMaterial().registerBlock('blockName')
// 刷新物料
await useMaterial().refreshMaterial()
```

View File

@ -764,22 +764,6 @@ const cancelCheckAll = () => {
selectedBlockArray.value = []
}
const getBlockAssetsByVersion = (block: Block, version?: string) => {
let assets = block.assets
if (version) {
const replaceUri = (uri: string) => uri.replace(/@\d{1,3}(\.\d{1,3}){0,2}\//, `@${version}/`)
assets = {
...block.assets,
scripts: (block.assets?.scripts || []).map(replaceUri),
styles: (block.assets?.styles || []).map(replaceUri)
}
}
return assets
}
const shouldReplaceCategoryWithGroup = () => {
const { mergeCategoriesAndGroups } = getOptions(meta.id)
return mergeCategoriesAndGroups
@ -797,7 +781,6 @@ export default function () {
addBlock,
delBlock,
createBlock,
getBlockAssetsByVersion,
createEmptyBlock,
groupChange,
addDefaultGroup,

View File

@ -17,7 +17,6 @@ import { meta as BuiltinComponentMaterials } from '@opentiny/tiny-engine-builtin
import {
getMergeMeta,
getOptions,
useNotify,
useCanvas,
useBlock,
useMessage,
@ -31,7 +30,6 @@ import type {
Block,
BlockResource,
Component,
ComponentMap,
Dependency,
InitMaterialOptions,
Material,
@ -58,9 +56,6 @@ const materialState = reactive<MaterialState>({
packages: [] // 物料依赖的包
})
const componentState = reactive<{ componentsMap: Record<string, ComponentMap> }>({
componentsMap: {}
})
const getSnippet = (component: string) => {
let schema: Schema = {}
materialState.components.some(({ children }) => {
@ -143,69 +138,6 @@ const registerComponentToResource = (data: Component) => {
}
}
export const fetchBlockDetail = async (blockName: string) => {
const { getBlockAssetsByVersion } = useBlock()
const currentVersion = componentState.componentsMap?.[blockName]?.version
const block: Block = (await getMetaApi(META_SERVICE.Http).get(`/material-center/api/block?label=${blockName}`))?.[0]
if (!block) {
throw new Error(`区块${blockName}不存在!`)
}
block.assets = getBlockAssetsByVersion(block, currentVersion)
block.assets = history?.assets || block.assets
return block
}
/**
* registerBlock
* @deprecated
* @param data
* @param notFetchResouce js css资源到页面
* @returns
*/
const registerBlock = async (data: string | any, notFetchResouce?: boolean) => {
let block = data
if (typeof block === 'string') {
try {
block = await fetchBlockDetail(block)
} catch (error: any) {
useNotify({
type: 'warning',
title: '区块读取错误',
message: error?.message || error
})
return false
}
}
if (!block) {
return false
}
block.type = MATERIAL_TYPE.Block
block.component = block.component || block.blockName || block.label || block.fileName
// 区块还原备份时, 后台改变current_history, 所以assets优先从current_history里取
const assets = block.assets
const label = block.component
const { scripts = [], styles = [] } = assets || {}
if (!notFetchResouce && !blockResource.get(label)) {
const { addScript, addStyle } = useCanvas().canvasApi.value
const promises = scripts
.filter((item: string) => item.includes('umd.js'))
.map(addScript)
.concat(styles.map(addStyle))
// 此处删除await提前放行区块数据在区块渲染前找到区块数据源映射关系
Promise.allSettled(promises)
blockResource.set(label, block.content)
}
return block
}
const clearMaterials = () => {
materialState.components = []
materialState.blocks = []
@ -483,12 +415,10 @@ const initBuiltinMaterial = () => {
const initMaterial = ({ isInit = true, appData = {} }: InitMaterialOptions = {}) => {
initBuiltinMaterial()
if (isInit) {
componentState.componentsMap = {}
appData.componentsMap?.forEach((component) => {
if (component.dependencies) {
getBlockDeps(component.dependencies)
}
componentState.componentsMap[component.componentName] = component
})
}
}
@ -553,7 +483,6 @@ export default function () {
getMaterial, // 获取单个物料,(property) getMaterial: (name: string) => Material
setMaterial, // 设置单个物料 (property) setMaterial: (name: string, data: Material) => void
addMaterials, // 添加多个物料
registerBlock, // 注册新的区块
getCanvasDeps, // 组装画布依赖,包含物料和工具类的依赖。
updateCanvasDeps, // 通知画布更新依赖
getConfigureMap, // 获取物料组件的配置信息

View File

@ -77,8 +77,7 @@ export default {
emits: ['check', 'close', 'checkAll', 'cancelCheckAll'],
setup(props, { emit }) {
const { generateNode, getBlockByName } = useMaterial()
const { isDefaultGroupId, isAllGroupId, selectedBlock, selectedGroup, isRefresh, getBlockAssetsByVersion } =
useBlock()
const { isDefaultGroupId, isAllGroupId, selectedBlock, selectedGroup, isRefresh } = useBlock()
const blockRef = ref(null)
const panelState = inject('panelState', {})
const displayType = inject('displayType')
@ -114,8 +113,6 @@ export default {
}
const { isShortcutPanel, emitEvent } = panelState
block.assets = getBlockAssetsByVersion(block, block.current_version)
//
getBlockByName(block.label)