-
Notifications
You must be signed in to change notification settings - Fork 341
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 router page embedded view toggle #1010
Merged
gene9831
merged 7 commits into
opentiny:feat/router-page
from
rhlin:feat-router-page-embedded-view-toggle
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a788437
feat(canvas, toolbar/view-setting): add router view setting view mode…
rhlin 4b26149
fix(canvas/render): fix switch locale failed
rhlin 47ef33d
feat(canvas): add window.onpopstate listener
rhlin 9a05edd
fix(toolbars/view-setting): fix init view mode value no fallback caus…
rhlin e23f8fb
fix: using enum instead of multiple time literal string declaration, …
rhlin ebba65a
fix: simplify return value using enum, remove unnecessary style code
rhlin 8883149
fix(toolbars/view-setting): fix package.json wrong repository directory
rhlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding cleanup for broadcast channel subscription.
The implementation looks good, but the broadcast channel subscription should be cleaned up when the component is unmounted.
export function useRouterViewSetting() { const routerViewSetting = reactive<IRouterViewSetting>({ viewMode: getCacheValue() }) const { data, cleanup } = useBroadcastChannel<IRouterViewSetting, IRouterViewSetting>({ name: BROADCAST_CHANNEL.CanvasRouterViewSetting }) watch(data, () => { routerViewSetting.viewMode = data.value.viewMode }) return { routerViewSetting, + cleanup } }
📝 Committable suggestion