@teleporthq/teleport-project-generator-next 0.45.21 → 0.45.22

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 (151) hide show
  1. package/__tests__/code-copy-runtime.test.ts +31 -24
  2. package/__tests__/forum-files-route.test.ts +147 -0
  3. package/__tests__/forum-markdown.test.ts +136 -0
  4. package/__tests__/forum-page-data.test.ts +1329 -0
  5. package/__tests__/forum-project-plugin.test.ts +789 -0
  6. package/__tests__/forum-replies-route.test.ts +82 -0
  7. package/__tests__/forum-topics-only-end2end.test.ts +124 -0
  8. package/__tests__/i18n-app-runtime.test.ts +187 -0
  9. package/__tests__/page-revalidate-plugin.test.ts +111 -0
  10. package/__tests__/rich-text-editor-frame.test.ts +25 -0
  11. package/dist/cjs/forum/files-route.d.ts +26 -0
  12. package/dist/cjs/forum/files-route.d.ts.map +1 -0
  13. package/dist/cjs/forum/files-route.js +42 -0
  14. package/dist/cjs/forum/files-route.js.map +1 -0
  15. package/dist/cjs/forum/markdown-source.d.ts +17 -0
  16. package/dist/cjs/forum/markdown-source.d.ts.map +1 -0
  17. package/dist/cjs/forum/markdown-source.js +23 -0
  18. package/dist/cjs/forum/markdown-source.js.map +1 -0
  19. package/dist/cjs/forum/notifications-route.d.ts +17 -0
  20. package/dist/cjs/forum/notifications-route.d.ts.map +1 -0
  21. package/dist/cjs/forum/notifications-route.js +30 -0
  22. package/dist/cjs/forum/notifications-route.js.map +1 -0
  23. package/dist/cjs/forum/page-data-source.d.ts +58 -0
  24. package/dist/cjs/forum/page-data-source.d.ts.map +1 -0
  25. package/dist/cjs/forum/page-data-source.js +168 -0
  26. package/dist/cjs/forum/page-data-source.js.map +1 -0
  27. package/dist/cjs/forum/page-rewrite.d.ts +50 -0
  28. package/dist/cjs/forum/page-rewrite.d.ts.map +1 -0
  29. package/dist/cjs/forum/page-rewrite.js +473 -0
  30. package/dist/cjs/forum/page-rewrite.js.map +1 -0
  31. package/dist/cjs/forum/project-plugin.d.ts +34 -0
  32. package/dist/cjs/forum/project-plugin.d.ts.map +1 -0
  33. package/dist/cjs/forum/project-plugin.js +272 -0
  34. package/dist/cjs/forum/project-plugin.js.map +1 -0
  35. package/dist/cjs/forum/replies-route.d.ts +21 -0
  36. package/dist/cjs/forum/replies-route.d.ts.map +1 -0
  37. package/dist/cjs/forum/replies-route.js +33 -0
  38. package/dist/cjs/forum/replies-route.js.map +1 -0
  39. package/dist/cjs/forum/seo.d.ts +29 -0
  40. package/dist/cjs/forum/seo.d.ts.map +1 -0
  41. package/dist/cjs/forum/seo.js +61 -0
  42. package/dist/cjs/forum/seo.js.map +1 -0
  43. package/dist/cjs/forum/settings.d.ts +97 -0
  44. package/dist/cjs/forum/settings.d.ts.map +1 -0
  45. package/dist/cjs/forum/settings.js +162 -0
  46. package/dist/cjs/forum/settings.js.map +1 -0
  47. package/dist/cjs/index.d.ts +1 -0
  48. package/dist/cjs/index.d.ts.map +1 -1
  49. package/dist/cjs/index.js +87 -80
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/instant-search/sections.d.ts.map +1 -1
  52. package/dist/cjs/instant-search/sections.js +18 -0
  53. package/dist/cjs/instant-search/sections.js.map +1 -1
  54. package/dist/cjs/instant-search/settings.d.ts +1 -1
  55. package/dist/cjs/instant-search/settings.d.ts.map +1 -1
  56. package/dist/cjs/instant-search/settings.js +2 -0
  57. package/dist/cjs/instant-search/settings.js.map +1 -1
  58. package/dist/cjs/internationalization/app-i18n-runtime.d.ts +39 -0
  59. package/dist/cjs/internationalization/app-i18n-runtime.d.ts.map +1 -0
  60. package/dist/cjs/internationalization/app-i18n-runtime.js +126 -0
  61. package/dist/cjs/internationalization/app-i18n-runtime.js.map +1 -0
  62. package/dist/cjs/internationalization/project.d.ts.map +1 -1
  63. package/dist/cjs/internationalization/project.js +6 -0
  64. package/dist/cjs/internationalization/project.js.map +1 -1
  65. package/dist/cjs/page-revalidate/project-plugin.d.ts.map +1 -1
  66. package/dist/cjs/page-revalidate/project-plugin.js +5 -1
  67. package/dist/cjs/page-revalidate/project-plugin.js.map +1 -1
  68. package/dist/cjs/rich-text-editor/content-support-source.d.ts +2 -1
  69. package/dist/cjs/rich-text-editor/content-support-source.d.ts.map +1 -1
  70. package/dist/cjs/rich-text-editor/content-support-source.js +9 -2
  71. package/dist/cjs/rich-text-editor/content-support-source.js.map +1 -1
  72. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  73. package/dist/esm/forum/files-route.d.ts +26 -0
  74. package/dist/esm/forum/files-route.d.ts.map +1 -0
  75. package/dist/esm/forum/files-route.js +38 -0
  76. package/dist/esm/forum/files-route.js.map +1 -0
  77. package/dist/esm/forum/markdown-source.d.ts +17 -0
  78. package/dist/esm/forum/markdown-source.d.ts.map +1 -0
  79. package/dist/esm/forum/markdown-source.js +19 -0
  80. package/dist/esm/forum/markdown-source.js.map +1 -0
  81. package/dist/esm/forum/notifications-route.d.ts +17 -0
  82. package/dist/esm/forum/notifications-route.d.ts.map +1 -0
  83. package/dist/esm/forum/notifications-route.js +26 -0
  84. package/dist/esm/forum/notifications-route.js.map +1 -0
  85. package/dist/esm/forum/page-data-source.d.ts +58 -0
  86. package/dist/esm/forum/page-data-source.d.ts.map +1 -0
  87. package/dist/esm/forum/page-data-source.js +164 -0
  88. package/dist/esm/forum/page-data-source.js.map +1 -0
  89. package/dist/esm/forum/page-rewrite.d.ts +50 -0
  90. package/dist/esm/forum/page-rewrite.d.ts.map +1 -0
  91. package/dist/esm/forum/page-rewrite.js +446 -0
  92. package/dist/esm/forum/page-rewrite.js.map +1 -0
  93. package/dist/esm/forum/project-plugin.d.ts +34 -0
  94. package/dist/esm/forum/project-plugin.d.ts.map +1 -0
  95. package/dist/esm/forum/project-plugin.js +269 -0
  96. package/dist/esm/forum/project-plugin.js.map +1 -0
  97. package/dist/esm/forum/replies-route.d.ts +21 -0
  98. package/dist/esm/forum/replies-route.d.ts.map +1 -0
  99. package/dist/esm/forum/replies-route.js +29 -0
  100. package/dist/esm/forum/replies-route.js.map +1 -0
  101. package/dist/esm/forum/seo.d.ts +29 -0
  102. package/dist/esm/forum/seo.d.ts.map +1 -0
  103. package/dist/esm/forum/seo.js +56 -0
  104. package/dist/esm/forum/seo.js.map +1 -0
  105. package/dist/esm/forum/settings.d.ts +97 -0
  106. package/dist/esm/forum/settings.d.ts.map +1 -0
  107. package/dist/esm/forum/settings.js +158 -0
  108. package/dist/esm/forum/settings.js.map +1 -0
  109. package/dist/esm/index.d.ts +1 -0
  110. package/dist/esm/index.d.ts.map +1 -1
  111. package/dist/esm/index.js +6 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/instant-search/sections.d.ts.map +1 -1
  114. package/dist/esm/instant-search/sections.js +18 -0
  115. package/dist/esm/instant-search/sections.js.map +1 -1
  116. package/dist/esm/instant-search/settings.d.ts +1 -1
  117. package/dist/esm/instant-search/settings.d.ts.map +1 -1
  118. package/dist/esm/instant-search/settings.js +2 -0
  119. package/dist/esm/instant-search/settings.js.map +1 -1
  120. package/dist/esm/internationalization/app-i18n-runtime.d.ts +39 -0
  121. package/dist/esm/internationalization/app-i18n-runtime.d.ts.map +1 -0
  122. package/dist/esm/internationalization/app-i18n-runtime.js +120 -0
  123. package/dist/esm/internationalization/app-i18n-runtime.js.map +1 -0
  124. package/dist/esm/internationalization/project.d.ts.map +1 -1
  125. package/dist/esm/internationalization/project.js +6 -0
  126. package/dist/esm/internationalization/project.js.map +1 -1
  127. package/dist/esm/page-revalidate/project-plugin.d.ts.map +1 -1
  128. package/dist/esm/page-revalidate/project-plugin.js +5 -1
  129. package/dist/esm/page-revalidate/project-plugin.js.map +1 -1
  130. package/dist/esm/rich-text-editor/content-support-source.d.ts +2 -1
  131. package/dist/esm/rich-text-editor/content-support-source.d.ts.map +1 -1
  132. package/dist/esm/rich-text-editor/content-support-source.js +9 -2
  133. package/dist/esm/rich-text-editor/content-support-source.js.map +1 -1
  134. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  135. package/package.json +19 -19
  136. package/src/forum/files-route.ts +133 -0
  137. package/src/forum/markdown-source.ts +177 -0
  138. package/src/forum/notifications-route.ts +87 -0
  139. package/src/forum/page-data-source.ts +810 -0
  140. package/src/forum/page-rewrite.ts +567 -0
  141. package/src/forum/project-plugin.ts +328 -0
  142. package/src/forum/replies-route.ts +91 -0
  143. package/src/forum/seo.ts +245 -0
  144. package/src/forum/settings.ts +261 -0
  145. package/src/index.ts +6 -0
  146. package/src/instant-search/sections.ts +20 -0
  147. package/src/instant-search/settings.ts +2 -0
  148. package/src/internationalization/app-i18n-runtime.ts +165 -0
  149. package/src/internationalization/project.ts +7 -0
  150. package/src/page-revalidate/project-plugin.ts +5 -1
  151. package/src/rich-text-editor/content-support-source.ts +14 -2
