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

refactor: The plugin fixed state is persisted using vueuse. #738

Merged
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
44 changes: 30 additions & 14 deletions packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ const PLUGIN_NAME = {
}

const pluginWidth = {
Materials: '300',
OutlineTree: '300',
AppManage: '300',
BlockManage: '300',
Collections: '300',
Bridge: '300',
I18n: '620',
PageController: '1000',
DataSource: '300',
Schema: '1000',
SettingProps: '320',
SettingStyles: '320',
SettingEvents: '320'
Materials: 300,
OutlineTree: 300,
AppManage: 300,
BlockManage: 300,
Collections: 300,
Bridge: 300,
I18n: 620,
PageController: 1000,
DataSource: 300,
Schema: 1000,
SettingProps: 320,
SettingStyles: 320,
SettingEvents: 32
}
const pluginWidthStorage = useStorage('pluginWidth', pluginWidth)
const getPluginWidth = (name) => {
Expand Down Expand Up @@ -97,7 +97,19 @@ const layoutState = reactive({
},
pageStatus: ''
})
const leftFixedPanelsStorage = useStorage('leftFixedPanels', layoutState.plugins.fixedPanels)
const rightFixedPanelsStorage = useStorage('rightFixedPanels', layoutState.settings.fixedPanels)

const changeLeftFixedPanels = (pluginName) => {
leftFixedPanelsStorage.value = leftFixedPanelsStorage.value?.includes(pluginName)
? leftFixedPanelsStorage.value?.filter((item) => item !== pluginName)
: [...leftFixedPanelsStorage.value, pluginName]
}
const changeRightFixedPanels = (pluginName) => {
rightFixedPanelsStorage.value = rightFixedPanelsStorage.value?.includes(pluginName)
? rightFixedPanelsStorage.value?.filter((item) => item !== pluginName)
: [...rightFixedPanelsStorage.value, pluginName]
}
const registerPluginApi = (api) => {
Object.assign(layoutState.plugins.api, api)
}
Expand Down Expand Up @@ -180,6 +192,10 @@ export default () => {
pluginState,
isEmptyPage,
getPluginWidth,
changePluginWidth
changePluginWidth,
leftFixedPanelsStorage,
rightFixedPanelsStorage,
changeLeftFixedPanels,
changeRightFixedPanels
}
}
18 changes: 6 additions & 12 deletions packages/design-core/src/DesignPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
<div
v-show="renderPanel && components[renderPanel]"
id="tiny-engine-left-panel"
:class="[renderPanel, { 'is-fixed': pluginsState.fixedPanels.includes(renderPanel) }]"
:class="[renderPanel, { 'is-fixed': leftFixedPanelsStorage.includes(renderPanel) }]"
>
<div class="left-panel-wrap">
<keep-alive>
<component
:is="components[renderPanel]"
ref="pluginRef"
:fixed-panels="pluginsState.fixedPanels"
:fixed-panels="leftFixedPanelsStorage"
@close="close"
@fixPanel="fixPanel"
></component>
Expand Down Expand Up @@ -134,11 +134,7 @@ export default {
const { isTemporaryPage } = usePage()
const HELP_PLUGIN_ID = 'EditorHelp'

const {
pluginState,
registerPluginApi,
layoutState: { plugins: pluginsState }
} = useLayout()
const { pluginState, registerPluginApi, changeLeftFixedPanels, leftFixedPanelsStorage } = useLayout()

Addons.plugins.forEach(({ id, component, api, icon }) => {
components[id] = component
Expand Down Expand Up @@ -209,9 +205,7 @@ export default {

//切换面板状态
const fixPanel = (pluginName) => {
pluginsState.fixedPanels = pluginsState.fixedPanels?.includes(pluginName)
? pluginsState.fixedPanels?.filter((item) => item !== pluginName)
: [...pluginsState.fixedPanels, pluginName]
changeLeftFixedPanels(pluginName)
}

return {
Expand All @@ -223,12 +217,12 @@ export default {
robotComponent,
close,
fixPanel,
pluginsState,
components,
iconComponents,
completed,
doCompleted,
pluginState
pluginState,
leftFixedPanelsStorage
}
}
}
Expand Down
62 changes: 32 additions & 30 deletions packages/design-core/src/DesignSettings.vue
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
<!-- 右侧插件栏-->
<template>
<!-- 插件面板 -->
<div>
<!-- 插件面板 -->
<div
v-show="renderPanel && components[renderPanel]"
id="tiny-engine-right-panel"
:class="[renderPanel, { 'is-fixed': settingsState.fixedPanels.includes(renderPanel) }]"
:class="[renderPanel, { 'is-fixed': rightFixedPanelsStorage.includes(renderPanel) }]"
>
<div class="right-panel-wrap">
<component
:is="components[renderPanel]"
:fixed-panels="settingsState.fixedPanels"
:fixed-panels="rightFixedPanelsStorage"
@close="close"
@fixPanel="fixPanel"
></component>
<div v-show="activating" class="active2" />
</div>
</div>
<div id="tiny-engine-nav-panel">
<!-- 图标菜单 -->
<ul class="nav-panel-lists">
<li
v-for="(item, index) in state.leftList"
:key="index"
:class="{
'list-item': true,
'first-item': index === 0,
active: item.id === renderPanel
}"
:title="item.title"
@click="clickMenu({ item, index })"
>
<div>
<span class="item-icon">
<svg-icon v-if="iconComponents[item.id]" :name="iconComponents[item.id]" class="panel-icon"></svg-icon>
<component v-else :is="iconComponents[item.id]" class="panel-icon"></component>
</span>
</div>
</li>
</ul>
</div>
</div>

<div id="tiny-engine-nav-panel">
<!-- 图标菜单 -->
<ul class="nav-panel-lists">
<li
v-for="(item, index) in state.leftList"
:key="index"
:class="{
'list-item': true,
'first-item': index === 0,
active: item.id === renderPanel
}"
:title="item.title"
@click="clickMenu({ item, index })"
>
<div>
<span class="item-icon">
<svg-icon v-if="iconComponents[item.id]" :name="iconComponents[item.id]" class="panel-icon"></svg-icon>
<component v-else :is="iconComponents[item.id]" class="panel-icon"></component>
</span>
</div>
</li>
</ul>
</div>
</template>

Expand All @@ -66,6 +67,8 @@ export default {
setup(props) {
const { renderPanel } = toRefs(props)
const {
rightFixedPanelsStorage,
changeRightFixedPanels,
layoutState: { settings: settingsState }
} = useLayout()
const settings = Addons && Addons.settings
Expand Down Expand Up @@ -106,9 +109,7 @@ export default {

//切换面板状态
const fixPanel = (pluginName) => {
settingsState.fixedPanels = settingsState.fixedPanels?.includes(pluginName)
? settingsState.fixedPanels?.filter((item) => item !== pluginName)
: [...settingsState.fixedPanels, pluginName]
changeRightFixedPanels(pluginName)
}

return {
Expand All @@ -121,7 +122,8 @@ export default {
iconComponents,
clickMenu,
close,
fixPanel
fixPanel,
rightFixedPanelsStorage
}
}
}
Expand Down