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

fix: fix the error when starting the saas official website #2594

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Dec 3, 2024

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)

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:

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

Release Notes

  • New Features

    • Introduced a new theme configuration with multilingual support, including properties for ID, name, and CSS.
  • Bug Fixes

    • Streamlined theme-switching functionality for improved management of CSS styles.
  • Chores

    • Removed several unused theme files and exports to declutter the codebase, including tinyBaseAuroraTheme, deepTheme, galaxyTheme, impressionTheme, infinityTheme, and tinyBaseSmbTheme.
    • Deleted the flattenObject utility function as it was no longer needed.

Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

This pull request introduces a new default export in old-theme-index.js that defines a theme configuration object with multilingual support. It also modifies the TinyThemeTool class in theme-tool.js to streamline theme management and introduces a new import for the tinyOldTheme. Several theme-related files are deleted, including those for themes that were previously defined as empty objects, along with the removal of the flattenObject utility function. These changes collectively simplify the theme system and its management.

Changes

File Path Change Summary
packages/theme-saas/src/old-theme-index.js New default export: { id: 'tiny-old-theme', name: 'OldTheme', cnName: '旧的主题', css: `` }
packages/theme-saas/src/theme-tool.js - New import and export of tinyOldTheme
- Constructor simplified (removed styleSheetId)
- Updated changeTheme method to accept target parameter and utilize CSSStyleSheet API.
packages/theme-saas/src/theme/aurora-theme/index.js Export removed: export const tinyBaseAuroraTheme = {} (file deleted)
packages/theme-saas/src/theme/deep-theme/index.js Export removed: export const deepTheme = {} (file deleted)
packages/theme-saas/src/theme/galaxy-theme/index.js Export removed: export const galaxyTheme = {} (file deleted)
packages/theme-saas/src/theme/impression-theme/index.js Export removed: export const impressionTheme = {} (file deleted)
packages/theme-saas/src/theme/infinity-theme/index.js Export removed: export const infinityTheme = {} (file deleted)
packages/theme-saas/src/theme/smb-theme/index.js Export removed: export const tinyBaseSmbTheme = {} (file deleted)
packages/theme-saas/src/theme/index.js Multiple theme exports removed, including tinyImpressionTheme, tinyInfinityTheme, etc. (file deleted)
packages/theme-saas/src/theme/utils.js Function removed: export function flattenObject(obj) (file deleted)

Possibly related PRs

Suggested labels

bug

🐇 In the meadow where themes play,
A new old friend has come to stay.
With colors bright and names so fine,
The rabbit hops, "Oh, how divine!"
The old themes gone, but not in vain,
A simpler path we now obtain! 🌈


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 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 bug Something isn't working label Dec 3, 2024
Copy link

github-actions bot commented Dec 3, 2024

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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

Reviewing files that changed from the base of the PR and between 60e5402 and c8215b2.

📒 Files selected for processing (10)
  • packages/theme-saas/src/old-theme-index.js (1 hunks)
  • packages/theme-saas/src/theme-tool.js (1 hunks)
  • packages/theme-saas/src/theme/aurora-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/deep-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/galaxy-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/impression-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/infinity-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/smb-theme/index.js (0 hunks)
  • packages/theme-saas/src/theme/utils.js (0 hunks)
💤 Files with no reviewable changes (8)
  • packages/theme-saas/src/theme/deep-theme/index.js
  • packages/theme-saas/src/theme/galaxy-theme/index.js
  • packages/theme-saas/src/theme/utils.js
  • packages/theme-saas/src/theme/smb-theme/index.js
  • packages/theme-saas/src/theme/infinity-theme/index.js
  • packages/theme-saas/src/theme/impression-theme/index.js
  • packages/theme-saas/src/theme/aurora-theme/index.js
  • packages/theme-saas/src/theme/index.js

