@rubixstudios/payload-typesense 1.6.12 → 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.
Files changed (125) hide show
  1. package/README.md +76 -120
  2. package/dist/components/HeadlessSearchInput.d.ts.map +1 -1
  3. package/dist/components/HeadlessSearchInput.js +174 -142
  4. package/dist/components/ThemeProvider.d.ts +3 -3
  5. package/dist/components/ThemeProvider.d.ts.map +1 -1
  6. package/dist/components/ThemeProvider.js +6 -5
  7. package/dist/components/icons/clockIcon.d.ts +2 -0
  8. package/dist/components/icons/clockIcon.d.ts.map +1 -0
  9. package/dist/components/icons/clockIcon.js +16 -0
  10. package/dist/components/icons/collectionIcon.d.ts +2 -0
  11. package/dist/components/icons/collectionIcon.d.ts.map +1 -0
  12. package/dist/components/icons/collectionIcon.js +16 -0
  13. package/dist/components/icons/errorIcon.d.ts +2 -0
  14. package/dist/components/icons/errorIcon.d.ts.map +1 -0
  15. package/dist/components/icons/errorIcon.js +16 -0
  16. package/dist/components/icons/index.d.ts +6 -0
  17. package/dist/components/icons/index.d.ts.map +1 -0
  18. package/dist/components/icons/index.js +5 -0
  19. package/dist/components/icons/noResultsIcon.d.ts +6 -0
  20. package/dist/components/icons/noResultsIcon.d.ts.map +1 -0
  21. package/dist/components/icons/noResultsIcon.js +19 -0
  22. package/dist/components/icons/searchIcon.d.ts +6 -0
  23. package/dist/components/icons/searchIcon.d.ts.map +1 -0
  24. package/dist/components/icons/searchIcon.js +16 -0
  25. package/dist/components/index.d.ts +2 -1
  26. package/dist/components/index.d.ts.map +1 -1
  27. package/dist/components/index.js +2 -1
  28. package/dist/components/render/Header.d.ts +3 -3
  29. package/dist/components/render/Header.d.ts.map +1 -1
  30. package/dist/components/render/Header.js +29 -26
  31. package/dist/components/render/NoResults.d.ts +3 -3
  32. package/dist/components/render/NoResults.d.ts.map +1 -1
  33. package/dist/components/render/NoResults.js +34 -37
  34. package/dist/components/render/ResultError.d.ts +3 -3
  35. package/dist/components/render/ResultError.d.ts.map +1 -1
  36. package/dist/components/render/ResultError.js +27 -26
  37. package/dist/components/render/Results.d.ts +4 -4
  38. package/dist/components/render/Results.d.ts.map +1 -1
  39. package/dist/components/render/Results.js +140 -136
  40. package/dist/components/themes/hooks.d.ts +2 -40
  41. package/dist/components/themes/hooks.d.ts.map +1 -1
  42. package/dist/components/themes/hooks.js +33 -82
  43. package/dist/components/themes/themes.d.ts.map +1 -1
  44. package/dist/components/themes/themes.js +16 -20
  45. package/dist/components/themes/types.d.ts.map +1 -1
  46. package/dist/components/themes/utils.d.ts +2 -14
  47. package/dist/components/themes/utils.d.ts.map +1 -1
  48. package/dist/components/themes/utils.js +24 -37
  49. package/dist/endpoints/handler/createAdvancedSearch.d.ts +1 -1
  50. package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
  51. package/dist/endpoints/handler/createAdvancedSearch.js +72 -8
  52. package/dist/endpoints/handler/createCollections.d.ts +1 -1
  53. package/dist/endpoints/handler/createCollections.d.ts.map +1 -1
  54. package/dist/endpoints/handler/createCollections.js +8 -8
  55. package/dist/endpoints/handler/createSearch.d.ts +1 -1
  56. package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
  57. package/dist/endpoints/handler/createSearch.js +45 -44
  58. package/dist/endpoints/handler/createSuggest.d.ts +1 -1
  59. package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
  60. package/dist/endpoints/handler/createSuggest.js +26 -11
  61. package/dist/endpoints/health.d.ts +2 -2
  62. package/dist/endpoints/health.d.ts.map +1 -1
  63. package/dist/endpoints/health.js +58 -52
  64. package/dist/endpoints/search.d.ts +2 -9
  65. package/dist/endpoints/search.d.ts.map +1 -1
  66. package/dist/endpoints/search.js +17 -16
  67. package/dist/{utils → hooks}/useDebounce.d.ts.map +1 -1
  68. package/dist/{utils → hooks}/useDebounce.js +2 -2
  69. package/dist/{utils → hooks}/useSearch.d.ts.map +1 -1
  70. package/dist/hooks/useSearch.js +93 -0
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +38 -32
  73. package/dist/lib/cache.d.ts.map +1 -1
  74. package/dist/lib/cache.js +54 -25
  75. package/dist/lib/client.d.ts +1 -1
  76. package/dist/lib/client.d.ts.map +1 -1
  77. package/dist/lib/client.js +35 -31
  78. package/dist/lib/headlessSearch.d.ts +24 -20
  79. package/dist/lib/headlessSearch.d.ts.map +1 -1
  80. package/dist/lib/hooks.d.ts +3 -11
  81. package/dist/lib/hooks.d.ts.map +1 -1
  82. package/dist/lib/hooks.js +12 -45
  83. package/dist/lib/initialization.d.ts +1 -1
  84. package/dist/lib/initialization.d.ts.map +1 -1
  85. package/dist/lib/initialization.js +51 -49
  86. package/dist/lib/schema-mapper.d.ts +3 -6
  87. package/dist/lib/schema-mapper.d.ts.map +1 -1
  88. package/dist/lib/schema-mapper.js +82 -84
  89. package/dist/lib/validation.d.ts +26 -34
  90. package/dist/lib/validation.d.ts.map +1 -1
  91. package/dist/lib/validation.js +48 -58
  92. package/dist/types.d.ts +154 -127
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +1 -1
  95. package/dist/utils/buildError.d.ts +1 -1
  96. package/dist/utils/buildError.d.ts.map +1 -1
  97. package/dist/utils/buildError.js +2 -2
  98. package/dist/utils/ensureCollection.d.ts +2 -2
  99. package/dist/utils/ensureCollection.d.ts.map +1 -1
  100. package/dist/utils/ensureCollection.js +103 -23
  101. package/dist/utils/extractText.d.ts.map +1 -1
  102. package/dist/utils/extractText.js +11 -8
  103. package/dist/utils/getCacheStats.d.ts.map +1 -1
  104. package/dist/utils/getCacheStats.js +1 -8
  105. package/dist/utils/getCollectionInfo.d.ts.map +1 -1
  106. package/dist/utils/getCollectionInfo.js +1 -1
  107. package/dist/utils/{getAllCollections.d.ts → getCollections.d.ts} +2 -2
  108. package/dist/utils/getCollections.d.ts.map +1 -0
  109. package/dist/utils/getCollections.js +140 -0
  110. package/dist/utils/keyboard.d.ts +4 -4
  111. package/dist/utils/keyboard.d.ts.map +1 -1
  112. package/dist/utils/keyboard.js +20 -22
  113. package/dist/utils/sortResults.d.ts +3 -0
  114. package/dist/utils/sortResults.d.ts.map +1 -0
  115. package/dist/utils/sortResults.js +73 -0
  116. package/dist/utils/testConnection.d.ts.map +1 -1
  117. package/dist/utils/vectorSearch.d.ts +3 -2
  118. package/dist/utils/vectorSearch.d.ts.map +1 -1
  119. package/dist/utils/vectorSearch.js +9 -7
  120. package/package.json +14 -14
  121. package/dist/utils/getAllCollections.d.ts.map +0 -1
  122. package/dist/utils/getAllCollections.js +0 -103
  123. package/dist/utils/useSearch.js +0 -66
  124. /package/dist/{utils → hooks}/useDebounce.d.ts +0 -0
  125. /package/dist/{utils → hooks}/useSearch.d.ts +0 -0
