-
Notifications
You must be signed in to change notification settings - Fork 284
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
Conversation
WalkthroughThis pull request introduces a new default export in Changes
Possibly related PRs
Suggested labels
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
[e2e-test-warn] 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 |
There was a problem hiding this 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
📒 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
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 | |
} | |
} |
export default { | ||
id: 'tiny-old-theme', | ||
name: 'OldTheme', | ||
cnName: '旧的主题', | ||
css: `` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Chores
tinyBaseAuroraTheme
,deepTheme
,galaxyTheme
,impressionTheme
,infinityTheme
, andtinyBaseSmbTheme
.flattenObject
utility function as it was no longer needed.