Comment on lines +16 to +38
changeTheme(theme, target = document) {
let loadedSheet = this.loaded[target]
if (!loadedSheet) {
loadedSheet = new CSSStyleSheet()
target.adoptedStyleSheets = [...target.adoptedStyleSheets, loadedSheet]
this.loaded[target] = loadedSheet
}
this.contentElement.textContent = this.formatCSSVariables(currentTheme.data)

this.contentElement.setAttribute('tiny-theme', this.currentTheme.id)
}
if (theme && (theme.data || theme.css)) {
let cssContent = ''
if (theme.data && typeof theme.data === 'object') {
cssContent = Object.keys(theme.data)
.map((key) => `--${key}: ${theme.data[key]}; `)
.join('')

// 通过 `组件css变量`,来推导出组件名: 从 ti-checkbox-button-bg-color, 推导出 checkbox-button
findClassName(name) {
const compNameList = name.split('-')
if (compNameList.length < 2) {
return false
}
const compLength = definedComponents.length
let compName = ''
for (let i = 0; i < compLength; i++) {
// 先试试是不是双段式的组件名: 比如dialog-box 这种
if (definedComponents[i] === `${compNameList[1]}-${compNameList[2]}`) {
compName = `tiny-${definedComponents[i]}`
break
cssContent = `:root{${cssContent}}`
}
}
// 不是双段的组件,则取第一位为组件名
if (!compName) {
compName = `tiny-${compNameList[1]}`
}

// 提高权重,促使主题变换成功
compName = `${compName}[class*=tiny]`
return compName
}

formatCSSVariables(themeData) {
const componentsMap = {}
let rootCssVar = 'html:root {'
let componentsCssVar = ''

Object.keys(themeData).forEach((item) => {
const isBaseCssVar = item.startsWith('ti-base') || item.startsWith('ti-common')
if (isBaseCssVar) {
rootCssVar += `--${item}:${themeData[item]};`
} else {
const classkey = this.findClassName(item)
if (classkey) {
if (componentsMap[classkey]) {
componentsMap[classkey].push(`--${item}:${themeData[item]};`)
} else {
componentsMap[classkey] = [`--${item}:${themeData[item]};`]
}
}
if (theme.css && typeof theme.css === 'string') {
cssContent += theme.css
}
})

Object.keys(componentsMap).forEach((item) => {
componentsCssVar += `.${item}{${componentsMap[item].join('')}}`
})

return `${rootCssVar}}${componentsCssVar}`
loadedSheet.replaceSync(cssContent)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure cross-browser compatibility for adoptedStyleSheets and CSSStyleSheet

The use of CSSStyleSheet and adoptedStyleSheets is not supported in all browsers, such as older versions of Safari and Firefox. This could cause the theme switching functionality to fail or lead to runtime errors in unsupported browsers.

Consider adding a fallback mechanism for browsers that do not support these features. You can check for support and use a <style> element as a fallback. Apply this diff to implement the fallback:

 changeTheme(theme, target = document) {
   let loadedSheet = this.loaded[target]
   if (!loadedSheet) {
-    loadedSheet = new CSSStyleSheet()
-    target.adoptedStyleSheets = [...target.adoptedStyleSheets, loadedSheet]
+    if ('adoptedStyleSheets' in Document.prototype && 'replaceSync' in CSSStyleSheet.prototype) {
+      loadedSheet = new CSSStyleSheet()
+      target.adoptedStyleSheets = [...target.adoptedStyleSheets, loadedSheet]
+    } else {
+      loadedSheet = document.createElement('style')
+      target.head.appendChild(loadedSheet)
+    }
     this.loaded[target] = loadedSheet
   }

   if (theme && (theme.data || theme.css)) {
     let cssContent = ''
     if (theme.data && typeof theme.data === 'object') {
       cssContent = Object.keys(theme.data)
         .map((key) => `--${key}: ${theme.data[key]}; `)
         .join('')
       cssContent = `:root{${cssContent}}`
     }
     if (theme.css && typeof theme.css === 'string') {
       cssContent += theme.css
     }
-    loadedSheet.replaceSync(cssContent)
+    if (loadedSheet.replaceSync) {
+      loadedSheet.replaceSync(cssContent)
+    } else {
+      loadedSheet.textContent = cssContent
+    }
   }
 }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
changeTheme(theme, target = document) {
let loadedSheet = this.loaded[target]
if (!loadedSheet) {
loadedSheet = new CSSStyleSheet()
target.adoptedStyleSheets = [...target.adoptedStyleSheets, loadedSheet]
this.loaded[target] = loadedSheet
}
this.contentElement.textContent = this.formatCSSVariables(currentTheme.data)
this.contentElement.setAttribute('tiny-theme', this.currentTheme.id)
}
if (theme && (theme.data || theme.css)) {
let cssContent = ''
if (theme.data && typeof theme.data === 'object') {
cssContent = Object.keys(theme.data)
.map((key) => `--${key}: ${theme.data[key]}; `)
.join('')
// 通过 `组件css变量`,来推导出组件名: 从 ti-checkbox-button-bg-color, 推导出 checkbox-button
findClassName(name) {
const compNameList = name.split('-')
if (compNameList.length < 2) {
return false
}
const compLength = definedComponents.length
let compName = ''
for (let i = 0; i < compLength; i++) {
// 先试试是不是双段式的组件名: 比如dialog-box 这种
if (definedComponents[i] === `${compNameList[1]}-${compNameList[2]}`) {
compName = `tiny-${definedComponents[i]}`
break
cssContent = `:root{${cssContent}}`
}
}
// 不是双段的组件,则取第一位为组件名
if (!compName) {
compName = `tiny-${compNameList[1]}`
}
// 提高权重,促使主题变换成功
compName = `${compName}[class*=tiny]`
return compName
}
formatCSSVariables(themeData) {
const componentsMap = {}
let rootCssVar = 'html:root {'
let componentsCssVar = ''
Object.keys(themeData).forEach((item) => {
const isBaseCssVar = item.startsWith('ti-base') || item.startsWith('ti-common')
if (isBaseCssVar) {
rootCssVar += `--${item}:${themeData[item]};`
} else {
const classkey = this.findClassName(item)
if (classkey) {
if (componentsMap[classkey]) {
componentsMap[classkey].push(`--${item}:${themeData[item]};`)
} else {
componentsMap[classkey] = [`--${item}:${themeData[item]};`]
}
}
if (theme.css && typeof theme.css === 'string') {
cssContent += theme.css
}
})
Object.keys(componentsMap).forEach((item) => {
componentsCssVar += `.${item}{${componentsMap[item].join('')}}`
})
return `${rootCssVar}}${componentsCssVar}`
loadedSheet.replaceSync(cssContent)
}
changeTheme(theme, target = document) {
let loadedSheet = this.loaded[target]
if (!loadedSheet) {
if ('adoptedStyleSheets' in Document.prototype && 'replaceSync' in CSSStyleSheet.prototype) {
loadedSheet = new CSSStyleSheet()
target.adoptedStyleSheets = [...target.adoptedStyleSheets, loadedSheet]
} else {
loadedSheet = document.createElement('style')
target.head.appendChild(loadedSheet)
}
this.loaded[target] = loadedSheet
}
if (theme && (theme.data || theme.css)) {
let cssContent = ''
if (theme.data && typeof theme.data === 'object') {
cssContent = Object.keys(theme.data)
.map((key) => `--${key}: ${theme.data[key]}; `)
.join('')
cssContent = `:root{${cssContent}}`
}
if (theme.css && typeof theme.css === 'string') {
cssContent += theme.css
}
if (loadedSheet.replaceSync) {
loadedSheet.replaceSync(cssContent)
} else {
loadedSheet.textContent = cssContent
}
}

Comment on lines +1 to +6
export default {
id: 'tiny-old-theme',
name: 'OldTheme',
cnName: '旧的主题',
css: ``
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure that tinyOldTheme contains theme data or CSS

The tinyOldTheme object currently has an empty css string and lacks any data properties. Applying this theme may not result in any style changes since there are no styles or variables defined.

Consider adding relevant data or css content to tinyOldTheme to ensure that it applies the expected styles when used.

@zzcr zzcr merged commit ab2d0c8 into dev Dec 3, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant