@qualcomm-ui/mdx-vite 1.1.0 → 2.1.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.
Files changed (35) hide show
  1. package/dist/cli.js +322 -230
  2. package/dist/cli.js.map +4 -4
  3. package/dist/docs-plugin/docs-plugin.d.ts.map +1 -1
  4. package/dist/docs-plugin/generate-page-map.d.ts +2 -0
  5. package/dist/docs-plugin/generate-page-map.d.ts.map +1 -0
  6. package/dist/docs-plugin/internal/search-indexer.d.ts +2 -2
  7. package/dist/docs-plugin/internal/search-indexer.d.ts.map +1 -1
  8. package/dist/docs-plugin/internal/services/markdown/markdown-file-reader.d.ts +1 -0
  9. package/dist/docs-plugin/internal/services/markdown/markdown-file-reader.d.ts.map +1 -1
  10. package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts +17 -1
  11. package/dist/docs-plugin/internal/services/markdown/markdown.types.d.ts.map +1 -1
  12. package/dist/docs-plugin/internal/services/nav-builder/nav-builder.d.ts.map +1 -1
  13. package/dist/docs-plugin/internal/services/nav-builder/page-map.d.ts.map +1 -1
  14. package/dist/docs-plugin/mdx-plugins.d.ts +2 -0
  15. package/dist/docs-plugin/mdx-plugins.d.ts.map +1 -1
  16. package/dist/docs-plugin/remark/remark-code-tabs.d.ts +16 -0
  17. package/dist/docs-plugin/remark/remark-code-tabs.d.ts.map +1 -1
  18. package/dist/docs-plugin/shiki/index.d.ts +3 -0
  19. package/dist/docs-plugin/shiki/index.d.ts.map +1 -0
  20. package/dist/docs-plugin/shiki/shiki-transformer-code-attribute.d.ts +20 -0
  21. package/dist/docs-plugin/shiki/shiki-transformer-code-attribute.d.ts.map +1 -0
  22. package/dist/docs-plugin/shiki/shiki-transformer-preview-block.d.ts +7 -0
  23. package/dist/docs-plugin/shiki/shiki-transformer-preview-block.d.ts.map +1 -0
  24. package/dist/docs-plugin/shiki/utils.d.ts +2 -0
  25. package/dist/docs-plugin/shiki/utils.d.ts.map +1 -0
  26. package/dist/index.js +204 -671
  27. package/dist/index.js.map +4 -4
  28. package/dist/open-web-ui-knowledge/generate-knowledge.d.ts.map +1 -1
  29. package/dist/react-demo-plugin/demo-plugin-utils.d.ts +0 -21
  30. package/dist/react-demo-plugin/demo-plugin-utils.d.ts.map +1 -1
  31. package/dist/react-demo-plugin/react-demo-plugin.d.ts +5 -1
  32. package/dist/react-demo-plugin/react-demo-plugin.d.ts.map +1 -1
  33. package/dist/react-demo-plugin/virtual.d.ts +0 -12
  34. package/dist/tsbuildinfo +1 -1
  35. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -3501,172 +3501,11 @@ var {
3501
3501
  Help
3502
3502
  } = import_index.default;
3503
3503
 
