react-lib-tools 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/{CommonQuestionsRoute-D9K79upc.js → CommonQuestionsRoute-BwwqUJyI.js} +2 -2
  2. package/dist/{CommonQuestionsRoute-D9K79upc.js.map → CommonQuestionsRoute-BwwqUJyI.js.map} +1 -1
  3. package/dist/{CommonQuestionsRoute-CA0eEVPH.cjs → CommonQuestionsRoute-sImKiGx8.cjs} +2 -2
  4. package/dist/{CommonQuestionsRoute-CA0eEVPH.cjs.map → CommonQuestionsRoute-sImKiGx8.cjs.map} +1 -1
  5. package/dist/{GettingStartedRoute-rQVjSgEq.js → GettingStartedRoute-ClJU7JcL.js} +2 -2
  6. package/dist/{GettingStartedRoute-rQVjSgEq.js.map → GettingStartedRoute-ClJU7JcL.js.map} +1 -1
  7. package/dist/{GettingStartedRoute-B2gmhrI5.cjs → GettingStartedRoute-tyikH6yS.cjs} +2 -2
  8. package/dist/{GettingStartedRoute-B2gmhrI5.cjs.map → GettingStartedRoute-tyikH6yS.cjs.map} +1 -1
  9. package/dist/{PageNotFound-YcVoO6YV.cjs → PageNotFound-CSDM7qet.cjs} +2 -2
  10. package/dist/{PageNotFound-YcVoO6YV.cjs.map → PageNotFound-CSDM7qet.cjs.map} +1 -1
  11. package/dist/{PageNotFound-CrAUgSnt.js → PageNotFound-ibjIlKwX.js} +2 -2
  12. package/dist/{PageNotFound-CrAUgSnt.js.map → PageNotFound-ibjIlKwX.js.map} +1 -1
  13. package/dist/{SupportRoute-C74g_-rm.js → SupportRoute-BWxqeS9G.js} +2 -2
  14. package/dist/{SupportRoute-C74g_-rm.js.map → SupportRoute-BWxqeS9G.js.map} +1 -1
  15. package/dist/{SupportRoute-B4AetYXb.cjs → SupportRoute-CaVQtANn.cjs} +2 -2
  16. package/dist/{SupportRoute-B4AetYXb.cjs.map → SupportRoute-CaVQtANn.cjs.map} +1 -1
  17. package/dist/{VersionsRoute-CX4l8cMW.js → VersionsRoute-CRPHJWuY.js} +2 -2
  18. package/dist/{VersionsRoute-CX4l8cMW.js.map → VersionsRoute-CRPHJWuY.js.map} +1 -1
  19. package/dist/{VersionsRoute-Spk6Sna2.cjs → VersionsRoute-s9kvgKZE.cjs} +2 -2
  20. package/dist/{VersionsRoute-Spk6Sna2.cjs.map → VersionsRoute-s9kvgKZE.cjs.map} +1 -1
  21. package/dist/fuse-BvOe6mNx.js +1023 -0
  22. package/dist/fuse-BvOe6mNx.js.map +1 -0
  23. package/dist/fuse-CM2wbN_z.cjs +2 -0
  24. package/dist/fuse-CM2wbN_z.cjs.map +1 -0
  25. package/dist/index-D_pov2Kn.cjs +8 -0
  26. package/dist/index-D_pov2Kn.cjs.map +1 -0
  27. package/dist/{index-Bf43K_g2.js → index-DbkaDE2f.js} +2577 -2286
  28. package/dist/index-DbkaDE2f.js.map +1 -0
  29. package/dist/react-lib-tools.cjs +1 -1
  30. package/dist/react-lib-tools.d.ts +9 -3
  31. package/dist/react-lib-tools.js +1 -1
  32. package/lib/types.ts +6 -0
  33. package/package.json +5 -4
  34. package/scripts/compile-search-index.ts +39 -0
  35. package/scripts/utils/search/crawlPage.ts +103 -0
  36. package/scripts/utils/search/stopWords.ts +129 -0
  37. package/scripts/utils/search/types.ts +6 -0
  38. package/dist/index-BB-4-AeJ.cjs +0 -8
  39. package/dist/index-BB-4-AeJ.cjs.map +0 -1
  40. package/dist/index-Bf43K_g2.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-BB-4-AeJ.cjs");exports.AppRoot=o.AppRoot;exports.Block=o.Block;exports.Box=o.Box;exports.Button=o.Button;exports.Callout=o.Callout;exports.Checkbox=o.Checkbox;exports.Code=o.Code;exports.ComponentProps=o.ComponentProps;exports.ComponentPropsSection=o.ComponentPropsSection;exports.DocsSection=o.DocsSection;exports.ErrorBoundary=o.ErrorBoundary;exports.ExternalLink=o.ExternalLink;exports.Header=o.Header;exports.ImperativeHandle=o.ImperativeHandle;exports.Input=o.Input;exports.Link=o.Link;exports.LoadingSpinner=o.LoadingSpinner;exports.NavLink=o.NavLink;exports.NavSection=o.NavSection;exports.Radio=o.Radio;exports.Select=o.Select;exports.Tooltip=o.Tooltip;exports.assert=o.assert;exports.cn=o.cn;exports.getIntentClassNames=o.getIntentClassNames;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-D_pov2Kn.cjs");exports.AppRoot=o.AppRoot;exports.Block=o.Block;exports.Box=o.Box;exports.Button=o.Button;exports.Callout=o.Callout;exports.Checkbox=o.Checkbox;exports.Code=o.Code;exports.ComponentProps=o.ComponentProps;exports.ComponentPropsSection=o.ComponentPropsSection;exports.DocsSection=o.DocsSection;exports.ErrorBoundary=o.ErrorBoundary;exports.ExternalLink=o.ExternalLink;exports.Header=o.Header;exports.ImperativeHandle=o.ImperativeHandle;exports.Input=o.Input;exports.Link=o.Link;exports.LoadingSpinner=o.LoadingSpinner;exports.NavLink=o.NavLink;exports.NavSection=o.NavSection;exports.Radio=o.Radio;exports.Select=o.Select;exports.Tooltip=o.Tooltip;exports.assert=o.assert;exports.cn=o.cn;exports.getIntentClassNames=o.getIntentClassNames;
