@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,114 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Search } from "lucide-react";
|
|
4
|
+
import { useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
import { cx } from "../internal/cx.js";
|
|
7
|
+
import { EMOJI, EMOJI_GROUP_LABELS, searchEmoji, type EmojiEntry, type EmojiGroup } from "./emoji.js";
|
|
8
|
+
import { ghostButtonClass, PopoverContent, PopoverRoot, PopoverTrigger, TextInput } from "./ui.js";
|
|
9
|
+
|
|
10
|
+
interface EmojiPickerProps {
|
|
11
|
+
value: string | null;
|
|
12
|
+
onChange: (emoji: string | null) => void;
|
|
13
|
+
/** The trigger — whatever shows the current icon (or "Add icon"). Must accept a ref. */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
align?: "start" | "center" | "end";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const GROUP_ORDER: EmojiGroup[] = ["smileys", "people", "nature", "food", "activities", "travel", "objects", "symbols"];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A page-icon picker in the Notion mould: a searchable grid of emoji grouped by
|
|
22
|
+
* kind, with Remove when one is set. Backed by the curated set, so it opens
|
|
23
|
+
* instantly and never downloads a database.
|
|
24
|
+
*/
|
|
25
|
+
export function EmojiPicker({ value, onChange, children, align = "start" }: EmojiPickerProps) {
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
const [query, setQuery] = useState("");
|
|
28
|
+
|
|
29
|
+
const grouped = useMemo(() => {
|
|
30
|
+
const term = query.trim();
|
|
31
|
+
if (term) return [{ group: null as EmojiGroup | null, items: searchEmoji(term, 120) }];
|
|
32
|
+
return GROUP_ORDER.map((group) => ({ group, items: EMOJI.filter((entry) => entry.group === group) }));
|
|
33
|
+
}, [query]);
|
|
34
|
+
|
|
35
|
+
const pick = (entry: EmojiEntry) => {
|
|
36
|
+
onChange(entry.char);
|
|
37
|
+
setOpen(false);
|
|
38
|
+
setQuery("");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<PopoverRoot
|
|
43
|
+
open={open}
|
|
44
|
+
onOpenChange={(next) => {
|
|
45
|
+
setOpen(next);
|
|
46
|
+
if (!next) setQuery("");
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<PopoverTrigger asChild>{children}</PopoverTrigger>
|
|
50
|
+
<PopoverContent align={align} className="w-80 p-2">
|
|
51
|
+
<div className="relative">
|
|
52
|
+
<Search className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
53
|
+
<TextInput
|
|
54
|
+
value={query}
|
|
55
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
56
|
+
placeholder="Search emoji…"
|
|
57
|
+
aria-label="Search emoji"
|
|
58
|
+
className="pl-8"
|
|
59
|
+
autoFocus
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
62
|
+
<div className="mt-2 max-h-64 overflow-y-auto pr-1">
|
|
63
|
+
{grouped.every((section) => section.items.length === 0) ? (
|
|
64
|
+
<p className="px-1 py-6 text-center text-sm text-muted-foreground">Nothing matches “{query}”.</p>
|
|
65
|
+
) : (
|
|
66
|
+
grouped.map((section) =>
|
|
67
|
+
section.items.length === 0 ? null : (
|
|
68
|
+
<div key={section.group ?? "results"} className="mb-2">
|
|
69
|
+
{section.group ? (
|
|
70
|
+
<p className="px-1 pb-1 text-[11px] font-semibold tracking-wide text-muted-foreground uppercase">
|
|
71
|
+
{EMOJI_GROUP_LABELS[section.group]}
|
|
72
|
+
</p>
|
|
73
|
+
) : null}
|
|
74
|
+
<div className="grid grid-cols-8 gap-0.5">
|
|
75
|
+
{section.items.map((entry) => (
|
|
76
|
+
<button
|
|
77
|
+
key={entry.name}
|
|
78
|
+
type="button"
|
|
79
|
+
title={entry.name.replace(/_/g, " ")}
|
|
80
|
+
aria-label={entry.name.replace(/_/g, " ")}
|
|
81
|
+
aria-pressed={value === entry.char}
|
|
82
|
+
onClick={() => pick(entry)}
|
|
83
|
+
className={cx(
|
|
84
|
+
"flex size-8 items-center justify-center rounded-md text-xl leading-none hover:bg-accent",
|
|
85
|
+
value === entry.char && "bg-accent ring-1 ring-ring",
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
{entry.char}
|
|
89
|
+
</button>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
{value ? (
|
|
98
|
+
<div className="mt-1 flex justify-end border-t border-border pt-2">
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
className={`${ghostButtonClass} h-8 px-3`}
|
|
102
|
+
onClick={() => {
|
|
103
|
+
onChange(null);
|
|
104
|
+
setOpen(false);
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
Remove icon
|
|
108
|
+
</button>
|
|
109
|
+
</div>
|
|
110
|
+
) : null}
|
|
111
|
+
</PopoverContent>
|
|
112
|
+
</PopoverRoot>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
// A curated emoji set for the rich text editor's `:` shortcode picker and for
|
|
2
|
+
// page icons (a note, a notebook, a project).
|
|
3
|
+
//
|
|
4
|
+
// Deliberately hand-picked rather than a full Unicode database: the complete
|
|
5
|
+
// set is ~3,800 entries and over a megabyte of JSON, and the job here is a
|
|
6
|
+
// fast, searchable list of the few hundred people actually reach for when
|
|
7
|
+
// titling a page or punctuating a note. Every entry is a plain Unicode
|
|
8
|
+
// character, so it survives Markdown storage, every renderer, and copy-paste
|
|
9
|
+
// with nothing special-cased anywhere.
|
|
10
|
+
|
|
11
|
+
export type EmojiGroup = "smileys" | "people" | "nature" | "food" | "activities" | "travel" | "objects" | "symbols";
|
|
12
|
+
|
|
13
|
+
export interface EmojiEntry {
|
|
14
|
+
/** The character itself. */
|
|
15
|
+
char: string;
|
|
16
|
+
/** The `:shortcode:` name, lowercase, underscores. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Extra search words beyond the name. */
|
|
19
|
+
keywords: string[];
|
|
20
|
+
group: EmojiGroup;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const EMOJI_GROUP_LABELS: Record<EmojiGroup, string> = {
|
|
24
|
+
smileys: "Smileys",
|
|
25
|
+
people: "People & gestures",
|
|
26
|
+
nature: "Animals & nature",
|
|
27
|
+
food: "Food & drink",
|
|
28
|
+
activities: "Activities",
|
|
29
|
+
travel: "Travel & places",
|
|
30
|
+
objects: "Objects",
|
|
31
|
+
symbols: "Symbols",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const e = (char: string, name: string, group: EmojiGroup, ...keywords: string[]): EmojiEntry => ({
|
|
35
|
+
char,
|
|
36
|
+
name,
|
|
37
|
+
keywords,
|
|
38
|
+
group,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const EMOJI: EmojiEntry[] = [
|
|
42
|
+
// Smileys
|
|
43
|
+
e("😀", "grinning", "smileys", "happy", "smile"),
|
|
44
|
+
e("😃", "smiley", "smileys", "happy"),
|
|
45
|
+
e("😄", "smile", "smileys", "happy", "joy"),
|
|
46
|
+
e("😁", "grin", "smileys", "happy"),
|
|
47
|
+
e("😆", "laughing", "smileys", "haha"),
|
|
48
|
+
e("😅", "sweat_smile", "smileys", "relief"),
|
|
49
|
+
e("🤣", "rofl", "smileys", "laugh"),
|
|
50
|
+
e("😂", "joy", "smileys", "laugh", "tears"),
|
|
51
|
+
e("🙂", "slightly_smiling", "smileys", "ok"),
|
|
52
|
+
e("😉", "wink", "smileys"),
|
|
53
|
+
e("😊", "blush", "smileys", "happy", "shy"),
|
|
54
|
+
e("😇", "innocent", "smileys", "angel"),
|
|
55
|
+
e("🥰", "smiling_hearts", "smileys", "love"),
|
|
56
|
+
e("😍", "heart_eyes", "smileys", "love"),
|
|
57
|
+
e("🤩", "star_struck", "smileys", "wow"),
|
|
58
|
+
e("😘", "kissing_heart", "smileys", "kiss"),
|
|
59
|
+
e("😋", "yum", "smileys", "tasty"),
|
|
60
|
+
e("😛", "stuck_out_tongue", "smileys", "silly"),
|
|
61
|
+
e("🤪", "zany", "smileys", "crazy"),
|
|
62
|
+
e("🤔", "thinking", "smileys", "hmm", "wonder"),
|
|
63
|
+
e("🤫", "shushing", "smileys", "quiet", "secret"),
|
|
64
|
+
e("🤗", "hugs", "smileys", "hug"),
|
|
65
|
+
e("😐", "neutral", "smileys", "meh"),
|
|
66
|
+
e("😑", "expressionless", "smileys"),
|
|
67
|
+
e("🙄", "eye_roll", "smileys"),
|
|
68
|
+
e("😬", "grimacing", "smileys", "awkward"),
|
|
69
|
+
e("😴", "sleeping", "smileys", "tired", "zzz"),
|
|
70
|
+
e("🤒", "sick", "smileys", "ill", "thermometer"),
|
|
71
|
+
e("🤕", "head_bandage", "smileys", "hurt"),
|
|
72
|
+
e("🤯", "exploding_head", "smileys", "mind blown"),
|
|
73
|
+
e("🥳", "partying", "smileys", "celebrate", "party"),
|
|
74
|
+
e("😎", "sunglasses", "smileys", "cool"),
|
|
75
|
+
e("🤓", "nerd", "smileys", "glasses", "study"),
|
|
76
|
+
e("😕", "confused", "smileys"),
|
|
77
|
+
e("😟", "worried", "smileys"),
|
|
78
|
+
e("🙁", "slightly_frowning", "smileys", "sad"),
|
|
79
|
+
e("😮", "open_mouth", "smileys", "surprised"),
|
|
80
|
+
e("😲", "astonished", "smileys", "shocked"),
|
|
81
|
+
e("😢", "cry", "smileys", "sad", "tear"),
|
|
82
|
+
e("😭", "sob", "smileys", "cry"),
|
|
83
|
+
e("😤", "triumph", "smileys", "frustrated"),
|
|
84
|
+
e("😡", "rage", "smileys", "angry"),
|
|
85
|
+
e("😱", "scream", "smileys", "fear"),
|
|
86
|
+
e("🥺", "pleading", "smileys", "puppy eyes"),
|
|
87
|
+
e("😷", "mask", "smileys", "sick"),
|
|
88
|
+
e("💀", "skull", "smileys", "dead"),
|
|
89
|
+
e("👻", "ghost", "smileys", "boo"),
|
|
90
|
+
e("👽", "alien", "smileys"),
|
|
91
|
+
e("🤖", "robot", "smileys", "bot"),
|
|
92
|
+
e("💩", "poop", "smileys"),
|
|
93
|
+
|
|
94
|
+
// People & gestures
|
|
95
|
+
e("👍", "thumbsup", "people", "yes", "good", "like"),
|
|
96
|
+
e("👎", "thumbsdown", "people", "no", "bad"),
|
|
97
|
+
e("👏", "clap", "people", "applause", "bravo"),
|
|
98
|
+
e("🙌", "raised_hands", "people", "hooray", "praise"),
|
|
99
|
+
e("🙏", "pray", "people", "please", "thanks"),
|
|
100
|
+
e("🤝", "handshake", "people", "deal", "agree"),
|
|
101
|
+
e("👋", "wave", "people", "hello", "bye"),
|
|
102
|
+
e("✋", "raised_hand", "people", "stop"),
|
|
103
|
+
e("👌", "ok_hand", "people", "okay"),
|
|
104
|
+
e("✌️", "v", "people", "peace", "victory"),
|
|
105
|
+
e("🤞", "crossed_fingers", "people", "luck"),
|
|
106
|
+
e("💪", "muscle", "people", "strong", "flex"),
|
|
107
|
+
e("👉", "point_right", "people", "this"),
|
|
108
|
+
e("👈", "point_left", "people"),
|
|
109
|
+
e("☝️", "point_up", "people", "one"),
|
|
110
|
+
e("✍️", "writing_hand", "people", "write"),
|
|
111
|
+
e("👀", "eyes", "people", "look", "watch"),
|
|
112
|
+
e("🧠", "brain", "people", "think", "mind"),
|
|
113
|
+
e("👶", "baby", "people", "child"),
|
|
114
|
+
e("🧒", "child", "people", "kid"),
|
|
115
|
+
e("👦", "boy", "people"),
|
|
116
|
+
e("👧", "girl", "people"),
|
|
117
|
+
e("🧑", "person", "people", "adult"),
|
|
118
|
+
e("👩", "woman", "people"),
|
|
119
|
+
e("👨", "man", "people"),
|
|
120
|
+
e("🧑🏫", "teacher", "people", "tutor", "school"),
|
|
121
|
+
e("🧑🎓", "student", "people", "graduate", "learner"),
|
|
122
|
+
e("🧑💻", "technologist", "people", "coder", "laptop"),
|
|
123
|
+
e("🧑🔬", "scientist", "people", "lab"),
|
|
124
|
+
e("🧑🎨", "artist", "people", "paint"),
|
|
125
|
+
e("👨👩👧👦", "family", "people", "parents", "children"),
|
|
126
|
+
e("🧘", "meditate", "people", "yoga", "calm"),
|
|
127
|
+
e("🏃", "running", "people", "run", "exercise"),
|
|
128
|
+
|
|
129
|
+
// Animals & nature
|
|
130
|
+
e("🐶", "dog", "nature", "puppy", "pet"),
|
|
131
|
+
e("🐱", "cat", "nature", "kitten", "pet"),
|
|
132
|
+
e("🐭", "mouse", "nature"),
|
|
133
|
+
e("🐰", "rabbit", "nature", "bunny"),
|
|
134
|
+
e("🦊", "fox", "nature"),
|
|
135
|
+
e("🐻", "bear", "nature"),
|
|
136
|
+
e("🐼", "panda", "nature"),
|
|
137
|
+
e("🐨", "koala", "nature"),
|
|
138
|
+
e("🦁", "lion", "nature"),
|
|
139
|
+
e("🐯", "tiger", "nature"),
|
|
140
|
+
e("🐮", "cow", "nature"),
|
|
141
|
+
e("🐷", "pig", "nature"),
|
|
142
|
+
e("🐸", "frog", "nature"),
|
|
143
|
+
e("🐵", "monkey", "nature"),
|
|
144
|
+
e("🐔", "chicken", "nature", "hen"),
|
|
145
|
+
e("🐧", "penguin", "nature"),
|
|
146
|
+
e("🦉", "owl", "nature", "wise"),
|
|
147
|
+
e("🦋", "butterfly", "nature"),
|
|
148
|
+
e("🐝", "bee", "nature", "honey"),
|
|
149
|
+
e("🐛", "bug", "nature", "caterpillar"),
|
|
150
|
+
e("🐢", "turtle", "nature", "slow"),
|
|
151
|
+
e("🐍", "snake", "nature"),
|
|
152
|
+
e("🦕", "dinosaur", "nature", "dino"),
|
|
153
|
+
e("🐙", "octopus", "nature"),
|
|
154
|
+
e("🐟", "fish", "nature"),
|
|
155
|
+
e("🐬", "dolphin", "nature"),
|
|
156
|
+
e("🐳", "whale", "nature"),
|
|
157
|
+
e("🦄", "unicorn", "nature", "magic"),
|
|
158
|
+
e("🌱", "seedling", "nature", "plant", "grow", "sprout"),
|
|
159
|
+
e("🌿", "herb", "nature", "leaf"),
|
|
160
|
+
e("🍀", "four_leaf_clover", "nature", "luck"),
|
|
161
|
+
e("🌳", "tree", "nature", "forest"),
|
|
162
|
+
e("🌲", "evergreen", "nature", "pine"),
|
|
163
|
+
e("🌵", "cactus", "nature"),
|
|
164
|
+
e("🌸", "cherry_blossom", "nature", "flower", "spring"),
|
|
165
|
+
e("🌻", "sunflower", "nature", "flower"),
|
|
166
|
+
e("🌹", "rose", "nature", "flower"),
|
|
167
|
+
e("🍂", "fallen_leaf", "nature", "autumn"),
|
|
168
|
+
e("🍁", "maple_leaf", "nature", "autumn"),
|
|
169
|
+
e("🌍", "earth", "nature", "world", "globe", "geography"),
|
|
170
|
+
e("🌙", "moon", "nature", "night"),
|
|
171
|
+
e("⭐", "star", "nature", "favourite"),
|
|
172
|
+
e("🌟", "glowing_star", "nature", "sparkle"),
|
|
173
|
+
e("✨", "sparkles", "nature", "magic", "new"),
|
|
174
|
+
e("☀️", "sun", "nature", "sunny"),
|
|
175
|
+
e("⛅", "partly_sunny", "nature", "cloud"),
|
|
176
|
+
e("🌧️", "rain", "nature", "weather"),
|
|
177
|
+
e("⚡", "zap", "nature", "lightning", "energy"),
|
|
178
|
+
e("❄️", "snowflake", "nature", "winter", "cold"),
|
|
179
|
+
e("🌈", "rainbow", "nature"),
|
|
180
|
+
e("🔥", "fire", "nature", "hot", "lit"),
|
|
181
|
+
e("💧", "droplet", "nature", "water"),
|
|
182
|
+
e("🌊", "ocean_wave", "nature", "ocean", "sea", "wave"),
|
|
183
|
+
|
|
184
|
+
// Food & drink
|
|
185
|
+
e("🍎", "apple", "food", "fruit", "teacher"),
|
|
186
|
+
e("🍌", "banana", "food", "fruit"),
|
|
187
|
+
e("🍇", "grapes", "food", "fruit"),
|
|
188
|
+
e("🍓", "strawberry", "food", "fruit"),
|
|
189
|
+
e("🍉", "watermelon", "food", "fruit"),
|
|
190
|
+
e("🍊", "orange", "food", "fruit", "tangerine"),
|
|
191
|
+
e("🍋", "lemon", "food", "fruit"),
|
|
192
|
+
e("🥕", "carrot", "food", "vegetable"),
|
|
193
|
+
e("🥦", "broccoli", "food", "vegetable"),
|
|
194
|
+
e("🍞", "bread", "food", "loaf"),
|
|
195
|
+
e("🧀", "cheese", "food"),
|
|
196
|
+
e("🥚", "egg", "food"),
|
|
197
|
+
e("🍕", "pizza", "food"),
|
|
198
|
+
e("🍔", "hamburger", "food", "burger"),
|
|
199
|
+
e("🌮", "taco", "food"),
|
|
200
|
+
e("🍝", "spaghetti", "food", "pasta"),
|
|
201
|
+
e("🍜", "ramen", "food", "noodles"),
|
|
202
|
+
e("🍣", "sushi", "food"),
|
|
203
|
+
e("🍪", "cookie", "food", "biscuit"),
|
|
204
|
+
e("🎂", "birthday", "food", "cake"),
|
|
205
|
+
e("🧁", "cupcake", "food"),
|
|
206
|
+
e("🍫", "chocolate", "food"),
|
|
207
|
+
e("🍬", "candy", "food", "sweet"),
|
|
208
|
+
e("🍿", "popcorn", "food", "cinema"),
|
|
209
|
+
e("☕", "coffee", "food", "tea", "hot drink"),
|
|
210
|
+
e("🍵", "tea", "food", "green tea"),
|
|
211
|
+
e("🥤", "cup_with_straw", "food", "drink"),
|
|
212
|
+
e("🧃", "juice_box", "food", "drink"),
|
|
213
|
+
|
|
214
|
+
// Activities
|
|
215
|
+
e("⚽", "soccer", "activities", "football", "sport"),
|
|
216
|
+
e("🏀", "basketball", "activities", "sport"),
|
|
217
|
+
e("🏈", "football", "activities", "american football"),
|
|
218
|
+
e("🎾", "tennis", "activities", "sport"),
|
|
219
|
+
e("🏏", "cricket", "activities", "sport"),
|
|
220
|
+
e("🏊", "swimming", "activities", "swim", "pool"),
|
|
221
|
+
e("🚴", "cycling", "activities", "bike"),
|
|
222
|
+
e("🏆", "trophy", "activities", "winner", "award"),
|
|
223
|
+
e("🥇", "first_place", "activities", "gold", "medal"),
|
|
224
|
+
e("🎖️", "medal", "activities", "achievement"),
|
|
225
|
+
e("🎯", "dart", "activities", "target", "goal", "aim"),
|
|
226
|
+
e("🎮", "video_game", "activities", "gaming"),
|
|
227
|
+
e("🎲", "game_die", "activities", "dice", "random"),
|
|
228
|
+
e("🧩", "puzzle", "activities", "jigsaw", "piece"),
|
|
229
|
+
e("♟️", "chess", "activities", "strategy"),
|
|
230
|
+
e("🎨", "art", "activities", "paint", "palette"),
|
|
231
|
+
e("🎭", "performing_arts", "activities", "drama", "theatre"),
|
|
232
|
+
e("🎬", "clapper", "activities", "film", "movie"),
|
|
233
|
+
e("🎤", "microphone", "activities", "sing", "karaoke"),
|
|
234
|
+
e("🎧", "headphones", "activities", "music", "listen"),
|
|
235
|
+
e("🎵", "musical_note", "activities", "music", "song"),
|
|
236
|
+
e("🎹", "piano", "activities", "music", "keyboard"),
|
|
237
|
+
e("🎸", "guitar", "activities", "music"),
|
|
238
|
+
e("🥁", "drum", "activities", "music"),
|
|
239
|
+
e("🎻", "violin", "activities", "music"),
|
|
240
|
+
e("🎉", "tada", "activities", "party", "celebrate", "congratulations"),
|
|
241
|
+
e("🎈", "balloon", "activities", "party"),
|
|
242
|
+
e("🎁", "gift", "activities", "present"),
|
|
243
|
+
e("🎓", "mortar_board", "activities", "graduation", "school", "exam"),
|
|
244
|
+
e("🧪", "test_tube", "activities", "science", "chemistry", "experiment"),
|
|
245
|
+
e("🔬", "microscope", "activities", "science", "biology"),
|
|
246
|
+
e("🔭", "telescope", "activities", "space", "astronomy"),
|
|
247
|
+
e("🧮", "abacus", "activities", "maths", "count"),
|
|
248
|
+
e("🧲", "magnet", "activities", "physics"),
|
|
249
|
+
|
|
250
|
+
// Travel & places
|
|
251
|
+
e("🏠", "house", "travel", "home"),
|
|
252
|
+
e("🏫", "school", "travel", "education"),
|
|
253
|
+
e("🏛️", "classical_building", "travel", "museum", "history"),
|
|
254
|
+
e("🏰", "castle", "travel", "history"),
|
|
255
|
+
e("⛺", "tent", "travel", "camping", "outdoors"),
|
|
256
|
+
e("🏖️", "beach", "travel", "holiday", "summer"),
|
|
257
|
+
e("🏞️", "national_park", "travel", "nature", "outdoors"),
|
|
258
|
+
e("🗺️", "world_map", "travel", "geography", "map"),
|
|
259
|
+
e("🧭", "compass", "travel", "direction"),
|
|
260
|
+
e("🚗", "car", "travel", "drive"),
|
|
261
|
+
e("🚌", "bus", "travel"),
|
|
262
|
+
e("🚲", "bicycle", "travel", "bike"),
|
|
263
|
+
e("🚂", "train", "travel", "railway"),
|
|
264
|
+
e("✈️", "airplane", "travel", "flight", "trip"),
|
|
265
|
+
e("🚀", "rocket", "travel", "launch", "space", "fast"),
|
|
266
|
+
e("⛵", "sailboat", "travel", "boat"),
|
|
267
|
+
e("🌅", "sunrise", "travel", "morning"),
|
|
268
|
+
e("🌃", "night_stars", "travel", "night", "city"),
|
|
269
|
+
|
|
270
|
+
// Objects
|
|
271
|
+
e("📝", "memo", "objects", "note", "write", "pencil"),
|
|
272
|
+
e("📒", "ledger", "objects", "notebook", "yellow"),
|
|
273
|
+
e("📓", "notebook", "objects", "journal"),
|
|
274
|
+
e("📔", "notebook_decorative", "objects", "journal", "diary"),
|
|
275
|
+
e("📕", "closed_book", "objects", "book", "red"),
|
|
276
|
+
e("📗", "green_book", "objects", "book"),
|
|
277
|
+
e("📘", "blue_book", "objects", "book"),
|
|
278
|
+
e("📙", "orange_book", "objects", "book"),
|
|
279
|
+
e("📚", "books", "objects", "study", "library", "reading"),
|
|
280
|
+
e("📖", "open_book", "objects", "read", "reading"),
|
|
281
|
+
e("📄", "page", "objects", "document", "paper"),
|
|
282
|
+
e("📋", "clipboard", "objects", "list", "checklist"),
|
|
283
|
+
e("📌", "pushpin", "objects", "pin", "important"),
|
|
284
|
+
e("📍", "round_pushpin", "objects", "location", "pin"),
|
|
285
|
+
e("📎", "paperclip", "objects", "attach"),
|
|
286
|
+
e("✂️", "scissors", "objects", "cut", "craft"),
|
|
287
|
+
e("📏", "ruler", "objects", "measure", "maths"),
|
|
288
|
+
e("📐", "triangular_ruler", "objects", "geometry", "maths"),
|
|
289
|
+
e("✏️", "pencil", "objects", "write", "draw"),
|
|
290
|
+
e("🖊️", "pen", "objects", "write"),
|
|
291
|
+
e("🖍️", "crayon", "objects", "draw", "art", "colour"),
|
|
292
|
+
e("🖌️", "paintbrush", "objects", "art", "paint"),
|
|
293
|
+
e("📁", "file_folder", "objects", "folder"),
|
|
294
|
+
e("📂", "open_file_folder", "objects", "folder"),
|
|
295
|
+
e("🗂️", "card_index_dividers", "objects", "organise", "sections"),
|
|
296
|
+
e("🗓️", "calendar", "objects", "date", "schedule"),
|
|
297
|
+
e("📅", "date", "objects", "calendar", "day"),
|
|
298
|
+
e("⏰", "alarm_clock", "objects", "time", "reminder", "wake"),
|
|
299
|
+
e("⏳", "hourglass", "objects", "time", "waiting", "deadline"),
|
|
300
|
+
e("⌛", "hourglass_done", "objects", "time", "finished"),
|
|
301
|
+
e("🔔", "bell", "objects", "notification", "reminder"),
|
|
302
|
+
e("💡", "bulb", "objects", "idea", "light", "tip"),
|
|
303
|
+
e("🔦", "flashlight", "objects", "torch"),
|
|
304
|
+
e("🔑", "key", "objects", "unlock", "password"),
|
|
305
|
+
e("🔒", "lock", "objects", "private", "secure"),
|
|
306
|
+
e("🔓", "unlock", "objects", "open"),
|
|
307
|
+
e("🔍", "mag", "objects", "search", "find", "magnify"),
|
|
308
|
+
e("🧰", "toolbox", "objects", "tools"),
|
|
309
|
+
e("🔧", "wrench", "objects", "fix", "tool"),
|
|
310
|
+
e("🔨", "hammer", "objects", "build", "tool"),
|
|
311
|
+
e("⚙️", "gear", "objects", "settings", "cog"),
|
|
312
|
+
e("💻", "laptop", "objects", "computer"),
|
|
313
|
+
e("🖥️", "desktop", "objects", "computer", "monitor"),
|
|
314
|
+
e("⌨️", "keyboard", "objects", "type"),
|
|
315
|
+
e("🖱️", "computer_mouse", "objects", "click", "mouse"),
|
|
316
|
+
e("📱", "iphone", "objects", "phone", "mobile"),
|
|
317
|
+
e("📷", "camera", "objects", "photo", "picture"),
|
|
318
|
+
e("🎥", "movie_camera", "objects", "video", "film"),
|
|
319
|
+
e("📺", "tv", "objects", "television"),
|
|
320
|
+
e("📻", "radio", "objects"),
|
|
321
|
+
e("🎙️", "studio_microphone", "objects", "podcast", "record"),
|
|
322
|
+
e("💰", "moneybag", "objects", "money", "cash", "budget"),
|
|
323
|
+
e("💷", "pound", "objects", "money", "gbp", "fees"),
|
|
324
|
+
e("💳", "credit_card", "objects", "payment", "card"),
|
|
325
|
+
e("🧾", "receipt", "objects", "invoice", "bill"),
|
|
326
|
+
e("📈", "chart_up", "objects", "growth", "progress", "increase"),
|
|
327
|
+
e("📉", "chart_down", "objects", "decrease", "drop"),
|
|
328
|
+
e("📊", "bar_chart", "objects", "stats", "data", "report"),
|
|
329
|
+
e("🗃️", "card_file_box", "objects", "archive", "records"),
|
|
330
|
+
e("🗑️", "wastebasket", "objects", "bin", "delete", "trash"),
|
|
331
|
+
e("🧸", "teddy_bear", "objects", "toy", "child"),
|
|
332
|
+
e("🎒", "school_satchel", "objects", "backpack", "bag", "school"),
|
|
333
|
+
e("🧳", "luggage", "objects", "suitcase", "trip"),
|
|
334
|
+
e("🩺", "stethoscope", "objects", "doctor", "health"),
|
|
335
|
+
e("💊", "pill", "objects", "medicine", "health"),
|
|
336
|
+
e("🧬", "dna", "objects", "biology", "genetics"),
|
|
337
|
+
e("🪐", "ringed_planet", "objects", "saturn", "space"),
|
|
338
|
+
e("🌐", "globe_meridians", "objects", "web", "internet", "language"),
|
|
339
|
+
e("🏁", "checkered_flag", "objects", "finish", "done", "race"),
|
|
340
|
+
e("🚩", "triangular_flag", "objects", "flag", "attention", "issue"),
|
|
341
|
+
|
|
342
|
+
// Symbols
|
|
343
|
+
e("❤️", "heart", "symbols", "love", "red"),
|
|
344
|
+
e("🧡", "orange_heart", "symbols", "love"),
|
|
345
|
+
e("💛", "yellow_heart", "symbols", "love"),
|
|
346
|
+
e("💚", "green_heart", "symbols", "love"),
|
|
347
|
+
e("💙", "blue_heart", "symbols", "love"),
|
|
348
|
+
e("💜", "purple_heart", "symbols", "love"),
|
|
349
|
+
e("🖤", "black_heart", "symbols"),
|
|
350
|
+
e("💔", "broken_heart", "symbols", "sad"),
|
|
351
|
+
e("💯", "100", "symbols", "perfect", "score", "full marks"),
|
|
352
|
+
e("✅", "white_check_mark", "symbols", "done", "yes", "tick", "complete"),
|
|
353
|
+
e("☑️", "ballot_box_with_check", "symbols", "tick", "checked"),
|
|
354
|
+
e("✔️", "heavy_check_mark", "symbols", "tick", "done"),
|
|
355
|
+
e("❌", "x", "symbols", "no", "wrong", "cross", "cancel"),
|
|
356
|
+
e("❎", "negative_squared_cross", "symbols", "no"),
|
|
357
|
+
e("⭕", "o", "symbols", "circle", "correct"),
|
|
358
|
+
e("❓", "question", "symbols", "help", "ask"),
|
|
359
|
+
e("❗", "exclamation", "symbols", "important", "alert", "warning"),
|
|
360
|
+
e("⚠️", "warning", "symbols", "caution", "attention"),
|
|
361
|
+
e("🚫", "no_entry_sign", "symbols", "forbidden", "banned"),
|
|
362
|
+
e("♻️", "recycle", "symbols", "green", "environment"),
|
|
363
|
+
e("➕", "heavy_plus", "symbols", "add", "plus", "maths"),
|
|
364
|
+
e("➖", "heavy_minus", "symbols", "subtract", "minus", "maths"),
|
|
365
|
+
e("✖️", "heavy_multiplication", "symbols", "times", "maths"),
|
|
366
|
+
e("➗", "heavy_division", "symbols", "divide", "maths"),
|
|
367
|
+
e("🟰", "equals", "symbols", "maths"),
|
|
368
|
+
e("♾️", "infinity", "symbols", "forever", "maths"),
|
|
369
|
+
e("🔢", "1234", "symbols", "numbers", "maths"),
|
|
370
|
+
e("🔤", "abc", "symbols", "letters", "alphabet", "english"),
|
|
371
|
+
e("🔠", "capital_abcd", "symbols", "letters", "uppercase"),
|
|
372
|
+
e("ℹ️", "information", "symbols", "info"),
|
|
373
|
+
e("🆕", "new", "symbols"),
|
|
374
|
+
e("🆗", "ok", "symbols", "okay"),
|
|
375
|
+
e("🆙", "up", "symbols", "level up"),
|
|
376
|
+
e("🔝", "top", "symbols", "best"),
|
|
377
|
+
e("🔜", "soon", "symbols", "coming soon"),
|
|
378
|
+
e("▶️", "arrow_forward", "symbols", "play", "next"),
|
|
379
|
+
e("⏸️", "pause", "symbols"),
|
|
380
|
+
e("⏹️", "stop", "symbols"),
|
|
381
|
+
e("🔁", "repeat", "symbols", "loop", "recurring"),
|
|
382
|
+
e("🔀", "shuffle", "symbols", "random", "mix"),
|
|
383
|
+
e("➡️", "arrow_right", "symbols", "next", "then"),
|
|
384
|
+
e("⬅️", "arrow_left", "symbols", "back", "previous"),
|
|
385
|
+
e("⬆️", "arrow_up", "symbols", "up"),
|
|
386
|
+
e("⬇️", "arrow_down", "symbols", "down"),
|
|
387
|
+
e("↩️", "leftwards_arrow_with_hook", "symbols", "return", "undo"),
|
|
388
|
+
e("🔗", "link", "symbols", "url", "chain"),
|
|
389
|
+
e("💬", "speech_balloon", "symbols", "comment", "chat", "message"),
|
|
390
|
+
e("💭", "thought_balloon", "symbols", "thinking", "idea"),
|
|
391
|
+
e("🗨️", "left_speech_bubble", "symbols", "quote", "said"),
|
|
392
|
+
e("💤", "zzz", "symbols", "sleep", "tired"),
|
|
393
|
+
e("🔴", "red_circle", "symbols", "red", "stop", "urgent"),
|
|
394
|
+
e("🟠", "orange_circle", "symbols", "orange"),
|
|
395
|
+
e("🟡", "yellow_circle", "symbols", "yellow", "caution"),
|
|
396
|
+
e("🟢", "green_circle", "symbols", "green", "go", "good"),
|
|
397
|
+
e("🔵", "blue_circle", "symbols", "blue"),
|
|
398
|
+
e("🟣", "purple_circle", "symbols", "purple"),
|
|
399
|
+
e("⚫", "black_circle", "symbols", "black"),
|
|
400
|
+
e("⚪", "white_circle", "symbols", "white"),
|
|
401
|
+
e("🟥", "red_square", "symbols", "red"),
|
|
402
|
+
e("🟩", "green_square", "symbols", "green"),
|
|
403
|
+
e("🟦", "blue_square", "symbols", "blue"),
|
|
404
|
+
e("🔶", "large_orange_diamond", "symbols", "orange"),
|
|
405
|
+
e("🔷", "large_blue_diamond", "symbols", "blue"),
|
|
406
|
+
e("🔺", "small_red_triangle", "symbols", "up"),
|
|
407
|
+
e("🔻", "small_red_triangle_down", "symbols", "down"),
|
|
408
|
+
e("💠", "diamond_shape_with_a_dot_inside", "symbols"),
|
|
409
|
+
e("🏷️", "label", "symbols", "tag"),
|
|
410
|
+
e("🔖", "bookmark", "symbols", "save", "mark"),
|
|
411
|
+
e("📣", "mega", "symbols", "announce", "loud"),
|
|
412
|
+
e("🎗️", "reminder_ribbon", "symbols", "remember"),
|
|
413
|
+
e("♿", "wheelchair", "symbols", "accessible", "send"),
|
|
414
|
+
e("☪️", "star_and_crescent", "symbols", "islam", "ramadan", "eid"),
|
|
415
|
+
e("✝️", "latin_cross", "symbols", "christian", "church"),
|
|
416
|
+
e("✡️", "star_of_david", "symbols", "jewish"),
|
|
417
|
+
e("🕉️", "om", "symbols", "hindu"),
|
|
418
|
+
e("☮️", "peace_symbol", "symbols", "peace"),
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Case-insensitive search over names and keywords. An empty query returns the
|
|
423
|
+
* whole set in catalogue order, which is what a picker wants to open with.
|
|
424
|
+
*/
|
|
425
|
+
export function searchEmoji(query: string, limit = 60): EmojiEntry[] {
|
|
426
|
+
const term = query.trim().toLowerCase().replace(/^:/, "");
|
|
427
|
+
if (!term) return EMOJI.slice(0, limit);
|
|
428
|
+
const starts: EmojiEntry[] = [];
|
|
429
|
+
const contains: EmojiEntry[] = [];
|
|
430
|
+
for (const entry of EMOJI) {
|
|
431
|
+
if (entry.name.startsWith(term)) starts.push(entry);
|
|
432
|
+
else if (entry.name.includes(term) || entry.keywords.some((k) => k.includes(term))) contains.push(entry);
|
|
433
|
+
if (starts.length >= limit) break;
|
|
434
|
+
}
|
|
435
|
+
return [...starts, ...contains].slice(0, limit);
|
|
436
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export { RichTextEditor, type RichTextEditorProps } from "./editor.js";
|
|
4
|
+
export { EmojiPicker } from "./emoji-picker.js";
|
|
5
|
+
export { activeBlockType, BLOCK_TYPES, type BlockType } from "./blocks.js";
|
|
6
|
+
export { type SuggestionItem, type SuggestionSources } from "./suggestions.js";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Node } from "@tiptap/pm/model";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sections: a heading and everything under it. Moving, dragging or collapsing a
|
|
5
|
+
* heading acts on its whole section, the way an outline does.
|
|
6
|
+
*
|
|
7
|
+
* A heading's section runs from the heading to the block before the next
|
|
8
|
+
* *break*: a heading of the same or a higher level (a smaller number), a divider,
|
|
9
|
+
* or an empty paragraph. Any other block is a section of one. Only blocks at the
|
|
10
|
+
* top of the document form sections — inside a list or a quote, a block moves on
|
|
11
|
+
* its own.
|
|
12
|
+
*
|
|
13
|
+
* Pure: these read a document and return child indexes or positions; the editor
|
|
14
|
+
* decides what to do with them.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The heading level of a top-level block, or null if it isn't a heading. */
|
|
18
|
+
export function headingLevel(node: Node): number | null {
|
|
19
|
+
return node.type.name === "heading" ? Number(node.attrs.level ?? 1) : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isBreak(node: Node, level: number): boolean {
|
|
23
|
+
const own = headingLevel(node);
|
|
24
|
+
if (own !== null) return own <= level;
|
|
25
|
+
if (node.type.name === "horizontalRule") return true;
|
|
26
|
+
return node.type.name === "paragraph" && node.content.size === 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The child index just past the section that starts at `index` (`index + 1` for a block that isn't a heading). */
|
|
30
|
+
export function sectionEnd(doc: Node, index: number): number {
|
|
31
|
+
const start = doc.maybeChild(index);
|
|
32
|
+
const level = start ? headingLevel(start) : null;
|
|
33
|
+
if (level === null) return index + 1;
|
|
34
|
+
let end = index + 1;
|
|
35
|
+
while (end < doc.childCount && !isBreak(doc.child(end), level)) end += 1;
|
|
36
|
+
return end;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The position before the top-level child at `index` (or the document's end). */
|
|
40
|
+
export function positionOfChild(doc: Node, index: number): number {
|
|
41
|
+
let pos = 0;
|
|
42
|
+
for (let i = 0; i < index && i < doc.childCount; i += 1) pos += doc.child(i).nodeSize;
|
|
43
|
+
return pos;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The top-level child index of the block that starts at `pos`, or null if none does. */
|
|
47
|
+
export function childIndexAt(doc: Node, pos: number): number | null {
|
|
48
|
+
let at = 0;
|
|
49
|
+
for (let i = 0; i < doc.childCount; i += 1) {
|
|
50
|
+
if (at === pos) return i;
|
|
51
|
+
at += doc.child(i).nodeSize;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The section starting at the top-level block at `pos`, as document positions; null for a nested block. */
|
|
57
|
+
export function sectionRange(doc: Node, pos: number): { from: number; to: number; blocks: number } | null {
|
|
58
|
+
const index = childIndexAt(doc, pos);
|
|
59
|
+
if (index === null) return null;
|
|
60
|
+
const end = sectionEnd(doc, index);
|
|
61
|
+
return { from: pos, to: positionOfChild(doc, end), blocks: end - index };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* What a section at `[start, end)` swaps with when moved up (-1) or down (+1): the
|
|
66
|
+
* neighbouring unit, as child indexes. Moving down passes the next block, or the
|
|
67
|
+
* whole next section if it starts with a heading; moving up passes the nearest
|
|
68
|
+
* earlier section of the same or a higher level that ends exactly here, or else
|
|
69
|
+
* the block just before. Null at either end of the document.
|
|
70
|
+
*/
|
|
71
|
+
export function neighbourUnit(doc: Node, start: number, end: number, direction: -1 | 1): [number, number] | null {
|
|
72
|
+
if (direction === 1) {
|
|
73
|
+
if (end >= doc.childCount) return null;
|
|
74
|
+
return [end, sectionEnd(doc, end)];
|
|
75
|
+
}
|
|
76
|
+
if (start <= 0) return null;
|
|
77
|
+
const level = headingLevel(doc.child(start)) ?? Number.POSITIVE_INFINITY;
|
|
78
|
+
for (let j = start - 1; j >= 0; j -= 1) {
|
|
79
|
+
const own = headingLevel(doc.child(j));
|
|
80
|
+
if (own !== null && own <= level && sectionEnd(doc, j) === start) return [j, start];
|
|
81
|
+
}
|
|
82
|
+
return [start - 1, start];
|
|
83
|
+
}
|