@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5

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 (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,10 +1,5 @@
1
1
  'use client';
2
2
 
3
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
4
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
- import _extends from "@babel/runtime/helpers/esm/extends";
6
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
8
3
  import * as React from 'react';
9
4
  import { create, insertMultiple, search as oramaSearch } from '@orama/orama';
10
5
  import { pluginQPS } from '@orama/plugin-qps';
@@ -12,13 +7,11 @@ import { stemmer, language } from '@orama/stemmers/english';
12
7
  import { stopwords as englishStopwords } from '@orama/stopwords/english';
13
8
  // https://github.com/oramasearch/orama/blob/main/packages/stopwords/lib/en.js
14
9
  // Removed words that might be meaningful in a software documentation context
15
- var stopWords = englishStopwords.filter(function (word) {
16
- return word !== 'about' && word !== 'but' &&
17
- // start of button
18
- word !== 'for' &&
19
- // part of form
20
- word !== 'between' && word !== 'before' && word !== 'after' && word !== 'above' && word !== 'below' && word !== 'once' && word !== 'then' && word !== 'where' && word !== 'to' && word !== 'from' && word !== 'up' && word !== 'down' && word !== 'in' && word !== 'out' && word !== 'on' && word !== 'off' && word !== 'over' && word !== 'under';
21
- });
10
+ const stopWords = englishStopwords.filter(word => word !== 'about' && word !== 'but' &&
11
+ // start of button
12
+ word !== 'for' &&
13
+ // part of form
14
+ word !== 'between' && word !== 'before' && word !== 'after' && word !== 'above' && word !== 'below' && word !== 'once' && word !== 'then' && word !== 'where' && word !== 'to' && word !== 'from' && word !== 'up' && word !== 'down' && word !== 'in' && word !== 'out' && word !== 'on' && word !== 'off' && word !== 'over' && word !== 'under');
22
15
 
23
16
  /**
24
17
  * Type for our search document structure
@@ -27,7 +20,7 @@ var stopWords = englishStopwords.filter(function (word) {
27
20
  /**
28
21
  * Orama schema definition for our search document
29
22
  */
30
- var searchSchema = {
23
+ const searchSchema = {
31
24
  type: 'string',
32
25
  group: 'string',
33
26
  title: 'string',
@@ -42,7 +35,7 @@ var searchSchema = {
42
35
  sections: 'string',
43
36
  subsections: 'string',
44
37
  part: 'string',
45
- "export": 'string',
38
+ export: 'string',
46
39
  props: 'string',
47
40
  dataAttributes: 'string',
48
41
  cssVariables: 'string',
@@ -58,39 +51,33 @@ var searchSchema = {
58
51
  * Default function to flatten a sitemap page into search results
59
52
  */
60
53
  function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSections, generateSlug) {
61
- var _page$keywords;
62
- var results = [];
54
+ const results = [];
63
55
 
64
56
  // Extract top-level sections and all subsections with their slugs
65
57
  // Re-slugify from titles using the provided slugify function to match actual page IDs
66
- var sections = [];
67
- var subsections = [];
58
+ const sections = [];
59
+ const subsections = [];
68
60
  if (page.sections) {
69
- var _loop = function _loop() {
70
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
71
- originalSlug = _Object$entries$_i[0],
72
- sectionInfo = _Object$entries$_i[1];
61
+ // Top-level sections are the direct children
62
+ for (const [originalSlug, sectionInfo] of Object.entries(page.sections)) {
73
63
  // Use generateSlug if provided, otherwise use the original slug from sitemap
74
- var slug = generateSlug ? generateSlug(sectionInfo.title, []) : originalSlug;
64
+ const slug = generateSlug ? generateSlug(sectionInfo.title, []) : originalSlug;
75
65
  sections.push({
76
66
  title: sectionInfo.title,
77
- slug: slug
67
+ slug
78
68
  });
79
69
 
80
70
  // Subsections are all nested children (recursively)
81
71
  if (sectionInfo.children && Object.keys(sectionInfo.children).length > 0) {
82
- var _extractWithSlugs = function extractWithSlugs(hierarchy, parentSlugs, parentTitles) {
83
- var items = [];
84
- for (var _i2 = 0, _Object$entries2 = Object.entries(hierarchy); _i2 < _Object$entries2.length; _i2++) {
85
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
86
- childOriginalSlug = _Object$entries2$_i[0],
87
- childData = _Object$entries2$_i[1];
72
+ const extractWithSlugs = (hierarchy, parentSlugs, parentTitles) => {
73
+ const items = [];
74
+ for (const [childOriginalSlug, childData] of Object.entries(hierarchy)) {
88
75
  // Use generateSlug if provided, otherwise use the original slug from sitemap
89
76
  // When generateSlug is provided, pass parent titles for context
90
77
  // (e.g., for Releases pages: v1.0.0-rc.0-autocomplete)
91
- var childSlug = generateSlug ? generateSlug(childData.title, parentTitles) : childOriginalSlug;
92
- var currentSlugs = [].concat(_toConsumableArray(parentSlugs), [childSlug]);
93
- var currentTitles = [].concat(_toConsumableArray(parentTitles), [childData.title]);
78
+ const childSlug = generateSlug ? generateSlug(childData.title, parentTitles) : childOriginalSlug;
79
+ const currentSlugs = [...parentSlugs, childSlug];
80
+ const currentTitles = [...parentTitles, childData.title];
94
81
  items.push({
95
82
  title: childData.title,
96
83
  slug: childSlug,
@@ -98,66 +85,57 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
98
85
  parentTitles: currentTitles
99
86
  });
100
87
  if (childData.children && Object.keys(childData.children).length > 0) {
101
- items.push.apply(items, _toConsumableArray(_extractWithSlugs(childData.children, currentSlugs, currentTitles)));
88
+ items.push(...extractWithSlugs(childData.children, currentSlugs, currentTitles));
102
89
  }
103
90
  }
104
91
  return items;
105
92
  };
106
- subsections.push.apply(subsections, _toConsumableArray(_extractWithSlugs(sectionInfo.children, [slug], [sectionInfo.title])));
93
+ subsections.push(...extractWithSlugs(sectionInfo.children, [slug], [sectionInfo.title]));
107
94
  }
108
- };
109
- // Top-level sections are the direct children
110
- for (var _i = 0, _Object$entries = Object.entries(page.sections); _i < _Object$entries.length; _i++) {
111
- _loop();
112
95
  }
113
96
  }
114
- var flattened = {};
115
- if ((_page$keywords = page.keywords) != null && _page$keywords.length) {
97
+ const flattened = {};
98
+ if (page.keywords?.length) {
116
99
  flattened.keywords = page.keywords.join(' ');
117
100
  }
118
101
  if (sections.length > 0) {
119
- flattened.sections = sections.map(function (s) {
120
- return s.title;
121
- }).join(' ');
102
+ flattened.sections = sections.map(s => s.title).join(' ');
122
103
  }
123
104
  if (subsections.length > 0) {
124
- flattened.subsections = subsections.map(function (s) {
125
- return s.title;
126
- }).join(' ');
105
+ flattened.subsections = subsections.map(s => s.title).join(' ');
127
106
  }
128
107
 
129
108
  // Add base page result
130
- results.push(_extends(_extends({
109
+ results.push({
131
110
  type: 'page',
132
- group: includeCategoryInGroup ? "".concat(sectionData.title, " Pages") : 'Pages',
111
+ group: includeCategoryInGroup ? `${sectionData.title} Pages` : 'Pages',
133
112
  page: page.title,
134
113
  title: page.title,
135
114
  slug: page.slug,
136
115
  path: page.path,
137
116
  description: page.description,
138
117
  sectionTitle: sectionData.title,
139
- prefix: sectionData.prefix
140
- }, flattened.keywords ? {
141
- keywords: flattened.keywords
142
- } : {}), excludeSections ? {} : {
143
- sections: flattened.sections,
144
- subsections: flattened.subsections
145
- }));
118
+ prefix: sectionData.prefix,
119
+ ...(flattened.keywords ? {
120
+ keywords: flattened.keywords
121
+ } : {}),
122
+ ...(excludeSections ? {} : {
123
+ sections: flattened.sections,
124
+ subsections: flattened.subsections
125
+ })
126
+ });
146
127
 
147
128
  // Add entries for each part
148
129
  if (page.parts && Object.keys(page.parts).length > 0) {
149
- for (var _i3 = 0, _Object$entries3 = Object.entries(page.parts); _i3 < _Object$entries3.length; _i3++) {
150
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
151
- partName = _Object$entries3$_i[0],
152
- partData = _Object$entries3$_i[1];
130
+ for (const [partName, partData] of Object.entries(page.parts)) {
153
131
  results.push({
154
132
  type: 'part',
155
133
  group: 'API Reference',
156
134
  part: partName,
157
- "export": "".concat(page.slug, ".").concat(partName),
135
+ export: `${page.slug}.${partName}`,
158
136
  slug: partName.toLowerCase(),
159
137
  path: page.path,
160
- title: page.title ? "".concat(page.title, " \u2023 ").concat(partName) : partName,
138
+ title: page.title ? `${page.title} ${partName}` : partName,
161
139
  description: page.description,
162
140
  sectionTitle: sectionData.title,
163
141
  prefix: sectionData.prefix,
@@ -171,16 +149,13 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
171
149
 
172
150
  // Add entries for each export
173
151
  if (page.exports && Object.keys(page.exports).length > 0) {
174
- for (var _i4 = 0, _Object$entries4 = Object.entries(page.exports); _i4 < _Object$entries4.length; _i4++) {
175
- var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
176
- exportName = _Object$entries4$_i[0],
177
- exportData = _Object$entries4$_i[1];
152
+ for (const [exportName, exportData] of Object.entries(page.exports)) {
178
153
  // If export name matches page slug (case-insensitive), use #api-reference
179
- var exportSlug = exportName.toLowerCase() === page.slug.toLowerCase() ? 'api-reference' : exportName.toLowerCase();
154
+ const exportSlug = exportName.toLowerCase() === page.slug.toLowerCase() ? 'api-reference' : exportName.toLowerCase();
180
155
  results.push({
181
156
  type: 'export',
182
157
  group: 'API Reference',
183
- "export": exportSlug,
158
+ export: exportSlug,
184
159
  slug: page.slug,
185
160
  path: page.path,
186
161
  title: exportName,
@@ -196,15 +171,14 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
196
171
  }
197
172
 
198
173
  // Add entries for each section
199
- for (var _i5 = 0, _sections = sections; _i5 < _sections.length; _i5++) {
200
- var sectionItem = _sections[_i5];
174
+ for (const sectionItem of sections) {
201
175
  results.push({
202
176
  type: 'section',
203
177
  group: 'Sections',
204
178
  section: sectionItem.title,
205
- slug: "".concat(page.slug, "#").concat(sectionItem.slug),
179
+ slug: `${page.slug}#${sectionItem.slug}`,
206
180
  path: page.path,
207
- title: page.title ? "".concat(page.title, " \u2023 ").concat(sectionItem.title) : sectionItem.title,
181
+ title: page.title ? `${page.title} ${sectionItem.title}` : sectionItem.title,
208
182
  description: page.description,
209
183
  sectionTitle: sectionData.title,
210
184
  prefix: sectionData.prefix,
@@ -213,16 +187,15 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
213
187
  }
214
188
 
215
189
  // Add entries for each subsection
216
- for (var _i6 = 0, _subsections = subsections; _i6 < _subsections.length; _i6++) {
217
- var subsectionItem = _subsections[_i6];
218
- var fullTitle = subsectionItem.parentTitles.join(' ‣ ');
190
+ for (const subsectionItem of subsections) {
191
+ const fullTitle = subsectionItem.parentTitles.join(' ‣ ');
219
192
  results.push({
220
193
  type: 'subsection',
221
194
  group: 'Sections',
222
195
  subsection: fullTitle,
223
- slug: "".concat(page.slug, "#").concat(subsectionItem.slug.toLowerCase()),
196
+ slug: `${page.slug}#${subsectionItem.slug.toLowerCase()}`,
224
197
  path: page.path,
225
- title: page.title ? "".concat(page.title, " \u2023 ").concat(fullTitle) : fullTitle,
198
+ title: page.title ? `${page.title} ${fullTitle}` : fullTitle,
226
199
  description: page.description,
227
200
  sectionTitle: sectionData.title,
228
201
  prefix: sectionData.prefix,
@@ -236,7 +209,7 @@ function defaultFlattenPage(page, sectionData, includeCategoryInGroup, excludeSe
236
209
  * Default function to format search results
237
210
  */
238
211
  function defaultFormatResult(hit) {
239
- var base = {
212
+ const base = {
240
213
  id: hit.id,
241
214
  title: hit.document.title,
242
215
  description: hit.document.description,
@@ -247,50 +220,57 @@ function defaultFormatResult(hit) {
247
220
  score: hit.score,
248
221
  keywords: hit.document.keywords
249
222
  };
250
- var type = hit.document.type;
223
+ const type = hit.document.type;
251
224
  if (type === 'part') {
252
- return _extends(_extends({}, base), {}, {
225
+ return {
226
+ ...base,
253
227
  type: 'part',
254
228
  part: hit.document.part,
255
- "export": hit.document["export"],
229
+ export: hit.document.export,
256
230
  props: hit.document.props,
257
231
  dataAttributes: hit.document.dataAttributes,
258
232
  cssVariables: hit.document.cssVariables
259
- });
233
+ };
260
234
  }
261
235
  if (type === 'export') {
262
- return _extends(_extends({}, base), {}, {
236
+ return {
237
+ ...base,
263
238
  type: 'export',
264
- "export": hit.document["export"],
239
+ export: hit.document.export,
265
240
  props: hit.document.props,
266
241
  dataAttributes: hit.document.dataAttributes,
267
242
  cssVariables: hit.document.cssVariables
268
- });
243
+ };
269
244
  }
270
245
  if (type === 'section') {
271
- return _extends(_extends({}, base), {}, {
246
+ return {
247
+ ...base,
272
248
  type: 'section',
273
249
  section: hit.document.section
274
- });
250
+ };
275
251
  }
276
252
  if (type === 'subsection') {
277
- return _extends(_extends({}, base), {}, {
253
+ return {
254
+ ...base,
278
255
  type: 'subsection',
279
256
  subsection: hit.document.subsection
280
- });
257
+ };
281
258
  }
282
259
 
283
260
  // Default to page type
284
- return _extends(_extends(_extends({}, base), {}, {
261
+ return {
262
+ ...base,
285
263
  type: 'page',
286
- page: hit.document.title
287
- }, hit.document.sections ? {
288
- sections: hit.document.sections
289
- } : {}), hit.document.subsections ? {
290
- subsections: hit.document.subsections
291
- } : {});
264
+ page: hit.document.title,
265
+ ...(hit.document.sections ? {
266
+ sections: hit.document.sections
267
+ } : {}),
268
+ ...(hit.document.subsections ? {
269
+ subsections: hit.document.subsections
270
+ } : {})
271
+ };
292
272
  }
293
- export var defaultSearchBoost = {
273
+ export const defaultSearchBoost = {
294
274
  type: 100,
295
275
  group: 100,
296
276
  slug: 2,
@@ -300,7 +280,7 @@ export var defaultSearchBoost = {
300
280
  pageKeywords: 15,
301
281
  description: 1.5,
302
282
  part: 1.5,
303
- "export": 1.3,
283
+ export: 1.3,
304
284
  sectionTitle: 50,
305
285
  section: 3,
306
286
  subsection: 2.5,
@@ -319,329 +299,252 @@ export var defaultSearchBoost = {
319
299
  * @returns Search state and functions
320
300
  */
321
301
  export function useSearch(options) {
322
- var sitemapImport = options.sitemap,
323
- maxDefaultResults = options.maxDefaultResults,
324
- _options$tolerance = options.tolerance,
325
- tolerance = _options$tolerance === void 0 ? 1 : _options$tolerance,
326
- _options$limit = options.limit,
327
- defaultLimit = _options$limit === void 0 ? 20 : _options$limit,
328
- _options$boost = options.boost,
329
- boost = _options$boost === void 0 ? defaultSearchBoost : _options$boost,
330
- _options$enableStemmi = options.enableStemming,
331
- enableStemming = _options$enableStemmi === void 0 ? true : _options$enableStemmi,
332
- generateSlug = options.generateSlug,
333
- _options$flattenPage = options.flattenPage,
334
- flattenPage = _options$flattenPage === void 0 ? defaultFlattenPage : _options$flattenPage,
335
- _options$formatResult = options.formatResult,
336
- formatResult = _options$formatResult === void 0 ? defaultFormatResult : _options$formatResult;
337
- var _React$useState = React.useState(null),
338
- _React$useState2 = _slicedToArray(_React$useState, 2),
339
- index = _React$useState2[0],
340
- setIndex = _React$useState2[1];
341
- var _React$useState3 = React.useState({
342
- results: [],
343
- count: 0,
344
- elapsed: {
345
- raw: 0,
346
- formatted: '0ms'
347
- }
348
- }),
349
- _React$useState4 = _slicedToArray(_React$useState3, 2),
350
- defaultResults = _React$useState4[0],
351
- setDefaultResults = _React$useState4[1];
352
- var _React$useState5 = React.useState({
353
- results: [],
354
- count: 0,
355
- elapsed: {
356
- raw: 0,
357
- formatted: '0ms'
302
+ const {
303
+ sitemap: sitemapImport,
304
+ maxDefaultResults,
305
+ tolerance = 1,
306
+ limit: defaultLimit = 20,
307
+ boost = defaultSearchBoost,
308
+ enableStemming = true,
309
+ generateSlug,
310
+ flattenPage = defaultFlattenPage,
311
+ formatResult = defaultFormatResult
312
+ } = options;
313
+ const [index, setIndex] = React.useState(null);
314
+ const [defaultResults, setDefaultResults] = React.useState({
315
+ results: [],
316
+ count: 0,
317
+ elapsed: {
318
+ raw: 0,
319
+ formatted: '0ms'
320
+ }
321
+ });
322
+ const [results, setResults] = React.useState({
323
+ results: [],
324
+ count: 0,
325
+ elapsed: {
326
+ raw: 0,
327
+ formatted: '0ms'
328
+ }
329
+ });
330
+ React.useEffect(() => {
331
+ (async () => {
332
+ const {
333
+ sitemap
334
+ } = await sitemapImport();
335
+ if (!sitemap) {
336
+ console.error('Sitemap is undefined');
337
+ return;
358
338
  }
359
- }),
360
- _React$useState6 = _slicedToArray(_React$useState5, 2),
361
- results = _React$useState6[0],
362
- setResults = _React$useState6[1];
363
- React.useEffect(function () {
364
- _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
365
- var _yield$sitemapImport, sitemap, searchIndex, pages, pageResultsByGroup, pageResultsCount, dummyDoc, pageResultsGrouped, defaultResultsValue;
366
- return _regenerator().w(function (_context) {
367
- while (1) switch (_context.n) {
368
- case 0:
369
- _context.n = 1;
370
- return sitemapImport();
371
- case 1:
372
- _yield$sitemapImport = _context.v;
373
- sitemap = _yield$sitemapImport.sitemap;
374
- if (sitemap) {
375
- _context.n = 2;
376
- break;
377
- }
378
- console.error('Sitemap is undefined');
379
- return _context.a(2);
380
- case 2:
381
- _context.n = 3;
382
- return create({
383
- schema: searchSchema,
384
- components: enableStemming ? {
385
- tokenizer: {
386
- stemming: true,
387
- language: language,
388
- stemmer: stemmer,
389
- stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props'],
390
- stopWords: stopWords
391
- }
392
- } : undefined,
393
- plugins: [pluginQPS()]
394
- });
395
- case 3:
396
- searchIndex = _context.v;
397
- // Flatten the sitemap data structure to a single array of pages
398
- pages = [];
399
- pageResultsByGroup = {};
400
- pageResultsCount = 0;
401
- Object.entries(sitemap.data).forEach(function (_ref2) {
402
- var _ref3 = _slicedToArray(_ref2, 2),
403
- _sectionKey = _ref3[0],
404
- sectionData = _ref3[1];
405
- (sectionData.pages || []).forEach(function (page) {
406
- var flattened = flattenPage(page, sectionData, options.includeCategoryInGroup || false, options.excludeSections, generateSlug);
407
- pages.push.apply(pages, _toConsumableArray(flattened));
339
+ const searchIndex = await create({
340
+ schema: searchSchema,
341
+ components: enableStemming ? {
342
+ tokenizer: {
343
+ stemming: true,
344
+ language,
345
+ stemmer,
346
+ stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props'],
347
+ stopWords
348
+ }
349
+ } : undefined,
350
+ plugins: [pluginQPS()]
351
+ });
408
352
 
409
- // Add the first result (page type) to default results, grouped by their group
410
- if ((maxDefaultResults === undefined || pageResultsCount < maxDefaultResults) && flattened.length > 0) {
411
- var pageResult = flattened[0];
412
- var group = pageResult.group || 'Pages';
413
- if (!pageResultsByGroup[group]) {
414
- pageResultsByGroup[group] = [];
415
- }
416
- pageResultsByGroup[group].push(pageResult);
417
- pageResultsCount += 1;
418
- }
419
- });
420
- });
353
+ // Flatten the sitemap data structure to a single array of pages
354
+ const pages = [];
355
+ const pageResultsByGroup = {};
356
+ let pageResultsCount = 0;
357
+ Object.entries(sitemap.data).forEach(([_sectionKey, sectionData]) => {
358
+ (sectionData.pages || []).forEach(page => {
359
+ const flattened = flattenPage(page, sectionData, options.includeCategoryInGroup || false, options.excludeSections, generateSlug);
360
+ pages.push(...flattened);
421
361
 
422
- // Insert a dummy document with all fields to ensure QPS plugin initializes stats for all properties.
423
- // This is needed because QPS only creates stats for properties that have data inserted.
424
- // Using empty strings ensures no false matches while still initializing the stats.
425
- dummyDoc = {
426
- type: '',
427
- group: '',
428
- title: '',
429
- description: '',
430
- slug: '',
431
- sectionTitle: '',
432
- prefix: '',
433
- path: '',
434
- keywords: '',
435
- page: '',
436
- pageKeywords: '',
437
- sections: '',
438
- subsections: '',
439
- part: '',
440
- "export": '',
441
- props: '',
442
- dataAttributes: '',
443
- cssVariables: '',
444
- section: '',
445
- subsection: ''
446
- };
447
- _context.n = 4;
448
- return insertMultiple(searchIndex, [dummyDoc].concat(pages));
449
- case 4:
450
- pageResultsGrouped = Object.entries(pageResultsByGroup).map(function (_ref4) {
451
- var _ref5 = _slicedToArray(_ref4, 2),
452
- group = _ref5[0],
453
- items = _ref5[1];
454
- return {
455
- group: group,
456
- items: items
457
- };
458
- });
459
- defaultResultsValue = {
460
- results: pageResultsGrouped,
461
- count: pageResultsCount,
462
- elapsed: {
463
- raw: 0,
464
- formatted: '0ms'
465
- }
466
- };
467
- setIndex(searchIndex);
468
- setDefaultResults(defaultResultsValue);
469
- setResults(defaultResultsValue);
470
- case 5:
471
- return _context.a(2);
362
+ // Add the first result (page type) to default results, grouped by their group
363
+ if ((maxDefaultResults === undefined || pageResultsCount < maxDefaultResults) && flattened.length > 0) {
364
+ const pageResult = flattened[0];
365
+ const group = pageResult.group || 'Pages';
366
+ if (!pageResultsByGroup[group]) {
367
+ pageResultsByGroup[group] = [];
368
+ }
369
+ pageResultsByGroup[group].push(pageResult);
370
+ pageResultsCount += 1;
371
+ }
372
+ });
373
+ });
374
+
375
+ // Insert a dummy document with all fields to ensure QPS plugin initializes stats for all properties.
376
+ // This is needed because QPS only creates stats for properties that have data inserted.
377
+ // Using empty strings ensures no false matches while still initializing the stats.
378
+ const dummyDoc = {
379
+ type: '',
380
+ group: '',
381
+ title: '',
382
+ description: '',
383
+ slug: '',
384
+ sectionTitle: '',
385
+ prefix: '',
386
+ path: '',
387
+ keywords: '',
388
+ page: '',
389
+ pageKeywords: '',
390
+ sections: '',
391
+ subsections: '',
392
+ part: '',
393
+ export: '',
394
+ props: '',
395
+ dataAttributes: '',
396
+ cssVariables: '',
397
+ section: '',
398
+ subsection: ''
399
+ };
400
+ await insertMultiple(searchIndex, [dummyDoc, ...pages]);
401
+ const pageResultsGrouped = Object.entries(pageResultsByGroup).map(([group, items]) => ({
402
+ group,
403
+ items
404
+ }));
405
+ const defaultResultsValue = {
406
+ results: pageResultsGrouped,
407
+ count: pageResultsCount,
408
+ elapsed: {
409
+ raw: 0,
410
+ formatted: '0ms'
472
411
  }
473
- }, _callee);
474
- }))();
412
+ };
413
+ setIndex(searchIndex);
414
+ setDefaultResults(defaultResultsValue);
415
+ setResults(defaultResultsValue);
416
+ })();
475
417
  }, [sitemapImport, maxDefaultResults, flattenPage, generateSlug, enableStemming, options.includeCategoryInGroup, options.excludeSections]);
476
- var search = React.useCallback(/*#__PURE__*/function () {
477
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(value) {
478
- var _ref7,
479
- facets,
480
- groupBy,
481
- _ref7$limit,
482
- limit,
483
- where,
484
- valueLower,
485
- valueNormalized,
486
- useCustomSort,
487
- cache,
488
- getDocProps,
489
- searchResults,
490
- count,
491
- elapsed,
492
- groupedResults,
493
- formattedResults,
494
- _args2 = arguments;
495
- return _regenerator().w(function (_context2) {
496
- while (1) switch (_context2.n) {
497
- case 0:
498
- _ref7 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, facets = _ref7.facets, groupBy = _ref7.groupBy, _ref7$limit = _ref7.limit, limit = _ref7$limit === void 0 ? defaultLimit : _ref7$limit, where = _ref7.where;
499
- if (!(!index || !value.trim())) {
500
- _context2.n = 1;
501
- break;
502
- }
503
- setResults(defaultResults);
504
- return _context2.a(2);
505
- case 1:
506
- valueLower = value.toLowerCase(); // Normalize for comparison: convert spaces/hyphens to a common format
507
- valueNormalized = valueLower.replace(/[-\s]+/g, ' ').trim(); // For longer search terms, skip custom sorting and rely on Orama's scoring
508
- // The overhead of checking exact/startsWith/contains isn't worth it
509
- useCustomSort = valueLower.length <= 20; // Cache for computed document properties to avoid repeated string operations
510
- cache = new Map();
511
- getDocProps = function getDocProps(doc) {
512
- var key = doc.slug; // Use slug as cache key since it's unique per document
513
- var props = cache.get(key);
514
- if (!props) {
515
- var titleLower = doc.title.toLowerCase();
516
- var slugLower = doc.slug.toLowerCase();
517
- props = {
518
- titleLower: titleLower,
519
- slugLower: slugLower,
520
- slugNormalized: slugLower.replace(/-/g, ' ')
521
- };
522
- cache.set(key, props);
523
- }
524
- return props;
525
- };
526
- _context2.n = 2;
527
- return oramaSearch(index, {
528
- term: value,
529
- facets: facets,
530
- groupBy: groupBy,
531
- where: where,
532
- limit: limit,
533
- tolerance: tolerance,
534
- boost: boost,
535
- sortBy: useCustomSort ? function (_ref8, _ref9) {
536
- var _ref0 = _slicedToArray(_ref8, 3),
537
- _ = _ref0[0],
538
- aScore = _ref0[1],
539
- aDocument = _ref0[2];
540
- var _ref1 = _slicedToArray(_ref9, 3),
541
- __ = _ref1[0],
542
- bScore = _ref1[1],
543
- bDocument = _ref1[2];
544
- var a = getDocProps(aDocument);
545
- var b = getDocProps(bDocument);
418
+ const search = React.useCallback(async (value, {
419
+ facets,
420
+ groupBy,
421
+ limit = defaultLimit,
422
+ where
423
+ } = {}) => {
424
+ if (!index || !value.trim()) {
425
+ setResults(defaultResults);
426
+ return;
427
+ }
428
+ const valueLower = value.toLowerCase();
429
+ // Normalize for comparison: convert spaces/hyphens to a common format
430
+ const valueNormalized = valueLower.replace(/[-\s]+/g, ' ').trim();
546
431
 
547
- // Prioritize exact matches (short-circuit on first match)
548
- var aExact = a.titleLower === valueLower || a.slugLower === valueLower || a.slugNormalized === valueNormalized;
549
- var bExact = b.titleLower === valueLower || b.slugLower === valueLower || b.slugNormalized === valueNormalized;
550
- if (aExact !== bExact) {
551
- return aExact ? -1 : 1;
552
- }
432
+ // For longer search terms, skip custom sorting and rely on Orama's scoring
433
+ // The overhead of checking exact/startsWith/contains isn't worth it
434
+ const useCustomSort = valueLower.length <= 20;
553
435
 
554
- // Then prioritize startsWith matches
555
- var aStartsWith = a.titleLower.startsWith(valueLower) || a.slugNormalized.startsWith(valueNormalized);
556
- var bStartsWith = b.titleLower.startsWith(valueLower) || b.slugNormalized.startsWith(valueNormalized);
557
- if (aStartsWith !== bStartsWith) {
558
- return aStartsWith ? -1 : 1;
559
- }
436
+ // Cache for computed document properties to avoid repeated string operations
437
+ const cache = new Map();
438
+ const getDocProps = doc => {
439
+ const key = doc.slug; // Use slug as cache key since it's unique per document
440
+ let props = cache.get(key);
441
+ if (!props) {
442
+ const titleLower = doc.title.toLowerCase();
443
+ const slugLower = doc.slug.toLowerCase();
444
+ props = {
445
+ titleLower,
446
+ slugLower,
447
+ slugNormalized: slugLower.replace(/-/g, ' ')
448
+ };
449
+ cache.set(key, props);
450
+ }
451
+ return props;
452
+ };
453
+ const searchResults = await oramaSearch(index, {
454
+ term: value,
455
+ facets,
456
+ groupBy,
457
+ where,
458
+ limit,
459
+ tolerance,
460
+ boost,
461
+ sortBy: useCustomSort ? ([_, aScore, aDocument], [__, bScore, bDocument]) => {
462
+ const a = getDocProps(aDocument);
463
+ const b = getDocProps(bDocument);
560
464
 
561
- // Then prioritize contains matches
562
- var aContains = a.titleLower.includes(valueLower) || a.slugNormalized.includes(valueNormalized);
563
- var bContains = b.titleLower.includes(valueLower) || b.slugNormalized.includes(valueNormalized);
564
- if (aContains !== bContains) {
565
- return aContains ? -1 : 1;
566
- }
465
+ // Prioritize exact matches (short-circuit on first match)
466
+ const aExact = a.titleLower === valueLower || a.slugLower === valueLower || a.slugNormalized === valueNormalized;
467
+ const bExact = b.titleLower === valueLower || b.slugLower === valueLower || b.slugNormalized === valueNormalized;
468
+ if (aExact !== bExact) {
469
+ return aExact ? -1 : 1;
470
+ }
567
471
 
568
- // Then sort by score descending
569
- return bScore - aScore;
570
- } : undefined
571
- });
572
- case 2:
573
- searchResults = _context2.v;
574
- count = searchResults.count;
575
- elapsed = searchResults.elapsed;
576
- if (!searchResults.groups) {
577
- _context2.n = 3;
578
- break;
579
- }
580
- groupedResults = searchResults.groups.map(function (group) {
581
- return {
582
- group: group.values.join(' '),
583
- items: group.result.map(formatResult)
584
- };
585
- });
586
- setResults({
587
- results: groupedResults,
588
- count: count,
589
- elapsed: elapsed
590
- });
591
- return _context2.a(2);
592
- case 3:
593
- formattedResults = searchResults.hits.map(formatResult);
594
- setResults({
595
- results: [{
596
- group: 'Default',
597
- items: formattedResults
598
- }],
599
- count: count,
600
- elapsed: elapsed
601
- });
602
- case 4:
603
- return _context2.a(2);
472
+ // Then prioritize startsWith matches
473
+ const aStartsWith = a.titleLower.startsWith(valueLower) || a.slugNormalized.startsWith(valueNormalized);
474
+ const bStartsWith = b.titleLower.startsWith(valueLower) || b.slugNormalized.startsWith(valueNormalized);
475
+ if (aStartsWith !== bStartsWith) {
476
+ return aStartsWith ? -1 : 1;
604
477
  }
605
- }, _callee2);
606
- }));
607
- return function (_x) {
608
- return _ref6.apply(this, arguments);
609
- };
610
- }(), [index, defaultLimit, defaultResults, tolerance, boost, formatResult]);
478
+
479
+ // Then prioritize contains matches
480
+ const aContains = a.titleLower.includes(valueLower) || a.slugNormalized.includes(valueNormalized);
481
+ const bContains = b.titleLower.includes(valueLower) || b.slugNormalized.includes(valueNormalized);
482
+ if (aContains !== bContains) {
483
+ return aContains ? -1 : 1;
484
+ }
485
+
486
+ // Then sort by score descending
487
+ return bScore - aScore;
488
+ } : undefined
489
+ });
490
+ const count = searchResults.count;
491
+ const elapsed = searchResults.elapsed;
492
+ if (searchResults.groups) {
493
+ const groupedResults = searchResults.groups.map(group => ({
494
+ group: group.values.join(' '),
495
+ items: group.result.map(formatResult)
496
+ }));
497
+ setResults({
498
+ results: groupedResults,
499
+ count,
500
+ elapsed
501
+ });
502
+ return;
503
+ }
504
+ const formattedResults = searchResults.hits.map(formatResult);
505
+ setResults({
506
+ results: [{
507
+ group: 'Default',
508
+ items: formattedResults
509
+ }],
510
+ count,
511
+ elapsed
512
+ });
513
+ }, [index, defaultLimit, defaultResults, tolerance, boost, formatResult]);
611
514
 
612
515
  /**
613
516
  * Build a URL from a search result
614
517
  * Handles path normalization and hash fragments for different result types
615
518
  */
616
- var buildResultUrl = React.useCallback(function (result) {
617
- var url = result.path.startsWith('./') ? "".concat(result.prefix).concat(result.path.replace(/^\.\//, '').replace(/\/page\.mdx$/, '')) : result.path;
519
+ const buildResultUrl = React.useCallback(result => {
520
+ let url = result.path.startsWith('./') ? `${result.prefix}${result.path.replace(/^\.\//, '').replace(/\/page\.mdx$/, '')}` : result.path;
618
521
 
619
522
  // Add hash for non-page types
620
523
  if ('type' in result && result.type !== 'page') {
621
- var hash;
524
+ let hash;
622
525
  if (result.type === 'section' || result.type === 'subsection') {
623
526
  // For sections and subsections, extract hash from the slug field
624
527
  // which already contains the page slug + hash (e.g., "button#api-reference")
625
- var hashIndex = result.slug.indexOf('#');
528
+ const hashIndex = result.slug.indexOf('#');
626
529
  hash = hashIndex !== -1 ? result.slug.substring(hashIndex + 1) : '';
627
530
  } else if (result.type === 'part') {
628
531
  hash = result.part.toLowerCase();
629
532
  } else if (result.type === 'export') {
630
- hash = result["export"]; // already lowercase or api-reference
533
+ hash = result.export; // already lowercase or api-reference
631
534
  } else {
632
535
  hash = '';
633
536
  }
634
537
  if (hash) {
635
- url += "#".concat(hash);
538
+ url += `#${hash}`;
636
539
  }
637
540
  }
638
541
  return url;
639
542
  }, []);
640
543
  return {
641
- results: results,
544
+ results,
642
545
  isReady: index !== null,
643
- search: search,
644
- defaultResults: defaultResults,
645
- buildResultUrl: buildResultUrl
546
+ search,
547
+ defaultResults,
548
+ buildResultUrl
646
549
  };
647
550
  }