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(video-module): 为视频元素添加文本对齐属性 #429

Conversation

arcovery
Copy link
Contributor

@arcovery arcovery commented Dec 10, 2024

Changes Overview

Implementation Approach

Testing Done

Verification Steps

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

Summary by CodeRabbit

  • New Features

    • Introduced a textAlign parameter for video element generation, allowing customization of text alignment.
    • Enhanced parsing of HTML elements to extract and apply text alignment from style attributes.
  • Bug Fixes

    • Improved handling of <iframe> and <video> elements to ensure proper text alignment is applied.

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: 85cce79

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request involve updates to the genVideoElem and parseHtml functions within the parse-elem-html.ts file. A new parameter, textAlign, has been added to the genVideoElem function, defaulting to 'center', and is included in the returned VideoElement object. The parseHtml function now initializes a textAlign variable and extracts its value from the style attributes of parent HTML elements when processing <iframe> or <video> tags, passing it to the genVideoElem function.

Changes

File Path Change Summary
packages/video-module/src/module/parse-elem-html.ts Updated genVideoElem function to include a new textAlign parameter. Modified parseHtml to extract textAlign from style attributes of parent elements.
packages/video-module/tests/parse-html.test.ts Updated test cases for iframe and video elements to include the new textAlign property in expected output, set to 'center'.

Possibly related PRs

Suggested reviewers

  • cycleccc

🐇 In the land of video, where elements play,
A new textAlign joins in the fray.
With center so fine, it takes its stand,
Making sure all looks grand,
From iframes to videos, it’s a sight to see,
A hop and a skip, all aligned perfectly! 🎥✨


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>, 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.

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. (Experiment)
  • @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.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b421815 and e722f90.

📒 Files selected for processing (1)
  • packages/video-module/src/module/parse-elem-html.ts (5 hunks)
🔇 Additional comments (2)
packages/video-module/src/module/parse-elem-html.ts (2)

19-19: Consider alignment handling consistency across modules

The addition of text alignment specifically for video elements raises some architectural considerations:

  1. Does this align with how text alignment is handled in other editor modules?
  2. Should alignment be handled at a higher level in the editor's component hierarchy?

Consider reviewing the alignment implementation in other modules to ensure consistency across the editor.

Also applies to: 29-29, 40-40, 50-50, 70-70

✅ Verification successful

Based on the results, I can now generate the final response:

Text alignment implementation follows established patterns

The codebase shows consistent text alignment handling:

  • Video module aligns with the basic-modules' justify functionality, both using the textAlign property
  • The justify module (basic-modules/src/modules/justify/style-to-html.ts) appears to be the core text alignment handler
  • Text alignment is consistently handled at the element level with proper HTML attribute management
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar text alignment handling in other modules
rg -g "**/*.ts" "textAlign.*=.*'center'" -B 2 -A 2

# Search for other alignment-related code
ast-grep --pattern 'interface $_ {
  $$$
  textAlign: $_
  $$$
}'

Length of output: 2769


19-19: Verify VideoElement interface update

The textAlign property has been added to the function signature and return object. Please ensure that the VideoElement interface in custom-types.ts has been updated to include this new property.

Also applies to: 29-29

✅ Verification successful

VideoElement interface already includes textAlign property

The VideoElement interface in packages/video-module/src/module/custom-types.ts has already been updated to include the textAlign property:

export type VideoElement = {
  type: 'video'
  key?: string
  src: string
  poster?: string
  textAlign?: string  // <-- Property exists
  width?: string
  height?: string
  style?: videoStyle
  children: EmptyText[]
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for VideoElement interface definition
ast-grep --pattern 'interface VideoElement {
  $$$
}'

# Alternatively, search for the type definition file
rg -t typescript "interface VideoElement" -A 10

Length of output: 140


Script:

#!/bin/bash
# Search for interface or type definitions related to VideoElement
rg "VideoElement" --type ts -A 10

# Search for files that might contain type definitions
fd "types?.ts$" --type f

Length of output: 19542

@arcovery arcovery closed this Dec 11, 2024
@arcovery arcovery force-pushed the 428-bug-视频未按照设置对齐方式回显-默认显示居中(center) branch from dd9a06c to b421815 Compare December 11, 2024 17:06
- ��ㄨВ���瑙�棰����绱� HTML ��讹��浼����浜������榻���瑰�������峰����昏��
- 姝や慨��逛娇寰�瑙�棰����绱���互姝g‘��扮户��跨�跺��绱���������榻���瑰��
- ��存�颁����稿�虫��璇���ㄤ��锛�澧����浜�瀵规����榻�灞���х��妫����
- wangeditor-next#428
@arcovery arcovery reopened this Dec 11, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
packages/video-module/src/module/parse-elem-html.ts (1)

50-51: Consider extracting text alignment logic to reduce duplication

While the implementation is correct, the text alignment extraction logic is duplicated between the iframe and video sections.

Consider extracting this logic into a helper function:

function getTextAlign($elem: JQuery): string {
  return styleStringToObject($elem.attr('style') || '')['text-align'] || 'center'
}

// Usage:
textAlign = getTextAlign($elem)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e722f90 and 85cce79.

📒 Files selected for processing (2)
  • packages/video-module/__tests__/parse-html.test.ts (2 hunks)
  • packages/video-module/src/module/parse-elem-html.ts (5 hunks)
🔇 Additional comments (4)
packages/video-module/src/module/parse-elem-html.ts (2)

19-19: LGTM: Function signature and return object updates are consistent

The addition of the textAlign parameter with a default value of 'center' and its inclusion in the return object aligns well with the PR objectives.

Also applies to: 29-29


40-40: LGTM: Variable initialization is consistent

The initialization of textAlign with a default value of 'center' matches the default in genVideoElem.

packages/video-module/__tests__/parse-html.test.ts (2)

79-79: LGTM: Test case properly verifies text alignment

The test case correctly verifies that the text alignment is extracted and included in the parsed output.


103-103: LGTM: Test coverage is comprehensive

The video test case maintains consistency with the iframe test case and properly verifies the text alignment functionality.

@cycleccc cycleccc merged commit cb16457 into wangeditor-next:master Dec 13, 2024
4 checks passed
@cycleccc
Copy link
Collaborator

测试了没问题,方便的话可以给 video module 加上对应的 align hoverbar ,照着 image module 相似的仿一下就行,或是我后面加上,哈哈😄

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.

2 participants