@@ -0,0 +1,261 @@
1
+ import { ProjectUIDL, UIDLPluginSettingValue } from '@teleporthq/teleport-types'
2
+ import { ContentTables } from '@teleporthq/teleport-shared'
3
+ import { DetailsRoute, resolveTableDataSource } from '../instant-search/sections'
4
+
5
+ /**
6
+ * The Forum plugin's settings as the editor stores them
7
+ * (`features/plugins/registry/definitions/forum.ts` there), its pages' routes
8
+ * (`uidl.plugins.forum.pages`, by page type) and the data source its tables
9
+ * live in. Every value is checked: the published site bakes them into the
10
+ * forum data module and its routes.
11
+ */
12
+
13
+ export const FORUM_PLUGIN_KEY = 'forum'
14
+ export const FORUM_TABLES = ContentTables.FORUM_TABLES
15
+
16
+ /**
17
+ * How the forum is organised: in communities members join, or as one list of
18
+ * topics. A topic is always stored in a community, so a forum without
19
+ * communities keeps every topic in one of its own — the main community —
20
+ * which the published site reads for the rights and never shows.
21
+ */
22
+ export type ForumStructure = 'communities' | 'topics'
23
+
24
+ /**
25
+ * The slug of the main community. MUST stay in step with
26
+ * `FORUM_MAIN_COMMUNITY_SLUG` in the editor's
27
+ * `apps/gui/app/project-page/features/forum/constants/forum-structure.ts`.
28
+ */
29
+ export const FORUM_MAIN_COMMUNITY_SLUG = 'main'
30
+
31
+ export interface ForumSettings {
32
+ structure: ForumStructure
33
+ membersCreateCommunities: boolean
34
+ communityApproval: 'none' | 'owner'
35
+ maxCommunitiesPerMember: number
36
+ defaultVisibility: 'public' | 'restricted' | 'private'
37
+ attachments: boolean
38
+ maxAttachments: number
39
+ tags: boolean
40
+ editWindowMinutes: number
41
+ replyNesting: 'nested' | 'flat'
42
+ topicsPerDay: number
43
+ votes: 'updown' | 'up' | 'off'
44
+ reactions: boolean
45
+ acceptedAnswers: 'questions' | 'all' | 'off'
46
+ reputation: boolean
47
+ badges: boolean
48
+ moderation: 'none' | 'newMembers' | 'all'
49
+ newMemberPosts: number
50
+ holdLinks: boolean
51
+ notifications: boolean
52
+ emailOnReply: boolean
53
+ }
54
+
55
+ /** A page of a community's topic list: what a project that never set it gets, and the most it may hold. */
56
+ export const FORUM_COMMUNITY_TOPICS_PER_PAGE = 20
57
+ export const FORUM_COMMUNITY_TOPICS_PER_PAGE_MAX = 50
58
+
59
+ /** The page types the editor's plugin record names (`forum-markers.ts` there). */
60
+ export type ForumPageType = 'home' | 'communities' | 'community' | 'topic' | 'new-topic' | 'manage'
61
+
62
+ /**
63
+ * The pages served per record. Three of them are pages of a community: its
64
+ * own, Manage and New topic. A forum without communities has the topic page
65
+ * and New topic only, the latter a static page (`ForumConfig.composerPath`).
66
+ */
67
+ export type ForumDetailsPage = 'topic' | 'community' | 'manage' | 'newTopic'
68
+
69
+ export interface ForumConfig {
70
+ settings: ForumSettings
71
+ /**
72
+ * The route of each page a forum of this structure has, as the editor
73
+ * resolved it; a details page is `<base>` (`/forum/t`), without its `[slug]`.
74
+ */
75
+ pages: Partial<Record<ForumPageType, string>>
76
+ /** Where each details page is served: `<staticBase>/[column]`. */
77
+ routes: Record<ForumDetailsPage, DetailsRoute | null>
78
+ /**
79
+ * The New topic page of a forum without communities: a static page
80
+ * (`/forum/new`) that always writes in the main community. Null in a forum
81
+ * with communities, where it is a community's details page (`routes.newTopic`).
82
+ */
83
+ composerPath: string | null
84
+ /** How many topics a page of a community's list holds (the community page's own setting in the editor). */
85
+ communityTopicsPerPage: number
86
+ /** The data source the forum tables are read through (the project's TeleportHQ one). */
87
+ dataSource: { dataSourceId: string; dataSourceType: string } | null
88
+ }
89
+
90
+ export const FORUM_DEFAULTS: ForumSettings = {
91
+ structure: 'communities',
92
+ membersCreateCommunities: true,
93
+ communityApproval: 'none',
94
+ maxCommunitiesPerMember: 3,
95
+ defaultVisibility: 'public',
96
+ attachments: true,
97
+ maxAttachments: 4,
98
+ tags: true,
99
+ editWindowMinutes: 30,
100
+ replyNesting: 'nested',
101
+ topicsPerDay: 20,
102
+ votes: 'updown',
103
+ reactions: false,
104
+ acceptedAnswers: 'questions',
105
+ reputation: true,
106
+ badges: true,
107
+ // Every post shows at once unless the owner chose approval (the editor's registry default).
108
+ moderation: 'none',
109
+ newMemberPosts: 3,
110
+ holdLinks: false,
111
+ notifications: true,
112
+ emailOnReply: false,
113
+ }
114
+
115
+ /** The pages a forum of each structure is built with (`forumPageTypes` in the editor's `forum-structure.ts`). */
116
+ const PAGE_TYPES: Record<ForumStructure, ForumPageType[]> = {
117
+ communities: ['home', 'communities', 'community', 'topic', 'new-topic', 'manage'],
118
+ topics: ['home', 'topic', 'new-topic'],
119
+ }
120
+
121
+ type Stored = Record<string, UIDLPluginSettingValue | undefined>
122
+
123
+ const bool = (value: unknown, fallback: boolean): boolean =>
124
+ typeof value === 'boolean' ? value : fallback
125
+
126
+ const integer = (value: unknown, fallback: number, min: number, max: number): number => {
127
+ const rounded = typeof value === 'number' && Number.isFinite(value) ? Math.round(value) : fallback
128
+ return Math.min(max, Math.max(min, rounded))
129
+ }
130
+
131
+ const oneOf = <T extends string>(value: unknown, options: readonly T[], fallback: T): T =>
132
+ typeof value === 'string' && (options as readonly string[]).includes(value)
133
+ ? (value as T)
134
+ : fallback
135
+
136
+ /** `/forum/t/[slug]` and `/forum/t` both name the base `/forum/t`. */
137
+ const routeBase = (route: unknown): string | null => {
138
+ if (typeof route !== 'string' || !route.startsWith('/')) {
139
+ return null
140
+ }
141
+ const base = route.replace(/\/\[[^\]]*\]$/, '').replace(/\/+$/, '')
142
+ return base || '/'
143
+ }
144
+
145
+ const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/
146
+
147
+ /**
148
+ * Where a details page is served, from ITS recorded base. The table cannot
149
+ * name the page: the community, Manage and New topic pages all bind the
150
+ * communities table. The project's routes only say which column the address
151
+ * ends with.
152
+ */
153
+ const detailsRoute = (uidl: ProjectUIDL, base: string | undefined): DetailsRoute | null => {
154
+ if (!base) {
155
+ return null
156
+ }
157
+ const staticBase = base === '/' ? '' : base
158
+ const values = (
159
+ uidl as unknown as { root?: { stateDefinitions?: { route?: { values?: unknown[] } } } }
160
+ ).root?.stateDefinitions?.route?.values
161
+ for (const value of Array.isArray(values) ? values : []) {
162
+ const pageOptions = (value as { pageOptions?: Record<string, unknown> })?.pageOptions
163
+ const navLink = String(pageOptions?.navLink || '')
164
+ if (!/\/\[[^\]]*\]$/.test(navLink) || routeBase(navLink) !== base) {
165
+ continue
166
+ }
167
+ const info = pageOptions?.detailsPageInfo as { differentiatorColumn?: unknown } | undefined
168
+ const column = info?.differentiatorColumn || pageOptions?.dynamicRouteAttribute
169
+ if (typeof column === 'string' && IDENTIFIER.test(column)) {
170
+ return { staticBase, column }
171
+ }
172
+ }
173
+ return { staticBase, column: 'slug' }
174
+ }
175
+
176
+ /** The plugin's configuration when the project has it on; null otherwise. */
177
+ export const resolveForumConfig = (uidl: ProjectUIDL): ForumConfig | null => {
178
+ const record = uidl.plugins?.[FORUM_PLUGIN_KEY]
179
+ if (
180
+ !record ||
181
+ typeof record !== 'object' ||
182
+ !record.settings ||
183
+ typeof record.settings !== 'object'
184
+ ) {
185
+ return null
186
+ }
187
+ const stored = record.settings as Stored
188
+ const settings: ForumSettings = {
189
+ structure: oneOf(stored.structure, ['communities', 'topics'], FORUM_DEFAULTS.structure),
190
+ membersCreateCommunities: bool(
191
+ stored.membersCreateCommunities,
192
+ FORUM_DEFAULTS.membersCreateCommunities
193
+ ),
194
+ communityApproval: oneOf(
195
+ stored.communityApproval,
196
+ ['none', 'owner'],
197
+ FORUM_DEFAULTS.communityApproval
198
+ ),
199
+ maxCommunitiesPerMember: integer(
200
+ stored.maxCommunitiesPerMember,
201
+ FORUM_DEFAULTS.maxCommunitiesPerMember,
202
+ 1,
203
+ 20
204
+ ),
205
+ defaultVisibility: oneOf(
206
+ stored.defaultVisibility,
207
+ ['public', 'restricted', 'private'],
208
+ FORUM_DEFAULTS.defaultVisibility
209
+ ),
210
+ attachments: bool(stored.attachments, FORUM_DEFAULTS.attachments),
211
+ maxAttachments: integer(stored.maxAttachments, FORUM_DEFAULTS.maxAttachments, 1, 10),
212
+ tags: bool(stored.tags, FORUM_DEFAULTS.tags),
213
+ editWindowMinutes: integer(stored.editWindowMinutes, FORUM_DEFAULTS.editWindowMinutes, 0, 1440),
214
+ replyNesting: oneOf(stored.replyNesting, ['nested', 'flat'], FORUM_DEFAULTS.replyNesting),
215
+ topicsPerDay: integer(stored.topicsPerDay, FORUM_DEFAULTS.topicsPerDay, 1, 200),
216
+ votes: oneOf(stored.votes, ['updown', 'up', 'off'], FORUM_DEFAULTS.votes),
217
+ reactions: bool(stored.reactions, FORUM_DEFAULTS.reactions),
218
+ acceptedAnswers: oneOf(
219
+ stored.acceptedAnswers,
220
+ ['questions', 'all', 'off'],
221
+ FORUM_DEFAULTS.acceptedAnswers
222
+ ),
223
+ reputation: bool(stored.reputation, FORUM_DEFAULTS.reputation),
224
+ badges: bool(stored.badges, FORUM_DEFAULTS.badges),
225
+ moderation: oneOf(stored.moderation, ['none', 'newMembers', 'all'], FORUM_DEFAULTS.moderation),
226
+ newMemberPosts: integer(stored.newMemberPosts, FORUM_DEFAULTS.newMemberPosts, 1, 20),
227
+ holdLinks: bool(stored.holdLinks, FORUM_DEFAULTS.holdLinks),
228
+ notifications: bool(stored.notifications, FORUM_DEFAULTS.notifications),
229
+ emailOnReply: bool(stored.emailOnReply, FORUM_DEFAULTS.emailOnReply),
230
+ }
231
+
232
+ const pages: Partial<Record<ForumPageType, string>> = {}
233
+ const recorded = record.pages && typeof record.pages === 'object' ? record.pages : {}
234
+ for (const type of PAGE_TYPES[settings.structure]) {
235
+ const base = routeBase(recorded[type])
236
+ if (base) {
237
+ pages[type] = base
238
+ }
239
+ }
240
+ const composer = pages['new-topic']
241
+ const hasCommunities = settings.structure === 'communities'
242
+
243
+ return {
244
+ settings,
245
+ pages,
246
+ routes: {
247
+ topic: detailsRoute(uidl, pages.topic),
248
+ community: detailsRoute(uidl, pages.community),
249
+ manage: detailsRoute(uidl, pages.manage),
250
+ newTopic: hasCommunities ? detailsRoute(uidl, composer) : null,
251
+ },
252
+ composerPath: hasCommunities ? null : composer ?? null,
253
+ communityTopicsPerPage: integer(
254
+ record.data?.communityTopicsPerPage,
255
+ FORUM_COMMUNITY_TOPICS_PER_PAGE,
256
+ 1,
257
+ FORUM_COMMUNITY_TOPICS_PER_PAGE_MAX
258
+ ),
259
+ dataSource: resolveTableDataSource(uidl, FORUM_TABLES.topics),
260
+ }
261
+ }
package/src/index.ts CHANGED
@@ -50,6 +50,7 @@ import { NextCollapsibleTextProjectPlugin } from './collapsible-text/project-plu
50
50
  import { NextEcommerceProjectPlugin } from './ecommerce/project-plugin'
