@qualcomm-ui/mdx-vite 3.1.0 → 3.2.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.
@@ -0,0 +1,31 @@
1
+ import type { PluginOption } from "vite";
2
+ /**
3
+ * Options for the {@link frontmatterHmrPlugin}.
4
+ */
5
+ export interface FrontmatterHmrPluginOptions {
6
+ /**
7
+ * The name of the frontmatter export to target. This needs to match the
8
+ * '@mdx-js/react' frontmatter export name, which defaults to `frontmatter`.
9
+ *
10
+ * @default frontmatter
11
+ */
12
+ exportName?: string;
13
+ }
14
+ /**
15
+ * A Vite plugin that fixes Hot Module Replacement (HMR) for MDX frontmatter exports.
16
+ *
17
+ * By default, React Fast Refresh only processes modules that export React
18
+ * components. Since frontmatter is a plain object, changes to it don't trigger HMR
19
+ * updates and instead prompt a full refresh.
20
+ *
21
+ * This plugin works around the issue by attaching a `$$typeof` property set to
22
+ * `Symbol.for('react.memo')` on the exported `frontmatter` object, tricking React
23
+ * Fast Refresh's {@link https://github.com/facebook/react/blob/f5af92d2c47d1e1f455faf912b1d3221d1038c37/packages/react-refresh/src/ReactFreshRuntime.js#L717-L723 isLikelyComponentType}
24
+ * check into treating the module as a component module eligible for HMR.
25
+ *
26
+ * @since 3.2.0
27
+ *
28
+ * @returns A Vite plugin option that transforms modules containing frontmatter exports.
29
+ */
30
+ export declare function frontmatterHmrPlugin(opts?: FrontmatterHmrPluginOptions): PluginOption;
31
+ //# sourceMappingURL=frontmatter-hmr-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter-hmr-plugin.d.ts","sourceRoot":"","sources":["../../src/docs-plugin/frontmatter-hmr-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,MAAM,CAAA;AAEtC;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,GAAE,2BAAgC,GACrC,YAAY,CAkBd"}
@@ -1,5 +1,6 @@
1
1
  export * from "./config";
2
2
  export * from "./docs-plugin";
3
+ export * from "./frontmatter-hmr-plugin";
3
4
  export type * from "./nav-builder";
4
5
  export * from "./mdx-plugins";
5
6
  export * from "./rehype";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docs-plugin/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,mBAAmB,eAAe,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docs-plugin/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,mBAAmB,eAAe,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
package/dist/index.js CHANGED
@@ -3806,6 +3806,25 @@ function quiDocsPlugin(opts) {
3806
3806
  };
3807
3807
  }
3808
3808
 
3809
+ // src/docs-plugin/frontmatter-hmr-plugin.ts
3810
+ function frontmatterHmrPlugin(opts = {}) {
3811
+ const { exportName = "frontmatter" } = opts;
3812
+ return {
3813
+ name: "frontmatter-hmr-fix",
3814
+ transform(code) {
3815
+ if (code.includes(`export const ${exportName}`)) {
3816
+ code += `
3817
+ ;Object.defineProperty(${exportName}, "$$typeof", {
3818
+ enumerable: false,
3819
+ value: Symbol.for('react.memo')
3820
+ });
3821
+ `;
3822
+ return code;
3823
+ }
3824
+ }
3825
+ };
3826
+ }
3827
+
3809
3828
  // src/docs-plugin/mdx-plugins.ts
3810
3829
  import rehypeShiki from "@shikijs/rehype";
3811
3830
  import {
@@ -6252,6 +6271,7 @@ export {
6252
6271
  createDemoName,
6253
6272
  extractFileImports,
6254
6273
  extractPageId,
6274
+ frontmatterHmrPlugin,
6255
6275
  getAlertIcon,
6256
6276
  getRehypePlugins,
6257
6277
  getRemarkPlugins,