@@ -1,144 +1,148 @@
1
- import React from 'react';
2
- export function RenderedResult({ index, onResultClick, renderDate = true, result, resultItemClassName = '', resultsContainerClassName = '', themeConfig }) {
3
- return /*#__PURE__*/ React.createElement("div", {
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
- 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: (e)=>{
29
- e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackgroundHover;
30
- },
31
- onMouseLeave: (e)=>{
32
- e.currentTarget.style.backgroundColor = themeConfig.theme.colors.resultBackground;
33
- },
34
- role: "button",
35
- tabIndex: 0
36
- }, /*#__PURE__*/ React.createElement("div", {
37
- style: {
38
- alignItems: 'flex-start',
39
- display: 'flex',
40
- gap: '12px',
41
- overflow: 'hidden',
42
- padding: '6px'
43
- }
44
- }, /*#__PURE__*/ React.createElement("div", {
45
- style: {
46
- flexShrink: 0
47
- }
48
- }, /*#__PURE__*/ React.createElement("div", {
49
- style: {
50
- alignItems: 'center',
51
- backgroundColor: themeConfig.theme.colors.collectionBadge,
52
- borderRadius: themeConfig.theme.spacing.inputBorderRadius,
53
- color: themeConfig.theme.colors.collectionBadgeText,
54
- display: 'flex',
55
- fontSize: themeConfig.theme.typography.fontSizeBase,
56
- fontWeight: themeConfig.theme.typography.fontWeightMedium,
57
- height: '32px',
58
- justifyContent: 'center',
59
- width: '32px'
60
- }
61
- }, result.collection?.charAt(0).toUpperCase() || '📄')), /*#__PURE__*/ React.createElement("div", {
62
- style: {
63
- flex: 1,
64
- minWidth: 0
65
- }
66
- }, /*#__PURE__*/ React.createElement("div", {
67
- style: {
68
- alignItems: 'center',
69
- display: 'flex',
70
- justifyContent: 'space-between',
71
- marginBottom: '8px'
72
- }
73
- }, /*#__PURE__*/ React.createElement("h3", {
74
- style: {
75
- color: themeConfig.theme.colors.titleText,
76
- fontFamily: themeConfig.theme.typography.fontFamily,
77
- fontSize: themeConfig.theme.typography.fontSizeBase,
78
- fontWeight: themeConfig.theme.typography.fontWeightSemibold,
79
- lineHeight: themeConfig.theme.typography.lineHeightTight,
80
- margin: 0,
81
- overflow: 'hidden',
82
- textOverflow: 'ellipsis',
83
- whiteSpace: 'nowrap'
84
- }
85
- }, result.document?.title || result.document?.name || result.title || 'Untitled')), (result.highlight?.title?.snippet || result.highlight?.content?.snippet) && /*#__PURE__*/ React.createElement("div", {
86
- dangerouslySetInnerHTML: {
87
- __html: result.highlight?.title?.snippet || result.highlight?.content?.snippet || ''
88
- },
89
- style: {
90
- color: themeConfig.theme.colors.descriptionText,
91
- display: '-webkit-box',
92
- fontSize: themeConfig.theme.typography.fontSizeSm,
93
- fontWeight: themeConfig.theme.typography.fontWeightNormal,
94
- lineHeight: themeConfig.theme.typography.lineHeightNormal,
95
- marginTop: '4px',
96
- overflow: 'hidden',
97
- WebkitBoxOrient: 'vertical',
98
- WebkitLineClamp: 2
99
- }
100
- }), /*#__PURE__*/ React.createElement("div", {
101
- style: {
102
- alignItems: 'center',
103
- color: themeConfig.theme.colors.metaText,
104
- display: 'flex',
105
- fontSize: themeConfig.theme.typography.fontSizeXs,
106
- gap: '12px',
107
- marginTop: '8px'
108
- }
109
- }, result.collection && /*#__PURE__*/ React.createElement("span", {
110
- style: {
111
- alignItems: 'center',
112
- display: 'inline-flex'
113
- }
114
- }, /*#__PURE__*/ React.createElement("svg", {
115
- fill: "currentColor",
116
- style: {
117
- height: '12px',
118
- marginRight: '4px',
119
- width: '12px'
120
- },
121
- viewBox: "0 0 20 20"
122
- }, /*#__PURE__*/ React.createElement("path", {
123
- clipRule: "evenodd",
124
- d: "M3 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z",
125
- fillRule: "evenodd"
126
- })), result.collection), renderDate && (result.document?.updatedAt || result.updatedAt) && /*#__PURE__*/ React.createElement("span", {
127
- style: {
128
- alignItems: 'center',
129
- display: 'inline-flex'
130
- }
131
- }, /*#__PURE__*/ React.createElement("svg", {
132
- fill: "currentColor",
133
- style: {
134
- height: '12px',
135
- marginRight: '4px',
136
- width: '12px'
137
- },
138
- viewBox: "0 0 20 20"
139
- }, /*#__PURE__*/ React.createElement("path", {
140
- clipRule: "evenodd",
141
- d: "M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z",
142
- fillRule: "evenodd"
143
- })), new Date(result.document?.updatedAt || result.updatedAt).toLocaleDateString()))))));
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
- declare const ThemeContext: import("react").Context<ThemeContextValue | null>;
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;AAUjF,QAAA,MAAM,YAAY,mDAAgD,CAAA;AAElE;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,CAoBrE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK1E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,WAAW,CA8B1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,OAAO,GACd,WAAW,CAIb;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc3E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAKnE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAKrE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAK3E;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,OAAO,CAQjD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,GAC9B,WAAW,CAOb;AAED,OAAO,EAAE,YAAY,EAAE,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 { createContext, useCallback, useContext, useMemo } from 'react';
2
+ import { useCallback, useMemo, useSyncExternalStore } from 'react';
3
3
  import { applyTheme, generateThemeClasses, getThemeVariables, isDarkTheme, isLightTheme, mergeThemeConfig } from './utils.js';
