safe-mdx 1.3.8 → 1.3.10

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 (44) hide show
  1. package/README.md +4 -0
  2. package/dist/dynamic-esm-component.js.map +1 -1
  3. package/dist/esm-parser.js.map +1 -1
  4. package/dist/esm-parser.test.js.map +1 -1
  5. package/dist/html/convert-attributes.js.map +1 -1
  6. package/dist/html/html-and-md.test.d.ts +2 -0
  7. package/dist/html/html-and-md.test.d.ts.map +1 -0
  8. package/dist/html/html-and-md.test.js +869 -0
  9. package/dist/html/html-and-md.test.js.map +1 -0
  10. package/dist/html/html-to-mdx-ast.d.ts.map +1 -1
  11. package/dist/html/html-to-mdx-ast.js.map +1 -1
  12. package/dist/html/html-to-mdx-ast.test.js +3 -3
  13. package/dist/html/html-to-mdx-ast.test.js.map +1 -1
  14. package/dist/html/remark-mdx-jsx-normalize.d.ts.map +1 -1
  15. package/dist/html/remark-mdx-jsx-normalize.js.map +1 -1
  16. package/dist/html/valid-html-elements.d.ts.map +1 -1
  17. package/dist/html/valid-html-elements.js +1 -1
  18. package/dist/html/valid-html-elements.js.map +1 -1
  19. package/dist/parse.d.ts.map +1 -1
  20. package/dist/parse.js.map +1 -1
  21. package/dist/safe-mdx.d.ts +1 -1
  22. package/dist/safe-mdx.d.ts.map +1 -1
  23. package/dist/safe-mdx.js +1 -1
  24. package/dist/safe-mdx.js.map +1 -1
  25. package/dist/safe-mdx.test.js +5 -5
  26. package/dist/safe-mdx.test.js.map +1 -1
  27. package/dist/streaming.js.map +1 -1
  28. package/package.json +12 -7
  29. package/src/html/html-and-md.test.ts +953 -0
  30. package/src/html/html-to-mdx-ast.ts +9 -8
  31. package/src/safe-mdx.test.tsx +5 -5
  32. package/src/safe-mdx.tsx +2 -3
  33. package/dist/assets/HtmlToJsxConverter-Ds0bTjpw.js +0 -24
  34. package/dist/assets/_commonjsHelpers-CqkleIqs.js +0 -1
  35. package/dist/assets/index-B5fPOjPt.css +0 -1
  36. package/dist/assets/index-B7ATSoRE.js +0 -9
  37. package/dist/assets/index-BwZ2FTRd.js +0 -146
  38. package/dist/assets/index-R1UqLMGJ.js +0 -1
  39. package/dist/assets/index-c0qeY2gs.js +0 -9
  40. package/dist/assets/jsx-runtime-BhZZLbvw.js +0 -9
  41. package/dist/assets/jsx-runtime-NArryeSM.js +0 -1
  42. package/dist/assets/react-Ca6JzGpx.js +0 -1
  43. package/dist/assets/react-dom-BYRHYqYl.js +0 -1
  44. package/dist/index.html +0 -19
@@ -67,10 +67,11 @@ function defaultConvertAttributeValue({
67
67
  return value
68
68
  }
69
69
 
70
+
70
71
  // Remove common indentation from multi-line text while preserving relative indentation
71
72
  function deindent(text: string): string {
72
73
  const lines = text.split('\n')
73
-
74
+
74
75
  // Find minimum indentation (excluding empty lines)
75
76
  let minIndent = Infinity
76
77
  for (const line of lines) {
@@ -81,12 +82,12 @@ function deindent(text: string): string {
81
82
  }
82
83
  }
83
84
  }
84
-
85
+
85
86
  // If no indentation found, return as is
86
87
  if (minIndent === 0 || minIndent === Infinity) {
87
88
  return text
88
89
  }
89
-
90
+
90
91
  // Remove common indentation from each line, preserving relative indentation
91
92
  return lines
92
93
  .map(line => line.slice(minIndent))
@@ -197,24 +198,24 @@ function htmlNodeToMdxAst(
197
198
 
198
199
  if (isTextNode(node)) {
199
200
  let textValue = node.textContent || ''
200
-
201
+
201
202
  // Skip whitespace-only nodes between elements
202
203
  if (!textValue.trim()) {
203
204
  const prevSibling = node.previousSibling
204
205
  const nextSibling = node.nextSibling
205
-
206
+
206
207
  // If between elements and contains newlines, it's likely formatting
207
- if (textValue.includes('\n') &&
208
+ if (textValue.includes('\n') &&
208
209
  ((prevSibling && isElementNode(prevSibling)) ||
209
210
  (nextSibling && isElementNode(nextSibling)))) {
210
211
  return []
211
212
  }
212
213
  // Otherwise preserve the whitespace (could be intentional space)
213
214
  }
214
-
215
+
215
216
  // Always deindent text content
216
217
  textValue = deindent(textValue).trim()
217
-
218
+
218
219
  // Skip empty text after processing
219
220
  if (!textValue) {
220
221
  return []
@@ -2529,17 +2529,17 @@ test('component props schema validation with zod', () => {
2529
2529
  "errors": [
2530
2530
  {
2531
2531
  "line": 5,
2532
- "message": "Invalid props for component "Heading" at "level": Number must be less than or equal to 6",
2532
+ "message": "Invalid props for component "Heading" at "level": Too big: expected number to be <=6",
2533
2533
  "schemaPath": "level",
2534
2534
  },
2535
2535
  {
2536
2536
  "line": 7,
2537
- "message": "Invalid props for component "Cards" at "count": Number must be greater than 0",
2537
+ "message": "Invalid props for component "Cards" at "count": Too small: expected number to be >0",
2538
2538
  "schemaPath": "count",
2539
2539
  },
2540
2540
  {
2541
2541
  "line": 9,
2542
- "message": "Invalid props for component "Cards" at "count": Expected number, received string",
2542
+ "message": "Invalid props for component "Cards" at "count": Invalid input: expected number, received string",
2543
2543
  "schemaPath": "count",
2544
2544
  },
2545
2545
  ],
@@ -2748,12 +2748,12 @@ test('validation error includes schema path', () => {
2748
2748
  "errors": [
2749
2749
  {
2750
2750
  "line": 1,
2751
- "message": "Invalid props for component "Heading" at "user.age": Number must be greater than or equal to 0",
2751
+ "message": "Invalid props for component "Heading" at "user.age": Too small: expected number to be >=0",
2752
2752
  "schemaPath": "user.age",
2753
2753
  },
2754
2754
  {
2755
2755
  "line": 1,
2756
- "message": "Invalid props for component "Heading" at "settings.theme": Invalid enum value. Expected 'light' | 'dark', received 'invalid'",
2756
+ "message": "Invalid props for component "Heading" at "settings.theme": Invalid option: expected one of "light"|"dark"",
2757
2757
  "schemaPath": "settings.theme",
2758
2758
  },
2759
2759
  ],
package/src/safe-mdx.tsx CHANGED
@@ -7,7 +7,7 @@ import type { Node, Parent, Root, RootContent } from 'mdast'
7
7
  import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx'
8
8
 
9
9
  import { Fragment, ReactNode } from 'react'
10
- import { DynamicEsmComponent } from './dynamic-esm-component.js'
10
+ import { DynamicEsmComponent } from 'safe-mdx/client'
11
11
  import { extractComponentInfo, parseEsmImports } from './esm-parser.js'
12
12
  import { htmlToMdxAst } from './html/html-to-mdx-ast.js'
13
13
  import { validHtmlElements, nativeTags } from './html/valid-html-elements.js'
@@ -54,7 +54,7 @@ export const SafeMdxRenderer = React.memo(function SafeMdxRenderer({
54
54
  }: {
55
55
  components?: ComponentsMap
56
56
  markdown?: string
57
- mdast: MyRootContent
57
+ mdast?: MyRootContent
58
58
  renderNode?: RenderNode
59
59
  componentPropsSchema?: ComponentPropsSchema
60
60
  createElement?: CreateElementFunction
@@ -240,7 +240,6 @@ export class MdastToJsx {
240
240
  // Handle ESM imported component
241
241
  const { importUrl, componentName } =
242
242
  extractComponentInfo(esmImportInfo)
243
-
244
243
  Component = DynamicEsmComponent
245
244
  let attrsList = this.getJsxAttrs(node, (err) => {
246
245
  this.errors.push(err)