Skip to content

feat: add plugin panel displays or hides plugin #1322

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

SonyLeo
Copy link
Contributor

@SonyLeo SonyLeo commented Apr 22, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

目前不支持插件面板的显示与隐藏

Issue Number: N/A

What is the new behavior?

支持插件面板的显示与隐藏

入口:点击右上角 ... 按钮
步骤:点击按钮,展示左侧面板和右侧面板,悬浮对应的面板,展示对应侧的面板列表

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Introduced a toolbar toggle feature enabling users to show or hide plugins via a dedicated button.
    • Added a dropdown menu for managing visibility of left and right side panel plugins with individual toggles.
  • Enhancements
    • Enhanced toolbar with a plugin toggle button for streamlined plugin management.
    • Improved UI with visual indicators reflecting active plugin states.

Copy link
Contributor

coderabbitai bot commented Apr 22, 2025

Walkthrough

This update introduces a new toolbar plugin called PluginToggle to the project. The plugin is implemented as a Vue component with supporting composable logic, metadata, and styles, and is packaged as @opentiny/tiny-engine-toolbar-plugin-toggle. Integration occurs across the codebase: the plugin is registered in the toolbar configuration, exported via the design core package, and made available through aliasing in both development and TypeScript configurations. The plugin provides a UI for toggling the visibility of left and right panel plugins, with dropdown menus and submenu interactions.

Changes

File(s) Change Summary
designer-demo/registry.js Added PluginToggle to imports, toolbar configuration, and exports.
packages/design-core/index.js Re-exported PluginToggle from the new toolbar plugin package.
packages/design-core/package.json Added @opentiny/tiny-engine-toolbar-plugin-toggle as a dependency.
packages/build/vite-config/src/vite-plugins/devAliasPlugin.js
tsconfig.app.json
Added alias for @opentiny/tiny-engine-toolbar-plugin-toggle for dev and TypeScript.
packages/layout/src/Main.vue Added title property to plugin objects in setup function.
packages/toolbars/plugin-toggle/index.ts
meta.js
src/Main.vue
src/composable/index.ts
vite.config.ts
Introduced new toolbar plugin: entry file, metadata, Vue component, composable, and Vite config.
packages/toolbars/plugin-toggle/package.json New package declaration for the toolbar plugin.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Toolbar as PluginToggle Toolbar
    participant PluginMenu as Plugin Menu
    participant Layout as Layout API

    User->>Toolbar: Clicks PluginToggle button
    Toolbar->>PluginMenu: Show dropdown menu
    User->>PluginMenu: Hover left/right panel item
    PluginMenu->>PluginMenu: Show submenu with plugins
    User->>PluginMenu: Clicks a plugin item
    PluginMenu->>Layout: Toggle plugin visibility
    Layout-->>PluginMenu: Update state
    PluginMenu-->>Toolbar: Update menu/checkmark
Loading

Poem

🐇
A toggle appears in the toolbar bright,
With menus that open, left and right.
Plugins now dance at a rabbit’s command,
Hide or reveal them with a gentle hand.
In dropdowns and submenus, features abound—
Hopping with joy, new toggles are found!
🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6dc460a and 16527b3.

📒 Files selected for processing (1)
  • packages/toolbars/plugin-toggle/vite.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/toolbars/plugin-toggle/vite.config.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request label Apr 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (9)
packages/toolbars/plugin-toggle/meta.js (1)

1-12: Metadata configuration follows the project's conventions

The metadata is properly structured with the correct ID format, type, title, and rendering options. The configuration sets it to render as an icon and be initially collapsed, which aligns with the PR description.

Consider adding a descriptive title that better reflects the component's purpose of toggling plugin panels, which would improve discoverability in the UI.

-  title: 'pluginToggle',
+  title: 'Toggle Plugin Panels',
packages/toolbars/plugin-toggle/src/Main.vue (4)

3-3: Consider internationalization for UI text.

The UI text "插件显示隐藏" (Plugin Show/Hide) is hardcoded in Chinese. Consider using internationalization to support multiple languages.

-    <ToolbarBase content="插件显示隐藏" :icon="options.icon.default || options.icon" :options="options" />
+    <ToolbarBase :content="$t('toolbar.pluginToggle')" :icon="options.icon.default || options.icon" :options="options" />

7-10: Consider internationalization for menu items.

