@connextar/house 0.23.1 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +55 -13
  2. package/dist/analytics/browser.d.ts +1 -0
  3. package/dist/analytics/browser.d.ts.map +1 -1
  4. package/dist/analytics/browser.js +22 -5
  5. package/dist/analytics/browser.js.map +1 -1
  6. package/dist/analytics/config.d.ts +5 -0
  7. package/dist/analytics/config.d.ts.map +1 -1
  8. package/dist/analytics/config.js +4 -1
  9. package/dist/analytics/config.js.map +1 -1
  10. package/dist/analytics/posthog-extensions.d.ts +19 -0
  11. package/dist/analytics/posthog-extensions.d.ts.map +1 -0
  12. package/dist/analytics/posthog-extensions.js +19 -0
  13. package/dist/analytics/posthog-extensions.js.map +1 -0
  14. package/dist/analytics/react.d.ts.map +1 -1
  15. package/dist/analytics/react.js +4 -2
  16. package/dist/analytics/react.js.map +1 -1
  17. package/dist/analytics/redact.d.ts.map +1 -1
  18. package/dist/analytics/redact.js +6 -1
  19. package/dist/analytics/redact.js.map +1 -1
  20. package/dist/house.css +19 -0
  21. package/package.json +17 -3
  22. package/src/account/data-contract.ts +112 -0
  23. package/src/account/index.ts +11 -0
  24. package/src/admin/access.ts +267 -0
  25. package/src/admin/audit.ts +238 -0
  26. package/src/admin/bootstrap.ts +220 -0
  27. package/src/admin/client-index.ts +19 -0
  28. package/src/admin/client.tsx +187 -0
  29. package/src/admin/index.ts +91 -0
  30. package/src/admin/proof.ts +155 -0
  31. package/src/admin/second-factor-index.ts +16 -0
  32. package/src/admin/second-factor.ts +403 -0
  33. package/src/admin/testing-index.ts +13 -0
  34. package/src/admin/testing.ts +299 -0
  35. package/src/admin/view-as.ts +511 -0
  36. package/src/ai/config-index.ts +40 -0
  37. package/src/ai/config.ts +176 -0
  38. package/src/ai/images.ts +18 -0
  39. package/src/ai/index.ts +21 -0
  40. package/src/ai/pricing.ts +107 -0
  41. package/src/ai/provider.ts +403 -0
  42. package/src/analytics/browser.ts +400 -0
  43. package/src/analytics/client-index.ts +12 -0
  44. package/src/analytics/config.ts +89 -0
  45. package/src/analytics/index.ts +17 -0
  46. package/src/analytics/ingest.ts +81 -0
  47. package/src/analytics/posthog-extensions.ts +19 -0
  48. package/src/analytics/react-index.ts +16 -0
  49. package/src/analytics/react.tsx +241 -0
  50. package/src/analytics/redact.ts +146 -0
  51. package/src/analytics/server-index.ts +17 -0
  52. package/src/analytics/server.ts +277 -0
  53. package/src/auth/index.ts +30 -0
  54. package/src/auth/second-factor-index.ts +16 -0
  55. package/src/auth/second-factor-next.ts +136 -0
  56. package/src/auth/second-factor-routes.ts +40 -0
  57. package/src/auth/second-factor.ts +226 -0
  58. package/src/auth/step-up-client-index.ts +13 -0
  59. package/src/auth/step-up-client.ts +23 -0
  60. package/src/auth/step-up-index.ts +19 -0
  61. package/src/auth/step-up-routes.ts +99 -0
  62. package/src/auth/step-up.ts +432 -0
  63. package/src/auth/two-factor-policy.ts +112 -0
  64. package/src/changelog/changelog.tsx +367 -0
  65. package/src/changelog/index.ts +12 -0
  66. package/src/editor/block-handle.tsx +312 -0
  67. package/src/editor/blocks.ts +169 -0
  68. package/src/editor/bubble-toolbar.tsx +208 -0
  69. package/src/editor/collapsible.ts +159 -0
  70. package/src/editor/content-index.ts +1 -0
  71. package/src/editor/content.tsx +343 -0
  72. package/src/editor/editor.tsx +333 -0
  73. package/src/editor/emoji-index.ts +1 -0
  74. package/src/editor/emoji-picker.tsx +114 -0
  75. package/src/editor/emoji.ts +436 -0
  76. package/src/editor/index.ts +6 -0
  77. package/src/editor/sections.ts +83 -0
  78. package/src/editor/suggestion-popup.tsx +136 -0
  79. package/src/editor/suggestions.ts +309 -0
  80. package/src/editor/ui.tsx +171 -0
  81. package/src/errors/error-shell.tsx +72 -0
  82. package/src/errors/global-error-shell.tsx +116 -0
  83. package/src/errors/index.ts +2 -0
  84. package/src/grid/columns.ts +48 -0
  85. package/src/grid/compare.ts +35 -0
  86. package/src/grid/hidden-columns.ts +95 -0
  87. package/src/grid/index.ts +27 -0
  88. package/src/grid/use-grid.ts +282 -0
  89. package/src/grid/views.ts +70 -0
  90. package/src/guides/guide-article.tsx +92 -0
  91. package/src/guides/guide-figure-zoom.tsx +533 -0
  92. package/src/guides/guide-figure.tsx +68 -0
  93. package/src/guides/guide-toc.tsx +133 -0
  94. package/src/guides/guides-landing.tsx +57 -0
  95. package/src/guides/guides-search.tsx +160 -0
  96. package/src/guides/guides-shell.tsx +60 -0
  97. package/src/guides/guides-sidebar.tsx +93 -0
  98. package/src/guides/index.ts +28 -0
  99. package/src/guides/library.ts +165 -0
  100. package/src/health/health.ts +115 -0
  101. package/src/health/index.ts +11 -0
  102. package/src/internal/cx.ts +4 -0
  103. package/src/internal/next-link.ts +23 -0
  104. package/src/jobs/counts.ts +151 -0
  105. package/src/jobs/cron-auth.ts +60 -0
  106. package/src/jobs/health.ts +315 -0
  107. package/src/jobs/idle.ts +86 -0
  108. package/src/jobs/index.ts +120 -0
  109. package/src/jobs/job-health-list.tsx +316 -0
  110. package/src/jobs/next-index.ts +4 -0
  111. package/src/jobs/next.ts +65 -0
  112. package/src/jobs/prisma-index.ts +12 -0
  113. package/src/jobs/prisma.ts +170 -0
  114. package/src/jobs/prune.ts +79 -0
  115. package/src/jobs/react-index.ts +35 -0
  116. package/src/jobs/registry.ts +189 -0
  117. package/src/jobs/scheduler.ts +437 -0
  118. package/src/jobs/store.ts +212 -0
  119. package/src/jobs/windows.ts +157 -0
  120. package/src/maintenance/core.ts +270 -0
  121. package/src/maintenance/gate.ts +171 -0
  122. package/src/maintenance/index.ts +40 -0
  123. package/src/maintenance/page.ts +76 -0
  124. package/src/maintenance/proxy.ts +88 -0
  125. package/src/maintenance/react-index.ts +7 -0
  126. package/src/maintenance/react.tsx +190 -0
  127. package/src/maintenance/route.ts +82 -0
  128. package/src/maintenance/unavailable.ts +61 -0
  129. package/src/markdown/figure.tsx +132 -0
  130. package/src/markdown/figures.ts +237 -0
  131. package/src/markdown/guide.tsx +536 -0
  132. package/src/markdown/index.ts +53 -0
  133. package/src/markdown/table-view.tsx +74 -0
  134. package/src/markdown/table.ts +90 -0
  135. package/src/password/common.ts +58 -0
  136. package/src/password/estimate-index.ts +18 -0
  137. package/src/password/estimate.ts +715 -0
  138. package/src/password/index.ts +40 -0
  139. package/src/password/password-input.tsx +116 -0
  140. package/src/password/password-strength.tsx +157 -0
  141. package/src/password/reveal.ts +151 -0
  142. package/src/rate-limit/better-auth.ts +94 -0
  143. package/src/rate-limit/index.ts +32 -0
  144. package/src/rate-limit/keys.ts +110 -0
  145. package/src/rate-limit/limiter.ts +276 -0
  146. package/src/rate-limit/prisma-index.ts +12 -0
  147. package/src/rate-limit/prisma.ts +157 -0
  148. package/src/rate-limit/store.ts +47 -0
  149. package/src/release/changelog.ts +364 -0
  150. package/src/release/index.ts +32 -0
  151. package/src/release/version.ts +64 -0
  152. package/src/setup-guide/bits.tsx +420 -0
  153. package/src/setup-guide/card.tsx +358 -0
  154. package/src/setup-guide/class-names.ts +144 -0
  155. package/src/setup-guide/context.tsx +239 -0
  156. package/src/setup-guide/guide.ts +271 -0
  157. package/src/setup-guide/index.ts +76 -0
  158. package/src/setup-guide/launcher.tsx +207 -0
  159. package/src/setup-guide/strip.tsx +127 -0
  160. package/src/styles/house.css +403 -0
  161. package/src/trail/index.ts +12 -0
  162. package/src/trail/rules.ts +84 -0
  163. package/src/trail/trail.tsx +367 -0
  164. package/src/ux/errors.ts +32 -0
  165. package/src/ux/feedback.tsx +41 -0
  166. package/src/ux/index.ts +44 -0
  167. package/src/ux/navigation-index.ts +16 -0
  168. package/src/ux/navigation-progress.tsx +270 -0
  169. package/src/ux/optimistic.ts +415 -0
  170. package/src/ux/use-action.ts +155 -0
  171. package/src/ux/use-optimistic-list.ts +227 -0
  172. package/src/ux/use-optimistic-value.ts +136 -0
  173. package/src/web-search/index.ts +13 -0
  174. package/src/web-search/providers.ts +177 -0
  175. package/src/web-search/types.ts +98 -0
  176. package/src/whats-new/body.tsx +190 -0
  177. package/src/whats-new/index.ts +43 -0
  178. package/src/whats-new/seen.ts +40 -0
  179. package/src/whats-new/select.ts +230 -0
  180. package/src/whats-new/use-whats-new.ts +109 -0
  181. package/src/wizard/index.ts +61 -0
  182. package/src/wizard/invalid.ts +152 -0
  183. package/src/wizard/react-hook-form-index.ts +11 -0
  184. package/src/wizard/rhf-adapter.ts +67 -0
  185. package/src/wizard/rules.ts +137 -0
  186. package/src/wizard/wizard.tsx +442 -0
