Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize block code saving and publishing logic #996

Open
wants to merge 5 commits into
base: refactor/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/common/component/BlockDeployDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
Popover as TinyPopover,
FormItem as TinyFormItem
} from '@opentiny/vue'
import { useNotify, getMetaApi, META_APP } from '@opentiny/tiny-engine-meta-register'
import { useCanvas, useNotify, getMetaApi, META_APP } from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import VueMonaco from './VueMonaco.vue'

Expand Down Expand Up @@ -172,6 +172,8 @@ export default {

const setVisible = (visible) => emit('update:visible', visible)

const { setSaved } = useCanvas()

const deployBlock = async () => {
deployBlockRef.value.validate((valid) => {
const { publishBlock } = getMetaApi(META_APP.BlockManage)
Expand All @@ -186,6 +188,9 @@ export default {
}
publishBlock(params)
setVisible(false)
if (formState.needToSave) {
SonyLeo marked this conversation as resolved.
Show resolved Hide resolved
setSaved(true)
}
formState.deployInfo = ''
formState.version = ''
formState.needToSave = true
Expand Down
65 changes: 33 additions & 32 deletions packages/plugins/block/src/js/blockSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -646,42 +646,43 @@ const updateBlock = (block = {}) => {
* @returns
*/
const generateBlockDeps = (children, deps = { scripts: [], styles: new Set() }) => {
children.forEach((child) => {
const component = useMaterial().getMaterial(child.componentName)

if (!component) return

const { npm, component: componentName } = component

if (npm) {
const { package: pkg, exportName, css, version, script } = npm
const currentPkg = deps.scripts.find((item) => item.package === pkg)
if (Array.isArray(children)) {
SonyLeo marked this conversation as resolved.
Show resolved Hide resolved
children.forEach((child) => {
const component = useMaterial().getMaterial(child.componentName)

if (!component) return

const { npm, component: componentName } = component

if (npm) {
const { package: pkg, exportName, css, version, script } = npm
const currentPkg = deps.scripts.find((item) => item.package === pkg)

if (currentPkg) {
currentPkg.components[componentName] = exportName
} else {
deps.scripts.push({
package: pkg,
version,
script,
css,
components: {
[componentName]: exportName
}
})
}

if (currentPkg) {
currentPkg.components[componentName] = exportName
} else {
deps.scripts.push({
package: pkg,
version,
script,
css,
components: {
[componentName]: exportName
}
})
if (css) {
deps.styles.add(css)
}
}

if (css) {
deps.styles.add(css)
// 递归查找子区块或子组件
if (child.children) {
generateBlockDeps(child.children, deps)
}
}

// 递归查找子区块或子组件
if (child.children) {
generateBlockDeps(child.children, deps)
}
})

})
}
return deps
}

Expand Down
Loading