-
Notifications
You must be signed in to change notification settings - Fork 5
Allow removal and adding for plugins in iconMenu #861
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,13 @@ | |
| */ | ||
| /* eslint-enable tsdoc/syntax */ | ||
|
|
||
| import type { Component } from 'vue' | ||
| import type { Icon } from '@/core' | ||
| import type { Menu } from './types' | ||
|
|
||
| import { toMerged } from 'es-toolkit' | ||
| import { t } from 'i18next' | ||
| import { acceptHMRUpdate, defineStore } from 'pinia' | ||
| import { computed, markRaw, ref } from 'vue' | ||
| import { computed, markRaw, ref, watch } from 'vue' | ||
|
|
||
| import { useCoreStore } from '@/core/stores' | ||
|
|
||
|
|
@@ -42,6 +41,33 @@ export const useIconMenuStore = defineStore('plugins/iconMenu', () => { | |
| () => coreStore.configuration.iconMenu?.layoutTag ?? '' | ||
| ) | ||
|
|
||
| const flatMenuItems = computed(() => | ||
| menus.value.concat(focusMenus.value).flat() | ||
| ) | ||
| watch( | ||
| flatMenuItems, | ||
| (newItems, oldItems) => { | ||
| const getDiffItems = (to, from) => | ||
| to.filter( | ||
| (item) => | ||
| !from.some((oldItem) => oldItem.plugin.id === item.plugin.id) | ||
| ) | ||
| getDiffItems(newItems, oldItems).forEach((newItem) => { | ||
| coreStore.addPlugin(toMerged(newItem.plugin, { independent: false })) | ||
| }) | ||
| getDiffItems(oldItems, newItems).forEach((oldItem) => { | ||
| if (open.value === oldItem.plugin.id) { | ||
| open.value = null | ||
| } | ||
| if (focusOpen.value === oldItem.plugin.id) { | ||
| focusOpen.value = null | ||
| } | ||
| coreStore.removePlugin(oldItem.plugin.id) | ||
| }) | ||
| }, | ||
| { deep: true } | ||
| ) | ||
|
Comment on lines
+47
to
+69
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that However, I would've thought adding its own
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My first approach was to implement a If you prefer to have these actions, I can add them. I'd stick to this watcher to keep the more flexible option of direct editing, but we could e.g. mark only the actions as stable to keep
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer these actions, yeah. |
||
|
|
||
| function setupPlugin() { | ||
| menus.value = (coreStore.configuration.iconMenu?.menus || []).map( | ||
| (menuGroup) => | ||
|
|
@@ -64,24 +90,6 @@ export const useIconMenuStore = defineStore('plugins/iconMenu', () => { | |
| coreStore.addPlugin(toMerged(plugin, { independent: false })) | ||
| }) | ||
|
|
||
| // Otherwise, the component itself is made reactive | ||
| menus.value.map((menuGroup) => | ||
| menuGroup.map((menuItem) => | ||
| toMerged(menuItem, { | ||
| plugin: { | ||
| component: markRaw(menuItem.plugin.component as Component), | ||
| }, | ||
| }) | ||
| ) | ||
| ) | ||
| focusMenus.value.map((menuItem) => | ||
| toMerged(menuItem, { | ||
| plugin: { | ||
| component: markRaw(menuItem.plugin.component as Component), | ||
| }, | ||
| }) | ||
| ) | ||
|
|
||
|
Comment on lines
-67
to
-84
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The important part - making the component non-reactive with
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines have no effect anymore. Or do I miss anything? |
||
| const initiallyOpen = coreStore.configuration.iconMenu?.initiallyOpen | ||
| if ( | ||
| !coreStore.hasSmallHeight && | ||
|
|
@@ -104,21 +112,31 @@ export const useIconMenuStore = defineStore('plugins/iconMenu', () => { | |
|
|
||
| function openMenuById(openId: string) { | ||
| const entry = menus.value.flat().find(({ plugin: { id } }) => id === openId) | ||
|
|
||
| if (entry) { | ||
| open.value = openId | ||
| openInMoveHandle(openId) | ||
| } | ||
| } | ||
| watch(open, (open) => { | ||
| if (open) { | ||
| openInMoveHandle(open) | ||
| } else { | ||
| coreStore.setMoveHandle(null) | ||
| } | ||
| }) | ||
|
Comment on lines
+119
to
+125
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the previously implemented version in favour of this side effect solution. Same goes for What is the practical reason why this is needed or is simply personal preference?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Practical reason. We had that logic already duplicated in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could also be de-duplicated by abstracting the |
||
|
|
||
| function openFocusMenuById(openId: string) { | ||
| const entry = focusMenus.value.find(({ plugin: { id } }) => id === openId) | ||
|
|
||
| if (entry) { | ||
| focusOpen.value = openId | ||
| openInMoveHandle(openId, true) | ||
| } | ||
| } | ||
| watch(focusOpen, (focusOpen) => { | ||
| if (focusOpen) { | ||
| openInMoveHandle(focusOpen, true) | ||
| } else { | ||
| coreStore.setMoveHandle(null) | ||
| } | ||
| }) | ||
|
|
||
| function openInMoveHandle(openId: string, focusMenu = false) { | ||
| const menu = (focusMenu ? focusMenus.value : menus.value.flat()).find( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.