2
2
  //# sourceMappingURL=react-lib-tools.cjs.map
@@ -15,7 +15,7 @@ import { ReactNode } from 'react';
15
15
  /**
16
16
  * Displays an application shell with desktop and mobile layouts.
17
17
  */
18
- export declare function AppRoot({ commonQuestions, navLinks, overview, packageDescription, packageName, repositoryUrl, routes, showOpenCollectLink, versions }: {
18
+ export declare function AppRoot({ navLinks, routes, ...context }: {
19
19
  commonQuestions?: CommonQuestion[];
20
20
  navLinks: ReactNode;
21
21
  overview?: ReactNode | undefined;
@@ -163,9 +163,9 @@ export declare function Link({ children, onClick, to, ...rest }: Omit<HTMLAttrib
163
163
 
164
164
  export declare function LoadingSpinner(): JSX.Element;
165
165
 
166
- export declare function NavLink({ children, className, path }: PropsWithChildren<{
166
+ export declare function NavLink<Path extends string = DefaultPath>({ children, className, path }: PropsWithChildren<{
167
167
  className?: string | undefined;
168
- path: string;
168
+ path: Path;
169
169
  }>): JSX.Element;
170
170
 
171
171
  export declare function NavSection({ children, label }: PropsWithChildren<{
@@ -218,6 +218,12 @@ export declare function Select<Value extends string>({ className, defaultValue,
218
218
  value: Option_2<Value> | undefined;
219
219
  }): JSX.Element;
220
220
 
221
+ export declare type SiteSearchRecord = {
222
+ path: string;
223
+ section?: string | undefined;
224
+ title: string;
225
+ };
226
+
221
227
  declare function SupportRoute(): JSX.Element;
222
228
 
223
229
  export declare function Tooltip({ children, className, content, positions, showOnFocus, showOnHover, usePortal }: PropsWithChildren<{
@@ -1,4 +1,4 @@
1
- import { A as o, a as e, B as n, b as t, C as r, c as i, d as p, i as c, j as l, D as d, e as C, E as k, H as m, I as B, f as L, L as S, g as u, N as x, h as I, R as N, k as g, T as v, l as E, m as H, n as R } from "./index-Bf43K_g2.js";
1
+ import { A as o, a as e, B as n, b as t, C as r, c as i, d as p, i as c, j as l, D as d, e as C, E as k, H as m, I as B, f as L, L as S, g as u, N as x, h as I, R as N, k as g, T as v, l as E, m as H, n as R } from "./index-DbkaDE2f.js";
2
2
  export {
3
3
  o as AppRoot,
4
4
  e as Block,
package/lib/types.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
+ export type SiteSearchRecord = {
4
+ path: string;
5
+ section?: string | undefined;
6
+ title: string;
7
+ };
8
+
3
9
  export type Intent = "danger" | "none" | "primary" | "success" | "warning";
4
10
 
5
11
  export type Section = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-lib-tools",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)",
6
6
  "contributors": [
@@ -51,7 +51,9 @@
51
51
  "@codemirror/language": "^6.12.1",
52
52
  "@codemirror/state": "^6.5.3",
53
53
  "@lezer/highlight": "^1.2.3",
54
- "@ts-ast-parser/core": "^0.8.0"
54
+ "@ts-ast-parser/core": "^0.8.0",
55
+ "fuse.js": "^7.1.0",
56
+ "puppeteer": "^24.38.0"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@csstools/postcss-oklab-function": "^4.0.11",
@@ -113,7 +115,6 @@
113
115
  "vite-plugin-dts": "^4.5.4",
114
116
  "vite-plugin-svgr": "^4.3.0",
115
117
  "vitest": "^3.2.4",
116
- "vitest-fail-on-console": "^0.10.1",
117
- "zustand": "^5.0.7"
118
+ "vitest-fail-on-console": "^0.10.1"
118
119
  }
119
120
  }
@@ -0,0 +1,39 @@
1
+ import Fuse from "fuse.js";
2
+ import { writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import type { SiteSearchRecord } from "react-lib-tools";
5
+ import { crawlPage } from "./utils/search/crawlPage";
6
+ import type { SiteSearchPage } from "./utils/search/types";
7
+
8
+ export async function compileSearchIndex({
9
+ host = "http://localhost:3000",
10
+ outputPath = ["public", "generated"]
11
+ }: {
12
+ host?: string;
13
+ outputPath?: string[];
14
+ } = {}) {
15
+ const recordsMap: Record<string, SiteSearchPage> = {};
16
+
17
+ await crawlPage({
18
+ host,
19
+ path: "/",
20
+ records: recordsMap
21
+ });
22
+
23
+ const records = Object.values(recordsMap);
24
+
25
+ const searchIndex = Fuse.createIndex<SiteSearchRecord>(
26
+ ["title", "section", "text"],
27
+ records
28
+ );
29
+
30
+ await writeFile(
31
+ join(...outputPath, `search-records.json`),
32
+ JSON.stringify(records, null, 2)
33
+ );
34
+
35
+ await writeFile(
36
+ join(...outputPath, `search-index.json`),
37
+ JSON.stringify(searchIndex, null, 2)
38
+ );
39
+ }
@@ -0,0 +1,103 @@
1
+ import puppeteer from "puppeteer";
2
+ import { stopWords } from "./stopWords";
3
+ import type { SiteSearchPage } from "./types";
4
+
5
+ export async function crawlPage({
6
+ host,
7
+ path,
8
+ records
9
+ }: {
10
+ host: string;
11
+ path: string;
12
+ records: Record<string, SiteSearchPage>;
13
+ }) {
14
+ console.log(`Crawling ${host}${path} ...`);
15
+
16
+ const browser = await puppeteer.launch({
17
+ headless: true
18
+ });
19
+
20
+ const page = await browser.newPage();
21
+
22
+ // Navigate the page to a URL.
23
+ await page.goto(`${host}${path}`);
24
+ await page.waitForSelector("main");
25
+
26
+ const result = await page.evaluate(
27
+ async ([stopWords]) => {
28
+ const paths: string[] = [];
29
+ for (const element of document.body.querySelectorAll("[data-link]")) {
30
+ const to = element.getAttribute("data-link");
31
+ if (to) {
32
+ paths.push(to.split("#")[0]);
33
+ }
34
+ }
35
+
36
+ const section =
37
+ document.body.querySelector("header [data-section]")?.textContent ||
38
+ undefined;
39
+ const title =
40
+ document.body.querySelector("header [data-title]")?.textContent ?? "";
41
+
42
+ const words = new Set<string>();
43
+
44
+ const main = document.body.querySelector("header")?.parentElement;
45
+ if (main) {
46
+ for (const child of main.children) {
47
+ switch (child.tagName) {
48
+ case "CODE":
49
+ case "HEADER": {
50
+ continue;
51
+ }
52
+ }
53
+
54
+ if (child.hasAttribute("data-demo")) {
55
+ continue;
56
+ }
57
+
58
+ child.textContent?.split(/[\s.:]/).forEach((word) => {
59
+ word = word.trim().toLowerCase();
60
+ if (word && !stopWords.includes(word)) {
61
+ words.add(word);
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ return {
68
+ paths,
69
+ section,
70
+ title,
71
+ words: Array.from(words)
72
+ };
73
+ },
74
+ [stopWords]
75
+ );
76
+
77
+ records[path] = {
78
+ path,
79
+ section: result.section,
80
+ text: result.words.join(" "),
81
+ title: result.title
82
+ };
83
+
84
+ await Promise.all(
85
+ result.paths
86
+ .filter((current) => !records[current])
87
+ .map((current) => {
88
+ records[current] = {
89
+ path: current,
90
+ text: "",
91
+ title: ""
92
+ };
93
+
94
+ return crawlPage({
95
+ host,
96
+ path: current,
97
+ records
98
+ });
99
+ })
100
+ );
101
+
102
+ await browser.close();
103
+ }
@@ -0,0 +1,129 @@
1
+ export const stopWords = [
2
+ "a",
3
+ "about",
4
+ "above",
5
+ "after",
6
+ "again",
7
+ "against",
8
+ "all",
9
+ "am",
10
+ "an",
11
+ "and",
12
+ "any",
13
+ "are",
14
+ "as",
15
+ "at",
16
+ "be",
17
+ "because",
18
+ "been",
19
+ "before",
20
+ "being",
21
+ "below",
22
+ "between",
23
+ "both",
24
+ "but",
25
+ "by",
26
+ "can",
27
+ "did",
28
+ "do",
29
+ "does",
30
+ "doing",
31
+ "don",
32
+ "down",
33
+ "during",
34
+ "each",
35
+ "few",
36
+ "for",
37
+ "from",
38
+ "further",
39
+ "had",
40
+ "has",
41
+ "have",
42
+ "having",
43
+ "he",
44
+ "her",
45
+ "here",
46
+ "hers",
47
+ "herself",
48
+ "him",
49
+ "himself",
50
+ "his",
51
+ "how",
52
+ "i",
53
+ "if",
54
+ "in",
55
+ "into",
56
+ "is",
57
+ "it",
58
+ "its",
59
+ "itself",
60
+ "just",
61
+ "me",
62
+ "more",
63
+ "most",
64
+ "my",
65
+ "myself",
66
+ "no",
67
+ "nor",
68
+ "not",
69
+ "now",
70
+ "of",
71
+ "off",
72
+ "on",
73
+ "once",
74
+ "only",
75
+ "or",
76
+ "other",
77
+ "our",
78
+ "ours",
79
+ "ourselves",
80
+ "out",
81
+ "over",
82
+ "own",
83
+ "s",
84
+ "same",
85
+ "she",
86
+ "should",
87
+ "so",
88
+ "some",
89
+ "such",
90
+ "t",
91
+ "than",
92
+ "that",
93
+ "the",
94
+ "their",
95
+ "theirs",
96
+ "them",
97
+ "themselves",
98
+ "then",
99
+ "there",
100
+ "these",
101
+ "they",
102
+ "this",
103
+ "those",
104
+ "through",
105
+ "to",
106
+ "too",
107
+ "under",
108
+ "until",
109
+ "up",
110
+ "very",
111
+ "was",
112
+ "we",
113
+ "were",
114
+ "what",
115
+ "when",
116
+ "where",
117
+ "which",
118
+ "while",
119
+ "who",
120
+ "whom",
121
+ "why",
122
+ "will",
123
+ "with",
124
+ "you",
125
+ "your",
126
+ "yours",
127
+ "yourself",
128
+ "yourselves"
129
+ ];
@@ -0,0 +1,6 @@
1
+ export type SiteSearchPage = {
2
+ path: string;
3
+ section?: string | undefined;
4
+ text: string;
5
+ title: string;
6
+ };