@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.
- package/README.md +55 -13
- package/dist/analytics/browser.d.ts +1 -0
- package/dist/analytics/browser.d.ts.map +1 -1
- package/dist/analytics/browser.js +22 -5
- package/dist/analytics/browser.js.map +1 -1
- package/dist/analytics/config.d.ts +5 -0
- package/dist/analytics/config.d.ts.map +1 -1
- package/dist/analytics/config.js +4 -1
- package/dist/analytics/config.js.map +1 -1
- package/dist/analytics/posthog-extensions.d.ts +19 -0
- package/dist/analytics/posthog-extensions.d.ts.map +1 -0
- package/dist/analytics/posthog-extensions.js +19 -0
- package/dist/analytics/posthog-extensions.js.map +1 -0
- package/dist/analytics/react.d.ts.map +1 -1
- package/dist/analytics/react.js +4 -2
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics/redact.d.ts.map +1 -1
- package/dist/analytics/redact.js +6 -1
- package/dist/analytics/redact.js.map +1 -1
- package/dist/house.css +19 -0
- package/package.json +17 -3
- package/src/account/data-contract.ts +112 -0
- package/src/account/index.ts +11 -0
- package/src/admin/access.ts +267 -0
- package/src/admin/audit.ts +238 -0
- package/src/admin/bootstrap.ts +220 -0
- package/src/admin/client-index.ts +19 -0
- package/src/admin/client.tsx +187 -0
- package/src/admin/index.ts +91 -0
- package/src/admin/proof.ts +155 -0
- package/src/admin/second-factor-index.ts +16 -0
- package/src/admin/second-factor.ts +403 -0
- package/src/admin/testing-index.ts +13 -0
- package/src/admin/testing.ts +299 -0
- package/src/admin/view-as.ts +511 -0
- package/src/ai/config-index.ts +40 -0
- package/src/ai/config.ts +176 -0
- package/src/ai/images.ts +18 -0
- package/src/ai/index.ts +21 -0
- package/src/ai/pricing.ts +107 -0
- package/src/ai/provider.ts +403 -0
- package/src/analytics/browser.ts +400 -0
- package/src/analytics/client-index.ts +12 -0
- package/src/analytics/config.ts +89 -0
- package/src/analytics/index.ts +17 -0
- package/src/analytics/ingest.ts +81 -0
- package/src/analytics/posthog-extensions.ts +19 -0
- package/src/analytics/react-index.ts +16 -0
- package/src/analytics/react.tsx +241 -0
- package/src/analytics/redact.ts +146 -0
- package/src/analytics/server-index.ts +17 -0
- package/src/analytics/server.ts +277 -0
- package/src/auth/index.ts +30 -0
- package/src/auth/second-factor-index.ts +16 -0
- package/src/auth/second-factor-next.ts +136 -0
- package/src/auth/second-factor-routes.ts +40 -0
- package/src/auth/second-factor.ts +226 -0
- package/src/auth/step-up-client-index.ts +13 -0
- package/src/auth/step-up-client.ts +23 -0
- package/src/auth/step-up-index.ts +19 -0
- package/src/auth/step-up-routes.ts +99 -0
- package/src/auth/step-up.ts +432 -0
- package/src/auth/two-factor-policy.ts +112 -0
- package/src/changelog/changelog.tsx +367 -0
- package/src/changelog/index.ts +12 -0
- package/src/editor/block-handle.tsx +312 -0
- package/src/editor/blocks.ts +169 -0
- package/src/editor/bubble-toolbar.tsx +208 -0
- package/src/editor/collapsible.ts +159 -0
- package/src/editor/content-index.ts +1 -0
- package/src/editor/content.tsx +343 -0
- package/src/editor/editor.tsx +333 -0
- package/src/editor/emoji-index.ts +1 -0
- package/src/editor/emoji-picker.tsx +114 -0
- package/src/editor/emoji.ts +436 -0
- package/src/editor/index.ts +6 -0
- package/src/editor/sections.ts +83 -0
- package/src/editor/suggestion-popup.tsx +136 -0
- package/src/editor/suggestions.ts +309 -0
- package/src/editor/ui.tsx +171 -0
- package/src/errors/error-shell.tsx +72 -0
- package/src/errors/global-error-shell.tsx +116 -0
- package/src/errors/index.ts +2 -0
- package/src/grid/columns.ts +48 -0
- package/src/grid/compare.ts +35 -0
- package/src/grid/hidden-columns.ts +95 -0
- package/src/grid/index.ts +27 -0
- package/src/grid/use-grid.ts +282 -0
- package/src/grid/views.ts +70 -0
- package/src/guides/guide-article.tsx +92 -0
- package/src/guides/guide-figure-zoom.tsx +533 -0
- package/src/guides/guide-figure.tsx +68 -0
- package/src/guides/guide-toc.tsx +133 -0
- package/src/guides/guides-landing.tsx +57 -0
- package/src/guides/guides-search.tsx +160 -0
- package/src/guides/guides-shell.tsx +60 -0
- package/src/guides/guides-sidebar.tsx +93 -0
- package/src/guides/index.ts +28 -0
- package/src/guides/library.ts +165 -0
- package/src/health/health.ts +115 -0
- package/src/health/index.ts +11 -0
- package/src/internal/cx.ts +4 -0
- package/src/internal/next-link.ts +23 -0
- package/src/jobs/counts.ts +151 -0
- package/src/jobs/cron-auth.ts +60 -0
- package/src/jobs/health.ts +315 -0
- package/src/jobs/idle.ts +86 -0
- package/src/jobs/index.ts +120 -0
- package/src/jobs/job-health-list.tsx +316 -0
- package/src/jobs/next-index.ts +4 -0
- package/src/jobs/next.ts +65 -0
- package/src/jobs/prisma-index.ts +12 -0
- package/src/jobs/prisma.ts +170 -0
- package/src/jobs/prune.ts +79 -0
- package/src/jobs/react-index.ts +35 -0
- package/src/jobs/registry.ts +189 -0
- package/src/jobs/scheduler.ts +437 -0
- package/src/jobs/store.ts +212 -0
- package/src/jobs/windows.ts +157 -0
- package/src/maintenance/core.ts +270 -0
- package/src/maintenance/gate.ts +171 -0
- package/src/maintenance/index.ts +40 -0
- package/src/maintenance/page.ts +76 -0
- package/src/maintenance/proxy.ts +88 -0
- package/src/maintenance/react-index.ts +7 -0
- package/src/maintenance/react.tsx +190 -0
- package/src/maintenance/route.ts +82 -0
- package/src/maintenance/unavailable.ts +61 -0
- package/src/markdown/figure.tsx +132 -0
- package/src/markdown/figures.ts +237 -0
- package/src/markdown/guide.tsx +536 -0
- package/src/markdown/index.ts +53 -0
- package/src/markdown/table-view.tsx +74 -0
- package/src/markdown/table.ts +90 -0
- package/src/password/common.ts +58 -0
- package/src/password/estimate-index.ts +18 -0
- package/src/password/estimate.ts +715 -0
- package/src/password/index.ts +40 -0
- package/src/password/password-input.tsx +116 -0
- package/src/password/password-strength.tsx +157 -0
- package/src/password/reveal.ts +151 -0
- package/src/rate-limit/better-auth.ts +94 -0
- package/src/rate-limit/index.ts +32 -0
- package/src/rate-limit/keys.ts +110 -0
- package/src/rate-limit/limiter.ts +276 -0
- package/src/rate-limit/prisma-index.ts +12 -0
- package/src/rate-limit/prisma.ts +157 -0
- package/src/rate-limit/store.ts +47 -0
- package/src/release/changelog.ts +364 -0
- package/src/release/index.ts +32 -0
- package/src/release/version.ts +64 -0
- package/src/setup-guide/bits.tsx +420 -0
- package/src/setup-guide/card.tsx +358 -0
- package/src/setup-guide/class-names.ts +144 -0
- package/src/setup-guide/context.tsx +239 -0
- package/src/setup-guide/guide.ts +271 -0
- package/src/setup-guide/index.ts +76 -0
- package/src/setup-guide/launcher.tsx +207 -0
- package/src/setup-guide/strip.tsx +127 -0
- package/src/styles/house.css +403 -0
- package/src/trail/index.ts +12 -0
- package/src/trail/rules.ts +84 -0
- package/src/trail/trail.tsx +367 -0
- package/src/ux/errors.ts +32 -0
- package/src/ux/feedback.tsx +41 -0
- package/src/ux/index.ts +44 -0
- package/src/ux/navigation-index.ts +16 -0
- package/src/ux/navigation-progress.tsx +270 -0
- package/src/ux/optimistic.ts +415 -0
- package/src/ux/use-action.ts +155 -0
- package/src/ux/use-optimistic-list.ts +227 -0
- package/src/ux/use-optimistic-value.ts +136 -0
- package/src/web-search/index.ts +13 -0
- package/src/web-search/providers.ts +177 -0
- package/src/web-search/types.ts +98 -0
- package/src/whats-new/body.tsx +190 -0
- package/src/whats-new/index.ts +43 -0
- package/src/whats-new/seen.ts +40 -0
- package/src/whats-new/select.ts +230 -0
- package/src/whats-new/use-whats-new.ts +109 -0
- package/src/wizard/index.ts +61 -0
- package/src/wizard/invalid.ts +152 -0
- package/src/wizard/react-hook-form-index.ts +11 -0
- package/src/wizard/rhf-adapter.ts +67 -0
- package/src/wizard/rules.ts +137 -0
- package/src/wizard/wizard.tsx +442 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Fragment, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
|
|
6
|
+
import { cx } from "../internal/cx.js";
|
|
7
|
+
import type { SuggestionItem } from "./suggestions.js";
|
|
8
|
+
|
|
9
|
+
interface SuggestionPopupProps {
|
|
10
|
+
items: SuggestionItem[];
|
|
11
|
+
activeIndex: number;
|
|
12
|
+
clientRect: (() => DOMRect | null) | null;
|
|
13
|
+
onSelect: (item: SuggestionItem) => void;
|
|
14
|
+
onHover: (index: number) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The floating list under an `@`, `#`, `/` or `:` being typed. Portalled to the
|
|
19
|
+
* body and positioned from the caret rect, so it works inside dialogs and scroll
|
|
20
|
+
* areas without a positioning library. Theme-safe by construction: popover and
|
|
21
|
+
* accent tokens only.
|
|
22
|
+
*/
|
|
23
|
+
export function SuggestionPopup({ items, activeIndex, clientRect, onSelect, onHover }: SuggestionPopupProps) {
|
|
24
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
25
|
+
const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
|
|
26
|
+
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
// The rect resolver holds a document position that this render may have
|
|
29
|
+
// outrun (an autosave refresh, an accepted suggestion shrinking the doc);
|
|
30
|
+
// ProseMirror then throws "Position out of range". A popup one frame from
|
|
31
|
+
// closing anyway must never be able to take the editor down with it.
|
|
32
|
+
let rect: DOMRect | null = null;
|
|
33
|
+
try {
|
|
34
|
+
rect = clientRect?.() ?? null;
|
|
35
|
+
} catch {
|
|
36
|
+
rect = null;
|
|
37
|
+
}
|
|
38
|
+
if (!rect) return;
|
|
39
|
+
const width = ref.current?.offsetWidth ?? 288;
|
|
40
|
+
const height = ref.current?.offsetHeight ?? 240;
|
|
41
|
+
// Below the caret unless that would leave the viewport; clamp horizontally.
|
|
42
|
+
const top = rect.bottom + height + 8 > window.innerHeight ? rect.top - height - 4 : rect.bottom + 4;
|
|
43
|
+
const left = Math.min(rect.left, window.innerWidth - width - 8);
|
|
44
|
+
setPosition({ left: Math.max(8, left), top: Math.max(8, top) });
|
|
45
|
+
}, [clientRect, items.length]);
|
|
46
|
+
|
|
47
|
+
// Keep the active row visible while arrowing through a long list.
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
ref.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
|
|
50
|
+
}, [activeIndex]);
|
|
51
|
+
|
|
52
|
+
if (items.length === 0) return null;
|
|
53
|
+
|
|
54
|
+
return createPortal(
|
|
55
|
+
<div
|
|
56
|
+
ref={ref}
|
|
57
|
+
role="listbox"
|
|
58
|
+
aria-label="Suggestions"
|
|
59
|
+
style={position ? { left: position.left, top: position.top } : { visibility: "hidden" }}
|
|
60
|
+
className="fixed z-50 max-h-80 w-80 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-md"
|
|
61
|
+
>
|
|
62
|
+
{items.map((item, index) => {
|
|
63
|
+
const Icon = item.icon;
|
|
64
|
+
return (
|
|
65
|
+
<Fragment key={item.key}>
|
|
66
|
+
{item.group && item.group !== items[index - 1]?.group ? (
|
|
67
|
+
<p
|
|
68
|
+
role="presentation"
|
|
69
|
+
className={cx(
|
|
70
|
+
"px-2 pb-1 text-xs font-medium text-muted-foreground",
|
|
71
|
+
index > 0 ? "mt-1 border-t border-border pt-2" : "pt-1",
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
{item.group}
|
|
75
|
+
</p>
|
|
76
|
+
) : null}
|
|
77
|
+
<button
|
|
78
|
+
type="button"
|
|
79
|
+
role="option"
|
|
80
|
+
aria-selected={index === activeIndex}
|
|
81
|
+
data-active={index === activeIndex}
|
|
82
|
+
// Mousedown, not click: click lands after the editor regains focus
|
|
83
|
+
// and the suggestion range has already been re-evaluated.
|
|
84
|
+
onMouseDown={(event) => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
onSelect(item);
|
|
87
|
+
}}
|
|
88
|
+
onMouseEnter={() => onHover(index)}
|
|
89
|
+
className={cx(
|
|
90
|
+
"flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-sm",
|
|
91
|
+
index === activeIndex ? "bg-accent text-accent-foreground" : "hover:bg-accent/60",
|
|
92
|
+
)}
|
|
93
|
+
>
|
|
94
|
+
{item.avatar ? (
|
|
95
|
+
<span
|
|
96
|
+
className="flex size-7 shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-[11px] font-semibold text-muted-foreground"
|
|
97
|
+
aria-hidden
|
|
98
|
+
>
|
|
99
|
+
{item.avatar.image ? (
|
|
100
|
+
// A 28px avatar from the account; there is no optimisation to gain.
|
|
101
|
+
<img src={item.avatar.image} alt="" className="size-full object-cover" />
|
|
102
|
+
) : (
|
|
103
|
+
item.avatar.initials
|
|
104
|
+
)}
|
|
105
|
+
</span>
|
|
106
|
+
) : Icon ? (
|
|
107
|
+
<span className="flex size-7 shrink-0 items-center justify-center rounded-md border border-border bg-background">
|
|
108
|
+
<Icon className="size-4" aria-hidden />
|
|
109
|
+
</span>
|
|
110
|
+
) : item.glyph ? (
|
|
111
|
+
<span className="flex size-7 shrink-0 items-center justify-center text-lg leading-none" aria-hidden>
|
|
112
|
+
{item.glyph}
|
|
113
|
+
</span>
|
|
114
|
+
) : null}
|
|
115
|
+
{item.avatar ? (
|
|
116
|
+
// People get two lines: who they are to you can be a phrase, not a word.
|
|
117
|
+
<span className="min-w-0 flex-1">
|
|
118
|
+
<span className="block truncate font-medium">{item.label}</span>
|
|
119
|
+
{item.hint ? <span className="block truncate text-xs text-muted-foreground">{item.hint}</span> : null}
|
|
120
|
+
</span>
|
|
121
|
+
) : (
|
|
122
|
+
<>
|
|
123
|
+
<span className="min-w-0 flex-1 truncate font-medium">{item.label}</span>
|
|
124
|
+
{item.hint ? (
|
|
125
|
+
<span className="max-w-[45%] shrink-0 truncate text-xs text-muted-foreground">{item.hint}</span>
|
|
126
|
+
) : null}
|
|
127
|
+
</>
|
|
128
|
+
)}
|
|
129
|
+
</button>
|
|
130
|
+
</Fragment>
|
|
131
|
+
);
|
|
132
|
+
})}
|
|
133
|
+
</div>,
|
|
134
|
+
document.body,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Extension, type Editor, type Range } from "@tiptap/core";
|
|
4
|
+
import { PluginKey } from "@tiptap/pm/state";
|
|
5
|
+
import { Suggestion, type SuggestionKeyDownProps, type SuggestionProps } from "@tiptap/suggestion";
|
|
6
|
+
import { AtSign, CalendarDays, Minus, SmilePlus, type LucideIcon } from "lucide-react";
|
|
7
|
+
|
|
8
|
+
import { BLOCK_TYPES } from "./blocks.js";
|
|
9
|
+
import { searchEmoji } from "./emoji.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The character-triggered lookups the editor offers:
|
|
13
|
+
*
|
|
14
|
+
* - `/` opens the block menu — the same list the bubble menu's "Turn into" and
|
|
15
|
+
* each block's grip use, plus a few insert-only actions;
|
|
16
|
+
* - `:` completes an emoji shortcode from the curated set;
|
|
17
|
+
* - `@` references something linkable, and `#` completes a tag — both only when
|
|
18
|
+
* the host app supplies a source, because only the app knows what its people,
|
|
19
|
+
* records and tags are.
|
|
20
|
+
*
|
|
21
|
+
* None of them inserts a custom node. `@` becomes ordinary text carrying an
|
|
22
|
+
* ordinary link mark (`[@label](href)` in Markdown), `#` and `:` become plain
|
|
23
|
+
* text, and `/` converts the current block through the same commands the
|
|
24
|
+
* Markdown input rules use — so the stored Markdown needs no special dialect,
|
|
25
|
+
* survives any renderer, and a server can mirror `@` and `#` by regex without an
|
|
26
|
+
* editor in the loop.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** One row in the suggestion popup — every kind, one shape. */
|
|
30
|
+
export interface SuggestionItem {
|
|
31
|
+
key: string;
|
|
32
|
+
label: string;
|
|
33
|
+
hint: string | null;
|
|
34
|
+
/** A lucide icon for block/action rows. */
|
|
35
|
+
icon?: LucideIcon;
|
|
36
|
+
/** A literal glyph instead of an icon — an emoji. */
|
|
37
|
+
glyph?: string;
|
|
38
|
+
/** A person: initials (and picture), shown as an avatar. */
|
|
39
|
+
avatar?: { initials: string; image: string | null };
|
|
40
|
+
/** The heading this row sits under; the popup prints one per run of rows. */
|
|
41
|
+
group?: string;
|
|
42
|
+
/** What accepting this row does to the document. */
|
|
43
|
+
insert:
|
|
44
|
+
| { kind: "reference"; href: string }
|
|
45
|
+
| { kind: "text"; text: string }
|
|
46
|
+
| { kind: "emoji"; char: string }
|
|
47
|
+
| { kind: "block"; run: (editor: Editor) => void };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Where `@` and `#` get their rows. Omit one and its trigger does nothing. */
|
|
51
|
+
export interface SuggestionSources {
|
|
52
|
+
references?: (query: string) => Promise<SuggestionItem[]>;
|
|
53
|
+
tags?: (query: string) => Promise<SuggestionItem[]>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What the editor component needs to render and drive the popup. */
|
|
57
|
+
export interface SuggestionSession {
|
|
58
|
+
items: SuggestionItem[];
|
|
59
|
+
clientRect: (() => DOMRect | null) | null;
|
|
60
|
+
command: (item: SuggestionItem) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface SuggestionUiHandle {
|
|
64
|
+
onOpen: (session: SuggestionSession) => void;
|
|
65
|
+
onClose: () => void;
|
|
66
|
+
/** Returns true when the popup consumed the key (arrows, Enter, Escape). */
|
|
67
|
+
onKeyDown: (event: KeyboardEvent) => boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SuggestionOptions {
|
|
71
|
+
/** Today's date as the `/` menu inserts it. */
|
|
72
|
+
formatDate: (date: Date) => string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ukShortDate = new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric" });
|
|
76
|
+
|
|
77
|
+
export const DEFAULT_SUGGESTION_OPTIONS: SuggestionOptions = {
|
|
78
|
+
formatDate: (date) => ukShortDate.format(date),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/* ── Item sources ─────────────────────────────────────────────────────── */
|
|
82
|
+
|
|
83
|
+
export function emojiItems(query: string): SuggestionItem[] {
|
|
84
|
+
return searchEmoji(query, 8).map((entry) => ({
|
|
85
|
+
key: `emoji:${entry.name}`,
|
|
86
|
+
label: entry.name.replace(/_/g, " "),
|
|
87
|
+
hint: null,
|
|
88
|
+
glyph: entry.char,
|
|
89
|
+
insert: { kind: "emoji", char: entry.char },
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The `/` menu: every block type, then the insert-only actions. Filtered by
|
|
95
|
+
* label and keywords so `/todo`, `/h2`, `/date` all land where expected.
|
|
96
|
+
*/
|
|
97
|
+
export function slashItems(query: string, sources: SuggestionSources, options: SuggestionOptions): SuggestionItem[] {
|
|
98
|
+
const term = query.trim().toLowerCase();
|
|
99
|
+
const blocks: SuggestionItem[] = BLOCK_TYPES.map((type) => ({
|
|
100
|
+
key: `block:${type.id}`,
|
|
101
|
+
label: type.label,
|
|
102
|
+
hint: type.shortcut.trim() || null,
|
|
103
|
+
icon: type.icon,
|
|
104
|
+
insert: { kind: "block", run: (editor) => void type.apply(editor.chain().focus()).run() },
|
|
105
|
+
}));
|
|
106
|
+
const today = options.formatDate(new Date());
|
|
107
|
+
const actions: SuggestionItem[] = [
|
|
108
|
+
{
|
|
109
|
+
key: "action:divider",
|
|
110
|
+
label: "Divider",
|
|
111
|
+
hint: "---",
|
|
112
|
+
icon: Minus,
|
|
113
|
+
insert: { kind: "block", run: (editor) => void editor.chain().focus().setHorizontalRule().run() },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
key: "action:date",
|
|
117
|
+
label: "Today's date",
|
|
118
|
+
hint: today,
|
|
119
|
+
icon: CalendarDays,
|
|
120
|
+
insert: { kind: "block", run: (editor) => void editor.chain().focus().insertContent(`${today} `).run() },
|
|
121
|
+
},
|
|
122
|
+
...(sources.references
|
|
123
|
+
? [
|
|
124
|
+
{
|
|
125
|
+
key: "action:reference",
|
|
126
|
+
label: "Reference…",
|
|
127
|
+
hint: "@",
|
|
128
|
+
icon: AtSign,
|
|
129
|
+
insert: { kind: "block", run: (editor: Editor) => void editor.chain().focus().insertContent("@").run() },
|
|
130
|
+
} satisfies SuggestionItem,
|
|
131
|
+
]
|
|
132
|
+
: []),
|
|
133
|
+
{
|
|
134
|
+
key: "action:emoji",
|
|
135
|
+
label: "Emoji…",
|
|
136
|
+
hint: ":",
|
|
137
|
+
icon: SmilePlus,
|
|
138
|
+
insert: { kind: "block", run: (editor) => void editor.chain().focus().insertContent(":").run() },
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
const all = [...blocks, ...actions];
|
|
142
|
+
if (!term) return all;
|
|
143
|
+
const keywordsOf = (item: SuggestionItem) =>
|
|
144
|
+
BLOCK_TYPES.find((type) => `block:${type.id}` === item.key)?.keywords ?? [];
|
|
145
|
+
return all.filter(
|
|
146
|
+
(item) =>
|
|
147
|
+
item.label.toLowerCase().includes(term) ||
|
|
148
|
+
(item.hint ?? "").toLowerCase().startsWith(term) ||
|
|
149
|
+
keywordsOf(item).some((keyword) => keyword.includes(term)),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ── Applying a choice ────────────────────────────────────────────────── */
|
|
154
|
+
|
|
155
|
+
/** Apply an accepted row to the document, replacing the trigger text. */
|
|
156
|
+
export function applySuggestion(editor: Editor, range: Range, item: SuggestionItem): void {
|
|
157
|
+
switch (item.insert.kind) {
|
|
158
|
+
case "reference":
|
|
159
|
+
editor
|
|
160
|
+
.chain()
|
|
161
|
+
.focus()
|
|
162
|
+
.insertContentAt(range, [
|
|
163
|
+
{ type: "text", text: `@${item.label}`, marks: [{ type: "link", attrs: { href: item.insert.href } }] },
|
|
164
|
+
// The space deliberately carries no marks, so the link stops here
|
|
165
|
+
// instead of bleeding into whatever is typed next.
|
|
166
|
+
{ type: "text", text: " " },
|
|
167
|
+
])
|
|
168
|
+
.run();
|
|
169
|
+
return;
|
|
170
|
+
case "text":
|
|
171
|
+
editor.chain().focus().insertContentAt(range, `${item.insert.text} `).run();
|
|
172
|
+
return;
|
|
173
|
+
case "emoji":
|
|
174
|
+
editor.chain().focus().insertContentAt(range, `${item.insert.char} `).run();
|
|
175
|
+
return;
|
|
176
|
+
case "block":
|
|
177
|
+
// Remove the "/query" first, then run the block command on what's left.
|
|
178
|
+
editor.chain().focus().deleteRange(range).run();
|
|
179
|
+
item.insert.run(editor);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* How far an `@` lookup reaches. Names have spaces in them ("Ben Okafor",
|
|
186
|
+
* "Commitments & obligation"), so the query runs on past a space — but only
|
|
187
|
+
* while it is still finding something. Once a query with a space in it comes
|
|
188
|
+
* back empty, anything typed after it is ordinary writing, and the lookup lets
|
|
189
|
+
* go instead of following the rest of the sentence. Any character may appear in
|
|
190
|
+
* the query; the source decides what matches.
|
|
191
|
+
*/
|
|
192
|
+
export function referenceReach() {
|
|
193
|
+
// The shortest query with a space in it that found nothing, normalised.
|
|
194
|
+
let deadEnd: string | null = null;
|
|
195
|
+
const normalise = (query: string) => query.replace(/\s+/g, " ").trimStart().toLowerCase();
|
|
196
|
+
return {
|
|
197
|
+
/** Whether the lookup should stay open for this query. */
|
|
198
|
+
reaches(query: string): boolean {
|
|
199
|
+
if (!/\s/.test(query)) {
|
|
200
|
+
// A new word-only query starts afresh.
|
|
201
|
+
deadEnd = null;
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return deadEnd === null || !normalise(query).startsWith(deadEnd);
|
|
205
|
+
},
|
|
206
|
+
/** Note what a query found, once its items arrive. True when it has just reached a dead end. */
|
|
207
|
+
found(query: string, count: number): boolean {
|
|
208
|
+
if (count > 0 || !/\s/.test(query)) return false;
|
|
209
|
+
const at = normalise(query);
|
|
210
|
+
if (deadEnd !== null && at.startsWith(deadEnd)) return false;
|
|
211
|
+
deadEnd = at;
|
|
212
|
+
return true;
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderInto(ui: { current: SuggestionUiHandle }) {
|
|
218
|
+
return () => ({
|
|
219
|
+
onStart: (props: SuggestionProps<SuggestionItem, SuggestionItem>) => {
|
|
220
|
+
ui.current.onOpen({ items: props.items, clientRect: props.clientRect ?? null, command: props.command });
|
|
221
|
+
},
|
|
222
|
+
onUpdate: (props: SuggestionProps<SuggestionItem, SuggestionItem>) => {
|
|
223
|
+
ui.current.onOpen({ items: props.items, clientRect: props.clientRect ?? null, command: props.command });
|
|
224
|
+
},
|
|
225
|
+
onKeyDown: (props: SuggestionKeyDownProps) => ui.current.onKeyDown(props.event),
|
|
226
|
+
onExit: () => ui.current.onClose(),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Every lookup as one extension. `ui` and `sources` are ref-like holders read
|
|
232
|
+
* lazily on every callback, so the extension (created once per editor) always
|
|
233
|
+
* talks to the current render's handlers and the app's current sources.
|
|
234
|
+
*/
|
|
235
|
+
export function createSuggestions(
|
|
236
|
+
ui: { current: SuggestionUiHandle },
|
|
237
|
+
sources: { current: SuggestionSources },
|
|
238
|
+
options: { current: SuggestionOptions },
|
|
239
|
+
) {
|
|
240
|
+
const shared = {
|
|
241
|
+
decorationClass: "house-suggestion",
|
|
242
|
+
command: ({ editor, range, props }: { editor: Editor; range: Range; props: SuggestionItem }) =>
|
|
243
|
+
applySuggestion(editor, range, props),
|
|
244
|
+
render: renderInto(ui),
|
|
245
|
+
};
|
|
246
|
+
const reach = referenceReach();
|
|
247
|
+
|
|
248
|
+
return Extension.create({
|
|
249
|
+
name: "houseSuggestions",
|
|
250
|
+
|
|
251
|
+
addProseMirrorPlugins() {
|
|
252
|
+
return [
|
|
253
|
+
Suggestion<SuggestionItem, SuggestionItem>({
|
|
254
|
+
...shared,
|
|
255
|
+
pluginKey: new PluginKey("houseReferenceSuggestion"),
|
|
256
|
+
editor: this.editor,
|
|
257
|
+
char: "@",
|
|
258
|
+
// Open on the `@` itself, as Notion does: the list shows what you
|
|
259
|
+
// work with before anything is typed.
|
|
260
|
+
minQueryLength: 0,
|
|
261
|
+
debounce: 150,
|
|
262
|
+
// Past spaces too, for names with more than one word — see `referenceReach`.
|
|
263
|
+
allowSpaces: true,
|
|
264
|
+
allow: () => Boolean(sources.current.references),
|
|
265
|
+
shouldShow: ({ query }) => reach.reaches(query),
|
|
266
|
+
items: async ({ editor, query }) => {
|
|
267
|
+
const items = (await sources.current.references?.(query)) ?? [];
|
|
268
|
+
// At a dead end, let go now rather than at the next keystroke, so the
|
|
269
|
+
// lookup's highlight doesn't sit over the sentence in the meantime.
|
|
270
|
+
if (reach.found(query, items.length))
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
if (!editor.isDestroyed) editor.view.dispatch(editor.state.tr.setMeta("houseReferenceReach", true));
|
|
273
|
+
});
|
|
274
|
+
return items;
|
|
275
|
+
},
|
|
276
|
+
}),
|
|
277
|
+
Suggestion<SuggestionItem, SuggestionItem>({
|
|
278
|
+
...shared,
|
|
279
|
+
pluginKey: new PluginKey("houseTagSuggestion"),
|
|
280
|
+
editor: this.editor,
|
|
281
|
+
char: "#",
|
|
282
|
+
minQueryLength: 1,
|
|
283
|
+
debounce: 150,
|
|
284
|
+
allow: () => Boolean(sources.current.tags),
|
|
285
|
+
items: ({ query }) => sources.current.tags?.(query) ?? [],
|
|
286
|
+
}),
|
|
287
|
+
Suggestion<SuggestionItem, SuggestionItem>({
|
|
288
|
+
...shared,
|
|
289
|
+
pluginKey: new PluginKey("houseSlashSuggestion"),
|
|
290
|
+
editor: this.editor,
|
|
291
|
+
char: "/",
|
|
292
|
+
// Only after a space or at the start of a block, so `and/or` and the
|
|
293
|
+
// `/` inside a URL never open the menu.
|
|
294
|
+
allowedPrefixes: [" "],
|
|
295
|
+
items: ({ query }) => slashItems(query, sources.current, options.current),
|
|
296
|
+
}),
|
|
297
|
+
Suggestion<SuggestionItem, SuggestionItem>({
|
|
298
|
+
...shared,
|
|
299
|
+
pluginKey: new PluginKey("houseEmojiSuggestion"),
|
|
300
|
+
editor: this.editor,
|
|
301
|
+
char: ":",
|
|
302
|
+
minQueryLength: 2,
|
|
303
|
+
allowedPrefixes: [" "],
|
|
304
|
+
items: ({ query }) => emojiItems(query),
|
|
305
|
+
}),
|
|
306
|
+
];
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
4
|
+
import * as Popover from "@radix-ui/react-popover";
|
|
5
|
+
import { forwardRef, type ButtonHTMLAttributes, type InputHTMLAttributes, type ReactNode } from "react";
|
|
6
|
+
|
|
7
|
+
import { cx } from "../internal/cx.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The few controls the editor's own chrome needs — a menu, a popover, a small
|
|
11
|
+
* button — built on Radix and the house token classes.
|
|
12
|
+
*
|
|
13
|
+
* Not the host app's design system, and not a replacement for it. The package
|
|
14
|
+
* README's rule is that nothing here brings a second Button into an app; these
|
|
15
|
+
* are the editor's internal parts (the formatting bubble, the block menu, the
|
|
16
|
+
* link box), never exported, and they exist because the apps' own primitive
|
|
17
|
+
* sets differ — several have no popover or toggle at all — so the editor
|
|
18
|
+
* cannot ask for them.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const buttonClass =
|
|
22
|
+
"inline-flex shrink-0 items-center justify-center gap-1.5 rounded-md text-sm font-medium whitespace-nowrap transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50";
|
|
23
|
+
|
|
24
|
+
export const ghostButtonClass = cx(buttonClass, "text-foreground hover:bg-accent hover:text-accent-foreground");
|
|
25
|
+
|
|
26
|
+
export const primaryButtonClass = cx(buttonClass, "h-8 bg-primary px-3 text-primary-foreground hover:bg-primary/90");
|
|
27
|
+
|
|
28
|
+
const menuSurfaceClass =
|
|
29
|
+
"z-50 min-w-[10rem] overflow-hidden rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md";
|
|
30
|
+
|
|
31
|
+
const menuItemClass =
|
|
32
|
+
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
|
|
33
|
+
|
|
34
|
+
export const IconButton = forwardRef<
|
|
35
|
+
HTMLButtonElement,
|
|
36
|
+
ButtonHTMLAttributes<HTMLButtonElement> & { pressed?: boolean }
|
|
37
|
+
>(function IconButton({ pressed, className, type = "button", ...props }, ref) {
|
|
38
|
+
return (
|
|
39
|
+
<button
|
|
40
|
+
ref={ref}
|
|
41
|
+
type={type}
|
|
42
|
+
aria-pressed={pressed}
|
|
43
|
+
className={cx(ghostButtonClass, "size-8 p-0", pressed && "bg-accent text-accent-foreground", className)}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const TextInput = forwardRef<HTMLInputElement, InputHTMLAttributes<HTMLInputElement>>(function TextInput(
|
|
50
|
+
{ className, ...props },
|
|
51
|
+
ref,
|
|
52
|
+
) {
|
|
53
|
+
return (
|
|
54
|
+
<input
|
|
55
|
+
ref={ref}
|
|
56
|
+
className={cx(
|
|
57
|
+
"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm text-foreground shadow-xs outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring",
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export function VerticalSeparator() {
|
|
66
|
+
return <span role="separator" aria-orientation="vertical" className="mx-0.5 h-5 w-px bg-border" />;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const Menu = DropdownMenu.Root;
|
|
70
|
+
export const MenuTrigger = DropdownMenu.Trigger;
|
|
71
|
+
export const MenuSub = DropdownMenu.Sub;
|
|
72
|
+
|
|
73
|
+
export function MenuContent({
|
|
74
|
+
children,
|
|
75
|
+
className,
|
|
76
|
+
align = "start",
|
|
77
|
+
onCloseAutoFocus,
|
|
78
|
+
}: {
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
className?: string;
|
|
81
|
+
align?: "start" | "center" | "end";
|
|
82
|
+
/** Radix's: `preventDefault()` and move focus yourself, when the trigger isn't where focus should go back to. */
|
|
83
|
+
onCloseAutoFocus?: (event: Event) => void;
|
|
84
|
+
}) {
|
|
85
|
+
return (
|
|
86
|
+
<DropdownMenu.Portal>
|
|
87
|
+
<DropdownMenu.Content
|
|
88
|
+
align={align}
|
|
89
|
+
sideOffset={4}
|
|
90
|
+
className={cx(menuSurfaceClass, className)}
|
|
91
|
+
onCloseAutoFocus={onCloseAutoFocus}
|
|
92
|
+
>
|
|
93
|
+
{children}
|
|
94
|
+
</DropdownMenu.Content>
|
|
95
|
+
</DropdownMenu.Portal>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function MenuItem({
|
|
100
|
+
children,
|
|
101
|
+
onSelect,
|
|
102
|
+
className,
|
|
103
|
+
}: {
|
|
104
|
+
children: ReactNode;
|
|
105
|
+
onSelect: () => void;
|
|
106
|
+
className?: string;
|
|
107
|
+
}) {
|
|
108
|
+
return (
|
|
109
|
+
<DropdownMenu.Item onSelect={onSelect} className={cx(menuItemClass, className)}>
|
|
110
|
+
{children}
|
|
111
|
+
</DropdownMenu.Item>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function MenuLabel({ children }: { children: ReactNode }) {
|
|
116
|
+
return (
|
|
117
|
+
<DropdownMenu.Label className="px-2 py-1.5 text-[11px] font-semibold tracking-wide text-muted-foreground uppercase">
|
|
118
|
+
{children}
|
|
119
|
+
</DropdownMenu.Label>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function MenuSeparator() {
|
|
124
|
+
return <DropdownMenu.Separator className="-mx-1 my-1 h-px bg-border" />;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function MenuSubTrigger({ children }: { children: ReactNode }) {
|
|
128
|
+
return (
|
|
129
|
+
<DropdownMenu.SubTrigger className={cx(menuItemClass, "data-[state=open]:bg-accent")}>
|
|
130
|
+
{children}
|
|
131
|
+
</DropdownMenu.SubTrigger>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function MenuSubContent({ children, className }: { children: ReactNode; className?: string }) {
|
|
136
|
+
return (
|
|
137
|
+
<DropdownMenu.Portal>
|
|
138
|
+
<DropdownMenu.SubContent sideOffset={4} className={cx(menuSurfaceClass, className)}>
|
|
139
|
+
{children}
|
|
140
|
+
</DropdownMenu.SubContent>
|
|
141
|
+
</DropdownMenu.Portal>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const PopoverRoot = Popover.Root;
|
|
146
|
+
export const PopoverTrigger = Popover.Trigger;
|
|
147
|
+
|
|
148
|
+
export function PopoverContent({
|
|
149
|
+
children,
|
|
150
|
+
className,
|
|
151
|
+
align = "start",
|
|
152
|
+
}: {
|
|
153
|
+
children: ReactNode;
|
|
154
|
+
className?: string;
|
|
155
|
+
align?: "start" | "center" | "end";
|
|
156
|
+
}) {
|
|
157
|
+
return (
|
|
158
|
+
<Popover.Portal>
|
|
159
|
+
<Popover.Content
|
|
160
|
+
align={align}
|
|
161
|
+
sideOffset={6}
|
|
162
|
+
className={cx(
|
|
163
|
+
"z-50 rounded-md border border-border bg-popover p-3 text-popover-foreground shadow-md outline-none",
|
|
164
|
+
className,
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
{children}
|
|
168
|
+
</Popover.Content>
|
|
169
|
+
</Popover.Portal>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The frame every error and not-found screen shares.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately dependency-light — no providers, no theme hook, no data fetching,
|
|
7
|
+
* and no component library. It renders plain elements with the house token
|
|
8
|
+
* classes (`bg-card`, `border-border`, `text-muted-foreground`), so it looks
|
|
9
|
+
* like the app it is dropped into without importing anything from it. That
|
|
10
|
+
* matters more here than anywhere else: this renders precisely when something
|
|
11
|
+
* upstream has already failed.
|
|
12
|
+
*
|
|
13
|
+
* Anything app-specific — where the buttons go, what they say — arrives as
|
|
14
|
+
* props. The package has no opinion about your routes.
|
|
15
|
+
*/
|
|
16
|
+
export function ErrorShell({
|
|
17
|
+
code,
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
actions,
|
|
21
|
+
digest,
|
|
22
|
+
}: {
|
|
23
|
+
/** Short marker above the heading — "404", "Error". */
|
|
24
|
+
code: string;
|
|
25
|
+
title: string;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
actions: ReactNode;
|
|
28
|
+
/** Next's error digest. The one thing support can correlate to a server log. */
|
|
29
|
+
digest?: string;
|
|
30
|
+
}) {
|
|
31
|
+
return (
|
|
32
|
+
<main className="flex min-h-[70vh] items-center justify-center px-6 py-16">
|
|
33
|
+
<div className="w-full max-w-lg rounded-xl border border-border bg-card p-8 shadow-sm sm:p-10">
|
|
34
|
+
<p className="font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground">{code}</p>
|
|
35
|
+
<h1 className="mt-3 text-balance text-2xl font-semibold tracking-tight sm:text-3xl">{title}</h1>
|
|
36
|
+
<div className="mt-4 space-y-3 text-sm leading-relaxed text-muted-foreground">{children}</div>
|
|
37
|
+
<div className="mt-8 flex flex-wrap gap-3">{actions}</div>
|
|
38
|
+
{digest ? (
|
|
39
|
+
<p className="mt-8 border-t border-border pt-4 font-mono text-xs text-muted-foreground">
|
|
40
|
+
Reference <span className="select-all text-foreground">{digest}</span>
|
|
41
|
+
</p>
|
|
42
|
+
) : null}
|
|
43
|
+
</div>
|
|
44
|
+
</main>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Button-shaped classes for an ErrorShell action.
|
|
50
|
+
*
|
|
51
|
+
* Returned as a class string rather than a component, because the one thing
|
|
52
|
+
* this package must not do is bring a second Button into an app that already
|
|
53
|
+
* has one. Wrap your own:
|
|
54
|
+
*
|
|
55
|
+
* ```tsx
|
|
56
|
+
* <Button asChild variant="outline"><Link href="/">Home</Link></Button>
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* and reach for this only where there is no Button to wrap — which is most
|
|
60
|
+
* often a `global-error.tsx`, where importing one is exactly the thing that
|
|
61
|
+
* might have broken.
|
|
62
|
+
*/
|
|
63
|
+
export function errorActionClassName(variant: "primary" | "secondary" = "secondary"): string {
|
|
64
|
+
const base =
|
|
65
|
+
"inline-flex items-center justify-center rounded-lg px-5 py-2.5 text-sm font-medium transition " +
|
|
66
|
+
"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring";
|
|
67
|
+
const tone =
|
|
68
|
+
variant === "primary"
|
|
69
|
+
? "bg-primary text-primary-foreground hover:brightness-[1.06]"
|
|
70
|
+
: "border border-border text-foreground hover:bg-accent";
|
|
71
|
+
return `${base} ${tone}`;
|
|
72
|
+
}
|