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

feat: add hooks entry #550

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion designer-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"vite": "^5.2.7",
"@opentiny/tiny-engine-cli": "workspace:^",
"@opentiny/tiny-engine-vite-plugin-meta-comments": "workspace:^"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
setup(props, { emit }) {
const { getMaterial } = useResource()
const { pageState } = useCanvas()
const { properties } = useProperty({ pageState })
const { properties } = useProperty().getProperty({ pageState })
const active = ref('props')

const propertiesList = computed(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"license": "MIT",
"homepage": "https://opentiny.design/tiny-engine",
"dependencies": {
"@opentiny/tiny-engine-canvas": "workspace:*",
"@opentiny/tiny-engine-controller": "workspace:*",
"@opentiny/tiny-engine-entry": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
Expand Down
3 changes: 1 addition & 2 deletions packages/controller/js/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*/

import { PAGE_STATUS } from './constants'
import useEditorInfo from '../src/useEditorInfo'
import useResource from '../src/useResource'
import { useEditorInfo, useResource } from '@opentiny/tiny-engine-entry'

export const getCanvasStatus = (data) => {
// 写死ID 待删除
Expand Down
3 changes: 1 addition & 2 deletions packages/controller/js/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*
*/

import useCanvas from '../src/useCanvas'
import useResource from '../src/useResource'
import { useCanvas, useResource } from '@opentiny/tiny-engine-entry'

const keyWords = [
'state',
Expand Down
5 changes: 2 additions & 3 deletions packages/controller/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
*/

import { useHttp } from '@opentiny/tiny-engine-http'
import usePage from '../src/usePage'
import useCanvas from '../src/useCanvas'
import useNotify from '../src/useNotify'
import useNotify from '../src/components/useNotify'
import { isVsCodeEnv } from './environments'
import { generateRouter, generatePage } from './vscodeGenerateFile'
import { usePage, useCanvas } from '@opentiny/tiny-engine-entry'

const http = useHttp()

Expand Down
2 changes: 1 addition & 1 deletion packages/controller/js/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { constants } from '@opentiny/tiny-engine-utils'
import { isDevelopEnv } from './environments'
import useResource from '../src/useResource'
import { useResource } from '@opentiny/tiny-engine-entry'
// prefer old unicode hacks for backward compatibility

const { COMPONENT_NAME } = constants
Expand Down
15 changes: 15 additions & 0 deletions packages/controller/src/hooks/mountHooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './useLayout'
import './useCanvas'
import './useApp'
import './useResource'
import './useHistory'
import './useProperties'
import './useSaveLocal'
import './useEditorInfo'
import './useBlock'
import './useTranslate'
import './usePage'
import './useDataSource'
import './useBreadcrumb'
import './useProperty'
import './useHelp'
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { reactive, watch } from 'vue'
import { useHttp } from '@opentiny/tiny-engine-http'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

const http = useHttp()

Expand Down Expand Up @@ -71,3 +72,10 @@ export default () => {
updateApp
}
}

initHook(HOOK_NAME.useApp, {
appInfoState,
fetchAppInfo,
fetchAppList,
updateApp
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import { extend, copyArray } from '@opentiny/vue-renderless/common/object'
import { format } from '@opentiny/vue-renderless/common/date'
import { remove } from '@opentiny/vue-renderless/common/array'
import { constants } from '@opentiny/tiny-engine-utils'
import { getCanvasStatus } from '../js/canvas'
import { ast2String, parseExpression } from '../js/ast'
import { getCssObjectFromStyleStr } from '../js/css'
import useCanvas from './useCanvas'
import useTranslate from './useTranslate'
import useEditorInfo from './useEditorInfo'
import useBreadcrumb from './useBreadcrumb'
import useLayout from './useLayout'
import { getGlobalConfig } from './globalConfig'
import { getCanvasStatus } from '../../js/canvas'
import { ast2String, parseExpression } from '../../js/ast'
import { getCssObjectFromStyleStr } from '../../js/css'
import { getGlobalConfig } from '../globalConfig'
import {
HOOK_NAME,
initHook,
useCanvas,
useTranslate,
useEditorInfo,
useBreadcrumb,
useLayout
} from '@opentiny/tiny-engine-entry'

const { SORT_TYPE, SCHEMA_DATA_TYPE, BLOCK_OPENNESS } = constants

Expand Down Expand Up @@ -764,3 +768,48 @@ export default function () {
getDateFromNow
}
}

initHook(HOOK_NAME.useBlock, {
NODE_TYPE_PAGE,
DEFAULT_GROUP_ID,
DEFAULT_GROUP_NAME,
selectedGroup,
selectedBlock,
selectedBlockArray,
isRefresh,
addBlock,
delBlock,
createBlock,
getBlockAssetsByVersion,
createEmptyBlock,
groupChange,
addDefaultGroup,
isDefaultGroupId,
isAllGroupId,
splitBackupGroups,
sort,
check,
cancelCheck,
getBlockList,
setBlockList,
getBlockI18n,
getGroupList,
setGroupList,
getCategoryList,
setCategoryList,
addBlockEvent,
getBlockEvents,
appendEventEmit,
getCurrentBlock,
initBlock,
setCurrentBlock,
removeEventLink,
getSelectedGroup,
setSelectedGroup,
addBlockProperty,
editBlockProperty,
removePropertyLink,
getBlockProperties,
getBlockPageSchema,
getDateFromNow
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { ref } from 'vue'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

let breadcrumbData = ref([])
const CONSTANTS = {
Expand All @@ -37,3 +38,10 @@ export default () => {
getBreadcrumbData
}
}

initHook(HOOK_NAME.useBreadcrumb, {
CONSTANTS,
setBreadcrumbPage,
setBreadcrumbBlock,
getBreadcrumbData
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* eslint-disable no-new-func */
import { reactive, ref } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import useHistory from './useHistory'
import { HOOK_NAME, initHook, useHistory } from '@opentiny/tiny-engine-entry'

const { COMPONENT_NAME } = constants

Expand Down Expand Up @@ -166,3 +166,23 @@ export default function () {
isCanvasApiReady
}
}

initHook(HOOK_NAME.useCanvas, {
pageState,
isBlock,
isSaved,
isLoading,
initData,
setSaved,
clearCanvas,
getPageSchema,
resetPageCanvasState,
resetBlockCanvasState,
clearCurrentState,
getCurrentSchema,
setCurrentSchema,
getCurrentPage,
initCanvasApi,
canvasApi,
isCanvasApiReady
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { reactive } from 'vue'
import { utils } from '@opentiny/tiny-engine-utils'
import { isEqual } from '@opentiny/vue-renderless/common/object'
import { isEmptyObject } from '@opentiny/vue-renderless/common/type'
import useModal from './useModal'
import useModal from '../components/useModal'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

const dataSourceState = reactive({
dataSource: {},
Expand Down Expand Up @@ -118,3 +119,5 @@ const saveDataSource = (callback) => {
export default () => {
return { dataSourceState, compareData, saveDataSource }
}

initHook(HOOK_NAME.useDataSource, { dataSourceState, compareData, saveDataSource })
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*/

import { useHttp } from '@opentiny/tiny-engine-http'
import useModal from './useModal'
import useModal from '../components/useModal'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

// web版获取配置信息: 从url中获取
const _getWebData = () => {
Expand Down Expand Up @@ -69,3 +70,10 @@ export default () => {
isAdmin
}
}

initHook(HOOK_NAME.useEditorInfo, {
useInfo: _getWebData,
getUserInfo,
userInfo,
isAdmin
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
*/

import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

const getBaseUrl = () => 'https://opentiny.design/tiny-engine#/help-center/course/engine/'

const helpState = {
Expand All @@ -33,3 +35,8 @@ export default () => ({
getBaseUrl,
getDocsUrl
})

initHook(HOOK_NAME.useHelp, {
getBaseUrl,
getDocsUrl
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { reactive, isProxy, toRaw, watch } from 'vue'
import useCanvas from './useCanvas'
import { HOOK_NAME, initHook, useCanvas } from '@opentiny/tiny-engine-entry'

const schema2String = (schema) => {
if (isProxy(schema)) {
Expand Down Expand Up @@ -121,3 +121,12 @@ export default () => {
addHistory
}
}


initHook(HOOK_NAME.useHistory, {
historyState,
back,
forward,
go,
addHistory
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { reactive, nextTick } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

const { PAGE_STATUS } = constants

Expand Down Expand Up @@ -140,3 +141,19 @@ export default () => {
isEmptyPage
}
}

initHook(HOOK_NAME.useLayout, {
PLUGIN_NAME,
activeSetting,
activePlugin,
closePlugin,
layoutState,
getScale,
setDimension,
getDimension,
registerPluginApi,
getPluginApi,
getPluginState,
pluginState,
isEmptyPage
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { reactive } from 'vue'
import { extend, isEqual } from '@opentiny/vue-renderless/common/object'
import { HOOK_NAME, initHook } from '@opentiny/tiny-engine-entry'

const DEFAULT_PAGE = {
app: '',
Expand Down Expand Up @@ -145,3 +146,17 @@ export default () => {
COMMON_PAGE_GROUP_ID
}
}

initHook(HOOK_NAME.usePage, {
DEFAULT_PAGE,
pageSettingState,
isTemporaryPage,
isCurrentDataSame,
changeTreeData,
getPageContent,
resetPageData,
initCurrentPageData,
isChangePageData,
STATIC_PAGE_GROUP_ID,
COMMON_PAGE_GROUP_ID
})
Loading