@wasto/cms-components 1.5.10 → 1.5.12

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 (101) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +181 -51
  3. package/dist/index.d.ts +181 -51
  4. package/dist/index.js +3614 -3015
  5. package/dist/index.mjs +3021 -2418
  6. package/package.json +12 -2
  7. package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
  8. package/src/components/article/Article.tsx +21 -21
  9. package/src/components/article/ArticleCard.tsx +81 -81
  10. package/src/components/article/ArticleExcerpts.tsx +80 -80
  11. package/src/components/article/ArticleList.tsx +114 -114
  12. package/src/components/article/ArticleMarkdown.tsx +170 -170
  13. package/src/components/article/ArticleReaderModal.tsx +93 -93
  14. package/src/components/article/ArticleSingle.tsx +57 -57
  15. package/src/components/bottom-tab/BottomTab.tsx +392 -392
  16. package/src/components/button/Button.tsx +154 -154
  17. package/src/components/challenge/Badges.tsx +84 -84
  18. package/src/components/challenge/BadgesModal.tsx +166 -166
  19. package/src/components/challenge/Challenge.tsx +380 -380
  20. package/src/components/challenge/ChallengeModal.tsx +231 -231
  21. package/src/components/challenge/ChallengeVignette.tsx +249 -249
  22. package/src/components/challenge/ChallengesModal.tsx +243 -243
  23. package/src/components/challenge/QuizModal.tsx +381 -381
  24. package/src/components/challenge/ResultModal.tsx +144 -144
  25. package/src/components/chat/Chat.tsx +928 -928
  26. package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
  27. package/src/components/columns/Columns.tsx +33 -33
  28. package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
  29. package/src/components/content-inset/ContentInset.tsx +33 -33
  30. package/src/components/header/Header.tsx +415 -391
  31. package/src/components/image/Image.tsx +15 -15
  32. package/src/components/image/ImageFrame.tsx +102 -102
  33. package/src/components/image/ImageMedia.tsx +31 -31
  34. package/src/components/image/ImageUrl.tsx +30 -30
  35. package/src/components/locations-map/LocationSheet.tsx +417 -417
  36. package/src/components/locations-map/LocationsMap.native.tsx +260 -260
  37. package/src/components/locations-map/LocationsMap.tsx +13 -13
  38. package/src/components/locations-map/LocationsMap.web.tsx +10 -10
  39. package/src/components/locations-map/LocationsMapShell.tsx +546 -527
  40. package/src/components/locations-map/LocationsMapView.tsx +108 -108
  41. package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
  42. package/src/components/nav-button/NavButton.tsx +59 -59
  43. package/src/components/next-collection/NextCollection.tsx +636 -621
  44. package/src/components/notifications/NotificationsScreen.tsx +247 -247
  45. package/src/components/page/Page.tsx +102 -64
  46. package/src/components/parapraph/Paragraph.tsx +67 -67
  47. package/src/components/profile/ProfileScreen.tsx +236 -236
  48. package/src/components/push/PushTokenRegistrar.tsx +47 -0
  49. package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
  50. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  51. package/src/components/search/Search.tsx +320 -320
  52. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  53. package/src/components/title/Title.tsx +100 -100
  54. package/src/components/vision/Vision.tsx +447 -447
  55. package/src/components/vision/VisionActionCard.tsx +117 -117
  56. package/src/components/vision/VisionCapture.tsx +30 -30
  57. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  58. package/src/contexts/AnnouncementsContext.tsx +171 -171
  59. package/src/contexts/AppDataContext.tsx +458 -0
  60. package/src/contexts/ChallengesContext.tsx +182 -182
  61. package/src/contexts/HeaderConfigContext.tsx +29 -0
  62. package/src/contexts/LocalContext.tsx +227 -227
  63. package/src/contexts/ThemeContext.tsx +37 -37
  64. package/src/contexts/WastoContext.tsx +132 -127
  65. package/src/helpers/blogPost.ts +72 -72
  66. package/src/helpers/generateQuizQuestions.ts +247 -247
  67. package/src/helpers/getContrastColor.ts +18 -18
  68. package/src/helpers/haptics.ts +20 -20
  69. package/src/helpers/hoursSchedule.ts +230 -230
  70. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  71. package/src/helpers/layout.ts +54 -54
  72. package/src/helpers/loadLinearGradient.ts +22 -22
  73. package/src/helpers/mapLocations.ts +170 -0
  74. package/src/helpers/maquetteTheme.ts +76 -76
  75. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  76. package/src/helpers/nextCollection.ts +122 -0
  77. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  78. package/src/helpers/publicMediaUrl.ts +8 -8
  79. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  80. package/src/helpers/systemRoutes.ts +7 -7
  81. package/src/helpers/themeStyles.ts +114 -114
  82. package/src/helpers/ttlCache.ts +41 -0
  83. package/src/helpers/useSafeAreaPadding.ts +14 -14
  84. package/src/hooks/useBadges.ts +100 -100
  85. package/src/hooks/useBlogPosts.ts +109 -105
  86. package/src/hooks/useChallenges.ts +110 -110
  87. package/src/hooks/useCities.ts +56 -56
  88. package/src/hooks/useCityAnnouncements.ts +118 -118
  89. package/src/hooks/useCollectionCalendar.ts +421 -421
  90. package/src/hooks/useColumns.ts +19 -19
  91. package/src/hooks/useConsignes.ts +62 -62
  92. package/src/hooks/useLocations.ts +120 -248
  93. package/src/hooks/useNextCollection.ts +163 -238
  94. package/src/hooks/useRecyclingInfo.ts +90 -90
  95. package/src/hooks/useWastoClient.ts +16 -16
  96. package/src/index.ts +161 -142
  97. package/src/navigation/NavigationContext.tsx +56 -56
  98. package/src/push/registerExpoPushToken.ts +133 -0
  99. package/src/sentry/initSentry.ts +120 -120
  100. package/src/types/Theme.ts +72 -72
  101. package/src/types/css-modules.d.ts +1 -1
