@publish.os/nextjs 0.0.1-alpha.4 → 0.0.1-alpha.6
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 +1 -1
- package/dist/config/createNextConfig.js +3 -3
- package/dist/index.js +7 -5
- package/dist/kernel/components/blocks/color-palette.js +35 -4
- package/dist/kernel/components/blocks/design-system-preview.js +18 -17
- package/dist/kernel/components/blocks/link-playground.js +3 -3
- package/dist/kernel/components/blocks/logo-block.js +1 -1
- package/dist/kernel/components/blocks/nav-breadcrumb.js +2 -12
- package/dist/kernel/components/blocks/navbar.js +1 -1
- package/dist/kernel/components/blocks/navigation-progress-playground.js +2 -2
- package/dist/kernel/components/mdx/components/image.js +1 -1
- package/dist/kernel/components/ui/breadcrumb-trail.d.ts +3 -1
- package/dist/kernel/components/ui/breadcrumb-trail.js +1 -0
- package/dist/kernel/components/ui/breadcrumb.d.ts +1 -5
- package/dist/kernel/components/ui/breadcrumb.js +1 -16
- package/dist/kernel/components/ui/button-group.d.ts +2 -2
- package/dist/kernel/components/ui/button-group.js +2 -3
- package/dist/kernel/components/ui/button.d.ts +3 -4
- package/dist/kernel/components/ui/button.js +4 -12
- package/dist/kernel/components/ui/card.d.ts +1 -1
- package/dist/kernel/components/ui/menu.js +5 -5
- package/dist/kernel/components/ui/navigation-menu.js +2 -2
- package/dist/kernel/components/ui/popover.js +5 -11
- package/dist/kernel/components/ui/select.js +5 -5
- package/dist/kernel/components/ui/tag.d.ts +14 -0
- package/dist/kernel/components/ui/tag.js +76 -0
- package/dist/kernel/components/ui/text.d.ts +1 -1
- package/dist/kernel/components/ui/text.js +109 -106
- package/dist/kernel/components/ui/theme-toggle.js +1 -1
- package/dist/kernel/components/ui/tooltip.js +2 -2
- package/dist/kernel/defaults.registry.d.ts +63 -72
- package/dist/kernel/defaults.registry.js +62 -70
- package/dist/kernel/routes/agent/markdown.js +2 -2
- package/dist/kernel/routes/metadata/feed.js +2 -2
- package/dist/kernel/routes/metadata/llms.js +4 -2
- package/dist/kernel/routes/metadata/og-image.d.ts +1 -1
- package/dist/kernel/routes/metadata/robots.js +2 -2
- package/dist/kernel/routes/metadata/sitemap.js +2 -2
- package/dist/utils/cn.d.ts +1 -1
- package/package.json +4 -9
- package/release/package.json +4 -3
- package/release/release.json +5 -5
- package/release/{pnpm-lock.yaml → runtime-pnpm-lock.yaml} +348 -224
- package/dist/cache/tags.cjs +0 -79
- package/dist/cache/tags.d.cts +0 -13
- package/dist/config/createNextConfig.cjs +0 -52
- package/dist/config/createNextConfig.d.cts +0 -8
- package/dist/config.cjs +0 -78
- package/dist/config.d.cts +0 -101
- package/dist/config.d.ts +0 -101
- package/dist/config.js +0 -48
- package/dist/index.cjs +0 -1266
- package/dist/index.d.cts +0 -18
- package/dist/kernel/components/blocks/AgentActions.cjs +0 -425
- package/dist/kernel/components/blocks/AgentActions.d.cts +0 -52
- package/dist/kernel/components/blocks/animated-icon-swap.cjs +0 -101
- package/dist/kernel/components/blocks/animated-icon-swap.d.cts +0 -16
- package/dist/kernel/components/blocks/color-palette.cjs +0 -413
- package/dist/kernel/components/blocks/color-palette.d.cts +0 -7
- package/dist/kernel/components/blocks/design-system-preview.cjs +0 -592
- package/dist/kernel/components/blocks/design-system-preview.d.cts +0 -29
- package/dist/kernel/components/blocks/link-playground.cjs +0 -816
- package/dist/kernel/components/blocks/link-playground.d.cts +0 -5
- package/dist/kernel/components/blocks/logo-block.cjs +0 -156
- package/dist/kernel/components/blocks/logo-block.d.cts +0 -21
- package/dist/kernel/components/blocks/nav-breadcrumb.cjs +0 -122
- package/dist/kernel/components/blocks/nav-breadcrumb.d.cts +0 -11
- package/dist/kernel/components/blocks/navbar.cjs +0 -154
- package/dist/kernel/components/blocks/navbar.d.cts +0 -16
- package/dist/kernel/components/blocks/navigation-progress-playground.cjs +0 -735
- package/dist/kernel/components/blocks/navigation-progress-playground.d.cts +0 -5
- package/dist/kernel/components/blocks/navigation-progress.cjs +0 -270
- package/dist/kernel/components/blocks/navigation-progress.d.cts +0 -16
- package/dist/kernel/components/blocks/next-prev.cjs +0 -142
- package/dist/kernel/components/blocks/next-prev.d.cts +0 -11
- package/dist/kernel/components/blocks/page-list.cjs +0 -59
- package/dist/kernel/components/blocks/page-list.d.cts +0 -11
- package/dist/kernel/components/blocks/search.cjs +0 -717
- package/dist/kernel/components/blocks/search.d.cts +0 -77
- package/dist/kernel/components/blocks/sidebar-node.cjs +0 -309
- package/dist/kernel/components/blocks/sidebar-node.d.cts +0 -8
- package/dist/kernel/components/blocks/sidebar.cjs +0 -317
- package/dist/kernel/components/blocks/sidebar.d.cts +0 -33
- package/dist/kernel/components/blocks/theme-toggle.cjs +0 -31
- package/dist/kernel/components/blocks/theme-toggle.d.cts +0 -6
- package/dist/kernel/components/blocks/toc.cjs +0 -356
- package/dist/kernel/components/blocks/toc.d.cts +0 -10
- package/dist/kernel/components/mdx/components/blockquote.cjs +0 -66
- package/dist/kernel/components/mdx/components/blockquote.d.cts +0 -6
- package/dist/kernel/components/mdx/components/callout.cjs +0 -137
- package/dist/kernel/components/mdx/components/callout.d.cts +0 -18
- package/dist/kernel/components/mdx/components/code-block.cjs +0 -39
- package/dist/kernel/components/mdx/components/code-block.d.cts +0 -9
- package/dist/kernel/components/mdx/components/figure-caption.cjs +0 -63
- package/dist/kernel/components/mdx/components/figure-caption.d.cts +0 -6
- package/dist/kernel/components/mdx/components/figure.cjs +0 -78
- package/dist/kernel/components/mdx/components/figure.d.cts +0 -10
- package/dist/kernel/components/mdx/components/footnotes.cjs +0 -66
- package/dist/kernel/components/mdx/components/footnotes.d.cts +0 -6
- package/dist/kernel/components/mdx/components/heading-copy-link.cjs +0 -108
- package/dist/kernel/components/mdx/components/heading-copy-link.d.cts +0 -23
- package/dist/kernel/components/mdx/components/heading.cjs +0 -166
- package/dist/kernel/components/mdx/components/heading.d.cts +0 -8
- package/dist/kernel/components/mdx/components/hr.cjs +0 -34
- package/dist/kernel/components/mdx/components/hr.d.cts +0 -9
- package/dist/kernel/components/mdx/components/image-zoom.cjs +0 -49
- package/dist/kernel/components/mdx/components/image-zoom.d.cts +0 -10
- package/dist/kernel/components/mdx/components/image.cjs +0 -192
- package/dist/kernel/components/mdx/components/image.d.cts +0 -21
- package/dist/kernel/components/mdx/components/inline-code.cjs +0 -66
- package/dist/kernel/components/mdx/components/inline-code.d.cts +0 -6
- package/dist/kernel/components/mdx/components/kbd.cjs +0 -34
- package/dist/kernel/components/mdx/components/kbd.d.cts +0 -10
- package/dist/kernel/components/mdx/components/link.cjs +0 -49
- package/dist/kernel/components/mdx/components/link.d.cts +0 -11
- package/dist/kernel/components/mdx/components/paragraph.cjs +0 -87
- package/dist/kernel/components/mdx/components/paragraph.d.cts +0 -5
- package/dist/kernel/components/mdx/components/pre.cjs +0 -66
- package/dist/kernel/components/mdx/components/pre.d.cts +0 -6
- package/dist/kernel/components/mdx/components/strikethrough.cjs +0 -63
- package/dist/kernel/components/mdx/components/strikethrough.d.cts +0 -6
- package/dist/kernel/components/mdx/components/table.cjs +0 -59
- package/dist/kernel/components/mdx/components/table.d.cts +0 -10
- package/dist/kernel/components/mdx/components/task-list.cjs +0 -88
- package/dist/kernel/components/mdx/components/task-list.d.cts +0 -8
- package/dist/kernel/components/mdx/components/video-player.cjs +0 -173
- package/dist/kernel/components/mdx/components/video-player.d.cts +0 -18
- package/dist/kernel/components/mdx/components/video.cjs +0 -185
- package/dist/kernel/components/mdx/components/video.d.cts +0 -15
- package/dist/kernel/components/mdx/error-boundary.cjs +0 -62
- package/dist/kernel/components/mdx/error-boundary.d.cts +0 -8
- package/dist/kernel/components/mdx/error-fallback.cjs +0 -58
- package/dist/kernel/components/mdx/error-fallback.d.cts +0 -9
- package/dist/kernel/components/mdx/mdx.cjs +0 -141
- package/dist/kernel/components/mdx/mdx.d.cts +0 -22
- package/dist/kernel/components/mdx/rehype-heading-ids.cjs +0 -113
- package/dist/kernel/components/mdx/rehype-heading-ids.d.cts +0 -10
- package/dist/kernel/components/mdx/types.cjs +0 -18
- package/dist/kernel/components/mdx/types.d.cts +0 -18
- package/dist/kernel/components/ui/accordion.cjs +0 -104
- package/dist/kernel/components/ui/accordion.d.cts +0 -16
- package/dist/kernel/components/ui/badge.cjs +0 -75
- package/dist/kernel/components/ui/badge.d.cts +0 -12
- package/dist/kernel/components/ui/badge.d.ts +0 -12
- package/dist/kernel/components/ui/badge.js +0 -47
- package/dist/kernel/components/ui/breadcrumb-trail.cjs +0 -238
- package/dist/kernel/components/ui/breadcrumb-trail.d.cts +0 -13
- package/dist/kernel/components/ui/breadcrumb.cjs +0 -399
- package/dist/kernel/components/ui/breadcrumb.d.cts +0 -52
- package/dist/kernel/components/ui/button-group.cjs +0 -144
- package/dist/kernel/components/ui/button-group.d.cts +0 -19
- package/dist/kernel/components/ui/button.cjs +0 -147
- package/dist/kernel/components/ui/button.d.cts +0 -23
- package/dist/kernel/components/ui/card.cjs +0 -133
- package/dist/kernel/components/ui/card.d.cts +0 -17
- package/dist/kernel/components/ui/dialog.cjs +0 -149
- package/dist/kernel/components/ui/dialog.d.cts +0 -22
- package/dist/kernel/components/ui/drawer.cjs +0 -163
- package/dist/kernel/components/ui/drawer.d.cts +0 -24
- package/dist/kernel/components/ui/input.cjs +0 -96
- package/dist/kernel/components/ui/input.d.cts +0 -18
- package/dist/kernel/components/ui/kbd.cjs +0 -105
- package/dist/kernel/components/ui/kbd.d.cts +0 -13
- package/dist/kernel/components/ui/link.cjs +0 -253
- package/dist/kernel/components/ui/link.d.cts +0 -31
- package/dist/kernel/components/ui/menu.cjs +0 -301
- package/dist/kernel/components/ui/menu.d.cts +0 -70
- package/dist/kernel/components/ui/meta-key.cjs +0 -34
- package/dist/kernel/components/ui/meta-key.d.cts +0 -12
- package/dist/kernel/components/ui/navigation-menu.cjs +0 -253
- package/dist/kernel/components/ui/navigation-menu.d.cts +0 -47
- package/dist/kernel/components/ui/popover.cjs +0 -168
- package/dist/kernel/components/ui/popover.d.cts +0 -24
- package/dist/kernel/components/ui/progress.cjs +0 -112
- package/dist/kernel/components/ui/progress.d.cts +0 -16
- package/dist/kernel/components/ui/scroll-area.cjs +0 -413
- package/dist/kernel/components/ui/scroll-area.d.cts +0 -58
- package/dist/kernel/components/ui/select.cjs +0 -244
- package/dist/kernel/components/ui/select.d.cts +0 -40
- package/dist/kernel/components/ui/separator.cjs +0 -73
- package/dist/kernel/components/ui/separator.d.cts +0 -8
- package/dist/kernel/components/ui/table.cjs +0 -131
- package/dist/kernel/components/ui/table.d.cts +0 -11
- package/dist/kernel/components/ui/tabs.cjs +0 -450
- package/dist/kernel/components/ui/tabs.d.cts +0 -82
- package/dist/kernel/components/ui/text.cjs +0 -184
- package/dist/kernel/components/ui/text.d.cts +0 -17
- package/dist/kernel/components/ui/theme-toggle.cjs +0 -108
- package/dist/kernel/components/ui/theme-toggle.d.cts +0 -10
- package/dist/kernel/components/ui/toast.cjs +0 -154
- package/dist/kernel/components/ui/toast.d.cts +0 -26
- package/dist/kernel/components/ui/tooltip.cjs +0 -127
- package/dist/kernel/components/ui/tooltip.d.cts +0 -20
- package/dist/kernel/defaults.registry.cjs +0 -541
- package/dist/kernel/defaults.registry.d.cts +0 -469
- package/dist/kernel/routes/agent/markdown.cjs +0 -202
- package/dist/kernel/routes/agent/markdown.d.cts +0 -58
- package/dist/kernel/routes/layouts/group.cjs +0 -181
- package/dist/kernel/routes/layouts/group.d.cts +0 -20
- package/dist/kernel/routes/metadata/feed.cjs +0 -293
- package/dist/kernel/routes/metadata/feed.d.cts +0 -20
- package/dist/kernel/routes/metadata/llms.cjs +0 -239
- package/dist/kernel/routes/metadata/llms.d.cts +0 -26
- package/dist/kernel/routes/metadata/og-image.cjs +0 -630
- package/dist/kernel/routes/metadata/og-image.d.cts +0 -62
- package/dist/kernel/routes/metadata/robots.cjs +0 -148
- package/dist/kernel/routes/metadata/robots.d.cts +0 -6
- package/dist/kernel/routes/metadata/sitemap.cjs +0 -192
- package/dist/kernel/routes/metadata/sitemap.d.cts +0 -8
- package/dist/kernel/routes/pages/group.cjs +0 -263
- package/dist/kernel/routes/pages/group.d.cts +0 -17
- package/dist/kernel/routes/pages/leaf.cjs +0 -421
- package/dist/kernel/routes/pages/leaf.d.cts +0 -36
- package/dist/kernel/routes/pages/root.cjs +0 -229
- package/dist/kernel/routes/pages/root.d.cts +0 -16
- package/dist/keyboard-shortcuts.cjs +0 -345
- package/dist/keyboard-shortcuts.d.cts +0 -34
- package/dist/resolvers/manifest-resolver.cjs +0 -111
- package/dist/resolvers/manifest-resolver.d.cts +0 -13
- package/dist/search.cjs +0 -411
- package/dist/search.d.cts +0 -20
- package/dist/types.cjs +0 -30
- package/dist/types.d.cts +0 -269
- package/dist/utils/cn.cjs +0 -49
- package/dist/utils/cn.d.cts +0 -15
- package/dist/utils/heading-ids.cjs +0 -119
- package/dist/utils/heading-ids.d.cts +0 -15
- package/dist/utils/pretty-date.cjs +0 -55
- package/dist/utils/pretty-date.d.cts +0 -6
package/dist/search.cjs
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/search.tsx
|
|
22
|
-
var search_exports = {};
|
|
23
|
-
__export(search_exports, {
|
|
24
|
-
SearchProvider: () => SearchProvider,
|
|
25
|
-
search: () => search,
|
|
26
|
-
useSearch: () => useSearch,
|
|
27
|
-
useSearchBlock: () => useSearchBlock
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(search_exports);
|
|
30
|
-
var import_keyboard_shortcuts = require("@publish.os/nextjs/keyboard-shortcuts");
|
|
31
|
-
var import_navigation = require("next/navigation");
|
|
32
|
-
var import_react = require("react");
|
|
33
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
-
var EMPTY_SEARCH_OUTPUT = {
|
|
35
|
-
items: [],
|
|
36
|
-
nextOffset: null,
|
|
37
|
-
status: "idle",
|
|
38
|
-
total: 0
|
|
39
|
-
};
|
|
40
|
-
var MAX_SEARCH_QUERY_LENGTH = 128;
|
|
41
|
-
var MAX_SEARCH_RESULTS = 20;
|
|
42
|
-
var DEFAULT_SEARCH_LIMIT = 10;
|
|
43
|
-
var SEARCH_DEBOUNCE_MS = 140;
|
|
44
|
-
var SearchBlockContext = (0, import_react.createContext)(null);
|
|
45
|
-
function normalizeSearchInput(input) {
|
|
46
|
-
return {
|
|
47
|
-
filters: input.filters,
|
|
48
|
-
limit: Math.min(
|
|
49
|
-
Math.max(1, Math.floor(input.limit ?? DEFAULT_SEARCH_LIMIT)),
|
|
50
|
-
MAX_SEARCH_RESULTS
|
|
51
|
-
),
|
|
52
|
-
offset: Math.max(0, Math.floor(input.offset ?? 0)),
|
|
53
|
-
q: input.q.trim().slice(0, MAX_SEARCH_QUERY_LENGTH)
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function inactiveIndexMessage() {
|
|
57
|
-
return {
|
|
58
|
-
items: [],
|
|
59
|
-
message: "Building search index...",
|
|
60
|
-
nextOffset: null,
|
|
61
|
-
status: "building",
|
|
62
|
-
total: 0
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
var SEARCH_STATUS_URL = "/pagefind/publishos-search-status.json";
|
|
66
|
-
var PAGEFIND_URL = "/pagefind/pagefind.js";
|
|
67
|
-
var pagefindModulePromise = null;
|
|
68
|
-
async function fetchSearchStatus(signal) {
|
|
69
|
-
const response = await fetch(SEARCH_STATUS_URL, {
|
|
70
|
-
cache: "no-store",
|
|
71
|
-
signal
|
|
72
|
-
}).catch((error) => {
|
|
73
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
});
|
|
78
|
-
if (!response?.ok) return null;
|
|
79
|
-
return await response.json();
|
|
80
|
-
}
|
|
81
|
-
async function loadPagefind() {
|
|
82
|
-
pagefindModulePromise ??= new Function("src", "return import(src)")(PAGEFIND_URL).then(async (mod) => {
|
|
83
|
-
const pagefind = mod;
|
|
84
|
-
await pagefind.options?.({ bundlePath: "/pagefind/" });
|
|
85
|
-
await pagefind.init?.();
|
|
86
|
-
return pagefind;
|
|
87
|
-
});
|
|
88
|
-
return pagefindModulePromise;
|
|
89
|
-
}
|
|
90
|
-
function pagefindFilters(filters) {
|
|
91
|
-
if (!filters) return void 0;
|
|
92
|
-
const entries = Object.entries({
|
|
93
|
-
author: filters.author,
|
|
94
|
-
group: filters.group,
|
|
95
|
-
tag: filters.tag
|
|
96
|
-
}).filter((entry) => Boolean(entry[1]));
|
|
97
|
-
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
98
|
-
}
|
|
99
|
-
function titleForResult(data) {
|
|
100
|
-
return data.meta?.title ?? data.sub_results?.find((subResult) => subResult.title)?.title ?? data.url;
|
|
101
|
-
}
|
|
102
|
-
function toSearchResult({
|
|
103
|
-
data,
|
|
104
|
-
fallbackId,
|
|
105
|
-
score
|
|
106
|
-
}) {
|
|
107
|
-
const title = titleForResult(data);
|
|
108
|
-
const excerpt = data.excerpt ?? "";
|
|
109
|
-
return {
|
|
110
|
-
excerpt,
|
|
111
|
-
id: data.url || fallbackId,
|
|
112
|
-
meta: data.meta ?? {},
|
|
113
|
-
plainExcerpt: data.plain_excerpt ?? excerpt.replace(/<[^>]*>/g, ""),
|
|
114
|
-
score,
|
|
115
|
-
subResults: (data.sub_results ?? []).map((result) => ({
|
|
116
|
-
excerpt: result.excerpt ?? "",
|
|
117
|
-
plainExcerpt: (result.excerpt ?? "").replace(/<[^>]*>/g, ""),
|
|
118
|
-
title: result.title ?? title,
|
|
119
|
-
url: result.url ?? data.url
|
|
120
|
-
})),
|
|
121
|
-
title,
|
|
122
|
-
url: data.url
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function statusOutput(status) {
|
|
126
|
-
if (status.status === "ready" || status.status === void 0) return null;
|
|
127
|
-
if (status.status === "empty") {
|
|
128
|
-
return {
|
|
129
|
-
items: [],
|
|
130
|
-
message: "No searchable pages are available.",
|
|
131
|
-
nextOffset: null,
|
|
132
|
-
status: "ready",
|
|
133
|
-
total: 0
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
if (status.status === "building") {
|
|
137
|
-
return {
|
|
138
|
-
items: [],
|
|
139
|
-
message: status.message ?? "Building search index...",
|
|
140
|
-
nextOffset: null,
|
|
141
|
-
status: "building",
|
|
142
|
-
total: 0
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (status.status === "stale") {
|
|
146
|
-
return {
|
|
147
|
-
items: [],
|
|
148
|
-
message: status.message ?? "Updating search index...",
|
|
149
|
-
nextOffset: null,
|
|
150
|
-
status: "stale",
|
|
151
|
-
total: 0
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (status.status === "error") {
|
|
155
|
-
return {
|
|
156
|
-
items: [],
|
|
157
|
-
message: status.message ?? "Search is temporarily unavailable",
|
|
158
|
-
nextOffset: null,
|
|
159
|
-
status: "error",
|
|
160
|
-
total: 0
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
async function runPagefindSearch(input) {
|
|
166
|
-
const normalized = normalizeSearchInput(input);
|
|
167
|
-
if (!normalized.q) {
|
|
168
|
-
return EMPTY_SEARCH_OUTPUT;
|
|
169
|
-
}
|
|
170
|
-
const status = await fetchSearchStatus(input.signal);
|
|
171
|
-
const blockedByStatus = status ? statusOutput(status) : null;
|
|
172
|
-
if (blockedByStatus) return blockedByStatus;
|
|
173
|
-
const pagefind = await loadPagefind();
|
|
174
|
-
const limit = normalized.limit ?? DEFAULT_SEARCH_LIMIT;
|
|
175
|
-
const offset = normalized.offset ?? 0;
|
|
176
|
-
const result = await pagefind.search(normalized.q, {
|
|
177
|
-
filters: pagefindFilters(normalized.filters),
|
|
178
|
-
limit,
|
|
179
|
-
offset
|
|
180
|
-
});
|
|
181
|
-
if (!result) return EMPTY_SEARCH_OUTPUT;
|
|
182
|
-
const items = await Promise.all(
|
|
183
|
-
result.results.map(
|
|
184
|
-
async (pagefindResult) => toSearchResult({
|
|
185
|
-
data: await pagefindResult.data(),
|
|
186
|
-
fallbackId: pagefindResult.id,
|
|
187
|
-
score: pagefindResult.score
|
|
188
|
-
})
|
|
189
|
-
)
|
|
190
|
-
);
|
|
191
|
-
const total = result.unfilteredResultCount ?? items.length;
|
|
192
|
-
const nextOffset = offset + limit < total ? offset + limit : null;
|
|
193
|
-
return {
|
|
194
|
-
items,
|
|
195
|
-
nextOffset,
|
|
196
|
-
status: "ready",
|
|
197
|
-
total
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
async function search(input) {
|
|
201
|
-
const normalized = normalizeSearchInput(input);
|
|
202
|
-
if (!normalized.q) {
|
|
203
|
-
return EMPTY_SEARCH_OUTPUT;
|
|
204
|
-
}
|
|
205
|
-
try {
|
|
206
|
-
return await runPagefindSearch(normalized);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
209
|
-
return EMPTY_SEARCH_OUTPUT;
|
|
210
|
-
}
|
|
211
|
-
return inactiveIndexMessage();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function useSearch(input) {
|
|
215
|
-
const { filters, limit, offset, q } = input;
|
|
216
|
-
const stableInput = (0, import_react.useMemo)(
|
|
217
|
-
() => normalizeSearchInput({ filters, limit, offset, q }),
|
|
218
|
-
[filters, limit, offset, q]
|
|
219
|
-
);
|
|
220
|
-
const [output, setOutput] = (0, import_react.useState)(EMPTY_SEARCH_OUTPUT);
|
|
221
|
-
const requestId = (0, import_react.useRef)(0);
|
|
222
|
-
(0, import_react.useEffect)(() => {
|
|
223
|
-
const nextRequestId = requestId.current + 1;
|
|
224
|
-
requestId.current = nextRequestId;
|
|
225
|
-
if (!stableInput.q) {
|
|
226
|
-
setOutput(EMPTY_SEARCH_OUTPUT);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const controller = new AbortController();
|
|
230
|
-
const timer = window.setTimeout(() => {
|
|
231
|
-
setOutput((current) => ({ ...current, status: "idle" }));
|
|
232
|
-
runPagefindSearch({ ...stableInput, signal: controller.signal }).then((result) => {
|
|
233
|
-
if (requestId.current !== nextRequestId) return;
|
|
234
|
-
setOutput(result);
|
|
235
|
-
}).catch((error) => {
|
|
236
|
-
if (requestId.current !== nextRequestId) return;
|
|
237
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
setOutput(inactiveIndexMessage());
|
|
241
|
-
});
|
|
242
|
-
}, SEARCH_DEBOUNCE_MS);
|
|
243
|
-
return () => {
|
|
244
|
-
window.clearTimeout(timer);
|
|
245
|
-
controller.abort();
|
|
246
|
-
};
|
|
247
|
-
}, [stableInput]);
|
|
248
|
-
return output;
|
|
249
|
-
}
|
|
250
|
-
function useSearchBlock() {
|
|
251
|
-
const value = (0, import_react.useContext)(SearchBlockContext);
|
|
252
|
-
if (!value) {
|
|
253
|
-
throw new Error("useSearchBlock must be used inside <Search.Root>.");
|
|
254
|
-
}
|
|
255
|
-
return value;
|
|
256
|
-
}
|
|
257
|
-
function SearchProvider({
|
|
258
|
-
children,
|
|
259
|
-
defaultOpen = false,
|
|
260
|
-
limit = DEFAULT_SEARCH_LIMIT,
|
|
261
|
-
onOpenChange,
|
|
262
|
-
open: controlledOpen,
|
|
263
|
-
shortcut = "mod+k",
|
|
264
|
-
variant = "desktop"
|
|
265
|
-
}) {
|
|
266
|
-
const [uncontrolledOpen, setUncontrolledOpen] = (0, import_react.useState)(defaultOpen);
|
|
267
|
-
const [query, setQuery] = (0, import_react.useState)("");
|
|
268
|
-
const [isTyping, setIsTyping] = (0, import_react.useState)(false);
|
|
269
|
-
const [selectedValue, setSelectedValue] = (0, import_react.useState)("");
|
|
270
|
-
const typingTimer = (0, import_react.useRef)(null);
|
|
271
|
-
const inputRef = (0, import_react.useRef)(null);
|
|
272
|
-
const listRef = (0, import_react.useRef)(null);
|
|
273
|
-
const router = (0, import_navigation.useRouter)();
|
|
274
|
-
const inputId = (0, import_react.useId)();
|
|
275
|
-
const listId = (0, import_react.useId)();
|
|
276
|
-
const open = controlledOpen ?? uncontrolledOpen;
|
|
277
|
-
const output = useSearch({ limit, q: query });
|
|
278
|
-
const [displayResults, setDisplayResults] = (0, import_react.useState)([]);
|
|
279
|
-
const selectedResult = displayResults.find((result) => result.id === selectedValue) ?? displayResults[0];
|
|
280
|
-
const selectedResultId = selectedResult?.id ?? "";
|
|
281
|
-
const loading = Boolean(query.trim()) && !isTyping && output.status === "idle";
|
|
282
|
-
const setOpen = (0, import_react.useCallback)(
|
|
283
|
-
(nextOpen) => {
|
|
284
|
-
if (controlledOpen === void 0) {
|
|
285
|
-
setUncontrolledOpen(nextOpen);
|
|
286
|
-
}
|
|
287
|
-
onOpenChange?.(nextOpen);
|
|
288
|
-
if (!nextOpen) {
|
|
289
|
-
setQuery("");
|
|
290
|
-
setSelectedValue("");
|
|
291
|
-
setIsTyping(false);
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
[controlledOpen, onOpenChange]
|
|
295
|
-
);
|
|
296
|
-
const setQueryValue = (0, import_react.useCallback)((value) => {
|
|
297
|
-
setQuery(value);
|
|
298
|
-
}, []);
|
|
299
|
-
const handleInputChange = (0, import_react.useCallback)((value) => {
|
|
300
|
-
setQuery(value);
|
|
301
|
-
setIsTyping(true);
|
|
302
|
-
if (typingTimer.current !== null) {
|
|
303
|
-
window.clearTimeout(typingTimer.current);
|
|
304
|
-
}
|
|
305
|
-
typingTimer.current = window.setTimeout(() => {
|
|
306
|
-
setIsTyping(false);
|
|
307
|
-
typingTimer.current = null;
|
|
308
|
-
}, SEARCH_DEBOUNCE_MS);
|
|
309
|
-
}, []);
|
|
310
|
-
const navigateToResult = (0, import_react.useCallback)(
|
|
311
|
-
(result) => {
|
|
312
|
-
setOpen(false);
|
|
313
|
-
router.push(result.url);
|
|
314
|
-
},
|
|
315
|
-
[router, setOpen]
|
|
316
|
-
);
|
|
317
|
-
(0, import_react.useEffect)(() => {
|
|
318
|
-
if (!open) return;
|
|
319
|
-
const frame = window.requestAnimationFrame(() => {
|
|
320
|
-
inputRef.current?.focus();
|
|
321
|
-
});
|
|
322
|
-
return () => window.cancelAnimationFrame(frame);
|
|
323
|
-
}, [open]);
|
|
324
|
-
(0, import_keyboard_shortcuts.useShortcut)(shortcut, () => setOpen(true), {
|
|
325
|
-
description: "Open search",
|
|
326
|
-
group: "Search",
|
|
327
|
-
priority: 100
|
|
328
|
-
});
|
|
329
|
-
(0, import_react.useEffect)(() => {
|
|
330
|
-
if (!query.trim()) {
|
|
331
|
-
setDisplayResults([]);
|
|
332
|
-
setSelectedValue("");
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
if (isTyping || loading) return;
|
|
336
|
-
if (output.status === "ready") {
|
|
337
|
-
setDisplayResults(output.items);
|
|
338
|
-
setSelectedValue(output.items[0]?.id ?? "");
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
if (output.status === "building" || output.status === "stale" || output.status === "error") {
|
|
342
|
-
setDisplayResults([]);
|
|
343
|
-
setSelectedValue("");
|
|
344
|
-
}
|
|
345
|
-
}, [isTyping, loading, output.items, output.status, query]);
|
|
346
|
-
(0, import_react.useEffect)(
|
|
347
|
-
() => () => {
|
|
348
|
-
if (typingTimer.current !== null) {
|
|
349
|
-
window.clearTimeout(typingTimer.current);
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
[]
|
|
353
|
-
);
|
|
354
|
-
const contextValue = (0, import_react.useMemo)(
|
|
355
|
-
() => ({
|
|
356
|
-
actions: {
|
|
357
|
-
handleInputChange,
|
|
358
|
-
navigateToResult,
|
|
359
|
-
setOpen,
|
|
360
|
-
setQuery: setQueryValue,
|
|
361
|
-
setSelectedValue
|
|
362
|
-
},
|
|
363
|
-
meta: {
|
|
364
|
-
inputId,
|
|
365
|
-
inputRef,
|
|
366
|
-
listId,
|
|
367
|
-
listRef,
|
|
368
|
-
shortcut,
|
|
369
|
-
variant
|
|
370
|
-
},
|
|
371
|
-
state: {
|
|
372
|
-
displayResults,
|
|
373
|
-
isTyping,
|
|
374
|
-
loading,
|
|
375
|
-
message: output.message,
|
|
376
|
-
open,
|
|
377
|
-
query,
|
|
378
|
-
selectedValue: selectedResultId,
|
|
379
|
-
status: output.status,
|
|
380
|
-
total: output.total
|
|
381
|
-
}
|
|
382
|
-
}),
|
|
383
|
-
[
|
|
384
|
-
displayResults,
|
|
385
|
-
handleInputChange,
|
|
386
|
-
inputId,
|
|
387
|
-
isTyping,
|
|
388
|
-
listId,
|
|
389
|
-
loading,
|
|
390
|
-
navigateToResult,
|
|
391
|
-
open,
|
|
392
|
-
output.message,
|
|
393
|
-
output.status,
|
|
394
|
-
output.total,
|
|
395
|
-
query,
|
|
396
|
-
selectedResultId,
|
|
397
|
-
setOpen,
|
|
398
|
-
setQueryValue,
|
|
399
|
-
shortcut,
|
|
400
|
-
variant
|
|
401
|
-
]
|
|
402
|
-
);
|
|
403
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SearchBlockContext.Provider, { value: contextValue, children });
|
|
404
|
-
}
|
|
405
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
406
|
-
0 && (module.exports = {
|
|
407
|
-
SearchProvider,
|
|
408
|
-
search,
|
|
409
|
-
useSearch,
|
|
410
|
-
useSearchBlock
|
|
411
|
-
});
|
package/dist/search.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { SearchBlockVariant, SearchInput, SearchOutput, SearchBlockContextValue } from '@publish.os/nextjs/types';
|
|
3
|
-
export { SearchBlockActions, SearchBlockContextValue, SearchBlockMeta, SearchBlockState, SearchBlockVariant, SearchInput, SearchOutput, SearchResult, SearchStatus, SearchSubResult } from '@publish.os/nextjs/types';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
|
-
|
|
6
|
-
declare function search(input: SearchInput): Promise<SearchOutput>;
|
|
7
|
-
declare function useSearch(input: SearchInput): SearchOutput;
|
|
8
|
-
declare function useSearchBlock(): SearchBlockContextValue;
|
|
9
|
-
type SearchProviderProps = {
|
|
10
|
-
children?: ReactNode;
|
|
11
|
-
defaultOpen?: boolean;
|
|
12
|
-
limit?: number;
|
|
13
|
-
onOpenChange?: (open: boolean) => void;
|
|
14
|
-
open?: boolean;
|
|
15
|
-
shortcut?: string;
|
|
16
|
-
variant?: SearchBlockVariant;
|
|
17
|
-
};
|
|
18
|
-
declare function SearchProvider({ children, defaultOpen, limit, onOpenChange, open: controlledOpen, shortcut, variant, }: SearchProviderProps): react_jsx_runtime.JSX.Element;
|
|
19
|
-
|
|
20
|
-
export { SearchProvider, type SearchProviderProps, search, useSearch, useSearchBlock };
|
package/dist/types.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/types.ts
|
|
21
|
-
var types_exports = {};
|
|
22
|
-
__export(types_exports, {
|
|
23
|
-
__publishOsTypesModule: () => __publishOsTypesModule
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(types_exports);
|
|
26
|
-
var __publishOsTypesModule = true;
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
__publishOsTypesModule
|
|
30
|
-
});
|