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

feat: add teleportRootEl config #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

CNlitai
Copy link

@CNlitai CNlitai commented May 18, 2024

Description 描述

增加teleportRootEl,解决uni在小程序中使用layout无法添加page-meta来解决滚动穿透问题

Linked Issues 关联的 Issues

#34

Additional context 额外上下文

Summary by CodeRabbit

  • New Features

    • Added a toggle button to the main page for showing/hiding content.
    • Introduced new styles for long content blocks.
  • Improvements

    • Enhanced page layout handling with dynamic overflow control based on toggle state.
  • Bug Fixes

    • Corrected page URLs for better navigation consistency.
  • Configuration

    • Updated configuration to support dynamic root element teleportation.

Copy link

coderabbitai bot commented May 18, 2024

Walkthrough

This update introduces a new reactive variable popShow and a corresponding function to toggle its value in the Vue component of the index page. It also modifies the Vite configuration to dynamically adjust the page overflow style based on popShow. Additionally, there are updates to type declarations and template handling to support this functionality.

Changes

File Path Change Summary
playground/src/pages/index/... Added popShow variable, handleChange function, button to toggle popShow, and new CSS style for long-block.
playground/src/uni-pages.d.ts Updated URLs to include a leading slash.
playground/vite.config.ts Modified UniLayouts call to include teleportRootEl with dynamic page overflow style.
src/context.ts Added a conditional block to handle teleportRootEl in the Context class.
src/types.ts Updated ResolvedOptions interface to include teleportRootEl property.

In the land of code, where changes bloom,
A rabbit hops, dispelling gloom.
With popShow toggles and styles anew,
The pages now dance in a vibrant hue.
🐇✨ The code evolves, a joyous spree,
With every change, more harmony.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between eb9eabc and 6d97c37.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (5)
  • playground/src/pages/index/index.vue (2 hunks)
  • playground/src/uni-pages.d.ts (1 hunks)
  • playground/vite.config.ts (1 hunks)
  • src/context.ts (1 hunks)
  • src/types.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • playground/src/uni-pages.d.ts
Additional comments not posted (3)
playground/vite.config.ts (1)

16-16: Ensure the dynamic behavior of teleportRootEl is tested across different platforms and scenarios.

src/types.ts (1)

21-21: The addition of teleportRootEl to ResolvedOptions is correctly implemented.

playground/src/pages/index/index.vue (1)

53-54: The CSS for long-block is correctly added to handle specific layout requirements.

Comment on lines +8 to +11
const popShow = ref<boolean>(true);
function handleChange() {
popShow.value = !popShow.value;
}
Copy link

Choose a reason for hiding this comment

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

Ensure that the function handleChange and variable popShow are adequately commented to explain their purpose in the UI interaction.

+ // `popShow` controls the visibility of the page meta style.
+ // `handleChange` toggles the `popShow` state.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const popShow = ref<boolean>(true);
function handleChange() {
popShow.value = !popShow.value;
}
// `popShow` controls the visibility of the page meta style.
const popShow = ref<boolean>(true);
// `handleChange` toggles the `popShow` state.
function handleChange() {
popShow.value = !popShow.value;
}

Comment on lines +111 to +115
if (this.options.teleportRootEl) {
ms.overwrite(sfc.template?.loc.start.offset, sfc.template?.loc.end.offset, `\n${this.options.teleportRootEl}\n<layout-${pageLayout?.kebabName}-uni ${pageLayoutProps.join(' ')}>${sfc.template.content}</layout-${pageLayout?.kebabName}-uni>\n`)
} else {
ms.overwrite(sfc.template?.loc.start.offset, sfc.template?.loc.end.offset, `<layout-${pageLayout?.kebabName}-uni ${pageLayoutProps.join(' ')}>${sfc.template.content}</layout-${pageLayout?.kebabName}-uni>\n`)
}
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Missing Test Cases for teleportRootEl

The search did not find any test cases handling teleportRootEl. It is crucial to add tests to ensure comprehensive coverage, especially for edge cases where teleportRootEl might be undefined or have unexpected values.

  • Add test cases in test/context.test.ts to cover scenarios with and without teleportRootEl.
Analysis chain

The conditional handling of teleportRootEl is implemented correctly. Ensure comprehensive testing, especially for edge cases where teleportRootEl might be undefined or have unexpected values.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of `teleportRootEl` for edge cases.

# Test: Search for edge cases in the usage of `teleportRootEl`.
rg --type ts $'teleportRootEl'

Length of output: 555



Script:

#!/bin/bash
# Description: Search for test cases or usage examples handling `teleportRootEl`.

# Search for test files or directories
test_files=$(fd --type f --name "*.test.ts")

# Search for `teleportRootEl` usage in test files
for file in $test_files; do
  rg --type ts 'teleportRootEl' "$file"
done

Length of output: 298



Script:

#!/bin/bash
# Description: Search for test cases or usage examples handling `teleportRootEl`.

# Search for test files or directories
test_files=$(fd --type f '.test.ts')

# Search for `teleportRootEl` usage in test files
for file in $test_files; do
  rg --type ts 'teleportRootEl' "$file"
done

Length of output: 1142

@KeJunMao
Copy link
Member

KeJunMao commented May 19, 2024

hi,感谢 PR, 当前的实现不是很优雅,如果是我的话,我应该会直接支持类似如下的方法(也许还有更好的),需要 @ModyQyW 来讨论下~

// 约定一个特殊的 slot,(不知道能不能实现)
<template>
    <template #layout:after>
        <page-meta />
    </template>
	<template #header>
        layout 的 header 插槽
    </template>
	<view>...page code</view>
    <template #footer>
        layout 的 footer 插槽
    </template>
<template>

正好,顺便可以直接支持一下不使用 uni-layout 组件的情况下直接使用 layout 的插槽?

@CNlitai
Copy link
Author

CNlitai commented May 19, 2024

hi,感谢 PR, 当前的实现不是很优雅,如果是我的话,我应该会直接支持类似如下的方法(也许还有更好的),需要 @ModyQyW 来讨论下~

// 约定一个特殊的 slot,(不知道能不能实现)
<template>
    <template #layout:after>
        <page-meta />
    </template>
	<template #header>
        layout 的 header 插槽
    </template>
	<view>...page code</view>
    <template #footer>
        layout 的 footer 插槽
    </template>
<template>

正好,顺便可以直接支持一下不使用 uni-layout 组件的情况下直接使用 layout 的插槽?

我试着改一下

@ModyQyW
Copy link
Member

ModyQyW commented May 21, 2024

hi,感谢 PR, 当前的实现不是很优雅,如果是我的话,我应该会直接支持类似如下的方法(也许还有更好的),需要 @ModyQyW 来讨论下~

// 约定一个特殊的 slot,(不知道能不能实现)
<template>
    <template #layout:after>
        <page-meta />
    </template>
	<template #header>
        layout 的 header 插槽
    </template>
	<view>...page code</view>
    <template #footer>
        layout 的 footer 插槽
    </template>
<template>

正好,顺便可以直接支持一下不使用 uni-layout 组件的情况下直接使用 layout 的插槽?

我的想法大致和这里一致。我感觉这里应该是写错了,不是 #layout:after 而是 #layout:before( 必须是页面第一个元素)。如果可以,同时支持 #layout:before 和 #layout:after 会更好。可以先尝试一下看看,不确定能不能实现🤔

@norangit
Copy link

有更新吗?有同样需求

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

Successfully merging this pull request may close these issues.

4 participants