Menu item texts are hardcoded in Chinese. Consider using internationalization for better maintainability and multilingual support.

-        <span>左侧面板</span>
+        <span>{{ $t('toolbar.leftPanel') }}</span>

...

-        <span>右侧面板</span>
+        <span>{{ $t('toolbar.rightPanel') }}</span>

Also applies to: 28-31


11-26: Add keyboard navigation for improved accessibility.

The current implementation only supports mouse interactions. Consider adding keyboard navigation for better accessibility.

Add keyboard support by implementing arrow key navigation, ENTER for selection, and ESC to close the menu:

    <div v-if="isMenuVisible" class="plugin-menu" :style="menuPosition" @click.stop
+        @keydown.down.prevent="navigateMenu('next')"
+        @keydown.up.prevent="navigateMenu('prev')"
+        @keydown.enter.prevent="selectFocusedItem"
+        @keydown.esc.prevent="closeMenu"
+        tabindex="0"
+        ref="menuRef">

Add corresponding navigation methods in the composable.

Also applies to: 32-47


90-99: Add aria attributes for improved accessibility.

Enhance accessibility by adding ARIA attributes to the menu components.

.plugin-menu {
  position: fixed;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  min-width: 92px;
  user-select: none;
+  role: "menu";
+  aria-labelledby: "plugin-toggle-button";
}

Also add corresponding aria attributes to menu items.

packages/toolbars/plugin-toggle/src/composable/index.ts (4)

36-39: Avoid hardcoded positioning constants.

The menu positioning constants (MENU_OFFSET and SUBMENU_OFFSET) are hardcoded and may not work well across different screen sizes and layouts.

// 菜单位置的常量
-const MENU_OFFSET = 17
-const SUBMENU_OFFSET = 258
+const MENU_OFFSET = 17
+const SUBMENU_OFFSET = 258
+
+// Responsive positioning based on screen size
+const getResponsiveOffset = (baseOffset: number) => {
+  const screenWidth = window.innerWidth
+  if (screenWidth < 768) {
+    return Math.floor(baseOffset * 0.8)
+  }
+  return baseOffset
+}

Then use getResponsiveOffset(MENU_OFFSET) instead of direct constants in positioning calculations.


66-79: Redundant showMenu method.

The showMenu method is not used anywhere in the code, and its functionality is already covered by toggleMenu.

-// 显示菜单
-const showMenu = (event: MouseEvent) => {
-  if (!toggleRef.value) return
-
-  const rect = toggleRef.value.getBoundingClientRect()
-  menuPosition.value = {
-    position: 'fixed',
-    top: `${rect.top}px`,
-    right: `${window.innerWidth - rect.left + MENU_OFFSET}px`,
-    transform: 'translateX(0)'
-  }
-  isMenuVisible.value = true
-  event.stopPropagation()
-}

Don't forget to remove it from the return object as well:

return {
  isPluginShown,
  isMenuVisible,
  showLeftMenu,
  showRightMenu,
  toggleRef,
  menuPosition,
  leftPlugins,
  rightPlugins,
  submenuStyle,
- showMenu,
  toggleMenu,
  showLeftPlugins,
  showRightPlugins,
  togglePlugin
}

121-133: Add debounce to click handler for better performance.

The handleClickOutside function is attached to document click events and could benefit from debouncing to improve performance.

+import { debounce } from '@opentiny/tiny-engine-utils'

// ...

-const handleClickOutside = (event: MouseEvent) => {
+const handleClickOutside = debounce((event: MouseEvent) => {
  // 检查点击目标是否在菜单区域内
  const isClickInMenu =
    (event.target as Element)?.closest('.plugin-menu') || (event.target as Element)?.closest('.submenu')

  // 如果点击的不是菜单区域,并且不是切换按钮本身,则隐藏菜单
  if (!isClickInMenu && (!toggleRef.value || !toggleRef.value.contains(event.target as Node))) {
    isMenuVisible.value = false
    showLeftMenu.value = false
    showRightMenu.value = false
  }
-}
+}, 50)

135-143: Add window resize event handler for menu repositioning.

The current implementation doesn't handle window resize events, which could cause menu positioning issues.