package/src/index.ts CHANGED
@@ -1,142 +1,161 @@
1
- export {
2
- Article,
3
- type ArticleProps,
4
- type ArticleDisplayMode
5
- } from "./components/article/Article"
6
- export {
7
- Challenge,
8
- type ChallengeProps
9
- } from "./components/challenge/Challenge"
10
- export {
11
- ChallengeVignette,
12
- type ChallengeVignetteProps
13
- } from "./components/challenge/ChallengeVignette"
14
- export {
15
- Chat,
16
- type ChatProps
17
- } from "./components/chat/Chat"
18
- export {
19
- CollectionCalendar,
20
- type CollectionCalendarProps
21
- } from "./components/collection-calendar/CollectionCalendar"
22
- export {
23
- Columns,
24
- type ColumnsProps,
25
- type ColumnsColumnCount
26
- } from "./components/columns/Columns"
27
- export {
28
- Image,
29
- ImageProps,
30
- } from "./components/image/Image"
31
- export {
32
- LocationsMap,
33
- type LocationsMapProps
34
- } from "./components/locations-map/LocationsMap"
35
- export {
36
- NextCollection,
37
- type NextCollectionProps
38
- } from "./components/next-collection/NextCollection"
39
- export {
40
- Page,
41
- type PageProps
42
- } from "./components/page/Page"
43
- export {
44
- ContentInset,
45
- type ContentInsetProps
46
- } from "./components/content-inset/ContentInset"
47
- export {
48
- Paragraph,
49
- type PararaphProps
50
- } from "./components/parapraph/Paragraph"
51
- export {
52
- RecyclingInfo,
53
- type RecyclingInfoProps
54
- } from "./components/recycling-info/RecyclingInfo"
55
- export {
56
- Search,
57
- type SearchProps
58
- } from "./components/search/Search"
59
- export {
60
- Title,
61
- type TitleProps,
62
- type TitleLevel
63
- } from "./components/title/Title"
64
- export {
65
- Header,
66
- type HeaderProps,
67
- type AppHeaderConfig,
68
- type AppHeaderElement,
69
- type AppHeaderLogoElement,
70
- type AppHeaderTitleElement,
71
- type AppHeaderActionElement,
72
- type AppHeaderSlot,
73
- } from "./components/header/Header"
74
- export {
75
- BottomTab,
76
- type BottomTabProps
77
- } from "./components/bottom-tab/BottomTab"
78
- export {
79
- NotificationsScreen,
80
- } from "./components/notifications/NotificationsScreen"
81
- export {
82
- ProfileScreen,
83
- } from "./components/profile/ProfileScreen"
84
- export {
85
- Vision,
86
- type VisionProps,
87
- type VisionCaptureResult,
88
- } from "./components/vision/Vision"
89
- export {
90
- type VisionSuggestion,
91
- type VisionActionCardProps,
92
- } from "./components/vision/VisionActionCard"
93
-
94
- export {
95
- WastoProvider,
96
- useWasto,
97
- type WastoProviderProps,
98
- type WastoContextType,
99
- } from "./contexts/WastoContext"
100
-
101
- export {
102
- initWastoSentry,
103
- wrapWithSentry,
104
- reportError,
105
- isWastoSentryActive,
106
- type WastoSentryConfig,
107
- type WastoErrorContext,
108
- } from "./sentry/initSentry"
109
-
110
- export { useWastoClient } from "./hooks/useWastoClient"
111
-
112
- export type {
113
- Theme,
114
- ResolvedTheme,
115
- ThemeShadowStyle,
116
- } from "./types/Theme"
117
-
118
- export {
119
- resolveTheme,
120
- cardStyle,
121
- softCardStyle,
122
- groupedSectionStyle,
123
- coloredShadow,
124
- } from "./helpers/themeStyles"
125
-
126
- export {
127
- SPACE,
128
- MAQUETTE_RADII,
129
- MAQUETTE_COLORS,
130
- } from "./helpers/layout"
131
-
132
- export { SYSTEM_ROUTES, type SystemRouteKey } from "./helpers/systemRoutes"
133
-
134
- export { createMaquetteTheme } from "./helpers/maquetteTheme"
135
-
136
- export {
137
- NavigationProvider,
138
- useAppNavigation,
139
- useOptionalAppNavigation,
140
- type NavigationApi,
141
- type NavigationProviderProps,
142
- } from "./navigation/NavigationContext"
1
+ export {
2
+ Article,
3
+ type ArticleProps,
4
+ type ArticleDisplayMode
5
+ } from "./components/article/Article"
6
+ export {
7
+ Challenge,
8
+ type ChallengeProps
9
+ } from "./components/challenge/Challenge"
10
+ export {
11
+ ChallengeVignette,
12
+ type ChallengeVignetteProps
13
+ } from "./components/challenge/ChallengeVignette"
14
+ export {
15
+ Chat,
16
+ type ChatProps
17
+ } from "./components/chat/Chat"
18
+ export {
19
+ CollectionCalendar,
20
+ type CollectionCalendarProps
21
+ } from "./components/collection-calendar/CollectionCalendar"
22
+ export {
23
+ Columns,
24
+ type ColumnsProps,
25
+ type ColumnsColumnCount
26
+ } from "./components/columns/Columns"
27
+ export {
28
+ Image,
29
+ ImageProps,
30
+ } from "./components/image/Image"
31
+ export {
32
+ LocationsMap,
33
+ type LocationsMapProps
34
+ } from "./components/locations-map/LocationsMap"
35
+ export {
36
+ NextCollection,
37
+ type NextCollectionProps
38
+ } from "./components/next-collection/NextCollection"
39
+ export {
40
+ Page,
41
+ type PageProps
42
+ } from "./components/page/Page"
43
+ export {
44
+ ContentInset,
45
+ type ContentInsetProps
46
+ } from "./components/content-inset/ContentInset"
47
+ export {
48
+ Paragraph,
49
+ type PararaphProps
50
+ } from "./components/parapraph/Paragraph"
51
+ export {
52
+ RecyclingInfo,
53
+ type RecyclingInfoProps
54
+ } from "./components/recycling-info/RecyclingInfo"
55
+ export {
56
+ Search,
57
+ type SearchProps
58
+ } from "./components/search/Search"
59
+ export {
60
+ Title,
61
+ type TitleProps,
62
+ type TitleLevel
63
+ } from "./components/title/Title"
64
+ export {
65
+ Header,
66
+ DEFAULT_HEADER_ACTIONS,
67
+ type HeaderProps,
68
+ type AppHeaderConfig,
69
+ type AppHeaderElement,
70
+ type AppHeaderLogoElement,
71
+ type AppHeaderTitleElement,
72
+ type AppHeaderActionElement,
73
+ type AppHeaderSlot,
74
+ } from "./components/header/Header"
75
+ export {
76
+ BottomTab,
77
+ type BottomTabProps
78
+ } from "./components/bottom-tab/BottomTab"
79
+ export {
80
+ NotificationsScreen,
81
+ } from "./components/notifications/NotificationsScreen"
82
+ export {
83
+ ProfileScreen,
84
+ } from "./components/profile/ProfileScreen"
85
+ export {
86
+ Vision,
87
+ type VisionProps,
88
+ type VisionCaptureResult,
89
+ } from "./components/vision/Vision"
90
+ export {
91
+ type VisionSuggestion,
92
+ type VisionActionCardProps,
93
+ } from "./components/vision/VisionActionCard"
94
+
95
+ export {
96
+ WastoProvider,
97
+ useWasto,
98
+ type WastoProviderProps,
99
+ type WastoContextType,
100
+ } from "./contexts/WastoContext"
101
+
102
+ export {
103
+ HeaderConfigProvider,
104
+ useHeaderConfig,
105
+ type HeaderConfigProviderProps,
106
+ } from "./contexts/HeaderConfigContext"
107
+
108
+ export {
109
+ useAppData,
110
+ useOptionalAppData,
111
+ NEXT_EVENTS_DAY_RADIUS,
112
+ type AppDataContextType,
113
+ } from "./contexts/AppDataContext"
114
+
115
+ export {
116
+ initWastoSentry,
117
+ wrapWithSentry,
118
+ reportError,
119
+ isWastoSentryActive,
120
+ type WastoSentryConfig,
121
+ type WastoErrorContext,
122
+ } from "./sentry/initSentry"
123
+
124
+ export {
125
+ registerExpoPushToken,
126
+ type RegisterExpoPushTokenOptions,
127
+ } from "./push/registerExpoPushToken"
128
+
129
+ export { useWastoClient } from "./hooks/useWastoClient"
130
+
131
+ export type {
132
+ Theme,
133
+ ResolvedTheme,
134
+ ThemeShadowStyle,
135
+ } from "./types/Theme"
136
+
137
+ export {
138
+ resolveTheme,
139
+ cardStyle,
140
+ softCardStyle,
141
+ groupedSectionStyle,
142
+ coloredShadow,
143
+ } from "./helpers/themeStyles"
144
+
145
+ export {
146
+ SPACE,
147
+ MAQUETTE_RADII,
148
+ MAQUETTE_COLORS,
149
+ } from "./helpers/layout"
150
+
151
+ export { SYSTEM_ROUTES, type SystemRouteKey } from "./helpers/systemRoutes"
152
+
153
+ export { createMaquetteTheme } from "./helpers/maquetteTheme"
154
+
155
+ export {
156
+ NavigationProvider,
157
+ useAppNavigation,
158
+ useOptionalAppNavigation,
159
+ type NavigationApi,
160
+ type NavigationProviderProps,
161
+ } from "./navigation/NavigationContext"
@@ -1,56 +1,56 @@
1
- import {
2
- createContext,
3
- useContext,
4
- useMemo,
5
- type PropsWithChildren,
6
- type ReactNode,
7
- } from "react";
8
-
9
- /**
10
- * Host-agnostic navigation API.
11
- * Expo Router apps pass `router.push` / `router.back`;
12
- * React Navigation apps pass `navigation.navigate` / `goBack`.
13
- */
14
- export type NavigationApi = {
15
- push: (href: string) => void;
16
- canGoBack?: () => boolean;
17
- goBack?: () => void;
18
- };
19
-
20
- const NavigationContext = createContext<NavigationApi | null>(null);
21
-
22
- export type NavigationProviderProps = PropsWithChildren & {
23
- value: NavigationApi;
24
- };
25
-
26
- export function NavigationProvider({ value, children }: NavigationProviderProps): ReactNode {
27
- const memo = useMemo(
28
- () => ({
29
- push: value.push,
30
- canGoBack: value.canGoBack,
31
- goBack: value.goBack,
32
- }),
33
- [value.push, value.canGoBack, value.goBack],
34
- );
35
-
36
- return (
37
- <NavigationContext.Provider value={memo}>
38
- {children}
39
- </NavigationContext.Provider>
40
- );
41
- }
42
-
43
- export function useAppNavigation(): NavigationApi {
44
- const nav = useContext(NavigationContext);
45
- if (!nav) {
46
- throw new Error(
47
- "[cms-components] NavigationProvider is required (wrap the app root).",
48
- );
49
- }
50
- return nav;
51
- }
52
-
53
- /** Soft read — returns null when no provider (e.g. isolated component tests). */
54
- export function useOptionalAppNavigation(): NavigationApi | null {
55
- return useContext(NavigationContext);
56
- }
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ useMemo,
5
+ type PropsWithChildren,
6
+ type ReactNode,
7
+ } from "react";
8
+
9
+ /**
10
+ * Host-agnostic navigation API.
11
+ * Expo Router apps pass `router.push` / `router.back`;
12
+ * React Navigation apps pass `navigation.navigate` / `goBack`.
13
+ */
14
+ export type NavigationApi = {
15
+ push: (href: string) => void;
16
+ canGoBack?: () => boolean;
17
+ goBack?: () => void;
18
+ };
19
+
20
+ const NavigationContext = createContext<NavigationApi | null>(null);
21
+
22
+ export type NavigationProviderProps = PropsWithChildren & {
23
+ value: NavigationApi;
24
+ };
25
+
26
+ export function NavigationProvider({ value, children }: NavigationProviderProps): ReactNode {
27
+ const memo = useMemo(
28
+ () => ({
29
+ push: value.push,
30
+ canGoBack: value.canGoBack,
31
+ goBack: value.goBack,
32
+ }),
33
+ [value.push, value.canGoBack, value.goBack],
34
+ );
35
+
36
+ return (
37
+ <NavigationContext.Provider value={memo}>
38
+ {children}
39
+ </NavigationContext.Provider>
40
+ );
41
+ }
42
+
43
+ export function useAppNavigation(): NavigationApi {
44
+ const nav = useContext(NavigationContext);
45
+ if (!nav) {
46
+ throw new Error(
47
+ "[cms-components] NavigationProvider is required (wrap the app root).",
48
+ );
49
+ }
50
+ return nav;
51
+ }
52
+
53
+ /** Soft read — returns null when no provider (e.g. isolated component tests). */
54
+ export function useOptionalAppNavigation(): NavigationApi | null {
55
+ return useContext(NavigationContext);
56
+ }
@@ -0,0 +1,133 @@
1
+ import { Platform } from "react-native";
2
+
3
+ type NotificationsModule = typeof import("expo-notifications");
4
+
5
+ type ExpoConstantsLike = {
6
+ expoConfig?: {
7
+ extra?: {
8
+ eas?: {
9
+ projectId?: string;
10
+ };
11
+ };
12
+ } | null;
13
+ easConfig?: {
14
+ projectId?: string;
15
+ };
16
+ };
17
+
18
+ let notificationsModule: NotificationsModule | null | undefined;
19
+ let constantsModule: ExpoConstantsLike | null | undefined;
20
+ let handlerConfigured = false;
21
+
22
+ function loadNotifications(): NotificationsModule | null {
23
+ if (notificationsModule !== undefined) return notificationsModule;
24
+ try {
25
+ // Optional peer — apps without the package still load cms-components.
26
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
27
+ notificationsModule = require("expo-notifications") as NotificationsModule;
28
+ } catch {
29
+ notificationsModule = null;
30
+ }
31
+ return notificationsModule;
32
+ }
33
+
34
+ function loadConstants(): ExpoConstantsLike | null {
35
+ if (constantsModule !== undefined) return constantsModule;
36
+ try {
37
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
38
+ const mod = require("expo-constants") as
39
+ | ExpoConstantsLike
40
+ | { default: ExpoConstantsLike };
41
+ constantsModule = "default" in mod && mod.default ? mod.default : (mod as ExpoConstantsLike);
42
+ } catch {
43
+ constantsModule = null;
44
+ }
45
+ return constantsModule;
46
+ }
47
+
48
+ function resolveEasProjectId(): string | null {
49
+ const Constants = loadConstants();
50
+ const fromExtra = Constants?.expoConfig?.extra?.eas?.projectId;
51
+ const fromEasConfig = Constants?.easConfig?.projectId;
52
+ const fromEnv =
53
+ typeof process !== "undefined"
54
+ ? String(process.env.EXPO_PUBLIC_EAS_PROJECT_ID ?? "").trim()
55
+ : "";
56
+ const projectId = String(fromExtra || fromEasConfig || fromEnv || "").trim();
57
+ return projectId || null;
58
+ }
59
+
60
+ export type RegisterExpoPushTokenOptions = {
61
+ deviceId: string;
62
+ registerPushToken: (deviceId: string, token: string) => Promise<unknown>;
63
+ };
64
+
65
+ /**
66
+ * Request OS permission, fetch Expo push token, register it on the API.
67
+ * No-op on web, preview, missing peer, missing EAS projectId, or denied permission.
68
+ */
69
+ export async function registerExpoPushToken(
70
+ options: RegisterExpoPushTokenOptions,
71
+ ): Promise<string | null> {
72
+ if (Platform.OS === "web") return null;
73
+
74
+ const deviceId = options.deviceId?.trim();
75
+ if (!deviceId) return null;
76
+
77
+ const Notifications = loadNotifications();
78
+ if (!Notifications) {
79
+ if (__DEV__) {
80
+ console.warn(
81
+ "[wasto] expo-notifications is not installed; push registration skipped",
82
+ );
83
+ }
84
+ return null;
85
+ }
86
+
87
+ const projectId = resolveEasProjectId();
88
+ if (!projectId) {
89
+ if (__DEV__) {
90
+ console.warn(
91
+ "[wasto] EAS projectId missing (extra.eas.projectId or EXPO_PUBLIC_EAS_PROJECT_ID); push registration skipped",
92
+ );
93
+ }
94
+ return null;
95
+ }
96
+
97
+ if (!handlerConfigured) {
98
+ Notifications.setNotificationHandler({
99
+ handleNotification: async () => ({
100
+ shouldShowAlert: true,
101
+ shouldPlaySound: true,
102
+ shouldSetBadge: false,
103
+ shouldShowBanner: true,
104
+ shouldShowList: true,
105
+ }),
106
+ });
107
+ handlerConfigured = true;
108
+ }
109
+
110
+ if (Platform.OS === "android") {
111
+ await Notifications.setNotificationChannelAsync("default", {
112
+ name: "default",
113
+ importance: Notifications.AndroidImportance.MAX,
114
+ vibrationPattern: [0, 250, 250, 250],
115
+ lightColor: "#FF231F7C",
116
+ });
117
+ }
118
+
119
+ const { status: existingStatus } = await Notifications.getPermissionsAsync();
120
+ let finalStatus = existingStatus;
121
+ if (existingStatus !== "granted") {
122
+ const { status } = await Notifications.requestPermissionsAsync();
123
+ finalStatus = status;
124
+ }
125
+ if (finalStatus !== "granted") return null;
126
+
127
+ const push = await Notifications.getExpoPushTokenAsync({ projectId });
128
+ const token = push?.data?.trim();
129
+ if (!token) return null;
130
+
131
+ await options.registerPushToken(deviceId, token);
132
+ return token;
133
+ }