3504
- // src/open-web-ui-knowledge/download-knowledge.ts
3505
- import { mkdir, writeFile } from "node:fs/promises";
3506
- import { resolve } from "node:path";
3507
-
3508
- // src/open-web-ui-knowledge/common.ts
3509
- import { config } from "dotenv";
3510
- function loadEnv() {
3511
- const options = program.optsWithGlobals();
3512
- console.debug(options);
3513
- if (options.env) {
3514
- config({ path: options.env });
3515
- } else {
3516
- config();
3517
- }
3518
- }
3519
- function getConfigFromEnv() {
3520
- const openWebUiUrl = process.env.WEB_UI_URL;
3521
- const openWebUiKey = process.env.WEB_UI_KEY;
3522
- const knowledgeId = process.env.KNOWLEDGE_ID;
3523
- if (!openWebUiUrl || !openWebUiKey || !knowledgeId) {
3524
- throw new Error("WEB_UI_URL, WEB_UI_KEY, and KNOWLEDGE_ID must be set");
3525
- }
3526
- return {
3527
- knowledgeId,
3528
- webUiKey: openWebUiKey,
3529
- webUiUrl: openWebUiUrl
3530
- };
3531
- }
3532
- var KnowledgeApi = class {
3533
- config;
3534
- knowledgeCache = null;
3535
- constructor(config2) {
3536
- this.config = config2;
3537
- }
3538
- get headers() {
3539
- return {
3540
- Authorization: `Bearer ${this.config.webUiKey}`
3541
- };
3542
- }
3543
- async listKnowledgeFiles() {
3544
- if (this.knowledgeCache) {
3545
- return this.knowledgeCache;
3546
- }
3547
- const knowledge = await fetch(
3548
- `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}`,
3549
- {
3550
- headers: {
3551
- ...this.headers,
3552
- Accept: "application/json"
3553
- }
3554
- }
3555
- ).then((res) => res.json());
3556
- if ("detail" in knowledge) {
3557
- throw new Error(knowledge.detail);
3558
- } else {
3559
- this.knowledgeCache = knowledge;
3560
- }
3561
- return this.knowledgeCache;
3562
- }
3563
- async downloadFile(fileId) {
3564
- const fileResponse = await fetch(
3565
- `${this.config.webUiUrl}/api/v1/files/${fileId}`,
3566
- {
3567
- headers: {
3568
- ...this.headers,
3569
- Accept: "application/json"
3570
- }
3571
- }
3572
- ).then((res) => res.json());
3573
- return fileResponse?.data?.content ?? "";
3574
- }
3575
- async removeKnowledgeFile(id) {
3576
- return fetch(
3577
- `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}/file/remove`,
3578
- {
3579
- body: JSON.stringify({ file_id: id }),
3580
- headers: {
3581
- ...this.headers,
3582
- "Content-Type": "application/json"
3583
- },
3584
- method: "POST"
3585
- }
3586
- ).then((res) => res.json());
3587
- }
3588
- async deleteFile(id) {
3589
- return fetch(`${this.config.webUiUrl}/api/v1/files/${id}`, {
3590
- headers: {
3591
- ...this.headers,
3592
- "Content-Type": "application/json"
3593
- },
3594
- method: "DELETE"
3595
- }).then((res) => res.json());
3596
- }
3597
- async uploadFile(fileBuffer, name) {
3598
- const formData = new FormData();
3599
- formData.append("file", new Blob([fileBuffer]), name);
3600
- formData.append("knowledge_id", this.config.knowledgeId);
3601
- return fetch(`${this.config.webUiUrl}/api/v1/files/`, {
3602
- body: formData,
3603
- headers: {
3604
- ...this.headers,
3605
- Accept: "application/json"
3606
- },
3607
- method: "POST"
3608
- }).then((res) => res.json());
3609
- }
3610
- async associateFile(fileId) {
3611
- return fetch(
3612
- `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}/file/add`,
3613
- {
3614
- body: JSON.stringify({ file_id: fileId }),
3615
- headers: {
3616
- ...this.headers,
3617
- "Content-Type": "application/json"
3618
- },
3619
- method: "POST"
3620
- }
3621
- ).then((res) => res.json());
3622
- }
3623
- };
3624
-
3625
- // src/open-web-ui-knowledge/download-knowledge.ts
3626
- function addDownloadKnowledgeCommand() {
3627
- program.command("download-knowledge").description("Download files from an Open Web UI knowledge base").requiredOption("-o, --output-dir <outputDir>", "Folder path").action(async (opts) => {
3628
- loadEnv();
3629
- await mkdir(opts.outputDir, { recursive: true }).catch();
3630
- const api = new KnowledgeApi(getConfigFromEnv());
3631
- const knowledge = await api.listKnowledgeFiles();
3632
- for (const file of knowledge.files) {
3633
- const data = await api.downloadFile(file.id);
3634
- if (data) {
3635
- await writeFile(
3636
- resolve(opts.outputDir, file.meta.name),
3637
- data,
3638
- "utf-8"
3639
- );
3640
- }
3641
- }
3642
- });
3643
- }
3644
-
3645
- // src/open-web-ui-knowledge/generate-knowledge.ts
3646
- import { kebabCase } from "change-case";
3647
- import {
3648
- access,
3649
- mkdir as mkdir2,
3650
- readdir,
3651
- readFile,
3652
- rm,
3653
- stat,
3654
- writeFile as writeFile2
3655
- } from "node:fs/promises";
3656
- import { basename, dirname, extname, join as join3, resolve as resolve4 } from "node:path";
3657
- import remarkFrontmatter3 from "remark-frontmatter";
3658
- import remarkParse4 from "remark-parse";
3659
- import remarkParseFrontmatter2 from "remark-parse-frontmatter";
3660
- import remarkStringify3 from "remark-stringify";
3661
- import { unified as unified4 } from "unified";
3662
-
3663
- // src/docs-plugin/docs-plugin.ts
3664
- import chalk3 from "chalk";
3665
- import chokidar from "chokidar";
3504
+ // src/docs-plugin/generate-page-map.ts
3666
3505
  import { glob } from "glob";
3667
- import { readFileSync as readFileSync2 } from "node:fs";
3668
- import { resolve as resolve2 } from "node:path";
3669
- import prettyMilliseconds from "pretty-ms";
3506
+ import { writeFile } from "node:fs/promises";
3507
+ import { resolve } from "node:path";
3508
+ import { cwd } from "node:process";
3670
3509
 
3671
3510
  // src/docs-plugin/internal/config-loader.ts
3672
3511
  import { cosmiconfigSync } from "cosmiconfig";