@@ -0,0 +1,367 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ import { cx } from "../internal/cx.js";
4
+ import {
5
+ countChanges,
6
+ formatReleaseDate,
7
+ isInternalChange,
8
+ releaseAnchor,
9
+ type ChangeType,
10
+ type ChangelogRelease,
11
+ } from "../release/changelog.js";
12
+ import { releaseKind, type ReleaseKind } from "../release/version.js";
13
+
14
+ /**
15
+ * The body of a /changelog page: an index of releases beside the releases
16
+ * themselves.
17
+ *
18
+ * Each release shows its version, whether it is a major, minor or patch
19
+ * release, and its date, then a headline and a one-sentence summary. Changes
20
+ * sit under the product-area headings they were grouped by, each with a tag
21
+ * and a bold headline. The index is a sticky rail on wide screens and a
22
+ * scrolling strip of versions on a phone.
23
+ *
24
+ * Only the body: the page's header, hero, footer and metadata are the app's,
25
+ * because that is where every product already differs. Server-safe, no hooks.
26
+ *
27
+ * A long history can be shown a page at a time with `paging`: `releases` stays
28
+ * the whole history, so "Latest" and each release's kind are still right on
29
+ * page 4, the index lists the page's own releases, and a pager under them
30
+ * links the rest by version range. `changelogPageOf` says which page holds a
31
+ * version, for an app that wants an old `#v0-12-0` link to find its page.
32
+ *
33
+ * Tag colours default to tokens every house app has (`primary`, `accent`,
34
+ * `muted`, `border`). An app with `success` and `warning` tokens can pass
35
+ * `tagClassNames` for the fuller palette.
36
+ *
37
+ * The public sees `publicChangelog(CHANGELOG)`; the team sees the whole
38
+ * history. `showAudience` is for the team's view: it marks what the public
39
+ * doesn't see — internal sections and changes, a release not yet reviewed —
40
+ * and shows the public wording under any change that has one.
41
+ */
42
+
43
+ export const DEFAULT_TAG_CLASS_NAMES: Record<ChangeType, string> = {
44
+ new: "border-primary/40 bg-primary/10 text-primary",
45
+ improved: "border-border bg-accent text-accent-foreground",
46
+ changed: "border-foreground/30 bg-background text-foreground",
47
+ fixed: "border-border bg-muted text-muted-foreground",
48
+ };
49
+
50
+ export const TAG_LABELS: Record<ChangeType, string> = {
51
+ new: "New",
52
+ improved: "Improved",
53
+ changed: "Changed",
54
+ fixed: "Fixed",
55
+ };
56
+
57
+ export const KIND_LABELS: Record<ReleaseKind, string> = {
58
+ major: "Major release",
59
+ minor: "Minor release",
60
+ patch: "Patch release",
61
+ };
62
+
63
+ export interface ChangelogProps {
64
+ releases: readonly ChangelogRelease[];
65
+ /** Tag classes per change type; merged over the defaults. */
66
+ tagClassNames?: Partial<Record<ChangeType, string>>;
67
+ /** The release headline. Defaults to a plain 2xl semibold heading. */
68
+ releaseTitleClassName?: string;
69
+ /** The small uppercase label above the index. */
70
+ eyebrowClassName?: string;
71
+ /** The one-sentence summary under a release headline. */
72
+ summaryClassName?: string;
73
+ /** The "Latest" pill's colours. */
74
+ latestClassName?: string;
75
+ /** A section heading ("Notes", "Fixes"). */
76
+ sectionHeadingClassName?: string;
77
+ /** The "3 changes" count beside a section heading. */
78
+ sectionCountClassName?: string;
79
+ /**
80
+ * How a change's text is drawn. Defaults to rendering `**bold**` as strong —
81
+ * release notes name UI labels that way — and everything else as text.
82
+ */
83
+ renderText?: (text: string) => ReactNode;
84
+ /** Locale for release dates. */
85
+ locale?: string;
86
+ /** How far below the top a sticky index sits, and where an anchor lands. */
87
+ stickyTop?: string;
88
+ /** Show one page of the history rather than all of it (pages count from 1). */
89
+ paging?: ChangelogPaging;
90
+ /** Mark internal changes, unreviewed releases and public rewording — for the team's view only. */
91
+ showAudience?: boolean;
92
+ /** The "Internal" and "Not public yet" pills' colours. */
93
+ audienceClassName?: string;
94
+ className?: string;
95
+ }
96
+
97
+ export interface ChangelogPaging {
98
+ /** The page to show, from 1 (the newest releases). */
99
+ page: number;
100
+ /** Releases per page. */
101
+ pageSize: number;
102
+ /** The address of a page — the app's route, e.g. `p => p === 1 ? "/changelog" : `/changelog/page/${p}``. */
103
+ href: (page: number) => string;
104
+ }
105
+
106
+ /** How many pages a history fills at `pageSize` releases a page; an empty history is one empty page. */
107
+ export function changelogPageCount(releases: readonly ChangelogRelease[], pageSize: number): number {
108
+ return Math.max(1, Math.ceil(releases.length / Math.max(1, pageSize)));
109
+ }
110
+
111
+ /** The page (from 1) that holds `version`, or `null` when no release has it. */
112
+ export function changelogPageOf(
113
+ releases: readonly ChangelogRelease[],
114
+ version: string,
115
+ pageSize: number,
116
+ ): number | null {
117
+ const index = releases.findIndex((release) => release.version === version);
118
+ return index === -1 ? null : Math.floor(index / Math.max(1, pageSize)) + 1;
119
+ }
120
+
121
+ /** `**label**` → <strong>label</strong>; nothing else is interpreted. */
122
+ export function renderReleaseText(text: string): ReactNode {
123
+ const parts = text.split(/(\*\*[^*\n]+\*\*)/g);
124
+ return parts.map((part, i) =>
125
+ part.startsWith("**") && part.endsWith("**") && part.length > 4 ? (
126
+ <strong key={i} className="font-semibold text-foreground">
127
+ {part.slice(2, -2)}
128
+ </strong>
129
+ ) : (
130
+ part
131
+ ),
132
+ );
133
+ }
134
+
135
+ export function Changelog({
136
+ releases,
137
+ tagClassNames,
138
+ releaseTitleClassName = "text-2xl font-semibold tracking-tight text-balance sm:text-3xl",
139
+ eyebrowClassName = "text-xs font-semibold tracking-[0.14em] text-muted-foreground uppercase",
140
+ summaryClassName = "max-w-prose text-base leading-relaxed text-muted-foreground",
141
+ latestClassName = "border-primary bg-primary text-primary-foreground",
142
+ sectionHeadingClassName = "text-xs font-bold tracking-[0.14em] text-foreground uppercase",
143
+ sectionCountClassName = "text-[11px] font-medium tracking-normal text-muted-foreground normal-case",
144
+ renderText = renderReleaseText,
145
+ locale = "en-GB",
146
+ stickyTop = "7rem",
147
+ paging,
148
+ showAudience = false,
149
+ audienceClassName = "border-dashed border-foreground/40 bg-background text-muted-foreground",
150
+ className,
151
+ }: ChangelogProps) {
152
+ const audiencePill = (label: string) => (
153
+ <span
154
+ className={cx(
155
+ "inline-flex h-fit w-fit items-center rounded-full border px-2 py-0.5 text-[11px] font-semibold tracking-normal normal-case",
156
+ audienceClassName,
157
+ )}
158
+ >
159
+ {label}
160
+ </span>
161
+ );
162
+ const tags = { ...DEFAULT_TAG_CLASS_NAMES, ...tagClassNames };
163
+ const pageSize = paging ? Math.max(1, paging.pageSize) : releases.length;
164
+ const start = paging ? (paging.page - 1) * pageSize : 0;
165
+ const shown = releases.slice(start, start + pageSize);
166
+
167
+ return (
168
+ <div
169
+ className={cx("mx-auto grid max-w-6xl gap-10 px-4 py-12 lg:grid-cols-[14rem_minmax(0,1fr)] lg:gap-16", className)}
170
+ >
171
+ <nav aria-label="Releases" className="min-w-0">
172
+ <div className="lg:sticky" style={{ top: stickyTop }}>
173
+ <p className={eyebrowClassName}>Releases</p>
174
+ <ol className="-mx-4 mt-4 flex gap-2 overflow-x-auto px-4 pb-2 lg:mx-0 lg:block lg:max-h-[calc(100vh-10rem)] lg:space-y-0.5 lg:overflow-y-auto lg:border-l lg:border-border lg:px-0 lg:pb-0">
175
+ {shown.map((release) => (
176
+ <li key={release.version} className="shrink-0">
177
+ <a
178
+ href={`#${releaseAnchor(release.version)}`}
179
+ className="block rounded-full border border-border px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:border-primary hover:text-foreground lg:-ml-px lg:rounded-none lg:border-0 lg:border-l-2 lg:border-transparent lg:py-1.5 lg:pr-2 lg:pl-4"
180
+ >
181
+ <span className="font-mono text-xs font-semibold text-foreground">v{release.version}</span>
182
+ <span className="hidden truncate lg:block">{release.title}</span>
183
+ </a>
184
+ </li>
185
+ ))}
186
+ </ol>
187
+ </div>
188
+ </nav>
189
+
190
+ <div className="min-w-0 space-y-20">
191
+ {shown.map((release, i) => {
192
+ const anchor = releaseAnchor(release.version);
193
+ // A public list carries each release's real predecessor; the team's whole
194
+ // history has it next in the list.
195
+ const previousVersion = release.previousVersion ?? releases[start + i + 1]?.version;
196
+ const kind = previousVersion ? releaseKind(previousVersion, release.version) : null;
197
+
198
+ return (
199
+ <article
200
+ key={release.version}
201
+ id={anchor}
202
+ aria-labelledby={`${anchor}-title`}
203
+ style={{ scrollMarginTop: stickyTop }}
204
+ >
205
+ <header className="border-b border-border pb-7">
206
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-2">
207
+ <span className="rounded-full border border-primary/40 bg-primary/10 px-2.5 py-0.5 font-mono text-xs font-semibold text-primary">
208
+ v{release.version}
209
+ </span>
210
+ {start + i === 0 ? (
211
+ <span
212
+ className={cx("rounded-full border px-2.5 py-0.5 text-[11px] font-semibold", latestClassName)}
213
+ >
214
+ Latest
215
+ </span>
216
+ ) : null}
217
+ {kind ? <span className="text-xs text-muted-foreground">{KIND_LABELS[kind]}</span> : null}
218
+ {showAudience && !release.public ? audiencePill("Not public yet") : null}
219
+ <span className="text-xs text-muted-foreground" aria-hidden="true">
220
+ ·
221
+ </span>
222
+ <time dateTime={release.date} className="text-xs text-muted-foreground">
223
+ {formatReleaseDate(release.date, locale)}
224
+ </time>
225
+ </div>
226
+ <h2 id={`${anchor}-title`} className={cx("mt-4", releaseTitleClassName)}>
227
+ {release.title}
228
+ </h2>
229
+ <p className={cx("mt-3", summaryClassName)}>{release.summary}</p>
230
+ {showAudience && (release.public?.title || release.public?.summary) ? (
231
+ <p className="mt-3 text-sm text-muted-foreground">
232
+ <span className="font-semibold text-foreground">Public: </span>
233
+ {[release.public.title, release.public.summary].filter(Boolean).join(" — ")}
234
+ </p>
235
+ ) : null}
236
+ </header>
237
+
238
+ <div className="mt-9 space-y-10">
239
+ {release.sections.map((section) => (
240
+ <section key={section.heading} aria-label={`${section.heading} — v${release.version}`}>
241
+ <h3 className={cx("flex items-baseline gap-2", sectionHeadingClassName)}>
242
+ {section.heading}
243
+ <span className={sectionCountClassName}>
244
+ {section.changes.length} {section.changes.length === 1 ? "change" : "changes"}
245
+ </span>
246
+ {showAudience && section.audience === "internal" ? audiencePill("Internal") : null}
247
+ {showAudience && section.public?.heading ? (
248
+ <span className={sectionCountClassName}>public: {section.public.heading}</span>
249
+ ) : null}
250
+ </h3>
251
+ <ul className="mt-4 divide-y divide-border overflow-hidden rounded-2xl border border-border bg-card">
252
+ {section.changes.map((change) => (
253
+ <li
254
+ key={change.title}
255
+ className="grid gap-2.5 p-5 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-5"
256
+ >
257
+ <span
258
+ className={cx(
259
+ "inline-flex h-fit w-fit items-center rounded-full border px-2 py-0.5 text-[11px] font-semibold",
260
+ tags[change.type],
261
+ )}
262
+ >
263
+ {TAG_LABELS[change.type]}
264
+ </span>
265
+ <div>
266
+ <p className="flex flex-wrap items-center gap-2 leading-snug font-semibold text-card-foreground">
267
+ {change.title}
268
+ {showAudience && change.audience === "internal" && section.audience !== "internal"
269
+ ? audiencePill("Internal")
270
+ : null}
271
+ </p>
272
+ <p className="mt-1.5 text-sm leading-relaxed text-muted-foreground">
273
+ {renderText(change.text)}
274
+ </p>
275
+ {showAudience && change.public && !isInternalChange(change, section) ? (
276
+ <p className="mt-2 border-l-2 border-border pl-3 text-sm leading-relaxed text-muted-foreground">
277
+ <span className="font-semibold text-foreground">Public: </span>
278
+ {change.public.title ? <strong>{change.public.title}. </strong> : null}
279
+ {renderText(change.public.text ?? change.text)}
280
+ </p>
281
+ ) : null}
282
+ </div>
283
+ </li>
284
+ ))}
285
+ </ul>
286
+ </section>
287
+ ))}
288
+ </div>
289
+ </article>
290
+ );
291
+ })}
292
+ {paging ? <Pager releases={releases} paging={paging} pageSize={pageSize} /> : null}
293
+ </div>
294
+ </div>
295
+ );
296
+ }
297
+
298
+ const PAGE_LINK =
299
+ "rounded-full border border-border px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:border-primary hover:text-foreground";
300
+
301
+ /** Newer, older, and every page by the versions it holds — so an old release is two clicks away, not a guess. */
302
+ function Pager({
303
+ releases,
304
+ paging,
305
+ pageSize,
306
+ }: {
307
+ releases: readonly ChangelogRelease[];
308
+ paging: ChangelogPaging;
309
+ pageSize: number;
310
+ }) {
311
+ const pages = changelogPageCount(releases, pageSize);
312
+ if (pages < 2) return null;
313
+ const range = (page: number) => {
314
+ const first = releases[(page - 1) * pageSize];
315
+ const last = releases[Math.min(page * pageSize, releases.length) - 1];
316
+ return first && last ? `v${first.version} – v${last.version}` : `Page ${page}`;
317
+ };
318
+
319
+ return (
320
+ <nav aria-label="More releases" className="border-t border-border pt-10">
321
+ <div className="flex flex-wrap items-center justify-between gap-3">
322
+ {paging.page > 1 ? (
323
+ <a href={paging.href(paging.page - 1)} rel="prev" className={PAGE_LINK}>
324
+ ← Newer releases
325
+ </a>
326
+ ) : (
327
+ <span />
328
+ )}
329
+ {paging.page < pages ? (
330
+ <a href={paging.href(paging.page + 1)} rel="next" className={PAGE_LINK}>
331
+ Older releases →
332
+ </a>
333
+ ) : null}
334
+ </div>
335
+ <ol className="mt-6 flex flex-wrap gap-2">
336
+ {Array.from({ length: pages }, (_, i) => i + 1).map((page) => (
337
+ <li key={page}>
338
+ <a
339
+ href={paging.href(page)}
340
+ aria-current={page === paging.page ? "page" : undefined}
341
+ className={cx(
342
+ "block font-mono text-xs",
343
+ PAGE_LINK,
344
+ page === paging.page && "border-primary bg-primary/10 text-foreground",
345
+ )}
346
+ >
347
+ {range(page)}
348
+ </a>
349
+ </li>
350
+ ))}
351
+ </ol>
352
+ </nav>
353
+ );
354
+ }
355
+
356
+ /** Figures for a page hero: the latest version, how many releases, how many changes. */
357
+ export function changelogStats(releases: readonly ChangelogRelease[]): {
358
+ latest: string | null;
359
+ releases: number;
360
+ changes: number;
361
+ } {
362
+ return {
363
+ latest: releases[0]?.version ?? null,
364
+ releases: releases.length,
365
+ changes: releases.reduce((n, release) => n + countChanges(release), 0),
366
+ };
367
+ }
@@ -0,0 +1,12 @@
1
+ export {
2
+ Changelog,
3
+ changelogPageCount,
4
+ changelogPageOf,
5
+ changelogStats,
6
+ DEFAULT_TAG_CLASS_NAMES,
7
+ KIND_LABELS,
8
+ renderReleaseText,
9
+ TAG_LABELS,
10
+ type ChangelogPaging,
11
+ type ChangelogProps,
12
+ } from "./changelog.js";
@@ -0,0 +1,312 @@
1
+ "use client";
2
+
3
+ import { DragHandle } from "@tiptap/extension-drag-handle-react";
4
+ import type { Node } from "@tiptap/pm/model";
5
+ import { TextSelection } from "@tiptap/pm/state";
6
+ import { type Editor, useEditorState } from "@tiptap/react";
7
+ import { ArrowDown, ArrowUp, Check, ChevronDown, ChevronRight, Copy, GripVertical, Plus, Trash2 } from "lucide-react";
8
+ import { useCallback, useEffect, useRef, useState } from "react";
9
+
10
+ import { BLOCK_TYPES } from "./blocks.js";
11
+ import { collapseKey } from "./collapsible.js";
12
+ import { childIndexAt, neighbourUnit, positionOfChild, sectionEnd, sectionRange } from "./sections.js";
13
+ import {
14
+ ghostButtonClass,
15
+ Menu,
16
+ MenuContent,
17
+ MenuItem,
18
+ MenuSeparator,
19
+ MenuSub,
20
+ MenuSubContent,
21
+ MenuSubTrigger,
22
+ MenuTrigger,
23
+ } from "./ui.js";
24
+
25
+ interface Hovered {
26
+ node: Node;
27
+ pos: number;
28
+ }
29
+
30
+ /**
31
+ * Stable on purpose: the DragHandle wrapper re-registers its plugin when this
32
+ * changes identity, and a plugin re-registration recreates every plugin view in
33
+ * the editor — see the note in bubble-toolbar.tsx.
34
+ */
35
+ const HANDLE_POSITION = { placement: "left-start" as const };
36
+
37
+ const handleButtonClass = `${ghostButtonClass} size-6 p-0 text-muted-foreground hover:text-foreground`;
38
+
39
+ /** A top-level heading: the start of a section (sections.ts). */
40
+ const isSectionHeading = (editor: Editor, block: Hovered) =>
41
+ block.node.type.name === "heading" && childIndexAt(editor.state.doc, block.pos) !== null;
42
+
43
+ /**
44
+ * The gutter beside whichever block the pointer is over: a `+` that starts a new
45
+ * block underneath (with the `/` menu already open, as Notion does), a grip that
46
+ * drags the block to reorder it or, clicked, opens the block menu — turn into,
47
+ * duplicate, move up, move down, delete — and, beside a heading, a chevron that
48
+ * collapses or expands its section.
49
+ *
50
+ * A heading carries its section: dragging it, or moving it up or down, takes
51
+ * everything under it along (sections.ts). Everything works on the block's
52
+ * document position rather than the caret, so a block can be acted on without
53
+ * ever being clicked into. The drag itself is the extension's: it understands
54
+ * nested lists and shows the drop cursor.
55
+ *
56
+ * The grip is the drag source, so it must not be the menu's trigger: a menu
57
+ * trigger opens on pointer-down and cancels it, and a cancelled pointer-down
58
+ * never starts a drag. The menu opens on click instead, anchored to a still
59
+ * element beside the grip.
60
+ */
61
+ export function BlockHandle({ editor }: { editor: Editor }) {
62
+ const [hovered, setHovered] = useState<Hovered | null>(null);
63
+ const [menuOpen, setMenuOpen] = useState(false);
64
+ const menuOpenRef = useRef(false);
65
+ const hoveredRef = useRef<Hovered | null>(null);
66
+ const gripRef = useRef<HTMLButtonElement>(null);
67
+ useEffect(() => {
68
+ menuOpenRef.current = menuOpen;
69
+ }, [menuOpen]);
70
+ useEffect(() => {
71
+ hoveredRef.current = hovered;
72
+ }, [hovered]);
73
+
74
+ // Leave the last block in place while its menu is open, so the menu still
75
+ // knows what it belongs to after the pointer wanders. Stable identity for the
76
+ // same reason as HANDLE_POSITION.
77
+ const onNodeChange = useCallback(({ node, pos }: { node: Node | null; pos: number }) => {
78
+ if (menuOpenRef.current) return;
79
+ setHovered(node ? { node, pos } : null);
80
+ }, []);
81
+
82
+ // A heading's drag takes its section: select the whole section first, and the
83
+ // extension drags a selection that covers the grip's block as one piece.
84
+ const onElementDragStart = useCallback(() => {
85
+ const block = hoveredRef.current;
86
+ if (!block || block.node.type.name !== "heading") return;
87
+ const range = sectionRange(editor.state.doc, block.pos);
88
+ if (!range || range.blocks < 2) return;
89
+ const { doc, tr } = editor.state;
90
+ editor.view.dispatch(
91
+ tr.setSelection(TextSelection.between(doc.resolve(range.from + 1), doc.resolve(range.to - 1))),
92
+ );
93
+ }, [editor]);
94
+
95
+ const range = (block: Hovered) => ({ from: block.pos, to: block.pos + block.node.nodeSize });
96
+
97
+ /** Turn the whole block into another type, without moving the caret by hand. */
98
+ const turnInto = (block: Hovered, typeId: string) => {
99
+ const type = BLOCK_TYPES.find((t) => t.id === typeId);
100
+ if (!type) return;
101
+ const inside = { from: block.pos + 1, to: Math.max(block.pos + 1, block.pos + block.node.nodeSize - 1) };
102
+ type.apply(editor.chain().focus().setTextSelection(inside)).run();
103
+ };
104
+
105
+ const duplicate = (block: Hovered) => {
106
+ // The node is immutable, so it can be inserted twice.
107
+ editor
108
+ .chain()
109
+ .focus()
110
+ .insertContentAt(block.pos + block.node.nodeSize, block.node)
111
+ .run();
112
+ };
113
+
114
+ const remove = (block: Hovered) => {
115
+ editor.chain().focus().deleteRange(range(block)).run();
116
+ };
117
+
118
+ /**
119
+ * Move the block up (-1) or down (+1) past its neighbour. At the top of the
120
+ * document a heading moves with its section, past whole sections; inside a
121
+ * list or quote, a block swaps with its sibling.
122
+ */
123
+ const move = (block: Hovered, direction: -1 | 1) => {
124
+ const { doc } = editor.state;
125
+ const index = childIndexAt(doc, block.pos);
126
+ if (index !== null) {
127
+ const end = sectionEnd(doc, index);
128
+ const other = neighbourUnit(doc, index, end, direction);
129
+ if (!other) return;
130
+ const [first, last] = direction === 1 ? [[index, end], other] : [other, [index, end]];
131
+ const from = positionOfChild(doc, first[0]!);
132
+ const middle = positionOfChild(doc, last[0]!);
133
+ const to = positionOfChild(doc, last[1]!);
134
+ const upper = doc.slice(from, middle);
135
+ const lower = doc.slice(middle, to);
136
+ editor
137
+ .chain()
138
+ .focus()
139
+ .command(({ tr }) => {
140
+ // Swap the two runs of blocks: [first][last] becomes [last][first].
141
+ tr.replaceRange(from, to, lower);
142
+ tr.insert(from + lower.size, upper.content);
143
+ return true;
144
+ })
145
+ .run();
146
+ return;
147
+ }
148
+ const $pos = doc.resolve(block.pos);
149
+ const parent = $pos.parent;
150
+ const siblingIndex = $pos.index() + direction;
151
+ if (siblingIndex < 0 || siblingIndex >= parent.childCount) return;
152
+ const sibling = parent.child(siblingIndex);
153
+ const { from, to } = range(block);
154
+ editor
155
+ .chain()
156
+ .focus()
157
+ .command(({ tr }) => {
158
+ tr.delete(from, to);
159
+ const insertAt = direction === -1 ? from - sibling.nodeSize : from + sibling.nodeSize;
160
+ tr.insert(insertAt, block.node);
161
+ return true;
162
+ })
163
+ .run();
164
+ };
165
+
166
+ const toggleSection = (block: Hovered) => editor.chain().focus().toggleSection(block.pos).run();
167
+
168
+ /**
169
+ * The `+`: a fresh paragraph under this block with the `/` menu open — or, if
170
+ * this block is already an empty paragraph, just the menu, right here.
171
+ */
172
+ const insertBelow = (block: Hovered) => {
173
+ const isEmptyParagraph = block.node.type.name === "paragraph" && block.node.content.size === 0;
174
+ if (isEmptyParagraph) {
175
+ editor
176
+ .chain()
177
+ .focus()
178
+ .setTextSelection(block.pos + 1)
179
+ .insertContent("/")
180
+ .run();
181
+ return;
182
+ }
183
+ const after = block.pos + block.node.nodeSize;
184
+ editor
185
+ .chain()
186
+ .focus()
187
+ .insertContentAt(after, { type: "paragraph" })
188
+ .setTextSelection(after + 1)
189
+ .insertContent("/")
190
+ .run();
191
+ };
192
+
193
+ // Re-render when a section folds or opens, wherever that happened (the pill, the menu, a caret).
194
+ const collapsedAt =
195
+ useEditorState({
196
+ editor,
197
+ selector: ({ editor: current }) => collapseKey.getState(current.state)?.collapsed.join(",") ?? "",
198
+ }) ?? "";
199
+ const heading = hovered && isSectionHeading(editor, hovered) ? hovered : null;
200
+ const collapsed = heading ? collapsedAt.split(",").includes(String(heading.pos)) : false;
201
+ const canCollapse = heading ? (sectionRange(editor.state.doc, heading.pos)?.blocks ?? 1) > 1 || collapsed : false;
202
+
203
+ return (
204
+ <DragHandle
205
+ editor={editor}
206
+ nested
207
+ className="house-block-handle"
208
+ computePositionConfig={HANDLE_POSITION}
209
+ onNodeChange={onNodeChange}
210
+ onElementDragStart={onElementDragStart}
211
+ >
212
+ {/* Always in place, so the handle keeps one width and sits clear of the text; empty unless it applies. */}
213
+ {heading && canCollapse ? (
214
+ <button
215
+ type="button"
216
+ className={handleButtonClass}
217
+ aria-label={collapsed ? "Expand section" : "Collapse section"}
218
+ aria-expanded={!collapsed}
219
+ title={collapsed ? "Expand section" : "Collapse section"}
220
+ onClick={() => toggleSection(heading)}
221
+ >
222
+ {collapsed ? <ChevronRight className="size-4" aria-hidden /> : <ChevronDown className="size-4" aria-hidden />}
223
+ </button>
224
+ ) : (
225
+ <span className="inline-block size-6" aria-hidden />
226
+ )}
227
+ <button
228
+ type="button"
229
+ className={handleButtonClass}
230
+ aria-label="Add a block below"
231
+ title="Add a block below"
232
+ onClick={() => hovered && insertBelow(hovered)}
233
+ >
234
+ <Plus className="size-4" aria-hidden />
235
+ </button>
236
+ {/* The menu is portalled, so it survives the handle hiding itself when the
237
+ pointer leaves the block; `onNodeChange` holds the block steady while
238
+ the menu is open. Its trigger is the still, zero-width anchor beside the
239
+ grip — never the grip, which has to stay free to start a drag. */}
240
+ <Menu open={menuOpen} onOpenChange={setMenuOpen}>
241
+ <span className="relative inline-flex">
242
+ <button
243
+ ref={gripRef}
244
+ type="button"
245
+ className={`${handleButtonClass} cursor-grab active:cursor-grabbing`}
246
+ aria-label={heading ? "Section options — drag to move the section" : "Block options — drag to move"}
247
+ aria-haspopup="menu"
248
+ aria-expanded={menuOpen}
249
+ title={heading ? "Drag to move the section, click for options" : "Drag to move, click for options"}
250
+ onClick={() => setMenuOpen(true)}
251
+ >
252
+ <GripVertical className="size-4" aria-hidden />
253
+ </button>
254
+ {/* Laid over the grip, taking no room and no pointer: only the menu's position comes from it. */}
255
+ <MenuTrigger asChild>
256
+ <span aria-hidden className="pointer-events-none absolute inset-0" tabIndex={-1} />
257
+ </MenuTrigger>
258
+ </span>
259
+ <MenuContent
260
+ className="w-52"
261
+ onCloseAutoFocus={(event) => {
262
+ // Back to the grip, not the invisible anchor.
263
+ event.preventDefault();
264
+ gripRef.current?.focus();
265
+ }}
266
+ >
267
+ <MenuSub>
268
+ <MenuSubTrigger>Turn into</MenuSubTrigger>
269
+ <MenuSubContent className="w-48">
270
+ {BLOCK_TYPES.map((type) => (
271
+ <MenuItem key={type.id} onSelect={() => hovered && turnInto(hovered, type.id)}>
272
+ <type.icon className="size-4" aria-hidden />
273
+ <span className="flex-1">{type.label}</span>
274
+ {hovered && type.matchesNode(hovered.node) ? (
275
+ <Check className="size-4 text-primary" aria-hidden />
276
+ ) : null}
277
+ </MenuItem>
278
+ ))}
279
+ </MenuSubContent>
280
+ </MenuSub>
281
+ {heading && canCollapse ? (
282
+ <MenuItem onSelect={() => toggleSection(heading)}>
283
+ {collapsed ? (
284
+ <ChevronRight className="size-4" aria-hidden />
285
+ ) : (
286
+ <ChevronDown className="size-4" aria-hidden />
287
+ )}
288
+ {collapsed ? "Expand section" : "Collapse section"}
289
+ </MenuItem>
290
+ ) : null}
291
+ <MenuItem onSelect={() => hovered && duplicate(hovered)}>
292
+ <Copy className="size-4" aria-hidden />
293
+ Duplicate
294
+ </MenuItem>
295
+ <MenuItem onSelect={() => hovered && move(hovered, -1)}>
296
+ <ArrowUp className="size-4" aria-hidden />
297
+ {heading ? "Move section up" : "Move up"}
298
+ </MenuItem>
299
+ <MenuItem onSelect={() => hovered && move(hovered, 1)}>
300
+ <ArrowDown className="size-4" aria-hidden />
301
+ {heading ? "Move section down" : "Move down"}
302
+ </MenuItem>
303
+ <MenuSeparator />
304
+ <MenuItem className="text-destructive focus:text-destructive" onSelect={() => hovered && remove(hovered)}>
305
+ <Trash2 className="size-4" aria-hidden />
306
+ Delete
307
+ </MenuItem>
308
+ </MenuContent>
309
+ </Menu>
310
+ </DragHandle>
311
+ );
312
+ }