4
- const ThemeContext = createContext(null);
5
- /**
6
- * Hook to access theme context
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
- * Hook to create theme configuration
16
- */ export function useThemeConfig(config) {
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
- const mobileConfig = {
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
- // Disable animations on mobile for better performance
70
- animations: isMobile ? {
64
+ animations: {
71
65
  ...baseConfig.animations,
72
66
  transitionFast: '0s',
73
67
  transitionNormal: '0s',
74
68
  transitionSlow: '0s'
75
- } : baseConfig.animations
69
+ }
76
70
  };
77
- return mobileConfig;
78
71
  }, [
79
72
  baseConfig,
80
73
  isMobile
81
74
  ]);
82
75
  }
83
- /**
84
- * Hook to toggle between light and dark themes
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
- const classes = generateThemeClasses(theme, config);
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
- * Hook to detect system theme preference
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 useMemo(()=>{
155
- return systemTheme === 'dark' ? darkTheme : lightTheme;
156
- }, [
157
- systemTheme,
158
- lightTheme,
159
- darkTheme
160
- ]);
116
+ return systemTheme === 'dark' ? darkTheme : lightTheme;
161
117
  }
162
- /**
163
- * Hook to create theme with custom overrides
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;AA2DvC,eAAO,MAAM,WAAW,EAAE,KAqDzB,CAAA;AAGD,eAAO,MAAM,SAAS,EAAE,KAqDvB,CAAA;AAGD,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAGxC,CAAA;AAGD,eAAO,MAAM,YAAY,OAAc,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"}