@@ -4043,12 +3882,15 @@ var MarkdownFileReader = class {
4043
3882
  reset() {
4044
3883
  this.cachedFileCount = 0;
4045
3884
  }
4046
- checkCache(filepath, fileContents) {
3885
+ readCache(filePath) {
3886
+ return this.mdxCache[filePath] || null;
3887
+ }
3888
+ checkCache(filePath, fileContents) {
4047
3889
  if (!this.enabled) {
4048
3890
  return;
4049
3891
  }
4050
3892
  const fileMd5 = this.hash(fileContents);
4051
- const cached = this.mdxCache[filepath];
3893
+ const cached = this.mdxCache[filePath];
4052
3894
  if (cached?.md5 !== fileMd5) {
4053
3895
  return;
4054
3896
  }
@@ -4569,9 +4411,9 @@ function getRouteMeta(pathSegments, metaJson) {
4569
4411
  }
4570
4412
 
4571
4413
  // src/docs-plugin/internal/services/nav-builder/nav-builder.ts
4572
- import { capitalCase } from "change-case";
4573
4414
  import { sortBy } from "lodash-es";
4574
4415
  import { v4 as uuidv4 } from "uuid";
4416
+ import { capitalCase } from "@qualcomm-ui/utils/change-case";
4575
4417
  var NavBuilder = class {
4576
4418
  initialRoutes = [];
4577
4419
  flatNavItems = [];
@@ -4856,8 +4698,8 @@ var NavBuilder = class {
4856
4698
  };
4857
4699
 
4858
4700
  // src/docs-plugin/internal/services/nav-builder/page-map.ts
4859
- import { capitalCase as capitalCase2 } from "change-case";
4860
4701
  import { join } from "node:path";
4702
+ import { capitalCase as capitalCase2 } from "@qualcomm-ui/utils/change-case";
4861
4703
  function getPathnameFromPathSegments(segments) {
4862
4704
  return `/${segments.join("/")}`;
4863
4705
  }
@@ -5127,11 +4969,25 @@ var SearchIndexer = class {
5127
4969
  * Parses an MDX file to extract the site data for the nav items, doc props,
5128
4970
  * breadcrumbs, and search index.
5129
4971
  */
5130
- compileMdxFile(filepath) {
5131
- const { cached, fileContents, frontmatter } = this.fileCache.readFile(filepath);
4972
+ compileMdxFile(filePath) {
4973
+ const { cached, fileContents, frontmatter } = this.fileCache.readFile(filePath);
4974
+ const metadata = {
4975
+ changed: {},
4976
+ filePath
4977
+ };
4978
+ if (!cached) {
4979
+ const previousData = this.fileCache.readCache(filePath);
4980
+ if (previousData) {
4981
+ const cachedFm = JSON.stringify(previousData.frontmatter);
4982
+ const currentFm = JSON.stringify(frontmatter);
4983
+ if (cachedFm !== currentFm) {
4984
+ metadata.changed.frontmatter = true;
4985
+ }
4986
+ }
4987
+ }
5132
4988
  this.docPropsIndexer.reset();
5133
4989
  this.markdownIndexer.reset();
5134
- const defaultSection = this.getPageEntry(filepath, frontmatter);
4990
+ const defaultSection = this.getPageEntry(filePath, frontmatter);
5135
4991
  if (!defaultSection.categories.length && defaultSection.title) {
5136
4992
  defaultSection.categories = [defaultSection.title];
5137
4993
  }
@@ -5146,9 +5002,9 @@ var SearchIndexer = class {
5146
5002
  console.debug(
5147
5003
  `${chalk2.yellowBright.bold(
5148
5004
  "Failed to parse mdx page content."
5149
- )} ${chalk2.blueBright.bold(filepath)}`
5005
+ )} ${chalk2.blueBright.bold(filePath)}`
5150
5006
  );
5151
- return [defaultSection];
5007
+ return { metadata, pageSections: [defaultSection] };
5152
5008
  }
5153
5009
  const { sections, toc } = indexedPage;
5154
5010
  if (toc.length) {
@@ -5163,17 +5019,17 @@ var SearchIndexer = class {
5163
5019
  if (docPropSections.length) {
5164
5020
  this._pageDocProps[defaultSection.pathname] = docProps;
5165
5021
  }
5166
- this.fileCache.updateCache(filepath, fileContents, {
5022
+ this.fileCache.updateCache(filePath, fileContents, {
5167
5023
  frontmatter,
5168
5024
  page: indexedPage,
5169
5025
  pageDocProps: docProps,
5170
5026
  pageDocPropSections: docPropSections
5171
5027
  });
5172
5028
  if (frontmatter.hideFromSearch) {
5173
- return [defaultSection];
5029
+ return { metadata, pageSections: [defaultSection] };
5174
5030
  }
5175
5031
  if (!sections.length && !docPropSections.length) {
5176
- return [defaultSection];
5032
+ return { metadata, pageSections: [defaultSection] };
5177
5033
  }
5178
5034
  const sectionReturn = [
5179
5035
  ...this.formatSections(sections, defaultSection, false)
@@ -5183,7 +5039,7 @@ var SearchIndexer = class {
5183
5039
  ...this.formatSections(docPropSections, defaultSection, true)
5184
5040
  );
5185
5041
  }
5186
- return sectionReturn;
5042
+ return { metadata, pageSections: sectionReturn };
5187
5043
  }
5188
5044
  formatSections(sections, { toc: _toc, ...defaultSection }, isDocProp) {
5189
5045
  return sections.map((section, index) => {
@@ -5228,7 +5084,8 @@ var SearchIndexer = class {
5228
5084
  this.config.routingStrategy
5229
5085
  );
5230
5086
  this._mdxFileCount = mdxFileGlob.length;
5231
- const mdxIndex = mdxFileGlob.map((file) => this.compileMdxFile(file)).flat();
5087
+ const compiledFiles = mdxFileGlob.map((file) => this.compileMdxFile(file));
5088
+ const mdxIndex = compiledFiles.map((fileData) => fileData.pageSections).flat();
5232
5089
  filterFileGlob(
5233
5090
  fileGlob,
5234
5091
  "tsx",
@@ -5237,11 +5094,228 @@ var SearchIndexer = class {
5237
5094
  ).map((file) => this.compileTsxFile(file));
5238
5095
  this._searchIndex.push(...mdxIndex.filter((entry) => !entry.hideFromSearch));
5239
5096
  this.navBuilder.build();
5097
+ return compiledFiles;
5240
5098
  }
5241
5099
  };
5242
5100
 
5101
+ // src/docs-plugin/generate-page-map.ts
5102
+ function addGeneratePageMapCommand() {
5103
+ program.command("generate-page-map").description(
5104
+ "Invokes the docs-plugin once to build the site data and writes it to json"
5105
+ ).option(
5106
+ "-c, --config-file <configFile>",
5107
+ "Path to the qui-docs.config.ts config file"
5108
+ ).option(
5109
+ "-r, --routes-dir <routesDir>",
5110
+ "Path to the routes directory",
5111
+ "src/routes"
5112
+ ).option(
5113
+ "-o, --output <output>",
5114
+ "Output path for the site data json",
5115
+ "site-data.json"
5116
+ ).action(async (options) => {
5117
+ try {
5118
+ const configLoader = new ConfigLoader({ configFile: options.configFile });
5119
+ const resolvedConfig = configLoader.loadConfig();
5120
+ const routesDir = fixPath(
5121
+ resolve(resolvedConfig.appDirectory, resolvedConfig.pageDirectory)
5122
+ );
5123
+ const indexer = new SearchIndexer({
5124
+ ...resolvedConfig,
5125
+ srcDir: fixPath(resolve(cwd(), resolvedConfig.appDirectory)),
5126
+ typeDocProps: {}
5127
+ });
5128
+ const files = glob.sync(
5129
+ [`${routesDir}/**/*.mdx`, `${routesDir}/**/*.tsx`],
5130
+ {
5131
+ absolute: true,
5132
+ cwd: cwd()
5133
+ }
5134
+ );
5135
+ indexer.buildIndex(files, true);
5136
+ await writeFile(
5137
+ resolve(cwd(), options.output),
5138
+ JSON.stringify(indexer.pageMap, null, 2),
5139
+ "utf-8"
5140
+ );
5141
+ } catch (error) {
5142
+ console.error(
5143
+ "Generate Site Data Error:",
5144
+ error instanceof Error ? error.message : String(error)
5145
+ );
5146
+ process.exit(1);
5147
+ }
5148
+ });
5149
+ }
5150
+
5151
+ // src/open-web-ui-knowledge/download-knowledge.ts
5152
+ import { mkdir, writeFile as writeFile2 } from "node:fs/promises";
5153
+ import { resolve as resolve2 } from "node:path";
5154
+
5155
+ // src/open-web-ui-knowledge/common.ts
5156
+ import { config } from "dotenv";
5157
+ function loadEnv() {
5158
+ const options = program.optsWithGlobals();
5159
+ console.debug(options);
5160
+ if (options.env) {
5161
+ config({ path: options.env });
5162
+ } else {
5163
+ config();
5164
+ }
5165
+ }
5166
+ function getConfigFromEnv() {
5167
+ const openWebUiUrl = process.env.WEB_UI_URL;
5168
+ const openWebUiKey = process.env.WEB_UI_KEY;
5169
+ const knowledgeId = process.env.KNOWLEDGE_ID;
5170
+ if (!openWebUiUrl || !openWebUiKey || !knowledgeId) {
5171
+ throw new Error("WEB_UI_URL, WEB_UI_KEY, and KNOWLEDGE_ID must be set");
5172
+ }
5173
+ return {
5174
+ knowledgeId,
5175
+ webUiKey: openWebUiKey,
5176
+ webUiUrl: openWebUiUrl
5177
+ };
5178
+ }
5179
+ var KnowledgeApi = class {
5180
+ config;
5181
+ knowledgeCache = null;
5182
+ constructor(config2) {
5183
+ this.config = config2;
5184
+ }
5185
+ get headers() {
5186
+ return {
5187
+ Authorization: `Bearer ${this.config.webUiKey}`
5188
+ };
5189
+ }
5190
+ async listKnowledgeFiles() {
5191
+ if (this.knowledgeCache) {
5192
+ return this.knowledgeCache;
5193
+ }
5194
+ const knowledge = await fetch(
5195
+ `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}`,
5196
+ {
5197
+ headers: {
5198
+ ...this.headers,
5199
+ Accept: "application/json"
5200
+ }
5201
+ }
5202
+ ).then((res) => res.json());
5203
+ if ("detail" in knowledge) {
5204
+ throw new Error(knowledge.detail);
5205
+ } else {
5206
+ this.knowledgeCache = knowledge;
5207
+ }
5208
+ return this.knowledgeCache;
5209
+ }
5210
+ async downloadFile(fileId) {
5211
+ const fileResponse = await fetch(
5212
+ `${this.config.webUiUrl}/api/v1/files/${fileId}`,
5213
+ {
5214
+ headers: {
5215
+ ...this.headers,
5216
+ Accept: "application/json"
5217
+ }
5218
+ }
5219
+ ).then((res) => res.json());
5220
+ return fileResponse?.data?.content ?? "";
5221
+ }
5222
+ async removeKnowledgeFile(id) {
5223
+ return fetch(
5224
+ `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}/file/remove`,
5225
+ {
5226
+ body: JSON.stringify({ file_id: id }),
5227
+ headers: {
5228
+ ...this.headers,
5229
+ "Content-Type": "application/json"
5230
+ },
5231
+ method: "POST"
5232
+ }
5233
+ ).then((res) => res.json());
5234
+ }
5235
+ async deleteFile(id) {
5236
+ return fetch(`${this.config.webUiUrl}/api/v1/files/${id}`, {
5237
+ headers: {
5238
+ ...this.headers,
5239
+ "Content-Type": "application/json"
5240
+ },
5241
+ method: "DELETE"
5242
+ }).then((res) => res.json());
5243
+ }
5244
+ async uploadFile(fileBuffer, name) {
5245
+ const formData = new FormData();
5246
+ formData.append("file", new Blob([fileBuffer]), name);
5247
+ formData.append("knowledge_id", this.config.knowledgeId);
5248
+ return fetch(`${this.config.webUiUrl}/api/v1/files/`, {
5249
+ body: formData,
5250
+ headers: {
5251
+ ...this.headers,
5252
+ Accept: "application/json"
5253
+ },
5254
+ method: "POST"
5255
+ }).then((res) => res.json());
5256
+ }
5257
+ async associateFile(fileId) {
5258
+ return fetch(
5259
+ `${this.config.webUiUrl}/api/v1/knowledge/${this.config.knowledgeId}/file/add`,
5260
+ {
5261
+ body: JSON.stringify({ file_id: fileId }),
5262
+ headers: {
5263
+ ...this.headers,
5264
+ "Content-Type": "application/json"
5265
+ },
5266
+ method: "POST"
5267
+ }
5268
+ ).then((res) => res.json());
5269
+ }
5270
+ };
5271
+
5272
+ // src/open-web-ui-knowledge/download-knowledge.ts
5273
+ function addDownloadKnowledgeCommand() {
5274
+ program.command("download-knowledge").description("Download files from an Open Web UI knowledge base").requiredOption("-o, --output-dir <outputDir>", "Folder path").action(async (opts) => {
5275
+ loadEnv();
5276
+ await mkdir(opts.outputDir, { recursive: true }).catch();
5277
+ const api = new KnowledgeApi(getConfigFromEnv());
5278
+ const knowledge = await api.listKnowledgeFiles();
5279
+ for (const file of knowledge.files) {
5280
+ const data = await api.downloadFile(file.id);
5281
+ if (data) {
5282
+ await writeFile2(
5283
+ resolve2(opts.outputDir, file.meta.name),
5284
+ data,
5285
+ "utf-8"
5286
+ );
5287
+ }
5288
+ }
5289
+ });
5290
+ }
5291
+
5292
+ // src/open-web-ui-knowledge/generate-knowledge.ts
5293
+ import {
5294
+ access,
5295
+ mkdir as mkdir2,
5296
+ readdir,
5297
+ readFile,
5298
+ rm,
5299
+ stat,
5300
+ writeFile as writeFile3
5301
+ } from "node:fs/promises";
5302
+ import { basename, dirname, extname, join as join3, resolve as resolve5 } from "node:path";
5303
+ import remarkFrontmatter3 from "remark-frontmatter";
5304
+ import remarkParse4 from "remark-parse";
5305
+ import remarkParseFrontmatter2 from "remark-parse-frontmatter";
5306
+ import remarkStringify3 from "remark-stringify";
5307
+ import { unified as unified4 } from "unified";
5308
+ import { kebabCase } from "@qualcomm-ui/utils/change-case";
5309
+
5243
5310
  // src/docs-plugin/docs-plugin.ts
5311
+ import chalk3 from "chalk";
5312
+ import chokidar from "chokidar";
5313
+ import { glob as glob2 } from "glob";
5314
+ import { readFileSync as readFileSync2 } from "node:fs";
5315
+ import { resolve as resolve3 } from "node:path";
5316
+ import prettyMilliseconds from "pretty-ms";
5244
5317
  var isDev = process.env.NODE_ENV === "development";
5318
+ var VIRTUAL_MODULE_ID = "\0@qualcomm-ui/mdx-vite-plugin";
5245
5319
  var PluginState = class {
5246
5320
  buildCount = 0;
5247
5321
  configFilePath = "";
@@ -5252,14 +5326,9 @@ var PluginState = class {
5252
5326
  servers = [];
5253
5327
  timeout = void 0;
5254
5328
  watching = false;
5255
- resolvedVirtualModuleId;
5256
- virtualModuleId = "@qualcomm-ui/mdx-vite-plugin";
5257
5329
  cwd;
5258
- constructor() {
5259
- this.resolvedVirtualModuleId = `\0${this.virtualModuleId}`;
5260
- }
5261
- init(cwd) {
5262
- this.cwd = cwd;
5330
+ init(cwd2) {
5331
+ this.cwd = cwd2;
5263
5332
  }
5264
5333
  get docPropsDirectory() {
5265
5334
  if (!this.docPropsFilePath) {
@@ -5270,6 +5339,14 @@ var PluginState = class {
5270
5339
  this.docPropsFilePath.lastIndexOf("/")
5271
5340
  );
5272
5341
  }
5342
+ get siteData() {
5343
+ return {
5344
+ navItems: state.indexer.navItems,
5345
+ pageDocProps: state.indexer.pageDocProps,
5346
+ pageMap: state.indexer.pageMap,
5347
+ searchIndex: state.indexer.searchIndex
5348
+ };
5349
+ }
5273
5350
  resolveDocProps() {
5274
5351
  if (!this.docPropsFilePath) {
5275
5352
  return {};
@@ -5285,16 +5362,16 @@ var PluginState = class {
5285
5362
  }
5286
5363
  createIndexer(config2) {
5287
5364
  this.configFilePath = config2.filePath;
5288
- this.docPropsFilePath = config2.typeDocProps ? fixPath(resolve2(this.cwd, config2.typeDocProps)) : "";
5289
- this.routesDir = fixPath(resolve2(config2.appDirectory, config2.pageDirectory));
5365
+ this.docPropsFilePath = config2.typeDocProps ? fixPath(resolve3(this.cwd, config2.typeDocProps)) : "";
5366
+ this.routesDir = fixPath(resolve3(config2.appDirectory, config2.pageDirectory));
5290
5367
  this.indexer = new SearchIndexer({
5291
5368
  ...config2,
5292
- srcDir: fixPath(resolve2(this.cwd, config2.appDirectory)),
5369
+ srcDir: fixPath(resolve3(this.cwd, config2.appDirectory)),
5293
5370
  typeDocProps: this.resolveDocProps()
5294
5371
  });
5295
5372
  }
5296
5373
  buildIndex(shouldLog) {
5297
- const files = glob.sync(
5374
+ const files = glob2.sync(
5298
5375
  [`${this.routesDir}/**/*.mdx`, `${this.routesDir}/**/*.tsx`],
5299
5376
  {
5300
5377
  absolute: true,
@@ -5302,38 +5379,37 @@ var PluginState = class {
5302
5379
  }
5303
5380
  );
5304
5381
  if (!files.length) {
5305
- return;
5382
+ return [];
5306
5383
  }
5307
5384
  const startTime = Date.now();
5308
- this.indexer.buildIndex(files, shouldLog);
5385
+ const compiledMdxFiles = this.indexer.buildIndex(files, shouldLog);
5309
5386
  if (isDev && shouldLog) {
5310
5387
  console.debug(
5311
5388
  `${chalk3.magenta.bold(`@qualcomm-ui/mdx-vite/docs-plugin:`)} Compiled search index in: ${chalk3.blueBright.bold(prettyMilliseconds(Date.now() - startTime))}${state.indexer.cachedFileCount ? chalk3.greenBright.bold(` (${state.indexer.cachedFileCount}/${state.indexer.mdxFileCount} files cached)`) : ""}`
5312
5389
  );
5313
5390
  }
5391
+ return compiledMdxFiles;
5314
5392
  }
5315
5393
  /**
5316
- * When the user edits MDX content or modifies the plugin config, we re-index the
5317
- * site. This function handles module invalidation so that virtual file imports
5318
- * are refreshed as expected by the consumer's dev server.
5394
+ * When the user adds or removes mdx files, we re-index the site. This function
5395
+ * handles module invalidation so that virtual file imports are refreshed as
5396
+ * expected by the consumer's dev server.
5319
5397
  */
5320
5398
  sendUpdate() {
5321
5399
  for (const server of this.servers) {
5322
- const virtualModule = server.moduleGraph.getModuleById(
5323
- this.resolvedVirtualModuleId
5324
- );
5400
+ const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID);
5325
5401
  if (virtualModule) {
5326
5402
  server.moduleGraph.invalidateModule(virtualModule);
5327
5403
  server.reloadModule(virtualModule);
5328
5404
  }
5329
5405
  }
5330
5406
  }
5331
- handleChange(callback) {
5407
+ handleChange(opts = {}) {
5332
5408
  clearTimeout(this.timeout);
5333
5409
  this.timeout = setTimeout(() => {
5334
5410
  this.buildIndex(true);
5335
5411
  this.sendUpdate();
5336
- callback?.();
5412
+ opts?.onComplete?.();
5337
5413
  }, 300);
5338
5414
  }
5339
5415
  initWatchers(configFile) {
@@ -5356,7 +5432,13 @@ var PluginState = class {
5356
5432
  const resolvedConfig = this.configLoader.loadConfig();
5357
5433
  this.configFilePath = resolvedConfig.filePath;
5358
5434
  this.createIndexer(resolvedConfig);
5359
- this.handleChange();
5435
+ this.handleChange({
5436
+ onComplete: () => {
5437
+ this.servers.forEach(
5438
+ (server) => server.ws.send({ type: "full-reload" })
5439
+ );
5440
+ }
5441
+ });
5360
5442
  });
5361
5443
  }
5362
5444
  };
@@ -5364,6 +5446,16 @@ var state = new PluginState();
5364
5446
 
5365
5447
  // src/docs-plugin/mdx-plugins.ts
5366
5448
  import rehypeShiki from "@shikijs/rehype";
5449
+ import {
5450
+ transformerNotationDiff,
5451
+ transformerNotationErrorLevel,
5452
+ transformerNotationFocus,
5453
+ transformerNotationHighlight,
5454
+ transformerNotationWordHighlight,
5455
+ transformerRemoveNotationEscape,
5456
+ transformerRenderIndentGuides
5457
+ } from "@shikijs/transformers";
5458
+ import { merge } from "lodash-es";
5367
5459
  import { quiCustomDarkTheme } from "@qualcomm-ui/mdx-common";
5368
5460
 
5369
5461
  // src/exports.ts
@@ -5430,7 +5522,7 @@ import { visit as visit6 } from "unist-util-visit";
5430
5522
 
5431
5523
  // src/open-web-ui-knowledge/load-config-from-env.ts
5432
5524
  import { existsSync } from "node:fs";
5433
- import { join as join2, resolve as resolve3 } from "node:path";
5525
+ import { join as join2, resolve as resolve4 } from "node:path";
5434
5526
  function loadKnowledgeConfigFromEnv(options) {
5435
5527
  const knowledgeId = process.env.KNOWLEDGE_ID;
5436
5528
  const exclude = options.exclude || (process.env.FILE_EXCLUDE_PATTERN ?? "").split(",");
@@ -5448,7 +5540,7 @@ function loadKnowledgeConfigFromEnv(options) {
5448
5540
  resolvedConfig.appDirectory,
5449
5541
  resolvedConfig.pageDirectory
5450
5542
  );
5451
- if (!existsSync(resolve3(routeDir))) {
5543
+ if (!existsSync(resolve4(routeDir))) {
5452
5544
  throw new Error(`Route directory ${routeDir} does not exist`);
5453
5545
  }
5454
5546
  return {
@@ -5468,7 +5560,7 @@ async function exists(dirPath) {
5468
5560
  return access(dirPath).then(() => true).catch(() => false);
5469
5561
  }
5470
5562
  async function loadDocProps(routesFolder, docPropsPath, verbose) {
5471
- const resolvedDocPropsPath = docPropsPath ? await exists(docPropsPath) ? docPropsPath : resolve4(process.cwd(), docPropsPath) : join3(dirname(routesFolder), "doc-props.json");
5563
+ const resolvedDocPropsPath = docPropsPath ? await exists(docPropsPath) ? docPropsPath : resolve5(process.cwd(), docPropsPath) : join3(dirname(routesFolder), "doc-props.json");
5472
5564
  if (!await exists(resolvedDocPropsPath)) {
5473
5565
  if (verbose) {
5474
5566
  console.log(`Doc props file not found at: ${resolvedDocPropsPath}`);
@@ -5700,7 +5792,7 @@ function extractRelativeImports(content) {
5700
5792
  }
5701
5793
  async function resolveModulePath(importPath, fromFile) {
5702
5794
  const fromDir = dirname(fromFile);
5703
- const baseResolved = resolve4(fromDir, importPath);
5795
+ const baseResolved = resolve5(fromDir, importPath);
5704
5796
  const extensions = [".ts", ".tsx", ".js", ".jsx", ""];
5705
5797
  for (const ext of extensions) {
5706
5798
  const fullPath = baseResolved + ext;
@@ -5717,7 +5809,7 @@ async function resolveModulePath(importPath, fromFile) {
5717
5809
  return null;
5718
5810
  }
5719
5811
  async function collectRelativeImports(filePath, visited = /* @__PURE__ */ new Set(), verbose) {
5720
- const normalizedPath = resolve4(filePath);
5812
+ const normalizedPath = resolve5(filePath);
5721
5813
  if (visited.has(normalizedPath)) {
5722
5814
  return [];
5723
5815
  }
@@ -5796,10 +5888,10 @@ ${JSON.stringify(propsDoc, null, 2)}
5796
5888
  } else {
5797
5889
  processedContent = processedContent.replace(/<TypeDocProps\s+[^>]*\/>/g, "");
5798
5890
  }
5799
- let demoRegex = /<(?:QdsDemo|CodeDemo)\s+[^>]*name="(\w+)"[^>]*\/>/g;
5891
+ let demoRegex = /<(?:QdsDemo|CodeDemo|Demo)\s+[^>]*name="(\w+)"[^>]*\/>/g;
5800
5892
  let demoMatches = Array.from(processedContent.matchAll(demoRegex));
5801
5893
  if (!demoMatches.length) {
5802
- demoRegex = /<(?:QdsDemo|CodeDemo)\s+[^>]*node=\{Demo\.(\w+)\}[^>]*\/>/g;
5894
+ demoRegex = /<(?:QdsDemo|CodeDemo|Demo)\s+[^>]*node=\{Demo\.(\w+)\}[^>]*\/>/g;
5803
5895
  demoMatches = Array.from(processedContent.matchAll(demoRegex));
5804
5896
  }
5805
5897
  const replacements = await Promise.all(
@@ -5963,8 +6055,8 @@ async function generatePerPageExports({
5963
6055
  }
5964
6056
  }
5965
6057
  }
5966
- const outfile = `${resolve4(outputPath)}/${kebabCase(page.name)}.md`;
5967
- await writeFile2(outfile, lines.join("\n"), "utf-8");
6058
+ const outfile = `${resolve5(outputPath)}/${kebabCase(page.name)}.md`;
6059
+ await writeFile3(outfile, lines.join("\n"), "utf-8");
5968
6060
  const stats = await stat(outfile);
5969
6061
  totalSize += stats.size / 1024;
5970
6062
  })
@@ -6032,7 +6124,7 @@ async function generate({
6032
6124
  baseUrl
6033
6125
  );
6034
6126
  await mkdir2(dirname(outputPath), { recursive: true }).catch();
6035
- await writeFile2(outputPath, llmsTxtContent, "utf-8");
6127
+ await writeFile3(outputPath, llmsTxtContent, "utf-8");
6036
6128
  const outputStats = await stat(outputPath);
6037
6129
  const outputSizeKb = (outputStats.size / 1024).toFixed(1);
6038
6130
  console.log(
@@ -6078,9 +6170,9 @@ import {
6078
6170
  readdir as readdir2,
6079
6171
  readFile as readFile2,
6080
6172
  stat as stat2,
6081
- writeFile as writeFile3
6173
+ writeFile as writeFile4
6082
6174
  } from "node:fs/promises";
6083
- import { resolve as resolve5 } from "node:path";
6175
+ import { resolve as resolve6 } from "node:path";
6084
6176
  import { setTimeout as setTimeout2 } from "node:timers/promises";
6085
6177
  import ora from "ora";
6086
6178
  function calculateFileHash(fileData) {
@@ -6104,7 +6196,7 @@ var Uploader = class {
6104
6196
  const files = await Promise.all(
6105
6197
  fileNames.map(async (name) => ({
6106
6198
  contents: await readFile2(
6107
- resolve5(this.config.knowledgeFilePath, name),
6199
+ resolve6(this.config.knowledgeFilePath, name),
6108
6200
  "utf-8"
6109
6201
  ),
6110
6202
  name
@@ -6155,16 +6247,16 @@ var Uploader = class {
6155
6247
  if (calculateFileHash(data) === calculateFileHash(contents)) {
6156
6248
  return { skipped: true, success: true };
6157
6249
  }
6158
- await mkdir3(resolve5(process.cwd(), `./temp/diff`), {
6250
+ await mkdir3(resolve6(process.cwd(), `./temp/diff`), {
6159
6251
  recursive: true
6160
6252
  }).catch();
6161
- await writeFile3(
6162
- resolve5(process.cwd(), `./temp/diff/${name}-current.md`),
6253
+ await writeFile4(
6254
+ resolve6(process.cwd(), `./temp/diff/${name}-current.md`),
6163
6255
  contents,
6164
6256
  "utf-8"
6165
6257
  );
6166
- await writeFile3(
6167
- resolve5(process.cwd(), `./temp/diff/${name}-owui.md`),
6258
+ await writeFile4(
6259
+ resolve6(process.cwd(), `./temp/diff/${name}-owui.md`),
6168
6260
  data,
6169
6261
  "utf-8"
6170
6262
  );
@@ -6181,7 +6273,7 @@ var Uploader = class {
6181
6273
  }
6182
6274
  }
6183
6275
  const fileBuffer = await readFile2(
6184
- resolve5(this.config.knowledgeFilePath, name)
6276
+ resolve6(this.config.knowledgeFilePath, name)
6185
6277
  );
6186
6278
  if (knowledgeFile) {
6187
6279
  await this.api.removeKnowledgeFile(knowledgeFile.id);
@@ -6207,7 +6299,7 @@ var Uploader = class {
6207
6299
  }
6208
6300
  }
6209
6301
  async uploadKnowledge() {
6210
- const resolvedPath = resolve5(this.config.knowledgeFilePath);
6302
+ const resolvedPath = resolve6(this.config.knowledgeFilePath);
6211
6303
  if (!await access2(resolvedPath).then(() => true).catch(() => false)) {
6212
6304
  throw new Error(`File or folder not found at ${resolvedPath}`);
6213
6305
  }
@@ -6241,16 +6333,16 @@ function addUploadKnowledgeCommand() {
6241
6333
  }
6242
6334
 
6243
6335
  // src/react-demo-plugin/generate-lazy-demo-map.ts
6244
- import { glob as glob2 } from "glob";
6336
+ import { glob as glob3 } from "glob";
6245
6337
  import { uniqBy } from "lodash-es";
6246
- import { writeFile as writeFile4 } from "node:fs/promises";
6247
- import { resolve as resolve7 } from "node:path";
6338
+ import { writeFile as writeFile5 } from "node:fs/promises";
6339
+ import { resolve as resolve8 } from "node:path";
6248
6340
  import { dedent } from "@qualcomm-ui/utils/dedent";
6249
6341
 
6250
6342
  // src/react-demo-plugin/demo-plugin-utils.ts
6251
6343
  import chalk4 from "chalk";
6252
6344
  import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
6253
- import { dirname as dirname2, join as join4, relative, resolve as resolve6, sep } from "node:path";
6345
+ import { dirname as dirname2, join as join4, relative, resolve as resolve7, sep } from "node:path";
6254
6346
  import * as ts from "typescript";
6255
6347
  import { pascalCase } from "@qualcomm-ui/utils/change-case";
6256
6348
  function extractPageId(filePath, routesDir) {
@@ -6264,8 +6356,7 @@ function extractPageId(filePath, routesDir) {
6264
6356
  }
6265
6357
  function isDemoFile(filePath) {
6266
6358
  try {
6267
- return filePath.includes("/demos/") && filePath.endsWith(".tsx") && // could also be in a comment, probably need to use TS parser
6268
- readFileSync3(filePath, "utf-8").includes("export default");
6359
+ return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !readFileSync3(filePath).includes("export default");
6269
6360
  } catch (error) {
6270
6361
  return false;
6271
6362
  }
@@ -6276,7 +6367,7 @@ async function scanForDemoPages({
6276
6367
  demoPattern = "src/routes/**/demos/*.tsx",
6277
6368
  routesDir = "src/routes"
6278
6369
  }) {
6279
- const demoFiles = (await glob2(demoPattern)).filter((file) => isDemoFile(file));
6370
+ const demoFiles = (await glob3(demoPattern)).filter((file) => isDemoFile(file));
6280
6371
  return uniqBy(
6281
6372
  demoFiles.map((file) => ({
6282
6373
  pageId: extractPageId(file, routesDir),
@@ -6308,12 +6399,12 @@ function generateLazyDemoLoader(demoPages) {
6308
6399
  }
6309
6400
  async function generateLazyDemoMap(options) {
6310
6401
  const routesDir = options.routesDir;
6311
- const outputPath = resolve7(options.output);
6402
+ const outputPath = resolve8(options.output);
6312
6403
  console.log(`Scanning for demo pages in: ${routesDir}`);
6313
6404
  const demoPages = await scanForDemoPages({ routesDir });
6314
6405
  console.log(`Found ${demoPages.length} pages with demos`);
6315
6406
  const content = generateLazyDemoLoader(demoPages);
6316
- await writeFile4(outputPath, content, "utf-8");
6407
+ await writeFile5(outputPath, content, "utf-8");
6317
6408
  console.log(`
6318
6409
  Generated lazy demo loader at: ${outputPath}`);
6319
6410
  }
@@ -6344,6 +6435,7 @@ function setupCli() {
6344
6435
  addUploadKnowledgeCommand();
6345
6436
  addDownloadKnowledgeCommand();
6346
6437
  addGenerateLazyDemoMapCommand();
6438
+ addGeneratePageMapCommand();
6347
6439
  program.parse();
6348
6440
  }
6349
6441
  setupCli();