51
51
  import { NextBlogProjectPlugin } from './blog/project-plugin'
52
52
  import { NextCodeCopyProjectPlugin } from './blog/code-copy-project-plugin'
53
+ import { NextForumProjectPlugin } from './forum/project-plugin'
53
54
  import { NextBookingProjectPlugin } from './bookings/project-plugin'
54
55
  import { NextDashboardLayoutPlugin } from './dashboard-layout-plugin'
55
56
  import { createEntityMutationSsrFinalizerPlugin } from './entity-mutation-ssr-finalize-plugin'
@@ -116,6 +117,10 @@ export const createNextProjectPlugins = (): ProjectPlugin[] => [
116
117
  new NextEcommerceProjectPlugin(),
117
118
  new NextBlogProjectPlugin(),
118
119
  new NextCodeCopyProjectPlugin(),
120
+ // The forum's read side: its data module, routes and per-request pages.
121
+ // After the blog (the same site-index pattern), before Instant search, which
122
+ // reads the forum's section through the same tables.
123
+ new NextForumProjectPlugin(),
119
124
  new NextNewsletterProjectPlugin(),
120
125
  new NextBookingProjectPlugin(),
121
126
  new NextGlobalStateProjectPlugin(),
@@ -335,6 +340,7 @@ export { buildStandaloneWallMiddleware, wrapMiddlewareWithWall } from './passwor
335
340
  export { NextEcommerceProjectPlugin } from './ecommerce/project-plugin'
336
341
  export { NextBlogProjectPlugin } from './blog/project-plugin'
337
342
  export { NextCodeCopyProjectPlugin } from './blog/code-copy-project-plugin'
343
+ export { NextForumProjectPlugin } from './forum/project-plugin'
338
344
  export { NextBookingProjectPlugin } from './bookings/project-plugin'
339
345
  export { NextDashboardLayoutPlugin } from './dashboard-layout-plugin'
340
346
  export { createEntityMutationSsrFinalizerPlugin } from './entity-mutation-ssr-finalize-plugin'
@@ -1,4 +1,5 @@
1
1
  import { ProjectUIDL } from '@teleporthq/teleport-types'
2
+ import { ContentTables } from '@teleporthq/teleport-shared'
2
3
  import {
3
4
  resolveCustomProductPageRoutes,
4
5
  resolveProductDetailsRoute,
@@ -173,6 +174,25 @@ const BLUEPRINTS: SectionBlueprint[] = [
173
174
  imageColumns: ['image_url', 'imageUrl'],
174
175
  activeColumn: 'is_active',
175
176
  },
177
+ {
178
+ // The forum's topics: the read route serves a visitor only published
179
+ // topics of communities that are not private (the visitor row policy),
180
+ // so no active column is needed.
181
+ key: 'topics',
182
+ tableName: ContentTables.FORUM_TABLES.topics,
183
+ present: (uidl) => !!uidl.plugins?.forum,
184
+ route: (uidl) =>
185
+ resolveDetailsRouteForTable(uidl, ContentTables.FORUM_TABLES.topics) ??
186
+ toDetailsRoute(
187
+ String(uidl.plugins?.forum?.pages?.topic || '').replace(/\/\[[^\]]*\]$/, ''),
188
+ 'slug'
189
+ ),
190
+ searchColumns: ['title', 'body_text', 'tags'],
191
+ titleColumns: ['title'],
192
+ descriptionColumns: ['body_text'],
193
+ imageColumns: [],
194
+ activeColumn: null,
195
+ },
176
196
  ]
