-
Notifications
You must be signed in to change notification settings - Fork 19
refactor(genui-sdk-vue): move theme change logic to materials #267
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
gimmyhehe
wants to merge
17
commits into
dev
Choose a base branch
from
materials-theme-switch
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
500dc25
refactor(genui-sdk-vue): move theme change logic to materials
gimmyhehe 4246263
refactor(genui-sdk-vue): update theme application to return structure…
gimmyhehe 9acb6db
fix: enhance theme application with root instance management and dyna…
gimmyhehe 04c6924
fix: optimize materials theme switch
gimmyhehe 063e4f1
Merge remote-tracking branch 'origin/dev' into materials-theme-switch
gimmyhehe 1b23e8f
fix: remove null default value
gimmyhehe e28c8a7
Merge remote-tracking branch 'origin/dev' into materials-theme-switch
gimmyhehe 5b9fa5e
refactor: materials use createTheme factory
gimmyhehe 0c97e51
feat(materials): enhance theme options and update Vite config for Ele…
gimmyhehe b028456
Merge remote-tracking branch 'origin/dev' into materials-theme-switch
gimmyhehe e9c64ab
fix(materials): replace theme creation functions and streamline theme…
gimmyhehe e0cf26c
fix: add sfc component
gimmyhehe 090d09b
fix(materials): update Vite config for theme management and add Theme…
gimmyhehe b4f33e1
fix: rename createTheme to themeFactory
gimmyhehe 0c35032
Merge remote-tracking branch 'origin/dev' into materials-theme-switch
gimmyhehe d4cb170
fix: rename interfaces add "I" prefix
gimmyhehe 3674b20
fix: rename Root to root
gimmyhehe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export type ThemeColorScheme = 'light' | 'dark'; | ||
|
|
||
| export interface ThemeDescriptor { | ||
| id: string; | ||
| colorScheme?: ThemeColorScheme; | ||
| } | ||
|
|
||
| export interface ThemeApplyContext { | ||
| systemColorScheme: ThemeColorScheme; | ||
| } | ||
|
|
||
| export type ThemeDisposer = () => void; | ||
|
|
||
| export interface ThemeApplyResult { | ||
| descriptor: ThemeDescriptor; | ||
| dispose: ThemeDisposer; | ||
| Root?: unknown; | ||
| } | ||
|
|
||
| export interface IMaterialsTheme { | ||
| themes?: ThemeDescriptor[]; | ||
| apply(theme: string, ctx: ThemeApplyContext): ThemeApplyResult; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,55 @@ | ||
| import type { IMaterials } from './materials'; | ||
| import type { IMaterialsTheme } from './materials-theme'; | ||
|
|
||
| export function mergeMaterials(...list: IMaterials[]): IMaterials { | ||
| const result: IMaterials = { | ||
| components: {}, | ||
| defaultPropsMap: {}, | ||
| requiredCompleteFieldSelectors: [], | ||
| const KNOWN_KEYS = ['components', 'requiredCompleteFieldSelectors', 'defaultPropsMap', 'theme']; | ||
|
|
||
| export function mergeMaterials(...sources: (IMaterials | undefined)[]): IMaterials { | ||
| const components: Record<string, unknown> = {}; | ||
| const requiredCompleteFieldSelectors: string[] = []; | ||
| const defaultPropsMap: Record<string, any> = {}; | ||
| const themes: IMaterialsTheme[] = []; | ||
| const seenThemes = new Set<IMaterialsTheme>(); | ||
| const extra: Record<string, unknown> = {}; | ||
|
|
||
| for (const src of sources) { | ||
| if (!src) { | ||
| continue; | ||
| } | ||
| Object.assign(components, src.components ?? {}); | ||
| for (const selector of src.requiredCompleteFieldSelectors ?? []) { | ||
| if (!requiredCompleteFieldSelectors.includes(selector)) { | ||
| requiredCompleteFieldSelectors.push(selector); | ||
| } | ||
| } | ||
| Object.assign(defaultPropsMap, src.defaultPropsMap ?? {}); | ||
| if (src.theme) { | ||
| const arr = Array.isArray(src.theme) ? src.theme : [src.theme]; | ||
| for (const theme of arr) { | ||
| if (theme && !seenThemes.has(theme)) { | ||
| seenThemes.add(theme); | ||
| themes.push(theme); | ||
| } | ||
| } | ||
| } | ||
| for (const key of Object.keys(src)) { | ||
| if (!KNOWN_KEYS.includes(key)) { | ||
| extra[key] = (src as Record<string, unknown>)[key]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const merged: IMaterials = { | ||
| components, | ||
| requiredCompleteFieldSelectors, | ||
| defaultPropsMap, | ||
| ...extra, | ||
| }; | ||
|
|
||
| for (const item of list) { | ||
| if (!item) continue; | ||
| Object.assign(result.components!, item.components ?? {}); | ||
| Object.assign(result.defaultPropsMap!, item.defaultPropsMap ?? {}); | ||
| result.requiredCompleteFieldSelectors!.push( | ||
| ...(item.requiredCompleteFieldSelectors ?? []), | ||
| ); | ||
| if (themes.length === 1) { | ||
| merged.theme = themes[0]; | ||
| } else if (themes.length > 1) { | ||
| merged.theme = themes; | ||
| } | ||
|
|
||
| return result; | ||
| return merged; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
packages/frameworks/vue/src/config-provider/injection-tokens.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| import type { InjectionKey } from 'vue'; | ||
| import type { IMaterials } from '@opentiny/genui-sdk-core'; | ||
| import type { InjectionKey, ComputedRef } from 'vue'; | ||
| import type { IMaterials, ThemeColorScheme } from '@opentiny/genui-sdk-core'; | ||
|
|
||
| export const GENUI_I18N = Symbol('GENUI_I18N'); | ||
| export const GENUI_CONFIG = Symbol('GENUI_CONFIG'); | ||
| export interface GenuiConfigState { | ||
| colorScheme: ThemeColorScheme; | ||
| id: string; | ||
| } | ||
|
|
||
| export const GENUI_I18N = Symbol('GENUI_I18N'); | ||
| export const GENUI_CONFIG: InjectionKey<ComputedRef<GenuiConfigState>> = Symbol('GENUI_CONFIG'); | ||
| export const GENUI_MATERIALS: InjectionKey<IMaterials> = Symbol('GENUI_MATERIALS'); |
2 changes: 2 additions & 0 deletions
2
packages/materials/vue-element-plus/src/materials/materials.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { buildMaterialDefaultValueMap, type IMaterials } from '@opentiny/genui-sdk-core'; | ||
| import { materialsMeta } from '../meta'; | ||
| import { components } from './components'; | ||
| import { createElementPlusMaterialsTheme } from './theme'; | ||
|
|
||
| const standardRequiredCompleteFieldSelectors = ['[componentName=ElCard] > props > shadow']; | ||
|
|
||
| export const materials: IMaterials = { | ||
| components, | ||
| requiredCompleteFieldSelectors: standardRequiredCompleteFieldSelectors, | ||
| defaultPropsMap: buildMaterialDefaultValueMap(materialsMeta), | ||
| theme: createElementPlusMaterialsTheme(), | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.