+const handleResize = debounce(() => {
+  if (isMenuVisible.value && toggleRef.value) {
+    const rect = toggleRef.value.getBoundingClientRect()
+    menuPosition.value = {
+      position: 'fixed',
+      top: `${rect.top}px`,
+      right: `${window.innerWidth - rect.left + MENU_OFFSET}px`,
+      transform: 'translateX(0)'
+    }
+  }
+}, 150)

onMounted(() => {
  document.addEventListener('click', handleClickOutside)
+  window.addEventListener('resize', handleResize)
})

onBeforeUnmount(() => {
  document.removeEventListener('click', handleClickOutside)
+  window.removeEventListener('resize', handleResize)
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9de1275 and a8e5d27.

⛔ Files ignored due to path filters (1)
  • packages/design-core/assets/plugin-toggle.svg is excluded by !**/*.svg
📒 Files selected for processing (12)
  • designer-demo/registry.js (3 hunks)
  • packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1 hunks)
  • packages/design-core/index.js (1 hunks)
  • packages/design-core/package.json (1 hunks)
  • packages/layout/src/Main.vue (1 hunks)
  • packages/toolbars/plugin-toggle/index.ts (1 hunks)
  • packages/toolbars/plugin-toggle/meta.js (1 hunks)
  • packages/toolbars/plugin-toggle/package.json (1 hunks)
  • packages/toolbars/plugin-toggle/src/Main.vue (1 hunks)
  • packages/toolbars/plugin-toggle/src/composable/index.ts (1 hunks)
  • packages/toolbars/plugin-toggle/vite.config.ts (1 hunks)
  • tsconfig.app.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/toolbars/plugin-toggle/src/composable/index.ts (1)
packages/register/src/hooks.ts (1)
  • useLayout (76-76)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (14)
packages/layout/src/Main.vue (1)

112-112: Great addition of title property to support the new plugin toggle feature

Adding the title property from the plugin items will allow the new PluginToggle toolbar component to display meaningful names in its dropdown menus.

packages/design-core/index.js (1)

15-15: Clean export of the new PluginToggle component

This export properly integrates the new plugin toggle feature into the design core package's public API, following the established pattern for toolbar plugins.

packages/design-core/package.json (1)

82-82: Good dependency addition for the new plugin toggle package

The workspace protocol dependency is correctly added and follows the same pattern as other internal dependencies.

packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1)

44-44: Correctly configured development alias for the new plugin toggle package

The alias is properly added to the development environment configuration, ensuring consistent imports and module resolution during development.

tsconfig.app.json (1)

49-49: Path alias correctly added for the new plugin toggle module

The new path alias for "@opentiny/tiny-engine-toolbar-plugin-toggle" follows the established pattern for other toolbar components in the project, making the module properly accessible throughout the codebase.

packages/toolbars/plugin-toggle/index.ts (1)

1-20: Implementation follows standard pattern for toolbar components

The module exports the correct structure with metadata and entry component, consistent with other toolbar components in the project. The file properly imports the Vue component, metadata, and styles.

designer-demo/registry.js (3)

25-25: PluginToggle component correctly imported

The PluginToggle component is properly imported from the main engine package, following the pattern of other toolbar components.


78-78: PluginToggle appropriately added to collapse section

The plugin is correctly positioned in the collapse section of the toolbar layout, which aligns with the PR description of a "..." button that controls panel visibility.


101-101: PluginToggle properly registered in toolbars array

The PluginToggle component is correctly added to the exported toolbars array, making it available to the system alongside other toolbar components.

packages/toolbars/plugin-toggle/vite.config.ts (1)

13-35: Configuration looks good, follows project standards.

The Vite configuration is properly set up for the plugin-toggle toolbar package with appropriate plugins, build options, and external dependencies.

packages/toolbars/plugin-toggle/package.json (1)

1-43: Package configuration is appropriate.

The package structure, dependencies, and configuration follow project standards.

packages/toolbars/plugin-toggle/src/Main.vue (2)

52-82: The script section is well-structured and concise.

The script section effectively imports necessary components, defines props, and extracts the required methods and state from the composable.


84-172: CSS styles are well organized and functional.

The styles provide a clean, consistent interface with appropriate hover effects and visual hierarchy.

packages/toolbars/plugin-toggle/src/composable/index.ts (1)

19-171: Overall, the composable is well structured.

The composable effectively manages the state and behavior of the plugin toggle functionality with good separation of concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant