@rubixstudios/payload-typesense 1.6.13 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -120
- package/dist/components/HeadlessSearchInput.d.ts.map +1 -1
- package/dist/components/HeadlessSearchInput.js +173 -140
- package/dist/components/ThemeProvider.d.ts +2 -2
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +7 -5
- package/dist/components/icons/clockIcon.d.ts +2 -0
- package/dist/components/icons/clockIcon.d.ts.map +1 -0
- package/dist/components/icons/clockIcon.js +16 -0
- package/dist/components/icons/collectionIcon.d.ts +2 -0
- package/dist/components/icons/collectionIcon.d.ts.map +1 -0
- package/dist/components/icons/collectionIcon.js +16 -0
- package/dist/components/icons/errorIcon.d.ts +2 -0
- package/dist/components/icons/errorIcon.d.ts.map +1 -0
- package/dist/components/icons/errorIcon.js +16 -0
- package/dist/components/icons/index.d.ts +6 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/index.js +5 -0
- package/dist/components/icons/noResultsIcon.d.ts +6 -0
- package/dist/components/icons/noResultsIcon.d.ts.map +1 -0
- package/dist/components/icons/noResultsIcon.js +19 -0
- package/dist/components/icons/searchIcon.d.ts +6 -0
- package/dist/components/icons/searchIcon.d.ts.map +1 -0
- package/dist/components/icons/searchIcon.js +16 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/render/Header.d.ts +3 -3
- package/dist/components/render/Header.d.ts.map +1 -1
- package/dist/components/render/Header.js +29 -26
- package/dist/components/render/NoResults.d.ts +3 -3
- package/dist/components/render/NoResults.d.ts.map +1 -1
- package/dist/components/render/NoResults.js +34 -37
- package/dist/components/render/ResultError.d.ts +3 -3
- package/dist/components/render/ResultError.d.ts.map +1 -1
- package/dist/components/render/ResultError.js +27 -26
- package/dist/components/render/Results.d.ts +4 -4
- package/dist/components/render/Results.d.ts.map +1 -1
- package/dist/components/render/Results.js +140 -136
- package/dist/components/themes/hooks.d.ts +2 -40
- package/dist/components/themes/hooks.d.ts.map +1 -1
- package/dist/components/themes/hooks.js +33 -82
- package/dist/components/themes/themes.d.ts.map +1 -1
- package/dist/components/themes/themes.js +16 -20
- package/dist/components/themes/types.d.ts.map +1 -1
- package/dist/components/themes/utils.d.ts +2 -14
- package/dist/components/themes/utils.d.ts.map +1 -1
- package/dist/components/themes/utils.js +24 -37
- package/dist/endpoints/handler/createAdvancedSearch.d.ts +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.js +72 -8
- package/dist/endpoints/handler/createCollections.d.ts +1 -1
- package/dist/endpoints/handler/createCollections.d.ts.map +1 -1
- package/dist/endpoints/handler/createCollections.js +8 -8
- package/dist/endpoints/handler/createSearch.d.ts +1 -1
- package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createSearch.js +38 -30
- package/dist/endpoints/handler/createSuggest.d.ts +1 -1
- package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
- package/dist/endpoints/handler/createSuggest.js +26 -11
- package/dist/endpoints/health.d.ts +2 -2
- package/dist/endpoints/health.d.ts.map +1 -1
- package/dist/endpoints/health.js +58 -52
- package/dist/endpoints/search.d.ts +2 -9
- package/dist/endpoints/search.d.ts.map +1 -1
- package/dist/endpoints/search.js +17 -16
- package/dist/{utils → hooks}/useDebounce.d.ts.map +1 -1
- package/dist/{utils → hooks}/useDebounce.js +2 -2
- package/dist/{utils → hooks}/useSearch.d.ts.map +1 -1
- package/dist/hooks/useSearch.js +93 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -32
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +54 -25
- package/dist/lib/client.d.ts +1 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +35 -31
- package/dist/lib/headlessSearch.d.ts +24 -20
- package/dist/lib/headlessSearch.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts +3 -11
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +12 -45
- package/dist/lib/initialization.d.ts +1 -1
- package/dist/lib/initialization.d.ts.map +1 -1
- package/dist/lib/initialization.js +51 -49
- package/dist/lib/schema-mapper.d.ts +3 -6
- package/dist/lib/schema-mapper.d.ts.map +1 -1
- package/dist/lib/schema-mapper.js +82 -84
- package/dist/lib/validation.d.ts +26 -34
- package/dist/lib/validation.d.ts.map +1 -1
- package/dist/lib/validation.js +48 -58
- package/dist/types.d.ts +154 -127
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/buildError.d.ts +1 -1
- package/dist/utils/buildError.d.ts.map +1 -1
- package/dist/utils/buildError.js +2 -2
- package/dist/utils/ensureCollection.d.ts +2 -2
- package/dist/utils/ensureCollection.d.ts.map +1 -1
- package/dist/utils/ensureCollection.js +103 -23
- package/dist/utils/extractText.d.ts.map +1 -1
- package/dist/utils/extractText.js +11 -8
- package/dist/utils/getCacheStats.d.ts.map +1 -1
- package/dist/utils/getCacheStats.js +1 -8
- package/dist/utils/getCollectionInfo.js +1 -1
- package/dist/utils/{getAllCollections.d.ts → getCollections.d.ts} +2 -2
- package/dist/utils/getCollections.d.ts.map +1 -0
- package/dist/utils/getCollections.js +140 -0
- package/dist/utils/keyboard.d.ts +4 -4
- package/dist/utils/keyboard.d.ts.map +1 -1
- package/dist/utils/keyboard.js +20 -22
- package/dist/utils/sortResults.d.ts +3 -0
- package/dist/utils/sortResults.d.ts.map +1 -0
- package/dist/utils/sortResults.js +73 -0
- package/dist/utils/vectorSearch.d.ts +3 -2
- package/dist/utils/vectorSearch.d.ts.map +1 -1
- package/dist/utils/vectorSearch.js +9 -7
- package/package.json +9 -9
- package/dist/utils/getAllCollections.d.ts.map +0 -1
- package/dist/utils/getAllCollections.js +0 -103
- package/dist/utils/useSearch.js +0 -66
- /package/dist/{utils → hooks}/useDebounce.d.ts +0 -0
- /package/dist/{utils → hooks}/useSearch.d.ts +0 -0
|
@@ -1,144 +1,148 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ClockIcon, CollectionIcon } from '../icons/index.js';
|
|
3
|
+
export function RenderedResult({ index, onResultClick, onResultHover, renderDate = true, result, resultItemClassName = '', resultsContainerClassName = '', themeConfig }) {
|
|
4
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
4
5
|
className: resultsContainerClassName,
|
|
5
6
|
style: {
|
|
6
7
|
backgroundColor: themeConfig.theme.colors.resultBackground,
|
|
7
8
|
borderBottom: `1px solid ${themeConfig.theme.colors.resultBorder}`,
|
|
8
9
|
cursor: 'pointer',
|
|
9
10
|
transition: themeConfig.config.enableAnimations !== false ? `all ${themeConfig.theme.animations.transitionFast} ${themeConfig.theme.animations.easeInOut}` : 'none'
|
|
10
|
-
}
|
|
11
|
-
}, /*#__PURE__*/ React.createElement("div", {
|
|
12
|
-
className: `${themeConfig.classes.resultItem} ${resultItemClassName}`,
|
|
13
|
-
"data-result-item": true,
|
|
14
|
-
key: result.document?.id || result.id || index,
|
|
15
|
-
onBlur: (e)=>{
|
|
16
|
-
e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackground;
|
|
17
11
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
12
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
13
|
+
className: `${themeConfig.classes.resultItem} ${resultItemClassName}`,
|
|
14
|
+
"data-result-item": true,
|
|
15
|
+
onBlur: (e)=>{
|
|
16
|
+
e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackground;
|
|
17
|
+
},
|
|
18
|
+
onClick: ()=>onResultClick(result),
|
|
19
|
+
onFocus: (e)=>{
|
|
20
|
+
e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackgroundFocus;
|
|
21
|
+
},
|
|
22
|
+
onKeyDown: (e)=>{
|
|
23
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
onResultClick(result);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
onMouseEnter: (event)=>{
|
|
29
|
+
event.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackgroundHover;
|
|
30
|
+
onResultHover?.(result);
|
|
31
|
+
},
|
|
32
|
+
onMouseLeave: (e)=>{
|
|
33
|
+
e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackground;
|
|
34
|
+
},
|
|
35
|
+
role: "button",
|
|
36
|
+
tabIndex: 0,
|
|
37
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
38
|
+
style: {
|
|
39
|
+
alignItems: 'flex-start',
|
|
40
|
+
display: 'flex',
|
|
41
|
+
gap: '12px',
|
|
42
|
+
overflow: 'hidden',
|
|
43
|
+
padding: '6px'
|
|
44
|
+
},
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ _jsx("div", {
|
|
47
|
+
style: {
|
|
48
|
+
flexShrink: 0
|
|
49
|
+
},
|
|
50
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
51
|
+
style: {
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
backgroundColor: themeConfig.theme.colors.collectionBadge,
|
|
54
|
+
borderRadius: themeConfig.theme.spacing.inputBorderRadius,
|
|
55
|
+
color: themeConfig.theme.colors.collectionBadgeText,
|
|
56
|
+
display: 'flex',
|
|
57
|
+
fontSize: themeConfig.theme.typography.fontSizeBase,
|
|
58
|
+
fontWeight: themeConfig.theme.typography.fontWeightMedium,
|
|
59
|
+
height: '32px',
|
|
60
|
+
justifyContent: 'center',
|
|
61
|
+
width: '32px'
|
|
62
|
+
},
|
|
63
|
+
children: result.collection?.charAt(0).toUpperCase() || '📄'
|
|
64
|
+
})
|
|
65
|
+
}),
|
|
66
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
67
|
+
style: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
minWidth: 0
|
|
70
|
+
},
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ _jsx("div", {
|
|
73
|
+
style: {
|
|
74
|
+
alignItems: 'center',
|
|
75
|
+
display: 'flex',
|
|
76
|
+
justifyContent: 'space-between',
|
|
77
|
+
marginBottom: '8px'
|
|
78
|
+
},
|
|
79
|
+
children: /*#__PURE__*/ _jsx("h3", {
|
|
80
|
+
style: {
|
|
81
|
+
color: themeConfig.theme.colors.titleText,
|
|
82
|
+
fontFamily: themeConfig.theme.typography.fontFamily,
|
|
83
|
+
fontSize: themeConfig.theme.typography.fontSizeBase,
|
|
84
|
+
fontWeight: themeConfig.theme.typography.fontWeightSemibold,
|
|
85
|
+
lineHeight: themeConfig.theme.typography.lineHeightTight,
|
|
86
|
+
margin: 0,
|
|
87
|
+
overflow: 'hidden',
|
|
88
|
+
textOverflow: 'ellipsis',
|
|
89
|
+
whiteSpace: 'nowrap'
|
|
90
|
+
},
|
|
91
|
+
children: result.document?.title || result.document?.name || result.title || 'Untitled'
|
|
92
|
+
})
|
|
93
|
+
}),
|
|
94
|
+
(result.highlight?.title?.snippet || result.highlight?.content?.snippet) && /*#__PURE__*/ _jsx("div", {
|
|
95
|
+
dangerouslySetInnerHTML: {
|
|
96
|
+
__html: result.highlight?.title?.snippet || result.highlight?.content?.snippet || ''
|
|
97
|
+
},
|
|
98
|
+
style: {
|
|
99
|
+
color: themeConfig.theme.colors.descriptionText,
|
|
100
|
+
display: '-webkit-box',
|
|
101
|
+
fontSize: themeConfig.theme.typography.fontSizeSm,
|
|
102
|
+
fontWeight: themeConfig.theme.typography.fontWeightNormal,
|
|
103
|
+
lineHeight: themeConfig.theme.typography.lineHeightNormal,
|
|
104
|
+
marginTop: '4px',
|
|
105
|
+
overflow: 'hidden',
|
|
106
|
+
WebkitBoxOrient: 'vertical',
|
|
107
|
+
WebkitLineClamp: 2
|
|
108
|
+
}
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
111
|
+
style: {
|
|
112
|
+
alignItems: 'center',
|
|
113
|
+
color: themeConfig.theme.colors.metaText,
|
|
114
|
+
display: 'flex',
|
|
115
|
+
fontSize: themeConfig.theme.typography.fontSizeXs,
|
|
116
|
+
gap: '12px',
|
|
117
|
+
marginTop: '8px'
|
|
118
|
+
},
|
|
119
|
+
children: [
|
|
120
|
+
result.collection && /*#__PURE__*/ _jsxs("span", {
|
|
121
|
+
style: {
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
display: 'inline-flex'
|
|
124
|
+
},
|
|
125
|
+
children: [
|
|
126
|
+
/*#__PURE__*/ _jsx(CollectionIcon, {}),
|
|
127
|
+
result.collection
|
|
128
|
+
]
|
|
129
|
+
}),
|
|
130
|
+
renderDate && (result.document?.updatedAt || result.updatedAt) && /*#__PURE__*/ _jsxs("span", {
|
|
131
|
+
style: {
|
|
132
|
+
alignItems: 'center',
|
|
133
|
+
display: 'inline-flex'
|
|
134
|
+
},
|
|
135
|
+
children: [
|
|
136
|
+
/*#__PURE__*/ _jsx(ClockIcon, {}),
|
|
137
|
+
new Date(result.document?.updatedAt || result.updatedAt).toLocaleDateString()
|
|
138
|
+
]
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
})
|
|
144
|
+
]
|
|
145
|
+
})
|
|
146
|
+
}, result.document?.id || result.id || index)
|
|
147
|
+
});
|
|
144
148
|
}
|
|
@@ -1,52 +1,14 @@
|
|
|
1
1
|
import { type Theme, type ThemeConfig, type ThemeContextValue } from './types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Hook to access theme context
|
|
5
|
-
*/
|
|
6
|
-
export declare function useTheme(): ThemeContextValue;
|
|
7
|
-
/**
|
|
8
|
-
* Hook to create theme configuration
|
|
9
|
-
*/
|
|
2
|
+
import { generateThemeClasses } from './utils.js';
|
|
10
3
|
export declare function useThemeConfig(config: ThemeConfig): ThemeContextValue;
|
|
11
|
-
/**
|
|
12
|
-
* Hook to apply theme styles to CSS variables
|
|
13
|
-
*/
|
|
14
4
|
export declare function useThemeStyles(config: ThemeConfig): Record<string, string>;
|
|
15
|
-
/**
|
|
16
|
-
* Hook to get responsive theme configuration
|
|
17
|
-
*/
|
|
18
5
|
export declare function useResponsiveTheme(baseConfig: ThemeConfig, isMobile: boolean): ThemeConfig;
|
|
19
|
-
/**
|
|
20
|
-
* Hook to toggle between light and dark themes
|
|
21
|
-
*/
|
|
22
6
|
export declare function useThemeToggle(lightConfig: ThemeConfig, darkConfig: ThemeConfig, isDark: boolean): ThemeConfig;
|
|
23
|
-
|
|
24
|
-
* Hook to create theme-aware CSS classes
|
|
25
|
-
*/
|
|
26
|
-
export declare function useThemeClasses(config: ThemeConfig): Record<string, string>;
|
|
27
|
-
/**
|
|
28
|
-
* Hook to get theme-aware color values
|
|
29
|
-
*/
|
|
7
|
+
export declare function useThemeClasses(config: ThemeConfig): ReturnType<typeof generateThemeClasses>;
|
|
30
8
|
export declare function useThemeColors(config: ThemeConfig): Theme['colors'];
|
|
31
|
-
/**
|
|
32
|
-
* Hook to get theme-aware spacing values
|
|
33
|
-
*/
|
|
34
9
|
export declare function useThemeSpacing(config: ThemeConfig): Theme['spacing'];
|
|
35
|
-
/**
|
|
36
|
-
* Hook to get theme-aware typography values
|
|
37
|
-
*/
|
|
38
10
|
export declare function useThemeTypography(config: ThemeConfig): Theme['typography'];
|
|
39
|
-
/**
|
|
40
|
-
* Hook to detect system theme preference
|
|
41
|
-
*/
|
|
42
11
|
export declare function useSystemTheme(): 'dark' | 'light';
|
|
43
|
-
/**
|
|
44
|
-
* Hook to create auto theme configuration based on system preference
|
|
45
|
-
*/
|
|
46
12
|
export declare function useAutoTheme(lightTheme: string, darkTheme: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Hook to create theme with custom overrides
|
|
49
|
-
*/
|
|
50
13
|
export declare function useCustomTheme(baseThemeName: string, overrides: Partial<ThemeConfig>): ThemeConfig;
|
|
51
|
-
export { ThemeContext };
|
|
52
14
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/themes/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/themes/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACjF,OAAO,EAEL,oBAAoB,EAKrB,MAAM,YAAY,CAAA;AAoBnB,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,CAoBrE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM1E;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,WAAW,CAwB1F;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,OAAO,GACd,WAAW,CAEb;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAM5F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAMnE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAMrE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAM3E;AAED,wBAAgB,cAAc,IAAI,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,GAC9B,WAAW,CAQb"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { useCallback, useMemo, useSyncExternalStore } from 'react';
|
|
3
3
|
import { applyTheme, generateThemeClasses, getThemeVariables, isDarkTheme, isLightTheme, mergeThemeConfig } from './utils.js';
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/ export function useTheme() {
|
|
8
|
-
const context = useContext(ThemeContext);
|
|
9
|
-
if (!context) {
|
|
10
|
-
throw new Error('useTheme must be used within a ThemeProvider');
|
|
11
|
-
}
|
|
12
|
-
return context;
|
|
4
|
+
const SYSTEM_THEME_QUERY = '(prefers-color-scheme: dark)';
|
|
5
|
+
function getSystemTheme() {
|
|
6
|
+
return window.matchMedia(SYSTEM_THEME_QUERY).matches ? 'dark' : 'light';
|
|
13
7
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
function getServerTheme() {
|
|
9
|
+
return 'light';
|
|
10
|
+
}
|
|
11
|
+
function subscribeSystemTheme(callback) {
|
|
12
|
+
const media = window.matchMedia(SYSTEM_THEME_QUERY);
|
|
13
|
+
media.addEventListener('change', callback);
|
|
14
|
+
return ()=>media.removeEventListener('change', callback);
|
|
15
|
+
}
|
|
16
|
+
export function useThemeConfig(config) {
|
|
17
17
|
const theme = useMemo(()=>mergeThemeConfig(config), [
|
|
18
18
|
config
|
|
19
19
|
]);
|
|
@@ -38,9 +38,7 @@ const ThemeContext = createContext(null);
|
|
|
38
38
|
applyThemeToElement
|
|
39
39
|
]);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
* Hook to apply theme styles to CSS variables
|
|
43
|
-
*/ export function useThemeStyles(config) {
|
|
41
|
+
export function useThemeStyles(config) {
|
|
44
42
|
return useMemo(()=>{
|
|
45
43
|
const theme = mergeThemeConfig(config);
|
|
46
44
|
return getThemeVariables(theme);
|
|
@@ -48,68 +46,45 @@ const ThemeContext = createContext(null);
|
|
|
48
46
|
config
|
|
49
47
|
]);
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
* Hook to get responsive theme configuration
|
|
53
|
-
*/ export function useResponsiveTheme(baseConfig, isMobile) {
|
|
49
|
+
export function useResponsiveTheme(baseConfig, isMobile) {
|
|
54
50
|
return useMemo(()=>{
|
|
55
|
-
if (!baseConfig.responsive) {
|
|
51
|
+
if (!baseConfig.responsive || !isMobile) {
|
|
56
52
|
return baseConfig;
|
|
57
53
|
}
|
|
58
|
-
|
|
54
|
+
return {
|
|
59
55
|
...baseConfig,
|
|
60
56
|
spacing: {
|
|
61
57
|
...baseConfig.spacing,
|
|
62
|
-
// Adjust spacing for mobile
|
|
63
58
|
headerPadding: '0.75rem 1rem',
|
|
64
59
|
inputFontSize: '16px',
|
|
65
60
|
inputPadding: '0.875rem 1rem',
|
|
66
61
|
itemPadding: '0.875rem 1rem',
|
|
67
62
|
resultsMaxHeight: '20rem'
|
|
68
63
|
},
|
|
69
|
-
|
|
70
|
-
animations: isMobile ? {
|
|
64
|
+
animations: {
|
|
71
65
|
...baseConfig.animations,
|
|
72
66
|
transitionFast: '0s',
|
|
73
67
|
transitionNormal: '0s',
|
|
74
68
|
transitionSlow: '0s'
|
|
75
|
-
}
|
|
69
|
+
}
|
|
76
70
|
};
|
|
77
|
-
return mobileConfig;
|
|
78
71
|
}, [
|
|
79
72
|
baseConfig,
|
|
80
73
|
isMobile
|
|
81
74
|
]);
|
|
82
75
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*/ export function useThemeToggle(lightConfig, darkConfig, isDark) {
|
|
86
|
-
return useMemo(()=>{
|
|
87
|
-
return isDark ? darkConfig : lightConfig;
|
|
88
|
-
}, [
|
|
89
|
-
lightConfig,
|
|
90
|
-
darkConfig,
|
|
91
|
-
isDark
|
|
92
|
-
]);
|
|
76
|
+
export function useThemeToggle(lightConfig, darkConfig, isDark) {
|
|
77
|
+
return isDark ? darkConfig : lightConfig;
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
* Hook to create theme-aware CSS classes
|
|
96
|
-
*/ export function useThemeClasses(config) {
|
|
79
|
+
export function useThemeClasses(config) {
|
|
97
80
|
return useMemo(()=>{
|
|
98
81
|
const theme = mergeThemeConfig(config);
|
|
99
|
-
|
|
100
|
-
// Convert to a more usable format
|
|
101
|
-
const classMap = {};
|
|
102
|
-
Object.entries(classes).forEach(([key, value])=>{
|
|
103
|
-
classMap[key] = value;
|
|
104
|
-
});
|
|
105
|
-
return classMap;
|
|
82
|
+
return generateThemeClasses(theme, config);
|
|
106
83
|
}, [
|
|
107
84
|
config
|
|
108
85
|
]);
|
|
109
86
|
}
|
|
110
|
-
|
|
111
|
-
* Hook to get theme-aware color values
|
|
112
|
-
*/ export function useThemeColors(config) {
|
|
87
|
+
export function useThemeColors(config) {
|
|
113
88
|
return useMemo(()=>{
|
|
114
89
|
const theme = mergeThemeConfig(config);
|
|
115
90
|
return theme.colors;
|
|
@@ -117,9 +92,7 @@ const ThemeContext = createContext(null);
|
|
|
117
92
|
config
|
|
118
93
|
]);
|
|
119
94
|
}
|
|
120
|
-
|
|
121
|
-
* Hook to get theme-aware spacing values
|
|
122
|
-
*/ export function useThemeSpacing(config) {
|
|
95
|
+
export function useThemeSpacing(config) {
|
|
123
96
|
return useMemo(()=>{
|
|
124
97
|
const theme = mergeThemeConfig(config);
|
|
125
98
|
return theme.spacing;
|
|
@@ -127,9 +100,7 @@ const ThemeContext = createContext(null);
|
|
|
127
100
|
config
|
|
128
101
|
]);
|
|
129
102
|
}
|
|
130
|
-
|
|
131
|
-
* Hook to get theme-aware typography values
|
|
132
|
-
*/ export function useThemeTypography(config) {
|
|
103
|
+
export function useThemeTypography(config) {
|
|
133
104
|
return useMemo(()=>{
|
|
134
105
|
const theme = mergeThemeConfig(config);
|
|
135
106
|
return theme.typography;
|
|
@@ -137,39 +108,19 @@ const ThemeContext = createContext(null);
|
|
|
137
108
|
config
|
|
138
109
|
]);
|
|
139
110
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*/ export function useSystemTheme() {
|
|
143
|
-
return useMemo(()=>{
|
|
144
|
-
if (typeof window === 'undefined') {
|
|
145
|
-
return 'light';
|
|
146
|
-
}
|
|
147
|
-
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
148
|
-
}, []);
|
|
111
|
+
export function useSystemTheme() {
|
|
112
|
+
return useSyncExternalStore(subscribeSystemTheme, getSystemTheme, getServerTheme);
|
|
149
113
|
}
|
|
150
|
-
|
|
151
|
-
* Hook to create auto theme configuration based on system preference
|
|
152
|
-
*/ export function useAutoTheme(lightTheme, darkTheme) {
|
|
114
|
+
export function useAutoTheme(lightTheme, darkTheme) {
|
|
153
115
|
const systemTheme = useSystemTheme();
|
|
154
|
-
return
|
|
155
|
-
return systemTheme === 'dark' ? darkTheme : lightTheme;
|
|
156
|
-
}, [
|
|
157
|
-
systemTheme,
|
|
158
|
-
lightTheme,
|
|
159
|
-
darkTheme
|
|
160
|
-
]);
|
|
116
|
+
return systemTheme === 'dark' ? darkTheme : lightTheme;
|
|
161
117
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*/ export function useCustomTheme(baseThemeName, overrides) {
|
|
165
|
-
return useMemo(()=>{
|
|
166
|
-
return {
|
|
118
|
+
export function useCustomTheme(baseThemeName, overrides) {
|
|
119
|
+
return useMemo(()=>({
|
|
167
120
|
theme: baseThemeName,
|
|
168
121
|
...overrides
|
|
169
|
-
}
|
|
170
|
-
}, [
|
|
122
|
+
}), [
|
|
171
123
|
baseThemeName,
|
|
172
124
|
overrides
|
|
173
125
|
]);
|
|
174
126
|
}
|
|
175
|
-
export { ThemeContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"themes.d.ts","sourceRoot":"","sources":["../../../src/components/themes/themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"themes.d.ts","sourceRoot":"","sources":["../../../src/components/themes/themes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AA0DvC,eAAO,MAAM,WAAW,EAAE,KAqDzB,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAqDvB,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAGxC,CAAA;AAED,eAAO,MAAM,YAAY,OAAc,CAAA"}
|