Skip to content

Commit

Permalink
feat: move hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hexqi committed Jun 19, 2024
1 parent c4ea42c commit 4b06177
Show file tree
Hide file tree
Showing 54 changed files with 294 additions and 466 deletions.
24 changes: 1 addition & 23 deletions designer-demo/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,15 @@ import {
Layout,
Canvas,
EditorInfoService,
HelpService,
AppService,
BlockService,
BreadcrumbService,
DataSourceService,
PageService,
ResourceService,
PropertiesService,
PropertyService,
SaveLocalService,
TranslateService,
HistoryService,
} from '@opentiny/tiny-engine'

export default {
root: {
id: 'engine.root',
metas: [
EditorInfoService,
HelpService,
AppService,
BreadcrumbService,
BlockService,
DataSourceService,
PageService,
ResourceService,
PropertiesService,
PropertyService,
SaveLocalService,
TranslateService,
HistoryService,
AppService
]
},
config: {
Expand Down
6 changes: 5 additions & 1 deletion packages/canvas/breadcrumb/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { HOOK_NAME } from '@opentiny/tiny-engine-entry'
import CanvasBreadcrumb from './src/CanvasFooter.vue'
import metaData from './meta'
import useBreadcrumb from './src/useBreadcrumb'

export default {
...metaData,
apis: useBreadcrumb(),
entry: CanvasBreadcrumb
entry: CanvasBreadcrumb,
composable: {
name: HOOK_NAME.useBreadcrumb
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@

<script>
import { VueMonaco as MonacoEditor, SvgButton } from '../components' // TODO 等 common 包移除了 configurator 依赖后再更换成 @opentiny/tiny-engine-common
import { useApp, useCanvas, useData, useLayout, useProperties, useResource } from '@opentiny/tiny-engine-controller'
import { useApp, useCanvas, useLayout, useProperties, useResource } from '@opentiny/tiny-engine-controller'
import { getCommentByKey } from '@opentiny/tiny-engine-controller/js/comment'
import { theme } from '@opentiny/tiny-engine-controller/adapter'
import { formatString, generate, parse, traverse } from '@opentiny/tiny-engine-controller/js/ast'
import { DEFAULT_LOOP_NAME } from '@opentiny/tiny-engine-controller/js/constants'
Expand Down Expand Up @@ -318,7 +319,6 @@ export default {
const genRemoteMethodToLifeSetup = (variableName, sourceRef, pageSchema) => {
if (sourceRef?.data?.data) {
const setupFn = pageSchema.lifeCycles?.setup?.value
const { getCommentByKey } = useData()
const { start, end } = getCommentByKey(variableName)
const intervalId = `${CONSTANTS.INTERVALID}${capitalize(camelize(sourceRef.name))}`
const isPoll = state.isPoll && state.pollInterval !== undefined
Expand Down
37 changes: 0 additions & 37 deletions packages/controller/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,8 @@
*
*/

import { toRaw } from 'vue'
import { getMergeMeta } from '@opentiny/tiny-engine-entry'

/**
* 将画布pageSchema对象转换成编辑器中的string
*
* @param {*} obj
* @returns
*/
export const obj2String = (obj) => {
let out = null

try {
out = JSON.stringify(toRaw(obj), null, 2)
} catch (error) {
// do nothing
}

return out
}

/**
* 将编辑器中的string转换成画布识别的pageSchema对象
* @param {*} string
* @returns
*/

export const string2Obj = (string) => {
let obj = null

try {
obj = JSON.parse(string)
} catch (error) {
// do nothing
}

return obj
}

/**
* 判断 Monaco 编辑器背景色的主题
* @returns
Expand Down
16 changes: 16 additions & 0 deletions packages/controller/js/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

export const getCommentByKey = (key) => ({
start: `start-${key} 设计器生成的代码,为了避免出现问题,请勿修改`,
end: `end-${key}`
})
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const exampleMap = {
}
] `
}
export default (name) => {

export const getExample = (name) => {
const resetName = `${name || ''}`.toLocaleLowerCase()
return exampleMap[resetName]
}
3 changes: 0 additions & 3 deletions packages/controller/meta.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/controller/src/composable/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HOOK_NAME } from '@opentiny/tiny-engine-entry'

import useApp from './useApp'
import useEditorInfo from './useEditorInfo'

export const AppService = {
id: 'engine.service.app',
type: 'MetaService',
apis: useApp(),
composable: {
name: HOOK_NAME.useApp
}
}

export const EditorInfoService = {
id: 'engine.service.editorInfo',
type: 'MetaService',
apis: useEditorInfo(),
composable: {
name: HOOK_NAME.useEditorInfo
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import { reactive, watch } from 'vue'
import { useHttp } from '@opentiny/tiny-engine-http'

const http = useHttp()

const defaultState = {
// 应用列表
list: [],
Expand All @@ -41,7 +39,7 @@ const defaultState = {
const appInfoState = reactive({ ...defaultState })

// 获取当前应用的信息
const fetchAppInfo = (appId) => http.get(`/app-center/api/apps/detail/${appId}`)
const fetchAppInfo = (appId) => useHttp().get(`/app-center/api/apps/detail/${appId}`)

watch(
() => appInfoState.selectedId,
Expand All @@ -55,7 +53,7 @@ watch(
)

// 获取应用列表
const fetchAppList = (platformId) => http.get(`/app-center/api/apps/list/${platformId}`)
const fetchAppList = (platformId) => useHttp().get(`/app-center/api/apps/list/${platformId}`)

const updateApp = async (id) => {
const appInfo = await fetchAppInfo(id)
Expand Down
132 changes: 0 additions & 132 deletions packages/controller/src/hooks/index.js

This file was deleted.

13 changes: 3 additions & 10 deletions packages/controller/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
*
*/

export * from './hooks/'
import useMessage from './useMessage'
import useData from './useData'
export { default as metaData } from '../meta'
import example from './example'

export const getExample = example
export * from './composable/'

export {
useLayout,
Expand All @@ -36,7 +30,6 @@ export {
useHelp,
useModal,
useNotify,
useCustom
useCustom,
useMessage
} from '@opentiny/tiny-engine-entry'

export { useData, useMessage }
20 changes: 0 additions & 20 deletions packages/controller/src/useData.js

This file was deleted.

Loading

0 comments on commit 4b06177

Please sign in to comment.