@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
@@ -1,127 +1,132 @@
1
- import {
2
- createContext,
3
- PropsWithChildren,
4
- useContext,
5
- useEffect,
6
- useMemo,
7
- type ReactNode,
8
- } from "react";
9
- import type { WastoRequestErrorContext } from "@wasto/sdk";
10
- import { Theme } from "../types/Theme";
11
- import { ThemeProvider } from "./ThemeContext";
12
- import { LocalProvider } from "./LocalContext";
13
- import { ChallengesProvider } from "./ChallengesContext";
14
- import { AnnouncementsProvider } from "./AnnouncementsContext";
15
- import SelectStreetModal from "../components/select-street-modal/SelectStreetModal";
16
- import { AnnouncementModal } from "../components/announcement-modal/AnnouncementModal";
17
- import { OptionalSafeAreaProvider } from "../components/safe-area/OptionalSafeAreaProvider";
18
- import {
19
- initWastoSentry,
20
- reportError as sentryReportError,
21
- type WastoErrorContext,
22
- type WastoSentryConfig,
23
- } from "../sentry/initSentry";
24
-
25
- export type WastoContextType = {
26
- apiUrl: string;
27
- appId: string;
28
- cityGroupId: string | null;
29
- /**
30
- * Studio / iframe preview — no anonymous device registration or challenge writes.
31
- */
32
- previewMode: boolean;
33
- reportError: (error: unknown, context?: WastoErrorContext) => void;
34
- onRequestError?: (error: Error, context: WastoRequestErrorContext) => void;
35
- };
36
-
37
- export const WastoContext = createContext<WastoContextType | undefined>(undefined);
38
-
39
- export type WastoProviderProps = PropsWithChildren & {
40
- apiUrl: string;
41
- appId: string;
42
- theme: Theme;
43
- /** City group scoping street search / multi-city apps. */
44
- cityGroupId?: string | null;
45
- /** GitLab Error Tracking / Sentry config (DSN from env). */
46
- sentry?: WastoSentryConfig;
47
- /**
48
- * When true (Studio preview): LocalContext skips analytics.track / device id.
49
- */
50
- previewMode?: boolean;
51
- };
52
-
53
- export function WastoProvider(props: WastoProviderProps): ReactNode {
54
- const apiUrl = useMemo(() => props.apiUrl, [props.apiUrl]);
55
- const appId = useMemo(() => props.appId, [props.appId]);
56
- const cityGroupId = useMemo(
57
- () => props.cityGroupId?.trim() || null,
58
- [props.cityGroupId],
59
- );
60
- const previewMode = Boolean(props.previewMode);
61
- const sentryConfig = props.sentry;
62
-
63
- useEffect(() => {
64
- if (!sentryConfig) return;
65
- initWastoSentry({
66
- ...sentryConfig,
67
- appId: sentryConfig.appId ?? appId,
68
- });
69
- }, [appId, sentryConfig]);
70
-
71
- const reportError = useMemo(
72
- () => (error: unknown, context?: WastoErrorContext) => {
73
- sentryReportError(error, context);
74
- },
75
- [],
76
- );
77
-
78
- const onRequestError = useMemo(
79
- () => (error: Error, ctx: WastoRequestErrorContext) => {
80
- reportError(error, {
81
- source: "api",
82
- method: ctx.method,
83
- path: ctx.path,
84
- status: ctx.status,
85
- });
86
- },
87
- [reportError],
88
- );
89
-
90
- const value = useMemo<WastoContextType>(
91
- () => ({
92
- apiUrl,
93
- appId,
94
- cityGroupId,
95
- previewMode,
96
- reportError,
97
- onRequestError,
98
- }),
99
- [apiUrl, appId, cityGroupId, previewMode, reportError, onRequestError],
100
- );
101
-
102
- return (
103
- <WastoContext value={value}>
104
- <OptionalSafeAreaProvider>
105
- <LocalProvider previewMode={previewMode}>
106
- <ChallengesProvider>
107
- <AnnouncementsProvider apiUrl={apiUrl}>
108
- <ThemeProvider theme={props.theme}>
109
- {props.children}
110
- <SelectStreetModal />
111
- <AnnouncementModal />
112
- </ThemeProvider>
113
- </AnnouncementsProvider>
114
- </ChallengesProvider>
115
- </LocalProvider>
116
- </OptionalSafeAreaProvider>
117
- </WastoContext>
118
- );
119
- }
120
-
121
- export function useWasto() {
122
- const context = useContext(WastoContext);
123
- if (!context) {
124
- throw new Error("useContext must be used within a WastoProvider.");
125
- }
126
- return context;
127
- }
1
+ import {
2
+ createContext,
3
+ PropsWithChildren,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ type ReactNode,
8
+ } from "react";
9
+ import type { WastoRequestErrorContext } from "@wasto/sdk";
10
+ import { Theme } from "../types/Theme";
11
+ import { ThemeProvider } from "./ThemeContext";
12
+ import { LocalProvider } from "./LocalContext";
13
+ import { AppDataProvider } from "./AppDataContext";
14
+ import { ChallengesProvider } from "./ChallengesContext";
15
+ import { AnnouncementsProvider } from "./AnnouncementsContext";
16
+ import SelectStreetModal from "../components/select-street-modal/SelectStreetModal";
17
+ import { AnnouncementModal } from "../components/announcement-modal/AnnouncementModal";
18
+ import { PushTokenRegistrar } from "../components/push/PushTokenRegistrar";
19
+ import { OptionalSafeAreaProvider } from "../components/safe-area/OptionalSafeAreaProvider";
20
+ import {
21
+ initWastoSentry,
22
+ reportError as sentryReportError,
23
+ type WastoErrorContext,
24
+ type WastoSentryConfig,
25
+ } from "../sentry/initSentry";
26
+
27
+ export type WastoContextType = {
28
+ apiUrl: string;
29
+ appId: string;
30
+ cityGroupId: string | null;
31
+ /**
32
+ * Studio / iframe preview — no anonymous device registration or challenge writes.
33
+ */
34
+ previewMode: boolean;
35
+ reportError: (error: unknown, context?: WastoErrorContext) => void;
36
+ onRequestError?: (error: Error, context: WastoRequestErrorContext) => void;
37
+ };
38
+
39
+ export const WastoContext = createContext<WastoContextType | undefined>(undefined);
40
+
41
+ export type WastoProviderProps = PropsWithChildren & {
42
+ apiUrl: string;
43
+ appId: string;
44
+ theme: Theme;
45
+ /** City group scoping street search / multi-city apps. */
46
+ cityGroupId?: string | null;
47
+ /** GitLab Error Tracking / Sentry config (DSN from env). */
48
+ sentry?: WastoSentryConfig;
49
+ /**
50
+ * When true (Studio preview): LocalContext skips analytics.track / device id.
51
+ */
52
+ previewMode?: boolean;
53
+ };
54
+
55
+ export function WastoProvider(props: WastoProviderProps): ReactNode {
56
+ const apiUrl = useMemo(() => props.apiUrl, [props.apiUrl]);
57
+ const appId = useMemo(() => props.appId, [props.appId]);
58
+ const cityGroupId = useMemo(
59
+ () => props.cityGroupId?.trim() || null,
60
+ [props.cityGroupId],
61
+ );
62
+ const previewMode = Boolean(props.previewMode);
63
+ const sentryConfig = props.sentry;
64
+
65
+ useEffect(() => {
66
+ if (!sentryConfig) return;
67
+ initWastoSentry({
68
+ ...sentryConfig,
69
+ appId: sentryConfig.appId ?? appId,
70
+ });
71
+ }, [appId, sentryConfig]);
72
+
73
+ const reportError = useMemo(
74
+ () => (error: unknown, context?: WastoErrorContext) => {
75
+ sentryReportError(error, context);
76
+ },
77
+ [],
78
+ );
79
+
80
+ const onRequestError = useMemo(
81
+ () => (error: Error, ctx: WastoRequestErrorContext) => {
82
+ reportError(error, {
83
+ source: "api",
84
+ method: ctx.method,
85
+ path: ctx.path,
86
+ status: ctx.status,
87
+ });
88
+ },
89
+ [reportError],
90
+ );
91
+
92
+ const value = useMemo<WastoContextType>(
93
+ () => ({
94
+ apiUrl,
95
+ appId,
96
+ cityGroupId,
97
+ previewMode,
98
+ reportError,
99
+ onRequestError,
100
+ }),
101
+ [apiUrl, appId, cityGroupId, previewMode, reportError, onRequestError],
102
+ );
103
+
104
+ return (
105
+ <WastoContext value={value}>
106
+ <OptionalSafeAreaProvider>
107
+ <LocalProvider previewMode={previewMode}>
108
+ <PushTokenRegistrar />
109
+ <ChallengesProvider>
110
+ <AnnouncementsProvider apiUrl={apiUrl}>
111
+ <ThemeProvider theme={props.theme}>
112
+ <AppDataProvider apiUrl={apiUrl}>
113
+ {props.children}
114
+ <SelectStreetModal />
115
+ <AnnouncementModal />
116
+ </AppDataProvider>
117
+ </ThemeProvider>
118
+ </AnnouncementsProvider>
119
+ </ChallengesProvider>
120
+ </LocalProvider>
121
+ </OptionalSafeAreaProvider>
122
+ </WastoContext>
123
+ );
124
+ }
125
+
126
+ export function useWasto() {
127
+ const context = useContext(WastoContext);
128
+ if (!context) {
129
+ throw new Error("useContext must be used within a WastoProvider.");
130
+ }
131
+ return context;
132
+ }
@@ -1,72 +1,72 @@
1
- import { htmlContentToMarkdown } from "./htmlContentToMarkdown";
2
-
3
- export type BlogPost = {
4
- id: string;
5
- title: string;
6
- content: string;
7
- publishedAt?: string;
8
- createdAt?: string;
9
- coverMediaId?: string | null;
10
- };
11
-
12
- function asRecord(raw: unknown): Record<string, unknown> | null {
13
- if (raw == null || typeof raw !== "object") return null;
14
- const root = raw as Record<string, unknown>;
15
- if (root.data != null && typeof root.data === "object") {
16
- return root.data as Record<string, unknown>;
17
- }
18
- return root;
19
- }
20
-
21
- function pickStr(o: Record<string, unknown>, camel: string, snake?: string): string | undefined {
22
- const v = o[camel] ?? (snake ? o[snake] : undefined);
23
- return typeof v === "string" ? v : undefined;
24
- }
25
-
26
- export function normalizeBlogPost(raw: unknown): BlogPost | null {
27
- const o = asRecord(raw);
28
- if (!o) return null;
29
-
30
- const idRaw = o.id;
31
- const id = typeof idRaw === "string" ? idRaw : idRaw != null ? String(idRaw) : "";
32
- if (!id) return null;
33
-
34
- const coverFromRelation =
35
- o.coverMedia != null && typeof o.coverMedia === "object"
36
- ? (o.coverMedia as { id?: unknown }).id
37
- : undefined;
38
-
39
- return {
40
- id,
41
- title: pickStr(o, "title") || "Sans titre",
42
- content: pickStr(o, "content") || "",
43
- publishedAt: pickStr(o, "publishedAt", "published_at"),
44
- createdAt: pickStr(o, "createdAt", "created_at"),
45
- coverMediaId:
46
- pickStr(o, "coverMediaId", "cover_media_id") ??
47
- (typeof coverFromRelation === "string" ? coverFromRelation : null),
48
- };
49
- }
50
-
51
- export function stripToExcerpt(content: string, maxLen = 180): string {
52
- const fromHtml = htmlContentToMarkdown(content);
53
- const plain = fromHtml
54
- .replace(/```[\s\S]*?```/g, " ")
55
- .replace(/`[^`]*`/g, " ")
56
- .replace(/!\[[^\]]*]\([^)]*\)/g, " ")
57
- .replace(/\[[^\]]*]\([^)]*\)/g, " ")
58
- .replace(/\+\+([^+]+)\+\+/g, "$1")
59
- .replace(/[#>*_~\-|]+/g, " ")
60
- .replace(/\s+/g, " ")
61
- .trim();
62
- if (plain.length <= maxLen) return plain;
63
- return `${plain.slice(0, maxLen).trim()}…`;
64
- }
65
-
66
- export function formatArticleDate(value?: string): string | undefined {
67
- if (!value) return undefined;
68
- const slice = value.length >= 10 ? value.slice(0, 10) : value;
69
- const date = new Date(slice);
70
- if (Number.isNaN(date.getTime())) return slice;
71
- return date.toLocaleDateString("fr-FR", { day: "numeric", month: "long", year: "numeric" });
72
- }
1
+ import { htmlContentToMarkdown } from "./htmlContentToMarkdown";
2
+
3
+ export type BlogPost = {
4
+ id: string;
5
+ title: string;
6
+ content: string;
7
+ publishedAt?: string;
8
+ createdAt?: string;
9
+ coverMediaId?: string | null;
10
+ };
11
+
12
+ function asRecord(raw: unknown): Record<string, unknown> | null {
13
+ if (raw == null || typeof raw !== "object") return null;
14
+ const root = raw as Record<string, unknown>;
15
+ if (root.data != null && typeof root.data === "object") {
16
+ return root.data as Record<string, unknown>;
17
+ }
18
+ return root;
19
+ }
20
+
21
+ function pickStr(o: Record<string, unknown>, camel: string, snake?: string): string | undefined {
22
+ const v = o[camel] ?? (snake ? o[snake] : undefined);
23
+ return typeof v === "string" ? v : undefined;
24
+ }
25
+
26
+ export function normalizeBlogPost(raw: unknown): BlogPost | null {
27
+ const o = asRecord(raw);
28
+ if (!o) return null;
29
+
30
+ const idRaw = o.id;
31
+ const id = typeof idRaw === "string" ? idRaw : idRaw != null ? String(idRaw) : "";
32
+ if (!id) return null;
33
+
34
+ const coverFromRelation =
35
+ o.coverMedia != null && typeof o.coverMedia === "object"
36
+ ? (o.coverMedia as { id?: unknown }).id
37
+ : undefined;
38
+
39
+ return {
40
+ id,
41
+ title: pickStr(o, "title") || "Sans titre",
42
+ content: pickStr(o, "content") || "",
43
+ publishedAt: pickStr(o, "publishedAt", "published_at"),
44
+ createdAt: pickStr(o, "createdAt", "created_at"),
45
+ coverMediaId:
46
+ pickStr(o, "coverMediaId", "cover_media_id") ??
47
+ (typeof coverFromRelation === "string" ? coverFromRelation : null),
48
+ };
49
+ }
50
+
51
+ export function stripToExcerpt(content: string, maxLen = 180): string {
52
+ const fromHtml = htmlContentToMarkdown(content);
53
+ const plain = fromHtml
54
+ .replace(/```[\s\S]*?```/g, " ")
55
+ .replace(/`[^`]*`/g, " ")
56
+ .replace(/!\[[^\]]*]\([^)]*\)/g, " ")
57
+ .replace(/\[[^\]]*]\([^)]*\)/g, " ")
58
+ .replace(/\+\+([^+]+)\+\+/g, "$1")
59
+ .replace(/[#>*_~\-|]+/g, " ")
60
+ .replace(/\s+/g, " ")
61
+ .trim();
62
+ if (plain.length <= maxLen) return plain;
63
+ return `${plain.slice(0, maxLen).trim()}…`;
64
+ }
65
+
66
+ export function formatArticleDate(value?: string): string | undefined {
67
+ if (!value) return undefined;
68
+ const slice = value.length >= 10 ? value.slice(0, 10) : value;
69
+ const date = new Date(slice);
70
+ if (Number.isNaN(date.getTime())) return slice;
71
+ return date.toLocaleDateString("fr-FR", { day: "numeric", month: "long", year: "numeric" });
72
+ }