@jant/core 0.3.24 → 0.3.25

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 (206) hide show
  1. package/dist/app.js +50 -25
  2. package/dist/db/schema.js +1 -1
  3. package/dist/i18n/locales/en.js +1 -1
  4. package/dist/i18n/locales/zh-Hans.js +1 -1
  5. package/dist/i18n/locales/zh-Hant.js +1 -1
  6. package/dist/index.js +3 -9
  7. package/dist/lib/constants.js +1 -0
  8. package/dist/lib/nav-reorder.js +1 -1
  9. package/dist/lib/navigation.js +26 -1
  10. package/dist/lib/pagination.js +44 -0
  11. package/dist/lib/render.js +7 -11
  12. package/dist/lib/schemas.js +3 -3
  13. package/dist/lib/theme.js +4 -4
  14. package/dist/lib/timeline.js +24 -48
  15. package/dist/lib/view.js +2 -2
  16. package/dist/routes/api/collections.js +124 -0
  17. package/dist/routes/api/nav-items.js +104 -0
  18. package/dist/routes/api/pages.js +91 -0
  19. package/dist/routes/api/posts.js +2 -2
  20. package/dist/routes/api/search.js +2 -2
  21. package/dist/routes/api/settings.js +68 -0
  22. package/dist/routes/compose.js +48 -0
  23. package/dist/routes/dash/collections.js +2 -2
  24. package/dist/routes/dash/index.js +1 -1
  25. package/dist/routes/dash/media.js +2 -2
  26. package/dist/routes/dash/pages.js +411 -62
  27. package/dist/routes/dash/posts.js +3 -5
  28. package/dist/routes/dash/redirects.js +2 -2
  29. package/dist/routes/dash/settings.js +79 -5
  30. package/dist/routes/feed/rss.js +2 -2
  31. package/dist/routes/feed/sitemap.js +1 -1
  32. package/dist/routes/pages/archive.js +3 -6
  33. package/dist/routes/pages/collection.js +3 -6
  34. package/dist/routes/pages/collections.js +28 -0
  35. package/dist/routes/pages/featured.js +32 -0
  36. package/dist/routes/pages/home.js +9 -50
  37. package/dist/routes/pages/page.js +29 -32
  38. package/dist/routes/pages/post.js +3 -6
  39. package/dist/routes/pages/search.js +3 -6
  40. package/dist/services/page.js +5 -1
  41. package/dist/services/post.js +40 -6
  42. package/dist/services/search.js +1 -1
  43. package/dist/ui/compose/ComposeDialog.js +452 -0
  44. package/dist/ui/compose/ComposePrompt.js +55 -0
  45. package/dist/{theme/components/TypeBadge.js → ui/dash/FormatBadge.js} +1 -2
  46. package/dist/{theme/components → ui/dash}/PostForm.js +0 -27
  47. package/dist/{theme/components → ui/dash}/PostList.js +6 -6
  48. package/dist/{theme/components/VisibilityBadge.js → ui/dash/StatusBadge.js} +1 -2
  49. package/dist/{theme/components → ui/dash}/index.js +3 -6
  50. package/dist/{themes/threads/timeline → ui/feed}/LinkCard.js +6 -2
  51. package/dist/{themes/threads/timeline → ui/feed}/NoteCard.js +11 -6
  52. package/dist/{themes/threads/timeline → ui/feed}/QuoteCard.js +10 -6
  53. package/dist/{themes/threads/timeline → ui/feed}/ThreadPreview.js +7 -9
  54. package/dist/ui/feed/TimelineFeed.js +41 -0
  55. package/dist/ui/feed/TimelineItem.js +27 -0
  56. package/dist/{theme → ui}/layouts/BaseLayout.js +10 -0
  57. package/dist/{theme → ui}/layouts/DashLayout.js +0 -8
  58. package/dist/ui/layouts/SiteLayout.js +141 -0
  59. package/dist/{themes/threads → ui}/pages/ArchivePage.js +16 -14
  60. package/dist/{themes/threads → ui}/pages/CollectionPage.js +6 -1
  61. package/dist/ui/pages/CollectionsPage.js +76 -0
  62. package/dist/ui/pages/FeaturedPage.js +24 -0
  63. package/dist/ui/pages/HomePage.js +24 -0
  64. package/dist/{themes/threads → ui}/pages/PostPage.js +13 -8
  65. package/dist/{themes/threads → ui}/pages/SearchPage.js +9 -7
  66. package/dist/{themes/threads → ui}/pages/SinglePage.js +3 -2
  67. package/dist/{theme/components → ui/shared}/MediaGallery.js +1 -1
  68. package/dist/{theme/components → ui/shared}/Pagination.js +41 -2
  69. package/dist/{theme/components → ui/shared}/ThreadView.js +2 -2
  70. package/dist/ui/shared/index.js +5 -0
  71. package/package.json +1 -9
  72. package/src/__tests__/helpers/db.ts +3 -0
  73. package/src/app.tsx +57 -27
  74. package/src/db/migrations/0006_rename_slug_to_path.sql +5 -0
  75. package/src/db/migrations/meta/_journal.json +7 -0
  76. package/src/db/schema.ts +1 -1
  77. package/src/i18n/locales/en.po +332 -181
  78. package/src/i18n/locales/en.ts +1 -1
  79. package/src/i18n/locales/zh-Hans.po +332 -181
  80. package/src/i18n/locales/zh-Hans.ts +1 -1
  81. package/src/i18n/locales/zh-Hant.po +332 -181
  82. package/src/i18n/locales/zh-Hant.ts +1 -1
  83. package/src/index.ts +7 -36
  84. package/src/lib/__tests__/schemas.test.ts +60 -19
  85. package/src/lib/__tests__/timeline.test.ts +45 -81
  86. package/src/lib/__tests__/view.test.ts +13 -7
  87. package/src/lib/constants.ts +1 -0
  88. package/src/lib/nav-reorder.ts +1 -1
  89. package/src/lib/navigation.ts +40 -2
  90. package/src/lib/pagination.ts +50 -0
  91. package/src/lib/render.tsx +7 -14
  92. package/src/lib/schemas.ts +8 -6
  93. package/src/lib/theme.ts +5 -5
  94. package/src/lib/timeline.ts +28 -57
  95. package/src/lib/view.ts +2 -2
  96. package/src/preset.css +2 -1
  97. package/src/routes/__tests__/compose.test.ts +199 -0
  98. package/src/routes/api/__tests__/collections.test.ts +249 -0
  99. package/src/routes/api/__tests__/nav-items.test.ts +222 -0
  100. package/src/routes/api/__tests__/pages.test.ts +218 -0
  101. package/src/routes/api/__tests__/settings.test.ts +132 -0
  102. package/src/routes/api/collections.ts +143 -0
  103. package/src/routes/api/nav-items.ts +115 -0
  104. package/src/routes/api/pages.ts +101 -0
  105. package/src/routes/api/posts.ts +2 -2
  106. package/src/routes/api/search.ts +2 -2
  107. package/src/routes/api/settings.ts +91 -0
  108. package/src/routes/compose.ts +63 -0
  109. package/src/routes/dash/__tests__/pages.test.ts +225 -0
  110. package/src/routes/dash/collections.tsx +2 -2
  111. package/src/routes/dash/index.tsx +1 -1
  112. package/src/routes/dash/media.tsx +2 -2
  113. package/src/routes/dash/pages.tsx +443 -70
  114. package/src/routes/dash/posts.tsx +3 -7
  115. package/src/routes/dash/redirects.tsx +2 -2
  116. package/src/routes/dash/settings.tsx +83 -5
  117. package/src/routes/feed/rss.ts +2 -2
  118. package/src/routes/feed/sitemap.ts +1 -1
  119. package/src/routes/pages/__tests__/collections.test.ts +94 -0
  120. package/src/routes/pages/__tests__/featured.test.ts +94 -0
  121. package/src/routes/pages/archive.tsx +2 -6
  122. package/src/routes/pages/collection.tsx +2 -6
  123. package/src/routes/pages/collections.tsx +36 -0
  124. package/src/routes/pages/featured.tsx +38 -0
  125. package/src/routes/pages/home.tsx +9 -55
  126. package/src/routes/pages/page.tsx +28 -30
  127. package/src/routes/pages/post.tsx +2 -5
  128. package/src/routes/pages/search.tsx +2 -6
  129. package/src/services/__tests__/page.test.ts +106 -0
  130. package/src/services/__tests__/post.test.ts +114 -15
  131. package/src/services/page.ts +13 -1
  132. package/src/services/post.ts +57 -7
  133. package/src/services/search.ts +2 -2
  134. package/src/styles/tokens.css +47 -0
  135. package/src/styles/ui.css +491 -0
  136. package/src/types.ts +29 -159
  137. package/src/ui/compose/ComposeDialog.tsx +395 -0
  138. package/src/ui/compose/ComposePrompt.tsx +55 -0
  139. package/src/{theme/components/TypeBadge.tsx → ui/dash/FormatBadge.tsx} +2 -3
  140. package/src/{theme/components → ui/dash}/PostForm.tsx +0 -25
  141. package/src/{theme/components → ui/dash}/PostList.tsx +7 -7
  142. package/src/{theme/components/VisibilityBadge.tsx → ui/dash/StatusBadge.tsx} +2 -3
  143. package/src/ui/dash/index.ts +10 -0
  144. package/src/{themes/threads/timeline → ui/feed}/LinkCard.tsx +9 -4
  145. package/src/{themes/threads/timeline → ui/feed}/NoteCard.tsx +13 -8
  146. package/src/{themes/threads/timeline → ui/feed}/QuoteCard.tsx +13 -8
  147. package/src/{themes/threads/timeline → ui/feed}/ThreadPreview.tsx +7 -8
  148. package/src/ui/feed/TimelineFeed.tsx +49 -0
  149. package/src/ui/feed/TimelineItem.tsx +45 -0
  150. package/src/{theme → ui}/layouts/BaseLayout.tsx +11 -1
  151. package/src/{theme → ui}/layouts/DashLayout.tsx +0 -10
  152. package/src/ui/layouts/SiteLayout.tsx +150 -0
  153. package/src/{themes/threads → ui}/pages/ArchivePage.tsx +22 -17
  154. package/src/{themes/threads → ui}/pages/CollectionPage.tsx +14 -5
  155. package/src/ui/pages/CollectionsPage.tsx +73 -0
  156. package/src/ui/pages/FeaturedPage.tsx +31 -0
  157. package/src/{themes/threads → ui}/pages/HomePage.tsx +11 -15
  158. package/src/{themes/threads → ui}/pages/PostPage.tsx +23 -14
  159. package/src/{themes/threads → ui}/pages/SearchPage.tsx +13 -11
  160. package/src/{themes/threads → ui}/pages/SinglePage.tsx +4 -4
  161. package/src/{theme/components → ui/shared}/MediaGallery.tsx +1 -1
  162. package/src/{theme/components → ui/shared}/Pagination.tsx +67 -4
  163. package/src/{theme/components → ui/shared}/ThreadView.tsx +2 -2
  164. package/src/ui/shared/__tests__/pagination.test.ts +46 -0
  165. package/src/ui/shared/index.ts +12 -0
  166. package/bin/jant.js +0 -185
  167. package/dist/lib/theme-components.js +0 -46
  168. package/dist/routes/dash/navigation.js +0 -289
  169. package/dist/theme/index.js +0 -18
  170. package/dist/theme/layouts/index.js +0 -2
  171. package/dist/themes/threads/ThreadsSiteLayout.js +0 -172
  172. package/dist/themes/threads/index.js +0 -81
  173. package/dist/themes/threads/pages/HomePage.js +0 -25
  174. package/dist/themes/threads/timeline/TimelineFeed.js +0 -58
  175. package/dist/themes/threads/timeline/TimelineItem.js +0 -36
  176. package/dist/themes/threads/timeline/TimelineLoadMore.js +0 -23
  177. package/dist/themes/threads/timeline/groupByDate.js +0 -22
  178. package/dist/themes/threads/timeline/timelineMore.js +0 -107
  179. package/src/lib/__tests__/theme-components.test.ts +0 -105
  180. package/src/lib/theme-components.ts +0 -65
  181. package/src/routes/dash/navigation.tsx +0 -317
  182. package/src/theme/components/index.ts +0 -23
  183. package/src/theme/index.ts +0 -22
  184. package/src/theme/layouts/index.ts +0 -7
  185. package/src/themes/threads/ThreadsSiteLayout.tsx +0 -194
  186. package/src/themes/threads/index.ts +0 -100
  187. package/src/themes/threads/style.css +0 -336
  188. package/src/themes/threads/timeline/TimelineFeed.tsx +0 -62
  189. package/src/themes/threads/timeline/TimelineItem.tsx +0 -67
  190. package/src/themes/threads/timeline/TimelineLoadMore.tsx +0 -35
  191. package/src/themes/threads/timeline/groupByDate.ts +0 -30
  192. package/src/themes/threads/timeline/timelineMore.tsx +0 -130
  193. /package/dist/{theme → ui}/color-themes.js +0 -0
  194. /package/dist/{theme/components → ui/dash}/ActionButtons.js +0 -0
  195. /package/dist/{theme/components → ui/dash}/CrudPageHeader.js +0 -0
  196. /package/dist/{theme/components → ui/dash}/DangerZone.js +0 -0
  197. /package/dist/{theme/components → ui/dash}/ListItemRow.js +0 -0
  198. /package/dist/{theme/components → ui/dash}/PageForm.js +0 -0
  199. /package/dist/{theme/components → ui/shared}/EmptyState.js +0 -0
  200. /package/src/{theme → ui}/color-themes.ts +0 -0
  201. /package/src/{theme/components → ui/dash}/ActionButtons.tsx +0 -0
  202. /package/src/{theme/components → ui/dash}/CrudPageHeader.tsx +0 -0
  203. /package/src/{theme/components → ui/dash}/DangerZone.tsx +0 -0
  204. /package/src/{theme/components → ui/dash}/ListItemRow.tsx +0 -0
  205. /package/src/{theme/components → ui/dash}/PageForm.tsx +0 -0
  206. /package/src/{theme/components → ui/shared}/EmptyState.tsx +0 -0
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Tests for the page/nav management logic used by dashboard pages routes.
3
+ *
4
+ * Note: Route handler tests that import JSX components with @lingui/react/macro
5
+ * cannot run in vitest (requires SWC plugin). These tests verify the service
6
+ * layer operations that the routes orchestrate.
7
+ */
8
+
9
+ import { describe, it, expect, beforeEach } from "vitest";
10
+ import { createTestDatabase } from "../../../__tests__/helpers/db.js";
11
+ import { createPageService } from "../../../services/page.js";
12
+ import { createNavItemService } from "../../../services/navigation.js";
13
+ import type { Database } from "../../../db/index.js";
14
+
15
+ describe("Dashboard Pages - Nav Management Logic", () => {
16
+ let db: Database;
17
+ let pageService: ReturnType<typeof createPageService>;
18
+ let navItemService: ReturnType<typeof createNavItemService>;
19
+
20
+ beforeEach(() => {
21
+ const testDb = createTestDatabase();
22
+ db = testDb.db as unknown as Database;
23
+ pageService = createPageService(db);
24
+ navItemService = createNavItemService(db);
25
+ });
26
+
27
+ describe("add page to nav", () => {
28
+ it("creates a page-type nav item for the page", async () => {
29
+ const page = await pageService.create({
30
+ slug: "about",
31
+ title: "About Us",
32
+ });
33
+
34
+ // Simulate what the route handler does
35
+ await navItemService.create({
36
+ type: "page",
37
+ label: page.title || page.slug,
38
+ url: `/${page.slug}`,
39
+ pageId: page.id,
40
+ });
41
+
42
+ const navItems = await navItemService.list();
43
+ expect(navItems).toHaveLength(1);
44
+ expect(navItems[0]?.type).toBe("page");
45
+ expect(navItems[0]?.label).toBe("About Us");
46
+ expect(navItems[0]?.url).toBe("/about");
47
+ expect(navItems[0]?.pageId).toBe(page.id);
48
+ });
49
+
50
+ it("uses slug as label when page has no title", async () => {
51
+ const page = await pageService.create({ slug: "about" });
52
+
53
+ await navItemService.create({
54
+ type: "page",
55
+ label: page.title || page.slug,
56
+ url: `/${page.slug}`,
57
+ pageId: page.id,
58
+ });
59
+
60
+ const navItems = await navItemService.list();
61
+ expect(navItems[0]?.label).toBe("about");
62
+ });
63
+
64
+ it("page appears in nav and not in listNotInNav after adding", async () => {
65
+ const page = await pageService.create({
66
+ slug: "about",
67
+ title: "About",
68
+ });
69
+
70
+ // Before adding to nav
71
+ let notInNav = await pageService.listNotInNav();
72
+ expect(notInNav).toHaveLength(1);
73
+
74
+ // Add to nav
75
+ await navItemService.create({
76
+ type: "page",
77
+ label: page.title || page.slug,
78
+ url: `/${page.slug}`,
79
+ pageId: page.id,
80
+ });
81
+
82
+ // After adding to nav
83
+ notInNav = await pageService.listNotInNav();
84
+ expect(notInNav).toHaveLength(0);
85
+
86
+ const navItems = await navItemService.list();
87
+ expect(navItems).toHaveLength(1);
88
+ });
89
+ });
90
+
91
+ describe("remove page from nav", () => {
92
+ it("removes the nav item but keeps the page", async () => {
93
+ const page = await pageService.create({
94
+ slug: "about",
95
+ title: "About",
96
+ });
97
+ const navItem = await navItemService.create({
98
+ type: "page",
99
+ label: "About",
100
+ url: "/about",
101
+ pageId: page.id,
102
+ });
103
+
104
+ // Simulate what the route handler does: find and delete nav item by pageId
105
+ const allNavItems = await navItemService.list();
106
+ const found = allNavItems.find((item) => item.pageId === page.id);
107
+ expect(found).toBeDefined();
108
+ await navItemService.delete(found!.id);
109
+
110
+ // Nav item should be gone
111
+ const navItems = await navItemService.list();
112
+ expect(navItems).toHaveLength(0);
113
+
114
+ // Page should still exist
115
+ const foundPage = await pageService.getById(page.id);
116
+ expect(foundPage).not.toBeNull();
117
+
118
+ // Page should appear in "not in nav" list
119
+ const notInNav = await pageService.listNotInNav();
120
+ expect(notInNav).toHaveLength(1);
121
+ expect(notInNav[0]?.slug).toBe("about");
122
+ });
123
+ });
124
+
125
+ describe("reorder nav items", () => {
126
+ it("reorders nav items by position", async () => {
127
+ const a = await navItemService.create({
128
+ type: "link",
129
+ label: "A",
130
+ url: "/a",
131
+ });
132
+ const b = await navItemService.create({
133
+ type: "link",
134
+ label: "B",
135
+ url: "/b",
136
+ });
137
+
138
+ // Reverse order
139
+ await navItemService.reorder([b.id, a.id]);
140
+
141
+ const items = await navItemService.list();
142
+ expect(items[0]?.label).toBe("B");
143
+ expect(items[1]?.label).toBe("A");
144
+ });
145
+ });
146
+
147
+ describe("link CRUD", () => {
148
+ it("creates a link nav item", async () => {
149
+ await navItemService.create({
150
+ type: "link",
151
+ label: "Blog",
152
+ url: "/blog",
153
+ });
154
+
155
+ const navItems = await navItemService.list();
156
+ expect(navItems).toHaveLength(1);
157
+ expect(navItems[0]?.type).toBe("link");
158
+ expect(navItems[0]?.label).toBe("Blog");
159
+ expect(navItems[0]?.url).toBe("/blog");
160
+ });
161
+
162
+ it("updates a link nav item", async () => {
163
+ const item = await navItemService.create({
164
+ type: "link",
165
+ label: "Blog",
166
+ url: "/blog",
167
+ });
168
+
169
+ await navItemService.update(item.id, {
170
+ label: "Posts",
171
+ url: "/posts",
172
+ });
173
+
174
+ const updated = await navItemService.getById(item.id);
175
+ expect(updated?.label).toBe("Posts");
176
+ expect(updated?.url).toBe("/posts");
177
+ });
178
+
179
+ it("deletes a link nav item", async () => {
180
+ const item = await navItemService.create({
181
+ type: "link",
182
+ label: "Blog",
183
+ url: "/blog",
184
+ });
185
+
186
+ await navItemService.delete(item.id);
187
+
188
+ const found = await navItemService.getById(item.id);
189
+ expect(found).toBeNull();
190
+ });
191
+ });
192
+
193
+ describe("unified page listing", () => {
194
+ it("separates pages into nav and non-nav groups", async () => {
195
+ const aboutPage = await pageService.create({
196
+ slug: "about",
197
+ title: "About",
198
+ });
199
+ await pageService.create({ slug: "contact", title: "Contact" });
200
+
201
+ // Add about to nav
202
+ await navItemService.create({
203
+ type: "page",
204
+ label: "About",
205
+ url: "/about",
206
+ pageId: aboutPage.id,
207
+ });
208
+
209
+ // Also add a link nav item
210
+ await navItemService.create({
211
+ type: "link",
212
+ label: "External",
213
+ url: "https://example.com",
214
+ });
215
+
216
+ // Simulate the unified page view data fetch
217
+ const navItems = await navItemService.list();
218
+ const otherPages = await pageService.listNotInNav();
219
+
220
+ expect(navItems).toHaveLength(2); // page + link
221
+ expect(otherPages).toHaveLength(1); // only contact
222
+ expect(otherPages[0]?.slug).toBe("contact");
223
+ });
224
+ });
225
+ });
@@ -7,14 +7,14 @@ import { Hono } from "hono";
7
7
  import { useLingui } from "@lingui/react/macro";
