Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions 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 { useLayout, useNotify, useCanvas } from '@opentiny/tiny-engine-meta-register'
import { useNotify, useCanvas, 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 @@ -152,8 +152,7 @@ export default {

const deployBlock = async () => {
deployBlockRef.value.validate((valid) => {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getEditBlock, publishBlock } = getPluginApi(PLUGIN_NAME.BlockManage)
const { getEditBlock, publishBlock } = getMetaApi(META_APP.BlockManage)
if (valid) {
const params = {
block: getEditBlock(),
Expand All @@ -172,11 +171,9 @@ export default {
}

const changeCompare = async (value) => {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getEditBlock } = getPluginApi(PLUGIN_NAME.BlockManage)
const api = getMetaApi(META_APP.BlockManage)
if (value) {
const api = getPluginApi(PLUGIN_NAME.BlockManage)
const block = getEditBlock()
const block = api.getEditBlock()
const remote = await api.getBlockById(block?.id)
const originalObj = remote?.content || {}
state.originalCode = JSON.stringify(originalObj, null, 2)
Expand Down
5 changes: 2 additions & 3 deletions packages/common/component/ProgressBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
<script>
import { computed } from 'vue'
import { Progress as TinyProgress } from '@opentiny/vue'
import { useLayout } from '@opentiny/tiny-engine-meta-register'
import { getMetaApi, META_APP } from '@opentiny/tiny-engine-meta-register'

export default {
components: {
TinyProgress
},
setup() {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getEditBlock } = getPluginApi(PLUGIN_NAME.BlockManage)
const { getEditBlock } = getMetaApi(META_APP.BlockManage)
const editBlock = computed(getEditBlock)

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@

<script>
import { VueMonaco as MonacoEditor, SvgButton } from '@opentiny/tiny-engine-common'
import { useApp, useCanvas, useLayout, useProperties, useResource } from '@opentiny/tiny-engine-meta-register'
import {
useApp,
useCanvas,
useProperties,
useResource,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'
import { getCommentByKey } from '@opentiny/tiny-engine-common/js/comment'
import { formatString, generate, parse, traverse } from '@opentiny/tiny-engine-common/js/ast'
import { DEFAULT_LOOP_NAME } from '@opentiny/tiny-engine-common/js/constants'
Expand Down Expand Up @@ -460,8 +467,7 @@ export default {

if (item.id === 'function') {
state.bindPrefix = CONSTANTS.THIS
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getMethods } = getPluginApi(PLUGIN_NAME.PageController)
const { getMethods } = getMetaApi(META_APP.Page)
state.variables = { ...getMethods?.() }
} else if (item.id === 'bridge' || item.id === 'utils') {
state.bindPrefix = `${CONSTANTS.THIS}${item.id}.`
Expand Down
8 changes: 1 addition & 7 deletions packages/layout/src/DesignPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,12 @@ export default {
const {
PLUGIN_NAME,
pluginState,
registerPluginApi,
layoutState: { plugins: pluginsState }
} = useLayout()

props.plugins.forEach(({ id, entry, api, icon }) => {
props.plugins.forEach(({ id, entry, icon }) => {
components[id] = entry
iconComponents[id] = icon
if (api) {
registerPluginApi({
[id]: api
})
}
})

const state = reactive({
Expand Down
7 changes: 0 additions & 7 deletions packages/layout/src/DesignToolbars.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<script>
import { reactive, nextTick } from 'vue'
import { useLayout } from '@opentiny/tiny-engine-meta-register'
import { ProgressBar } from '@opentiny/tiny-engine-common'
import ToolbarCollapse from './ToolbarCollapse.vue'

Expand Down Expand Up @@ -50,12 +49,6 @@ export default {
} else {
leftBar.push(item)
}
if (item.id === 'lock') {
useLayout().registerPluginApi({ Lock: item.api })
}
if (item.id === 'save') {
useLayout().registerPluginApi({ save: item.api })
}
})
nextTick(() => {
state.showDeployBlock = true
Expand Down
37 changes: 3 additions & 34 deletions packages/layout/src/composable/useLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,10 @@

import { reactive, nextTick } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import { META_APP as PLUGIN_NAME, getMetaApi } from '@opentiny/tiny-engine-meta-register'

const { PAGE_STATUS } = constants

const PLUGIN_NAME = {
Materials: 'engine.plugins.materials',
AppManage: 'engine.plugins.appmanage',
BlockManage: 'engine.plugins.blockmanage',
Bridge: 'engine.plugins.bridge',
State: 'engine.plugins.state',
Collections: 'engine.plugins.collections',
EditorHelp: 'engine.plugins.editorhelp',
I18n: 'engine.plugins.i18n',
Robot: 'engine.plugins.robot',
Schema: 'engine.plugins.schema',
PageController: 'engine.plugins.pagecontroller',
OutlineTree: 'engine.plugins.outlinetree',
Tutorial: 'engine.plugins.tutorial',
Lock: 'Lock',
save: 'save'
}

const pluginState = reactive({
pluginEvent: 'all'
})
Expand All @@ -50,8 +33,7 @@ const layoutState = reactive({
},
plugins: {
fixedPanels: [PLUGIN_NAME.Materials],
render: null,
api: {} // 插件需要注册交互API到这里
render: null
},
settings: {
render: 'props',
Expand All @@ -65,10 +47,6 @@ const layoutState = reactive({
pageStatus: ''
})

const registerPluginApi = (api) => {
Object.assign(layoutState.plugins.api, api)
}

const getScale = () => layoutState.dimension.scale

// 激活setting面板并高亮提示
Expand All @@ -85,13 +63,6 @@ const activeSetting = (name) => {
})
}

// 获取当前插件注册的Api
const getPluginApi = (pluginName) => {
const { plugins } = layoutState

return plugins.api[pluginName] || plugins.api
}

// 激活plugin面板并返回当前插件注册的Api
const activePlugin = (name, noActiveRender) => {
const { plugins } = layoutState
Expand All @@ -101,7 +72,7 @@ const activePlugin = (name, noActiveRender) => {
}

return new Promise((resolve) => {
nextTick(() => resolve(getPluginApi(name)))
nextTick(() => resolve(getMetaApi(name)))
})
}

Expand Down Expand Up @@ -133,8 +104,6 @@ export default () => {
getScale,
setDimension,
getDimension,
registerPluginApi,
getPluginApi,
getPluginState,
pluginState,
isEmptyPage
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BlockService } from './src/composable'

export default {
...metaData,
api,
apis: api,
entry,
metas: [BlockService]
}
Expand Down
13 changes: 10 additions & 3 deletions packages/plugins/block/src/composable/useBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ import { getMergeMeta } from '@opentiny/tiny-engine-meta-register'
import { getCanvasStatus } from '@opentiny/tiny-engine-common/js/canvas'
import { ast2String, parseExpression } from '@opentiny/tiny-engine-common/js/ast'
import { getCssObjectFromStyleStr } from '@opentiny/tiny-engine-common/js/css'
import { useCanvas, useTranslate, useEditorInfo, useBreadcrumb, useLayout } from '@opentiny/tiny-engine-meta-register'
import {
useCanvas,
useTranslate,
useEditorInfo,
useBreadcrumb,
useLayout,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'

const { SORT_TYPE, SCHEMA_DATA_TYPE, BLOCK_OPENNESS } = constants

Expand Down Expand Up @@ -473,8 +481,7 @@ const appendEventEmit = ({ eventName, functionName } = {}) => {
return
}

const { PLUGIN_NAME, getPluginApi } = useLayout()
const getMethods = getPluginApi(PLUGIN_NAME.PageController)?.getMethods
const getMethods = getMetaApi(META_APP.Page)?.getMethods

if (getMethods && typeof getMethods === 'function') {
const method = getMethods()?.[functionName]
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/data/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ import {
useEditorInfo,
useResource,
useNotify,
useLayout,
useHelp
useHelp,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'
import { getCommentByKey } from '@opentiny/tiny-engine-common/js/comment'
import { iconSearch } from '@opentiny/vue-icon'
Expand Down Expand Up @@ -113,8 +114,7 @@ export default {
const activeName = ref(STATE.CURRENT_STATE)
const isBlock = computed(() => useCanvas().isBlock())
const { setSaved } = useCanvas()
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { openCommon } = getPluginApi(PLUGIN_NAME.save)
const { openCommon } = getMetaApi(META_APP.Save)
const docsUrl = useHelp().getDocsUrl('data')
const state = reactive({
dataSource: {},
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/materials/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default {
header: MaterialHeader
},
apis: { ...MaterialBlock.apis },
api: { ...MaterialBlock.apis },
metas: [MaterialBlock, MaterialComponent, ResourceService, MaterialService]
}

Expand Down
10 changes: 5 additions & 5 deletions packages/plugins/materials/src/composable/useResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
useBreadcrumb,
useLayout,
useBlock,
useMaterial
useMaterial,
getMetaApi,
META_APP
} from '@opentiny/tiny-engine-meta-register'

const { COMPONENT_NAME, DEFAULT_INTERCEPTOR } = constants
Expand Down Expand Up @@ -67,8 +69,7 @@ const initPage = (pageInfo) => {
* @param {string} blockId 区块 id
*/
const initBlock = async (blockId) => {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const blockApi = getPluginApi(PLUGIN_NAME.BlockManage)
const blockApi = getMetaApi(META_APP.BlockManage)
const blockContent = await blockApi.getBlockById(blockId)

if (blockContent.public_scope_tenants.length) {
Expand All @@ -86,8 +87,7 @@ const initPageOrBlock = async () => {
const { setBreadcrumbPage } = useBreadcrumb()

if (pageId) {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const pagePluginApi = getPluginApi(PLUGIN_NAME.AppManage)
const pagePluginApi = getMetaApi(META_APP.AppManage)

const data = await pagePluginApi.getPageById(pageId)

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PageService } from './src/composable'

export default {
...metaData,
api,
apis: api,
entry,
metas: [PageService]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ import metaData from './meta.js'

export default {
...metaData,
api,
apis: api,
Comment thread
hexqi marked this conversation as resolved.
entry
}
2 changes: 1 addition & 1 deletion packages/plugins/tutorial/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import metaData from './meta.js'
export default {
...metaData,
entry,
api
apis: api
Comment thread
hexqi marked this conversation as resolved.
}
8 changes: 3 additions & 5 deletions packages/plugins/tutorial/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import { onMounted, reactive, ref } from 'vue'
import { PluginPanel, SvgButton } from '@opentiny/tiny-engine-common'
import { IconChevronRight } from '@opentiny/vue-icon'
import { useLayout } from '@opentiny/tiny-engine-meta-register'
import { getMetaApi, META_APP } from '@opentiny/tiny-engine-meta-register'
import { Collapse, CollapseItem } from '@opentiny/vue'
import TutorialVideoPanel, { open as openPanel } from './TutorialVideoPanel.vue'
import { fetchTutorialList } from './js/http'
Expand Down Expand Up @@ -103,16 +103,14 @@ export default {
boxVisibility.value = false
}

const { PLUGIN_NAME, getPluginApi } = useLayout()

const openVideoPanel = () => {
const { open } = getPluginApi(PLUGIN_NAME.Tutorial)
const { open } = getMetaApi(META_APP.Tutorial)
open()
}

return {
state,
PLUGIN_NAME,
PLUGIN_NAME: META_APP,
playVideo,
boxVisibility,
close,
Expand Down
Loading