@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,169 @@
|
|
|
1
|
+
import type { ChainedCommands, Editor } from "@tiptap/core";
|
|
2
|
+
import type { Node as PMNode } from "@tiptap/pm/model";
|
|
3
|
+
import {
|
|
4
|
+
Code2,
|
|
5
|
+
Heading1,
|
|
6
|
+
Heading2,
|
|
7
|
+
Heading3,
|
|
8
|
+
List,
|
|
9
|
+
ListOrdered,
|
|
10
|
+
ListTodo,
|
|
11
|
+
Pilcrow,
|
|
12
|
+
Quote,
|
|
13
|
+
type LucideIcon,
|
|
14
|
+
} from "lucide-react";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The block vocabulary of the editor — one list, read by three surfaces: the
|
|
18
|
+
* `/` menu, the bubble menu's "Turn into", and each block's grip menu.
|
|
19
|
+
*
|
|
20
|
+
* These are exactly the blocks Markdown can say, which is the whole reason there
|
|
21
|
+
* are no callouts, toggles or columns: the stored format is Markdown text, and a
|
|
22
|
+
* block the read-only renderer (and every printed or emailed copy) could not show
|
|
23
|
+
* would silently degrade on the surfaces people hand to someone else.
|
|
24
|
+
*/
|
|
25
|
+
export interface BlockType {
|
|
26
|
+
id:
|
|
27
|
+
| "paragraph"
|
|
28
|
+
| "heading1"
|
|
29
|
+
| "heading2"
|
|
30
|
+
| "heading3"
|
|
31
|
+
| "bulletList"
|
|
32
|
+
| "orderedList"
|
|
33
|
+
| "taskList"
|
|
34
|
+
| "blockquote"
|
|
35
|
+
| "codeBlock";
|
|
36
|
+
label: string;
|
|
37
|
+
description: string;
|
|
38
|
+
icon: LucideIcon;
|
|
39
|
+
/** Extra words the `/` menu matches on. */
|
|
40
|
+
keywords: string[];
|
|
41
|
+
/** Markdown shortcut shown as a hint, e.g. "# ". */
|
|
42
|
+
shortcut: string;
|
|
43
|
+
/**
|
|
44
|
+
* Convert whatever the selection is in. `clearNodes()` first lifts the
|
|
45
|
+
* selection out of lists and quotes, so "turn a quote into a heading" and
|
|
46
|
+
* "turn a list into paragraphs" both work in one step.
|
|
47
|
+
*/
|
|
48
|
+
apply: (chain: ChainedCommands) => ChainedCommands;
|
|
49
|
+
isActive: (editor: Editor) => boolean;
|
|
50
|
+
/** Whether a given block node (from the grip, not the caret) is this type. */
|
|
51
|
+
matchesNode: (node: PMNode) => boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const named = (name: string) => (node: PMNode) => node.type.name === name;
|
|
55
|
+
const headingLevel = (level: number) => (node: PMNode) => node.type.name === "heading" && node.attrs.level === level;
|
|
56
|
+
|
|
57
|
+
const PARAGRAPH: BlockType = {
|
|
58
|
+
id: "paragraph",
|
|
59
|
+
label: "Text",
|
|
60
|
+
description: "Plain writing",
|
|
61
|
+
icon: Pilcrow,
|
|
62
|
+
keywords: ["paragraph", "plain", "body"],
|
|
63
|
+
shortcut: "",
|
|
64
|
+
apply: (chain) => chain.clearNodes().setParagraph(),
|
|
65
|
+
isActive: (editor) =>
|
|
66
|
+
editor.isActive("paragraph") &&
|
|
67
|
+
!editor.isActive("bulletList") &&
|
|
68
|
+
!editor.isActive("orderedList") &&
|
|
69
|
+
!editor.isActive("taskList") &&
|
|
70
|
+
!editor.isActive("blockquote"),
|
|
71
|
+
matchesNode: named("paragraph"),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const BLOCK_TYPES: readonly BlockType[] = [
|
|
75
|
+
PARAGRAPH,
|
|
76
|
+
{
|
|
77
|
+
id: "heading1",
|
|
78
|
+
label: "Heading 1",
|
|
79
|
+
description: "Big section heading",
|
|
80
|
+
icon: Heading1,
|
|
81
|
+
keywords: ["h1", "title", "big"],
|
|
82
|
+
shortcut: "# ",
|
|
83
|
+
apply: (chain) => chain.clearNodes().setHeading({ level: 1 }),
|
|
84
|
+
isActive: (editor) => editor.isActive("heading", { level: 1 }),
|
|
85
|
+
matchesNode: headingLevel(1),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "heading2",
|
|
89
|
+
label: "Heading 2",
|
|
90
|
+
description: "Medium section heading",
|
|
91
|
+
icon: Heading2,
|
|
92
|
+
keywords: ["h2", "subtitle"],
|
|
93
|
+
shortcut: "## ",
|
|
94
|
+
apply: (chain) => chain.clearNodes().setHeading({ level: 2 }),
|
|
95
|
+
isActive: (editor) => editor.isActive("heading", { level: 2 }),
|
|
96
|
+
matchesNode: headingLevel(2),
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "heading3",
|
|
100
|
+
label: "Heading 3",
|
|
101
|
+
description: "Small section heading",
|
|
102
|
+
icon: Heading3,
|
|
103
|
+
keywords: ["h3", "subheading"],
|
|
104
|
+
shortcut: "### ",
|
|
105
|
+
apply: (chain) => chain.clearNodes().setHeading({ level: 3 }),
|
|
106
|
+
isActive: (editor) => editor.isActive("heading", { level: 3 }),
|
|
107
|
+
matchesNode: headingLevel(3),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: "bulletList",
|
|
111
|
+
label: "Bulleted list",
|
|
112
|
+
description: "A simple list",
|
|
113
|
+
icon: List,
|
|
114
|
+
keywords: ["bullet", "unordered", "points"],
|
|
115
|
+
shortcut: "- ",
|
|
116
|
+
apply: (chain) => chain.clearNodes().toggleBulletList(),
|
|
117
|
+
isActive: (editor) => editor.isActive("bulletList"),
|
|
118
|
+
matchesNode: named("bulletList"),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "orderedList",
|
|
122
|
+
label: "Numbered list",
|
|
123
|
+
description: "A list with numbers",
|
|
124
|
+
icon: ListOrdered,
|
|
125
|
+
keywords: ["numbered", "ordered", "steps"],
|
|
126
|
+
shortcut: "1. ",
|
|
127
|
+
apply: (chain) => chain.clearNodes().toggleOrderedList(),
|
|
128
|
+
isActive: (editor) => editor.isActive("orderedList"),
|
|
129
|
+
matchesNode: named("orderedList"),
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "taskList",
|
|
133
|
+
label: "To-do list",
|
|
134
|
+
description: "Tick things off",
|
|
135
|
+
icon: ListTodo,
|
|
136
|
+
keywords: ["todo", "task", "checkbox", "tick", "checklist"],
|
|
137
|
+
shortcut: "[] ",
|
|
138
|
+
apply: (chain) => chain.clearNodes().toggleTaskList(),
|
|
139
|
+
isActive: (editor) => editor.isActive("taskList"),
|
|
140
|
+
matchesNode: named("taskList"),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "blockquote",
|
|
144
|
+
label: "Quote",
|
|
145
|
+
description: "Set a passage apart",
|
|
146
|
+
icon: Quote,
|
|
147
|
+
keywords: ["quote", "blockquote", "citation"],
|
|
148
|
+
shortcut: "> ",
|
|
149
|
+
apply: (chain) => chain.clearNodes().setBlockquote(),
|
|
150
|
+
isActive: (editor) => editor.isActive("blockquote"),
|
|
151
|
+
matchesNode: named("blockquote"),
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "codeBlock",
|
|
155
|
+
label: "Code",
|
|
156
|
+
description: "Monospaced block",
|
|
157
|
+
icon: Code2,
|
|
158
|
+
keywords: ["code", "snippet", "monospace", "pre"],
|
|
159
|
+
shortcut: "``` ",
|
|
160
|
+
apply: (chain) => chain.clearNodes().setCodeBlock(),
|
|
161
|
+
isActive: (editor) => editor.isActive("codeBlock"),
|
|
162
|
+
matchesNode: named("codeBlock"),
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
/** The block type the selection currently sits in, for "Turn into" state. */
|
|
167
|
+
export function activeBlockType(editor: Editor): BlockType {
|
|
168
|
+
return BLOCK_TYPES.find((type) => type.id !== "paragraph" && type.isActive(editor)) ?? PARAGRAPH;
|
|
169
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
4
|
+
import { useEditorState, type Editor } from "@tiptap/react";
|
|
5
|
+
import { BubbleMenu, type BubbleMenuProps } from "@tiptap/react/menus";
|
|
6
|
+
import { Bold, Check, ChevronDown, Code, Italic, Link as LinkIcon, Strikethrough } from "lucide-react";
|
|
7
|
+
import { useState, type ReactNode } from "react";
|
|
8
|
+
|
|
9
|
+
import { BLOCK_TYPES, activeBlockType } from "./blocks.js";
|
|
10
|
+
import {
|
|
11
|
+
ghostButtonClass,
|
|
12
|
+
IconButton,
|
|
13
|
+
Menu,
|
|
14
|
+
MenuContent,
|
|
15
|
+
MenuItem,
|
|
16
|
+
MenuLabel,
|
|
17
|
+
MenuTrigger,
|
|
18
|
+
PopoverContent,
|
|
19
|
+
PopoverRoot,
|
|
20
|
+
PopoverTrigger,
|
|
21
|
+
primaryButtonClass,
|
|
22
|
+
TextInput,
|
|
23
|
+
VerticalSeparator,
|
|
24
|
+
} from "./ui.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Everything the BubbleMenu wrapper is handed must be referentially stable. It
|
|
28
|
+
* re-registers its ProseMirror plugin whenever these props change identity, and
|
|
29
|
+
* re-registering reconfigures the editor's plugin set — which destroys and
|
|
30
|
+
* recreates *every* plugin view, including the suggestion popups, mid-session.
|
|
31
|
+
* An inline object here silently killed the `/` menu on its first re-render.
|
|
32
|
+
*/
|
|
33
|
+
const BUBBLE_OPTIONS = { placement: "top" as const, offset: 8 };
|
|
34
|
+
|
|
35
|
+
/** Only over a real text selection: not an empty caret, not a node selection (a
|
|
36
|
+
* dragged block), and not inside a code block, where inline marks are noise. */
|
|
37
|
+
const shouldShowBubble: NonNullable<BubbleMenuProps["shouldShow"]> = ({ editor: current, state: editorState }) => {
|
|
38
|
+
const { selection } = editorState;
|
|
39
|
+
if (!current.isEditable || selection.empty) return false;
|
|
40
|
+
if (!(selection instanceof TextSelection)) return false;
|
|
41
|
+
if (current.isActive("codeBlock")) return false;
|
|
42
|
+
return editorState.doc.textBetween(selection.from, selection.to).trim().length > 0;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The formatting controls, shown only over a text selection — the Notion model.
|
|
47
|
+
* There is no standing toolbar: an empty editor is just a page, and the controls
|
|
48
|
+
* appear when there is something to apply them to. Block changes live under
|
|
49
|
+
* "Turn into", the same list the `/` menu and the block grip use.
|
|
50
|
+
*/
|
|
51
|
+
export function BubbleToolbar({ editor }: { editor: Editor }) {
|
|
52
|
+
const state = useEditorState({
|
|
53
|
+
editor,
|
|
54
|
+
selector: ({ editor: current }) => ({
|
|
55
|
+
bold: current.isActive("bold"),
|
|
56
|
+
italic: current.isActive("italic"),
|
|
57
|
+
strike: current.isActive("strike"),
|
|
58
|
+
code: current.isActive("code"),
|
|
59
|
+
link: current.isActive("link"),
|
|
60
|
+
linkHref: (current.getAttributes("link").href as string | undefined) ?? "",
|
|
61
|
+
block: activeBlockType(current),
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!state) return null;
|
|
66
|
+
const chain = () => editor.chain().focus();
|
|
67
|
+
const BlockIcon = state.block.icon;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<BubbleMenu
|
|
71
|
+
editor={editor}
|
|
72
|
+
pluginKey="houseFormattingBubble"
|
|
73
|
+
updateDelay={120}
|
|
74
|
+
options={BUBBLE_OPTIONS}
|
|
75
|
+
shouldShow={shouldShowBubble}
|
|
76
|
+
className="house-bubble-menu flex items-center gap-0.5 rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-md"
|
|
77
|
+
>
|
|
78
|
+
<Menu>
|
|
79
|
+
<MenuTrigger asChild>
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
className={`${ghostButtonClass} h-8 px-2 text-xs`}
|
|
83
|
+
// The bubble hides itself when the editor loses focus — unless the press was on the bubble, which it learns
|
|
84
|
+
// from a mousedown. The menu opens on pointer-down and cancels that mousedown, then takes focus; the bubble
|
|
85
|
+
// hid, taking the trigger out of the page, and the menu lost its anchor and opened at the top-left of the
|
|
86
|
+
// screen. So the press is reported to the bubble here, before the menu takes focus.
|
|
87
|
+
onPointerDown={(event) => {
|
|
88
|
+
event.currentTarget.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<BlockIcon className="size-4" aria-hidden />
|
|
92
|
+
{state.block.label}
|
|
93
|
+
<ChevronDown className="size-3.5 opacity-60" aria-hidden />
|
|
94
|
+
</button>
|
|
95
|
+
</MenuTrigger>
|
|
96
|
+
<MenuContent className="w-52">
|
|
97
|
+
<MenuLabel>Turn into</MenuLabel>
|
|
98
|
+
{BLOCK_TYPES.map((type) => (
|
|
99
|
+
<MenuItem key={type.id} onSelect={() => void type.apply(chain()).run()}>
|
|
100
|
+
<type.icon className="size-4" aria-hidden />
|
|
101
|
+
<span className="flex-1">{type.label}</span>
|
|
102
|
+
{type.id === state.block.id ? <Check className="size-4 text-primary" aria-hidden /> : null}
|
|
103
|
+
</MenuItem>
|
|
104
|
+
))}
|
|
105
|
+
</MenuContent>
|
|
106
|
+
</Menu>
|
|
107
|
+
|
|
108
|
+
<VerticalSeparator />
|
|
109
|
+
|
|
110
|
+
<MarkToggle label="Bold" pressed={state.bold} onToggle={() => chain().toggleBold().run()}>
|
|
111
|
+
<Bold className="size-4" />
|
|
112
|
+
</MarkToggle>
|
|
113
|
+
<MarkToggle label="Italic" pressed={state.italic} onToggle={() => chain().toggleItalic().run()}>
|
|
114
|
+
<Italic className="size-4" />
|
|
115
|
+
</MarkToggle>
|
|
116
|
+
<MarkToggle label="Strikethrough" pressed={state.strike} onToggle={() => chain().toggleStrike().run()}>
|
|
117
|
+
<Strikethrough className="size-4" />
|
|
118
|
+
</MarkToggle>
|
|
119
|
+
<MarkToggle label="Inline code" pressed={state.code} onToggle={() => chain().toggleCode().run()}>
|
|
120
|
+
<Code className="size-4" />
|
|
121
|
+
</MarkToggle>
|
|
122
|
+
<LinkControl editor={editor} active={state.link} href={state.linkHref} />
|
|
123
|
+
</BubbleMenu>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function MarkToggle({
|
|
128
|
+
label,
|
|
129
|
+
pressed,
|
|
130
|
+
onToggle,
|
|
131
|
+
children,
|
|
132
|
+
}: {
|
|
133
|
+
label: string;
|
|
134
|
+
pressed: boolean;
|
|
135
|
+
onToggle: () => void;
|
|
136
|
+
children: ReactNode;
|
|
137
|
+
}) {
|
|
138
|
+
return (
|
|
139
|
+
<IconButton aria-label={label} title={label} pressed={pressed} onClick={onToggle}>
|
|
140
|
+
{children}
|
|
141
|
+
</IconButton>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Set, change or clear the link on the current selection. */
|
|
146
|
+
function LinkControl({ editor, active, href }: { editor: Editor; active: boolean; href: string }) {
|
|
147
|
+
const [open, setOpen] = useState(false);
|
|
148
|
+
const [draft, setDraft] = useState("");
|
|
149
|
+
|
|
150
|
+
const apply = () => {
|
|
151
|
+
const url = draft.trim();
|
|
152
|
+
const valid = /^https?:\/\//i.test(url) || (url.startsWith("/") && !url.startsWith("//"));
|
|
153
|
+
if (url && valid) {
|
|
154
|
+
editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
|
|
155
|
+
} else if (!url) {
|
|
156
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
157
|
+
}
|
|
158
|
+
setOpen(false);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<PopoverRoot
|
|
163
|
+
open={open}
|
|
164
|
+
onOpenChange={(next) => {
|
|
165
|
+
setOpen(next);
|
|
166
|
+
if (next) setDraft(href);
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
<PopoverTrigger asChild>
|
|
170
|
+
<IconButton aria-label="Link" title="Link" pressed={active}>
|
|
171
|
+
<LinkIcon className="size-4" />
|
|
172
|
+
</IconButton>
|
|
173
|
+
</PopoverTrigger>
|
|
174
|
+
<PopoverContent className="w-80 space-y-2">
|
|
175
|
+
<p className="text-sm font-medium">Link</p>
|
|
176
|
+
<TextInput
|
|
177
|
+
value={draft}
|
|
178
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
179
|
+
placeholder="https://…"
|
|
180
|
+
aria-label="Link address"
|
|
181
|
+
onKeyDown={(event) => {
|
|
182
|
+
if (event.key === "Enter") {
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
apply();
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
/>
|
|
188
|
+
<div className="flex justify-end gap-2">
|
|
189
|
+
{active ? (
|
|
190
|
+
<button
|
|
191
|
+
type="button"
|
|
192
|
+
className={`${ghostButtonClass} h-8 px-3`}
|
|
193
|
+
onClick={() => {
|
|
194
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
195
|
+
setOpen(false);
|
|
196
|
+
}}
|
|
197
|
+
>
|
|
198
|
+
Remove
|
|
199
|
+
</button>
|
|
200
|
+
) : null}
|
|
201
|
+
<button type="button" className={primaryButtonClass} onClick={apply}>
|
|
202
|
+
Apply
|
|
203
|
+
</button>
|
|
204
|
+
</div>
|
|
205
|
+
</PopoverContent>
|
|
206
|
+
</PopoverRoot>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import type { EditorState, Transaction } from "@tiptap/pm/state";
|
|
3
|
+
import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
|
|
4
|
+
import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view";
|
|
5
|
+
|
|
6
|
+
import { childIndexAt, sectionRange } from "./sections.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Collapsing a heading folds its section away (sections.ts): what's under it is
|
|
10
|
+
* hidden, and a "Show N more" pill at the end of the heading says how much. It
|
|
11
|
+
* is a view of the document, never part of it — nothing is written to the
|
|
12
|
+
* stored Markdown, and a fresh editor opens with everything showing.
|
|
13
|
+
*
|
|
14
|
+
* A caret that lands inside a hidden part (a search, an undo, Enter at the end
|
|
15
|
+
* of a collapsed heading) opens that section again, so nothing is ever typed
|
|
16
|
+
* where it can't be seen.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
interface CollapseState {
|
|
20
|
+
/** Positions of collapsed headings, kept current as the document changes. */
|
|
21
|
+
collapsed: number[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type CollapseMeta = { toggle: number } | { expand: number };
|
|
25
|
+
|
|
26
|
+
export const collapseKey = new PluginKey<CollapseState>("houseCollapsedSections");
|
|
27
|
+
|
|
28
|
+
declare module "@tiptap/core" {
|
|
29
|
+
interface Commands<ReturnType> {
|
|
30
|
+
houseCollapsible: {
|
|
31
|
+
/** Collapse the section of the heading at `pos`, or expand it if it is collapsed. */
|
|
32
|
+
toggleSection: (pos: number) => ReturnType;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Whether the heading at `pos` is collapsed. */
|
|
38
|
+
export function isSectionCollapsed(state: EditorState, pos: number): boolean {
|
|
39
|
+
return collapseKey.getState(state)?.collapsed.includes(pos) ?? false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The hidden part of each collapsed section: [from, to) positions, keyed by the heading's position. */
|
|
43
|
+
function hiddenRanges(state: EditorState): { heading: number; from: number; to: number }[] {
|
|
44
|
+
const out: { heading: number; from: number; to: number }[] = [];
|
|
45
|
+
for (const pos of collapseKey.getState(state)?.collapsed ?? []) {
|
|
46
|
+
const range = sectionRange(state.doc, pos);
|
|
47
|
+
const heading = state.doc.nodeAt(pos);
|
|
48
|
+
if (!range || !heading || range.blocks < 2) continue;
|
|
49
|
+
out.push({ heading: pos, from: pos + heading.nodeSize, to: range.to });
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function pill(view: EditorView, getPos: () => number | undefined, hidden: number): HTMLElement {
|
|
55
|
+
const button = document.createElement("button");
|
|
56
|
+
button.type = "button";
|
|
57
|
+
button.className = "house-section-more";
|
|
58
|
+
button.contentEditable = "false";
|
|
59
|
+
button.textContent = `Show ${hidden} more`;
|
|
60
|
+
button.setAttribute("aria-label", `Expand the section: ${hidden} hidden ${hidden === 1 ? "block" : "blocks"}`);
|
|
61
|
+
// Keep the caret where it is; the click does the work.
|
|
62
|
+
button.addEventListener("mousedown", (event) => event.preventDefault());
|
|
63
|
+
button.addEventListener("click", (event) => {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
const at = getPos();
|
|
66
|
+
if (at === undefined) return;
|
|
67
|
+
const heading = view.state.doc.resolve(at).before(1);
|
|
68
|
+
view.dispatch(view.state.tr.setMeta(collapseKey, { expand: heading } satisfies CollapseMeta));
|
|
69
|
+
});
|
|
70
|
+
return button;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const Collapsible = Extension.create({
|
|
74
|
+
name: "houseCollapsible",
|
|
75
|
+
|
|
76
|
+
addCommands() {
|
|
77
|
+
return {
|
|
78
|
+
toggleSection:
|
|
79
|
+
(pos: number) =>
|
|
80
|
+
({ tr, state, dispatch }) => {
|
|
81
|
+
const heading = tr.doc.nodeAt(pos);
|
|
82
|
+
if (childIndexAt(tr.doc, pos) === null || heading?.type.name !== "heading") return false;
|
|
83
|
+
if (dispatch) {
|
|
84
|
+
tr.setMeta(collapseKey, { toggle: pos } satisfies CollapseMeta);
|
|
85
|
+
// Folding away the part the caret is in would open it again at once: the caret goes to the heading.
|
|
86
|
+
const range = sectionRange(tr.doc, pos);
|
|
87
|
+
const head = tr.selection.head;
|
|
88
|
+
if (!isSectionCollapsed(state, pos) && range && head > pos + heading.nodeSize && head < range.to) {
|
|
89
|
+
tr.setSelection(TextSelection.create(tr.doc, pos + heading.nodeSize - 1));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
addProseMirrorPlugins() {
|
|
98
|
+
return [
|
|
99
|
+
new Plugin<CollapseState>({
|
|
100
|
+
key: collapseKey,
|
|
101
|
+
state: {
|
|
102
|
+
init: () => ({ collapsed: [] }),
|
|
103
|
+
apply(tr: Transaction, value: CollapseState, _old: EditorState, next: EditorState): CollapseState {
|
|
104
|
+
let collapsed = value.collapsed
|
|
105
|
+
.map((pos) => tr.mapping.mapResult(pos))
|
|
106
|
+
.filter((result) => !result.deleted)
|
|
107
|
+
.map((result) => result.pos)
|
|
108
|
+
.filter((pos) => childIndexAt(next.doc, pos) !== null && next.doc.nodeAt(pos)?.type.name === "heading");
|
|
109
|
+
const meta = tr.getMeta(collapseKey) as CollapseMeta | undefined;
|
|
110
|
+
if (meta && "toggle" in meta) {
|
|
111
|
+
collapsed = collapsed.includes(meta.toggle)
|
|
112
|
+
? collapsed.filter((pos) => pos !== meta.toggle)
|
|
113
|
+
: [...collapsed, meta.toggle];
|
|
114
|
+
} else if (meta && "expand" in meta) {
|
|
115
|
+
collapsed = collapsed.filter((pos) => pos !== meta.expand);
|
|
116
|
+
}
|
|
117
|
+
return { collapsed: [...new Set(collapsed)] };
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
// Whatever moved the caret into a hidden part opens it again.
|
|
121
|
+
appendTransaction(_trs, _old, next) {
|
|
122
|
+
const head = next.selection.head;
|
|
123
|
+
const opened = hiddenRanges(next).find((range) => head > range.from && head < range.to);
|
|
124
|
+
return opened ? next.tr.setMeta(collapseKey, { expand: opened.heading } satisfies CollapseMeta) : null;
|
|
125
|
+
},
|
|
126
|
+
props: {
|
|
127
|
+
decorations(state) {
|
|
128
|
+
const decorations: Decoration[] = [];
|
|
129
|
+
for (const range of hiddenRanges(state)) {
|
|
130
|
+
const heading = state.doc.nodeAt(range.heading)!;
|
|
131
|
+
decorations.push(
|
|
132
|
+
Decoration.node(range.heading, range.heading + heading.nodeSize, {
|
|
133
|
+
class: "house-section-collapsed",
|
|
134
|
+
"aria-expanded": "false",
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
let hidden = 0;
|
|
138
|
+
state.doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
139
|
+
if (pos < range.from) return false;
|
|
140
|
+
decorations.push(Decoration.node(pos, pos + node.nodeSize, { class: "house-section-hidden" }));
|
|
141
|
+
hidden += 1;
|
|
142
|
+
return false;
|
|
143
|
+
});
|
|
144
|
+
const count = hidden;
|
|
145
|
+
decorations.push(
|
|
146
|
+
Decoration.widget(range.heading + heading.nodeSize - 1, (view, getPos) => pill(view, getPos, count), {
|
|
147
|
+
side: 1,
|
|
148
|
+
ignoreSelection: true,
|
|
149
|
+
key: `more-${range.heading}-${count}`,
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return DecorationSet.create(state.doc, decorations);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}),
|
|
157
|
+
];
|
|
158
|
+
},
|
|
159
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RichTextContent, richTextPreview, safeHref } from "./content.js";
|