8
8
  import type { Bindings, Collection, Post } from "../../types.js";
9
9
  import type { AppVariables } from "../../app.js";
10
- import { DashLayout } from "../../theme/layouts/index.js";
10
+ import { DashLayout } from "../../ui/layouts/DashLayout.js";
11
11
  import {
12
12
  EmptyState,
13
13
  ListItemRow,
14
14
  ActionButtons,
15
15
  CrudPageHeader,
16
16
  DangerZone,
17
- } from "../../theme/components/index.js";
17
+ } from "../../ui/dash/index.js";
18
18
  import * as sqid from "../../lib/sqid.js";
19
19
  import { dsRedirect } from "../../lib/sse.js";
20
20
 
@@ -8,7 +8,7 @@ import { Hono } from "hono";
8
8
  import { Trans, useLingui } from "@lingui/react/macro";
9
9
  import type { Bindings } from "../../types.js";
10
10
  import type { AppVariables } from "../../app.js";
11
- import { DashLayout } from "../../theme/layouts/index.js";
11
+ import { DashLayout } from "../../ui/layouts/DashLayout.js";
12
12
  import { getSiteName } from "../../lib/config.js";
13
13
 
14
14
  type Env = { Bindings: Bindings; Variables: AppVariables };
@@ -10,8 +10,8 @@ import { Hono } from "hono";
10
10
  import { useLingui } from "@lingui/react/macro";
11
11
  import type { Bindings, Media } from "../../types.js";
12
12
  import type { AppVariables } from "../../app.js";
13
- import { DashLayout } from "../../theme/layouts/index.js";
14
- import { EmptyState, DangerZone } from "../../theme/components/index.js";
13
+ import { DashLayout } from "../../ui/layouts/DashLayout.js";
14
+ import { EmptyState, DangerZone } from "../../ui/dash/index.js";
15
15
  import * as time from "../../lib/time.js";
16
16
  import {
17
17
  getMediaUrl,