177
197
 
178
198
  /** The data source a table is read through: the page resource that binds it, else the shared TeleportHQ one. */
@@ -16,6 +16,7 @@ export const SEARCH_SECTION_KEYS = [
16
16
  'posts',
17
17
  'articles',
18
18
  'bookingItems',
19
+ 'topics',
19
20
  ] as const
20
21
  export type SearchSectionKey = (typeof SEARCH_SECTION_KEYS)[number]
21
22
 
@@ -25,6 +26,7 @@ export const SEARCH_SECTION_LABELS: Record<SearchSectionKey, string> = {
25
26
  posts: 'Blog posts',
26
27
  articles: 'Help articles',
27
28
  bookingItems: 'Bookable items',
29
+ topics: 'Forum topics',
28
30
  }
29
31
 
30
32
  export interface InstantSearchSettings {
@@ -0,0 +1,165 @@
1
+ import { FileType, GeneratedFile, ProjectPluginStructure } from '@teleporthq/teleport-types'
2
+ import { injectImportIntoApp } from '../app-import-injection'
3
+
4
+ export const I18N_RUNTIME_DIR = ['utils']
5
+ export const I18N_RUNTIME_MODULE = 'tq-i18n'
6
+ export const I18N_RUNTIME_IMPORT = `import { useTqI18n } from '../utils/${I18N_RUNTIME_MODULE}'`
7
+ export const I18N_RUNTIME_CALL = 'useTqI18n(pageProps)'
8
+
9
+ /**
10
+ * The range `@teleporthq/react-components` asks for: the same range lets npm
11
+ * install ONE dayjs that `_app` and `DateTimePrimitive` share. Two copies would
12
+ * each keep their own language, and the dates would stay in English.
13
+ */
14
+ export const DAYJS_VERSION = '^1.11.8'
15
+
16
+ /** The language files dayjs 1.11 ships (`dayjs/locale/<name>.js`), the same from 1.11.8 on. */
17
+ const DAYJS_LOCALES = new Set(
18
+ (
19
+ 'af am ar-dz ar-iq ar-kw ar-ly ar-ma ar-sa ar-tn ar az be bg bi bm bn-bd bn bo br bs ca cs cv ' +
20
+ 'cy da de-at de-ch de dv el en-au en-ca en-gb en-ie en-il en-in en-nz en-sg en-tt en eo es-do ' +
21
+ 'es-mx es-pr es-us es et eu fa fi fo fr-ca fr-ch fr fy ga gd gl gom-latn gu he hi hr ht hu ' +
22
+ 'hy-am id is it-ch it ja jv ka kk km kn ko ku ky lb lo lt lv me mi mk ml mn mr ms-my ms mt my ' +
23
+ 'nb ne nl-be nl nn oc-lnc pa-in pl pt-br pt rn ro ru rw sd se si sk sl sq sr-cyrl sr ss sv-fi ' +
24
+ 'sv sw ta te tet tg th tk tl-ph tlh tr tzl tzm-latn tzm ug-cn uk ur uz-latn uz vi yo zh-cn ' +
25
+ 'zh-hk zh-tw zh'
26
+ ).split(' ')
27
+ )
28
+
29
+ /** Language codes the editor offers that dayjs files under another name. */
30
+ const DAYJS_ALIASES: Record<string, string> = {
31
+ no: 'nb',
32
+ tl: 'tl-ph',
33
+ pa: 'pa-in',
34
+ hy: 'hy-am',
35
+ ug: 'ug-cn',
36
+ oc: 'oc-lnc',
37
+ yue: 'zh-hk',
38
+ sh: 'sr',
39
+ kok: 'gom-latn',
40
+ }
41
+
42
+ /** The dayjs language of a site language (`pt-BR` → `pt-br`, `no` → `nb`), or null when dayjs has none. */
43
+ export const dayjsLocaleOf = (code: string): string | null => {
44
+ const lower = String(code || '').toLowerCase()
45
+ const base = lower.split('-')[0]
46
+ const candidates = [lower, DAYJS_ALIASES[lower], base, DAYJS_ALIASES[base]]
47
+ return candidates.find((candidate) => candidate && DAYJS_LOCALES.has(candidate)) || null
48
+ }
49
+
50
+ /**
51
+ * `utils/tq-i18n.js`: the hook `_app` calls first thing on every render, so
52
+ * everything the page renders below it reads the page's language.
53
+ *
54
+ * - Dates: `DateTimePrimitive` formats with dayjs's global language, which is
55
+ * English unless something sets it. The hook sets it to the page's language
56
+ * (English when dayjs has no file for it), on the server and in the browser
57
+ * alike, so the server's HTML and the browser's first render agree.
58
+ * - `window.__TQ_I18N__ = { locale, defaultLocale, messages }`, in the browser
59
+ * only: workflow scripts run outside React and cannot reach the page's
60
+ * `translate`, so they read the page's language and words from here.
61
+ *
62
+ * One server process renders every language. Every render sets the language
63
+ * (never keeps the one before), before any of the page renders, and React 17's
64
+ * `renderToString` renders the whole page in one synchronous pass, so no other
65
+ * request's render can run between the two. Nothing else in a generated
66
+ * project formats dates with dayjs.
67
+ */
68
+ export const buildI18nRuntimeSource = (locales: string[], defaultLocale: string): string => {
69
+ const dateLocales: Record<string, string> = {}
70
+ locales.forEach((locale) => {
71
+ const dayjsLocale = dayjsLocaleOf(locale)
72
+ if (dayjsLocale) {
73
+ dateLocales[locale] = dayjsLocale
74
+ }
75
+ })
76
+ const imports = Array.from(new Set(Object.values(dateLocales)))
77
+ .filter((name) => name !== 'en')
78
+ .sort()
79
+ .map((name) => `import 'dayjs/locale/${name}'\n`)
80
+ .join('')
81
+
82
+ return `import { useRouter } from 'next/router'
83
+ import dayjs from 'dayjs'
84
+ ${imports}
85
+ // Each language of the site as dayjs names it. A language dayjs has no file
86
+ // for reads its dates in English.
87
+ var DATE_LOCALES = ${JSON.stringify(dateLocales)}
88
+ var DEFAULT_LOCALE = ${JSON.stringify(defaultLocale)}
89
+
90
+ // Called first thing in _app on every render: the page's language for its
91
+ // dates, and for the scripts its workflows run (window.__TQ_I18N__).
92
+ export function useTqI18n(pageProps) {
93
+ var router = useRouter()
94
+ var locale = (router && router.locale) || DEFAULT_LOCALE
95
+ var defaultLocale = (router && router.defaultLocale) || DEFAULT_LOCALE
96
+ dayjs.locale(DATE_LOCALES[locale] || 'en')
97
+ if (typeof window !== 'undefined') {
98
+ window.__TQ_I18N__ = {
99
+ locale: locale,
100
+ defaultLocale: defaultLocale,
101
+ messages: pageProps && pageProps.messages,
102
+ }
103
+ }
104
+ }
105
+ `
106
+ }
107
+
108
+ const findAppFile = (structure: ProjectPluginStructure): GeneratedFile | null => {
109
+ for (const [key, record] of Array.from(structure.files.entries())) {
110
+ if (key === '_app' || key.includes('_app')) {
111
+ const found = record.files?.find(
112
+ (file) => file.name === '_app' && (file.fileType === 'js' || file.fileType === 'tsx')
113
+ )
114
+ if (found) {
115
+ return found
116
+ }
117
+ }
118
+ }
119
+ return null
120
+ }
121
+
122
+ const APP_FUNCTION_OPENING = /export default function MyApp\s*\([^)]*\)\s*\{/
123
+
124
+ /**
125
+ * Ships `utils/tq-i18n.js`, calls its hook first thing in `_app`'s body and
126
+ * pins `dayjs`, which `_app` now imports. Only for a project with
127
+ * internationalization; leaves `_app` untouched when it cannot find its body.
128
+ */
129
+ export const addI18nRuntime = (
130
+ structure: ProjectPluginStructure,
131
+ locales: string[],
132
+ defaultLocale: string
133
+ ): void => {
134
+ const appFile = findAppFile(structure)
135
+ if (!appFile || typeof appFile.content !== 'string') {
136
+ return
137
+ }
138
+ if (!appFile.content.includes(I18N_RUNTIME_CALL)) {
139
+ const opening = appFile.content.match(APP_FUNCTION_OPENING)
140
+ if (!opening || opening.index === undefined) {
141
+ return
142
+ }
143
+ const at = opening.index + opening[0].length
144
+ appFile.content = `${appFile.content.slice(
145
+ 0,
146
+ at
147
+ )}\n ${I18N_RUNTIME_CALL}${appFile.content.slice(at)}`
148
+ injectImportIntoApp(structure, I18N_RUNTIME_IMPORT)
149
+ }
150
+
151
+ structure.files.set('tq-i18n-runtime', {
152
+ path: I18N_RUNTIME_DIR,
153
+ files: [
154
+ {
155
+ name: I18N_RUNTIME_MODULE,
156
+ fileType: FileType.JS,
157
+ content: buildI18nRuntimeSource(locales, defaultLocale),
158
+ },
159
+ ],
160
+ })
161
+
162
+ if (!structure.dependencies.dayjs) {
163
+ structure.dependencies.dayjs = DAYJS_VERSION
164
+ }
165
+ }
@@ -12,6 +12,7 @@ import {
12
12
  } from '@teleporthq/teleport-types'
13
13
  import { companyGlobalObject } from './company-global'
14
14
  import { localeStateSource } from './locale-state'
15
+ import { addI18nRuntime } from './app-i18n-runtime'
15
16
  import { RouteUtils } from '@teleporthq/teleport-plugin-common'
16
17
 
17
18
  const findFileInBuild = (
@@ -418,6 +419,12 @@ export class NextProjectPlugini18nConfig implements ProjectPlugin {
418
419
  }
419
420
  }
420
421
 
422
+ // The page's language for its dates and its workflow scripts: a site with
423
+ // internationalization only, so one without it is generated as before.
424
+ if (uidl.internationalization) {
425
+ addI18nRuntime(structure, Object.keys(languages), main.locale)
426
+ }
427
+
421
428
  const authEnabled = !!uidl.authentication?.enabled
422
429
  const customUserProperties = uidl.authentication?.customUserProperties || []
423
430
  const globalContextFile = generateGlobalContextFileContent(
@@ -5,6 +5,7 @@ import {
5
5
  ProjectUIDL,
6
6
  } from '@teleporthq/teleport-types'
7
7
  import { DataCache, PageRevalidate } from '@teleporthq/teleport-shared'
8
+ import { resolveAppLocales } from '../pwa/locales'
8
9
 
9
10
  const PAGE_REVALIDATE_NODE_TYPE = 'page-revalidate'
10
11
 
@@ -59,7 +60,10 @@ export class NextPageRevalidatePlugin implements ProjectPlugin {
59
60
  {
60
61
  name: PageRevalidate.REVALIDATE_ROUTE,
61
62
  fileType: FileType.JS,
62
- content: PageRevalidate.generatePageRevalidateRoute(),
63
+ // Every language's copy of a page is rebuilt, not the default one's alone.
64
+ content: PageRevalidate.generatePageRevalidateRoute({
65
+ locales: uidl.internationalization ? resolveAppLocales(uidl).locales : [],
66
+ }),
63
67
  },
64
68
  ],
65
69
  })
