Skip to content

Commit

Permalink
refactor: The plugin fixed state is persisted using vueuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
STATICHIT committed Aug 14, 2024
1 parent b28884b commit 78903ca
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
18 changes: 17 additions & 1 deletion packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
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

0 comments on commit 78903ca

Please sign in to comment.