-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat router page embedded view toggle (#1010)
* feat(canvas, toolbar/view-setting): add router view setting view mode switcher, support embedded and standalone mode in canvas * fix(canvas/render): fix switch locale failed * feat(canvas): add window.onpopstate listener * fix(toolbars/view-setting): fix init view mode value no fallback cause next view mode label error * fix: using enum instead of multiple time literal string declaration, add fallback for cache value getter in toolbar, fix typo mistake * fix: simplify return value using enum, remove unnecessary style code * fix(toolbars/view-setting): fix package.json wrong repository directory
- Loading branch information
Showing
17 changed files
with
301 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/canvas/render/src/canvas-function/router-view-setting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { reactive, watch } from 'vue' | ||
import { useBroadcastChannel } from '@vueuse/core' | ||
import { constants } from '@opentiny/tiny-engine-utils' | ||
|
||
const { BROADCAST_CHANNEL, CANVAS_ROUTER_VIEW_SETTING_VIEW_MODE_KEY } = constants | ||
|
||
export enum ViewMode { | ||
EMBEDDED = 'embedded', | ||
STANDALONE = 'standalone' | ||
} | ||
export interface IRouterViewSetting { | ||
viewMode: ViewMode | ||
} | ||
|
||
function getCacheValue() { | ||
const value = localStorage.getItem(CANVAS_ROUTER_VIEW_SETTING_VIEW_MODE_KEY) | ||
if (!(Object.values(ViewMode) as string[]).includes(value)) { | ||
return ViewMode.EMBEDDED | ||
} | ||
return value as ViewMode | ||
} | ||
|
||
export function useRouterViewSetting() { | ||
const routerViewSetting = reactive<IRouterViewSetting>({ | ||
viewMode: getCacheValue() | ||
}) | ||
|
||
const { data } = useBroadcastChannel<IRouterViewSetting, IRouterViewSetting>({ | ||
name: BROADCAST_CHANNEL.CanvasRouterViewSetting | ||
}) | ||
|
||
watch(data, () => { | ||
routerViewSetting.viewMode = data.value.viewMode | ||
}) | ||
|
||
return { | ||
routerViewSetting | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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. | ||
* | ||
*/ | ||
|
||
import entry from './src/Main.vue' | ||
import metaData from './meta' | ||
|
||
export default { | ||
...metaData, | ||
entry | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
id: 'engine.toolbars.viewSetting', | ||
type: 'toolbars', | ||
title: 'viewSetting', | ||
options: { | ||
icon: { | ||
default: 'routerview' | ||
}, | ||
renderType: 'icon', | ||
collapsed: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@opentiny/tiny-engine-toolbar-view-setting", | ||
"version": "2.1.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "vite build" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/opentiny/tiny-engine", | ||
"directory": "packages/toolbars/view-setting" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/opentiny/tiny-engine/issues" | ||
}, | ||
"author": "OpenTiny Team", | ||
"license": "MIT", | ||
"homepage": "https://opentiny.design/tiny-engine", | ||
"dependencies": { | ||
"@opentiny/tiny-engine-common": "workspace:*", | ||
"@opentiny/tiny-engine-utils": "workspace:*", | ||
"@vueuse/core": "^9.6.0" | ||
}, | ||
"devDependencies": { | ||
"@opentiny/tiny-engine-vite-plugin-meta-comments": "workspace:*", | ||
"@vitejs/plugin-vue": "^5.1.2", | ||
"@vitejs/plugin-vue-jsx": "^4.0.1", | ||
"vite": "^5.4.2" | ||
}, | ||
"peerDependencies": { | ||
"@opentiny/vue": "^3.14.0", | ||
"vue": "^3.4.15" | ||
} | ||
} |
Oops, something went wrong.