@@ -30,13 +30,25 @@ const PROTECTED_BLOCK_STYLES = `
30
30
  .ql-editor .${RichTextContent.PROTECTED_BLOCK_CLASS} ul, .ql-editor .${RichTextContent.PROTECTED_BLOCK_CLASS} ol { padding-left: 22px; }
31
31
  `
32
32
 
33
+ /**
34
+ * The writing area fills the box the page gave the editor (its `min-height`),
35
+ * instead of staying one line tall inside it. An editor whose box sets no
36
+ * height keeps its natural size: `inherit` then inherits nothing.
37
+ */
38
+ const EDITOR_FRAME_STYLES = `
39
+ .quill { display: flex; flex-direction: column; min-height: inherit; }
40
+ .quill > .ql-container { display: flex; flex: 1 1 auto; flex-direction: column; }
41
+ .quill > .ql-container > .ql-editor { flex: 1 1 auto; }
42
+ `
43
+
33
44
  /**
34
45
  * What the generated editor needs beside the runtime module: the protected
35
46
  * block registered as a Quill block embed, the format list widened so inline
36
- * code and the block are never stripped on load, and the block's styles.
47
+ * code and the block are never stripped on load, and the styles of the block
48
+ * and of the editor's frame.
37
49
  */
38
50
  export const CONTENT_SUPPORT_SOURCE = `const RICH_TEXT_CONTENT_STYLES = ${JSON.stringify(
39
- PROTECTED_BLOCK_STYLES
51
+ PROTECTED_BLOCK_STYLES + EDITOR_FRAME_STYLES
40
52
  )}
41
53
 
42
54
  let protectedBlockBlotRegistered = false