@tinacms/mdx 0.0.0-20220718181631 → 0.60.3

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 (90) hide show
  1. package/dist/index.cjs +887 -738
  2. package/dist/index.d.ts +21 -1
  3. package/dist/index.es.js +546 -406
  4. package/dist/{parse/plate-spec.d.ts → index.js} +4 -2
  5. package/dist/mdx.es.js +1092 -0
  6. package/dist/mdx.umd.js +1097 -0
  7. package/dist/parse/acorn.d.ts +2 -3
  8. package/dist/parse/acorn.js +201 -0
  9. package/dist/parse/index.d.ts +8 -2
  10. package/dist/parse/index.js +144 -0
  11. package/dist/parse/mdx.js +75 -0
  12. package/dist/parse/plate.d.ts +15 -2
  13. package/dist/parse/plate.js +1 -0
  14. package/dist/parse/remarkToPlate.d.ts +16 -1
  15. package/dist/parse/remarkToPlate.js +380 -0
  16. package/dist/stringify/acorn.d.ts +7 -2
  17. package/dist/stringify/acorn.js +241 -0
  18. package/dist/stringify/index.d.ts +15 -0
  19. package/dist/stringify/index.js +195 -0
  20. package/dist/stringify/marks.js +250 -0
  21. package/dist/tests/autotest/_config.d.ts +4 -0
  22. package/dist/tests/autotest/_config.js +159 -0
  23. package/dist/tests/autotest/_runner.test.d.ts +1 -0
  24. package/dist/tests/autotest/_runner.test.js +77 -0
  25. package/dist/tests/autotest/autoformat block elements in list items.test.d.ts +1 -0
  26. package/dist/tests/autotest/autoformat block elements in list items.test.js +33 -0
  27. package/dist/tests/autotest/autoformat blockquote.result.test.d.ts +1 -0
  28. package/dist/tests/autotest/autoformat blockquote.result.test.js +18 -0
  29. package/dist/tests/autotest/autoformat blockquote.test.d.ts +1 -0
  30. package/dist/tests/autotest/autoformat blockquote.test.js +18 -0
  31. package/dist/tests/autotest/autoformat list item.test.d.ts +1 -0
  32. package/dist/tests/autotest/autoformat list item.test.js +31 -0
  33. package/dist/tests/autotest/autoformat mdx with nested null children.test.d.ts +1 -0
  34. package/dist/tests/autotest/autoformat mdx with nested null children.test.js +23 -0
  35. package/dist/tests/autotest/autoformat syntax changes.test.d.ts +1 -0
  36. package/dist/tests/autotest/autoformat syntax changes.test.js +90 -0
  37. package/dist/tests/autotest/blockquote.test.d.ts +1 -0
  38. package/dist/tests/autotest/blockquote.test.js +17 -0
  39. package/dist/tests/autotest/break.test.d.ts +1 -0
  40. package/dist/tests/autotest/break.test.js +26 -0
  41. package/dist/tests/autotest/code block.test.d.ts +1 -0
  42. package/dist/tests/autotest/code block.test.js +27 -0
  43. package/dist/tests/autotest/image.test.d.ts +1 -0
  44. package/dist/tests/autotest/image.test.js +52 -0
  45. package/dist/tests/autotest/invalid mdx with a closing tag.test.d.ts +1 -0
  46. package/dist/tests/autotest/invalid mdx with a closing tag.test.js +27 -0
  47. package/dist/tests/autotest/invalid mdx with a const expression.test.d.ts +1 -0
  48. package/dist/tests/autotest/invalid mdx with a const expression.test.js +27 -0
  49. package/dist/tests/autotest/invalid mdx with an expression {{}}.test.d.ts +1 -0
  50. package/dist/tests/autotest/invalid mdx with an expression {{}}.test.js +27 -0
  51. package/dist/tests/autotest/invalid mdx with an expression.test.d.ts +1 -0
  52. package/dist/tests/autotest/invalid mdx with an expression.test.js +27 -0
  53. package/dist/tests/autotest/invalid mdx with an import statment.test.d.ts +1 -0
  54. package/dist/tests/autotest/invalid mdx with an import statment.test.js +27 -0
  55. package/dist/tests/autotest/kitchen sink.test.d.ts +1 -0
  56. package/dist/tests/autotest/kitchen sink.test.js +144 -0
  57. package/dist/tests/autotest/links.test.d.ts +1 -0
  58. package/dist/tests/autotest/links.test.js +29 -0
  59. package/dist/tests/autotest/lists.test.d.ts +1 -0
  60. package/dist/tests/autotest/lists.test.js +110 -0
  61. package/dist/tests/autotest/marks.test.d.ts +1 -0
  62. package/dist/tests/autotest/marks.test.js +102 -0
  63. package/dist/tests/autotest/mdx field with a scalar field as a list.test.d.ts +1 -0
  64. package/dist/tests/autotest/mdx field with a scalar field as a list.test.js +22 -0
  65. package/dist/tests/autotest/mdx which hasnt been registered returns html.test.d.ts +1 -0
  66. package/dist/tests/autotest/mdx which hasnt been registered returns html.test.js +26 -0
  67. package/dist/tests/autotest/mdx with a boolean field.test.d.ts +1 -0
  68. package/dist/tests/autotest/mdx with a boolean field.test.js +22 -0
  69. package/dist/tests/autotest/mdx with a number field.test.d.ts +1 -0
  70. package/dist/tests/autotest/mdx with a number field.test.js +22 -0
  71. package/dist/tests/autotest/mdx with a srtring field.test.d.ts +1 -0
  72. package/dist/tests/autotest/mdx with a srtring field.test.js +28 -0
  73. package/dist/tests/autotest/mdx with multiple rich-text fields.test.d.ts +1 -0
  74. package/dist/tests/autotest/mdx with multiple rich-text fields.test.js +53 -0
  75. package/dist/tests/autotest/mdx with nested children.test.d.ts +1 -0
  76. package/dist/tests/autotest/mdx with nested children.test.js +35 -0
  77. package/dist/tests/autotest/mdx with nested null children.test.d.ts +1 -0
  78. package/dist/tests/autotest/mdx with nested null children.test.js +23 -0
  79. package/dist/tests/autotest/mdx with number list field.test.d.ts +1 -0
  80. package/dist/tests/autotest/mdx with number list field.test.js +22 -0
  81. package/dist/tests/autotest/mdx with object list field.test.d.ts +1 -0
  82. package/dist/tests/autotest/mdx with object list field.test.js +25 -0
  83. package/dist/tests/autotest/mdx with object with templates.test.d.ts +1 -0
  84. package/dist/tests/autotest/mdx with object with templates.test.js +41 -0
  85. package/dist/tests/autotest/shortcodes.test.d.ts +1 -0
  86. package/dist/tests/autotest/shortcodes.test.js +51 -0
  87. package/dist/tests/setup.d.ts +14 -0
  88. package/dist/tests/setup.js +70 -0
  89. package/package.json +13 -14
  90. package/dist/stringify/mdx.d.ts +0 -38
package/dist/index.es.js CHANGED
@@ -59,7 +59,7 @@ var require_extend = __commonJS({
59
59
  var toStr = Object.prototype.toString;
60
60
  var defineProperty = Object.defineProperty;
61
61
  var gOPD = Object.getOwnPropertyDescriptor;
62
- var isArray2 = function isArray3(arr) {
62
+ var isArray3 = function isArray4(arr) {
63
63
  if (typeof Array.isArray === "function") {
64
64
  return Array.isArray(arr);
65
65
  }
@@ -122,10 +122,10 @@ var require_extend = __commonJS({
122
122
  src = getProperty(target, name);
123
123
  copy = getProperty(options, name);
124
124
  if (target !== copy) {
125
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray2(copy)))) {
125
+ if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray3(copy)))) {
126
126
  if (copyIsArray) {
127
127
  copyIsArray = false;
128
- clone = src && isArray2(src) ? src : [];
128
+ clone = src && isArray3(src) ? src : [];
129
129
  } else {
130
130
  clone = src && isPlainObject2(src) ? src : {};
131
131
  }
@@ -614,12 +614,12 @@ var require_acorn = __commonJS({
614
614
  var nonASCIIwhitespace2 = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
615
615
  var skipWhiteSpace2 = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
616
616
  var ref2 = Object.prototype;
617
- var hasOwnProperty3 = ref2.hasOwnProperty;
617
+ var hasOwnProperty5 = ref2.hasOwnProperty;
618
618
  var toString3 = ref2.toString;
619
619
  var hasOwn2 = Object.hasOwn || function(obj, propName) {
620
- return hasOwnProperty3.call(obj, propName);
620
+ return hasOwnProperty5.call(obj, propName);
621
621
  };
622
- var isArray2 = Array.isArray || function(obj) {
622
+ var isArray3 = Array.isArray || function(obj) {
623
623
  return toString3.call(obj) === "[object Array]";
624
624
  };
625
625
  function wordsRegexp2(words) {
@@ -697,22 +697,22 @@ var require_acorn = __commonJS({
697
697
  if (options.allowReserved == null) {
698
698
  options.allowReserved = options.ecmaVersion < 5;
699
699
  }
700
- if (isArray2(options.onToken)) {
700
+ if (isArray3(options.onToken)) {
701
701
  var tokens = options.onToken;
702
702
  options.onToken = function(token) {
703
703
  return tokens.push(token);
704
704
  };
705
705
  }
706
- if (isArray2(options.onComment)) {
706
+ if (isArray3(options.onComment)) {
707
707
  options.onComment = pushComment2(options, options.onComment);
708
708
  }
709
709
  return options;
710
710
  }
711
711
  function pushComment2(options, array) {
712
- return function(block, text4, start3, end, startLoc, endLoc) {
712
+ return function(block, text5, start3, end, startLoc, endLoc) {
713
713
  var comment = {
714
714
  type: block ? "Block" : "Line",
715
- value: text4,
715
+ value: text5,
716
716
  start: start3,
717
717
  end
718
718
  };
@@ -1519,16 +1519,16 @@ var require_acorn = __commonJS({
1519
1519
  classBody.body = [];
1520
1520
  this.expect(types$12.braceL);
1521
1521
  while (this.type !== types$12.braceR) {
1522
- var element2 = this.parseClassElement(node.superClass !== null);
1523
- if (element2) {
1524
- classBody.body.push(element2);
1525
- if (element2.type === "MethodDefinition" && element2.kind === "constructor") {
1522
+ var element = this.parseClassElement(node.superClass !== null);
1523
+ if (element) {
1524
+ classBody.body.push(element);
1525
+ if (element.type === "MethodDefinition" && element.kind === "constructor") {
1526
1526
  if (hadConstructor) {
1527
- this.raise(element2.start, "Duplicate constructor in the same class");
1527
+ this.raise(element.start, "Duplicate constructor in the same class");
1528
1528
  }
1529
1529
  hadConstructor = true;
1530
- } else if (element2.key && element2.key.type === "PrivateIdentifier" && isPrivateNameConflicted2(privateNameMap, element2)) {
1531
- this.raiseRecoverable(element2.key.start, "Identifier '#" + element2.key.name + "' has already been declared");
1530
+ } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted2(privateNameMap, element)) {
1531
+ this.raiseRecoverable(element.key.start, "Identifier '#" + element.key.name + "' has already been declared");
1532
1532
  }
1533
1533
  }
1534
1534
  }
@@ -1605,15 +1605,15 @@ var require_acorn = __commonJS({
1605
1605
  pp$82.isClassElementNameStart = function() {
1606
1606
  return this.type === types$12.name || this.type === types$12.privateId || this.type === types$12.num || this.type === types$12.string || this.type === types$12.bracketL || this.type.keyword;
1607
1607
  };
1608
- pp$82.parseClassElementName = function(element2) {
1608
+ pp$82.parseClassElementName = function(element) {
1609
1609
  if (this.type === types$12.privateId) {
1610
1610
  if (this.value === "constructor") {
1611
1611
  this.raise(this.start, "Classes can't have an element named '#constructor'");
1612
1612
  }
1613
- element2.computed = false;
1614
- element2.key = this.parsePrivateIdent();
1613
+ element.computed = false;
1614
+ element.key = this.parsePrivateIdent();
1615
1615
  } else {
1616
- this.parsePropertyName(element2);
1616
+ this.parsePropertyName(element);
1617
1617
  }
1618
1618
  };
1619
1619
  pp$82.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
@@ -1689,9 +1689,9 @@ var require_acorn = __commonJS({
1689
1689
  node.superClass = this.eat(types$12._extends) ? this.parseExprSubscripts(false) : null;
1690
1690
  };
1691
1691
  pp$82.enterClassBody = function() {
1692
- var element2 = { declared: Object.create(null), used: [] };
1693
- this.privateNameStack.push(element2);
1694
- return element2.declared;
1692
+ var element = { declared: Object.create(null), used: [] };
1693
+ this.privateNameStack.push(element);
1694
+ return element.declared;
1695
1695
  };
1696
1696
  pp$82.exitClassBody = function() {
1697
1697
  var ref3 = this.privateNameStack.pop();
@@ -1710,12 +1710,12 @@ var require_acorn = __commonJS({
1710
1710
  }
1711
1711
  }
1712
1712
  };
1713
- function isPrivateNameConflicted2(privateNameMap, element2) {
1714
- var name = element2.key.name;
1713
+ function isPrivateNameConflicted2(privateNameMap, element) {
1714
+ var name = element.key.name;
1715
1715
  var curr = privateNameMap[name];
1716
1716
  var next = "true";
1717
- if (element2.type === "MethodDefinition" && (element2.kind === "get" || element2.kind === "set")) {
1718
- next = (element2.static ? "s" : "i") + element2.kind;
1717
+ if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
1718
+ next = (element.static ? "s" : "i") + element.kind;
1719
1719
  }
1720
1720
  if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") {
1721
1721
  privateNameMap[name] = "true";
@@ -2594,19 +2594,19 @@ var require_acorn = __commonJS({
2594
2594
  var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base2.type === "Identifier" && base2.name === "async" && this.lastTokEnd === base2.end && !this.canInsertSemicolon() && base2.end - base2.start === 5 && this.potentialArrowAt === base2.start;
2595
2595
  var optionalChained = false;
2596
2596
  while (true) {
2597
- var element2 = this.parseSubscript(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
2598
- if (element2.optional) {
2597
+ var element = this.parseSubscript(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
2598
+ if (element.optional) {
2599
2599
  optionalChained = true;
2600
2600
  }
2601
- if (element2 === base2 || element2.type === "ArrowFunctionExpression") {
2601
+ if (element === base2 || element.type === "ArrowFunctionExpression") {
2602
2602
  if (optionalChained) {
2603
2603
  var chainNode = this.startNodeAt(startPos, startLoc);
2604
- chainNode.expression = element2;
2605
- element2 = this.finishNode(chainNode, "ChainExpression");
2604
+ chainNode.expression = element;
2605
+ element = this.finishNode(chainNode, "ChainExpression");
2606
2606
  }
2607
- return element2;
2607
+ return element;
2608
2608
  }
2609
- base2 = element2;
2609
+ base2 = element;
2610
2610
  }
2611
2611
  };
2612
2612
  pp$52.parseSubscript = function(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
@@ -5550,82 +5550,6 @@ var require_acorn_jsx = __commonJS({
5550
5550
  }
5551
5551
  });
5552
5552
 
5553
- // ../../../node_modules/.pnpm/lodash.flatten@4.4.0/node_modules/lodash.flatten/index.js
5554
- var require_lodash = __commonJS({
5555
- "../../../node_modules/.pnpm/lodash.flatten@4.4.0/node_modules/lodash.flatten/index.js"(exports, module) {
5556
- var MAX_SAFE_INTEGER = 9007199254740991;
5557
- var argsTag = "[object Arguments]";
5558
- var funcTag = "[object Function]";
5559
- var genTag = "[object GeneratorFunction]";
5560
- var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
5561
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
5562
- var root2 = freeGlobal || freeSelf || Function("return this")();
5563
- function arrayPush(array, values) {
5564
- var index2 = -1, length = values.length, offset2 = array.length;
5565
- while (++index2 < length) {
5566
- array[offset2 + index2] = values[index2];
5567
- }
5568
- return array;
5569
- }
5570
- var objectProto = Object.prototype;
5571
- var hasOwnProperty3 = objectProto.hasOwnProperty;
5572
- var objectToString = objectProto.toString;
5573
- var Symbol2 = root2.Symbol;
5574
- var propertyIsEnumerable = objectProto.propertyIsEnumerable;
5575
- var spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : void 0;
5576
- function baseFlatten(array, depth, predicate, isStrict, result) {
5577
- var index2 = -1, length = array.length;
5578
- predicate || (predicate = isFlattenable);
5579
- result || (result = []);
5580
- while (++index2 < length) {
5581
- var value = array[index2];
5582
- if (depth > 0 && predicate(value)) {
5583
- if (depth > 1) {
5584
- baseFlatten(value, depth - 1, predicate, isStrict, result);
5585
- } else {
5586
- arrayPush(result, value);
5587
- }
5588
- } else if (!isStrict) {
5589
- result[result.length] = value;
5590
- }
5591
- }
5592
- return result;
5593
- }
5594
- function isFlattenable(value) {
5595
- return isArray2(value) || isArguments(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
5596
- }
5597
- function flatten2(array) {
5598
- var length = array ? array.length : 0;
5599
- return length ? baseFlatten(array, 1) : [];
5600
- }
5601
- function isArguments(value) {
5602
- return isArrayLikeObject(value) && hasOwnProperty3.call(value, "callee") && (!propertyIsEnumerable.call(value, "callee") || objectToString.call(value) == argsTag);
5603
- }
5604
- var isArray2 = Array.isArray;
5605
- function isArrayLike(value) {
5606
- return value != null && isLength(value.length) && !isFunction(value);
5607
- }
5608
- function isArrayLikeObject(value) {
5609
- return isObjectLike(value) && isArrayLike(value);
5610
- }
5611
- function isFunction(value) {
5612
- var tag = isObject(value) ? objectToString.call(value) : "";
5613
- return tag == funcTag || tag == genTag;
5614
- }
5615
- function isLength(value) {
5616
- return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
5617
- }
5618
- function isObject(value) {
5619
- var type = typeof value;
5620
- return !!value && (type == "object" || type == "function");
5621
- }
5622
- function isObjectLike(value) {
5623
- return !!value && typeof value == "object";
5624
- }
5625
- module.exports = flatten2;
5626
- }
5627
- });
5628
-
5629
5553
  // ../../../node_modules/.pnpm/prettier@2.7.1/node_modules/prettier/standalone.js
5630
5554
  var require_standalone = __commonJS({
5631
5555
  "../../../node_modules/.pnpm/prettier@2.7.1/node_modules/prettier/standalone.js"(exports, module) {
@@ -18157,7 +18081,7 @@ function initializeContent(effects) {
18157
18081
  }
18158
18082
 
18159
18083
  // ../../../node_modules/.pnpm/micromark@3.0.10/node_modules/micromark/lib/initialize/document.js
18160
- var document2 = {
18084
+ var document = {
18161
18085
  tokenize: initializeDocument
18162
18086
  };
18163
18087
  var containerConstruct = {
@@ -18367,7 +18291,7 @@ function resolveAllAttention(events, context) {
18367
18291
  let index2 = -1;
18368
18292
  let open;
18369
18293
  let group;
18370
- let text4;
18294
+ let text5;
18371
18295
  let openingSequence;
18372
18296
  let closingSequence;
18373
18297
  let use;
@@ -18396,7 +18320,7 @@ function resolveAllAttention(events, context) {
18396
18320
  start: Object.assign({}, events[index2][1].start),
18397
18321
  end
18398
18322
  };
18399
- text4 = {
18323
+ text5 = {
18400
18324
  type: use > 1 ? "strongText" : "emphasisText",
18401
18325
  start: Object.assign({}, events[open][1].end),
18402
18326
  end: Object.assign({}, events[index2][1].start)
@@ -18419,11 +18343,11 @@ function resolveAllAttention(events, context) {
18419
18343
  ["enter", group, context],
18420
18344
  ["enter", openingSequence, context],
18421
18345
  ["exit", openingSequence, context],
18422
- ["enter", text4, context]
18346
+ ["enter", text5, context]
18423
18347
  ]);
18424
18348
  nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + 1, index2), context));
18425
18349
  nextEvents = push(nextEvents, [
18426
- ["exit", text4, context],
18350
+ ["exit", text5, context],
18427
18351
  ["enter", closingSequence, context],
18428
18352
  ["exit", closingSequence, context],
18429
18353
  ["exit", group, context]
@@ -18661,16 +18585,7 @@ function tokenizeCharacterEscape(effects, ok2, nok) {
18661
18585
  }
18662
18586
 
18663
18587
  // ../../../node_modules/.pnpm/decode-named-character-reference@1.0.2/node_modules/decode-named-character-reference/index.dom.js
18664
- var element = document.createElement("i");
18665
- function decodeNamedCharacterReference(value) {
18666
- const characterReference2 = "&" + value + ";";
18667
- element.innerHTML = characterReference2;
18668
- const char = element.textContent;
18669
- if (char.charCodeAt(char.length - 1) === 59 && value !== "semi") {
18670
- return false;
18671
- }
18672
- return char === characterReference2 ? false : char;
18673
- }
18588
+ var decodeNamedCharacterReference = (value) => value;
18674
18589
 
18675
18590
  // ../../../node_modules/.pnpm/micromark-core-commonmark@1.0.6/node_modules/micromark-core-commonmark/lib/character-reference.js
18676
18591
  var characterReference = {
@@ -19599,7 +19514,7 @@ function resolveHeadingAtx(events, context) {
19599
19514
  let contentEnd = events.length - 2;
19600
19515
  let contentStart = 3;
19601
19516
  let content3;
19602
- let text4;
19517
+ let text5;
19603
19518
  if (events[contentStart][1].type === "whitespace") {
19604
19519
  contentStart += 2;
19605
19520
  }
@@ -19615,7 +19530,7 @@ function resolveHeadingAtx(events, context) {
19615
19530
  start: events[contentStart][1].start,
19616
19531
  end: events[contentEnd][1].end
19617
19532
  };
19618
- text4 = {
19533
+ text5 = {
19619
19534
  type: "chunkText",
19620
19535
  start: events[contentStart][1].start,
19621
19536
  end: events[contentEnd][1].end,
@@ -19623,8 +19538,8 @@ function resolveHeadingAtx(events, context) {
19623
19538
  };
19624
19539
  splice(events, contentStart, contentEnd - contentStart + 1, [
19625
19540
  ["enter", content3, context],
19626
- ["enter", text4, context],
19627
- ["exit", text4, context],
19541
+ ["enter", text5, context],
19542
+ ["exit", text5, context],
19628
19543
  ["exit", content3, context]
19629
19544
  ]);
19630
19545
  }
@@ -20489,7 +20404,7 @@ function resolveToLabelEnd(events, context) {
20489
20404
  start: Object.assign({}, events[open][1].start),
20490
20405
  end: Object.assign({}, events[close][1].end)
20491
20406
  };
20492
- const text4 = {
20407
+ const text5 = {
20493
20408
  type: "labelText",
20494
20409
  start: Object.assign({}, events[open + offset2 + 2][1].end),
20495
20410
  end: Object.assign({}, events[close - 2][1].start)
@@ -20499,10 +20414,10 @@ function resolveToLabelEnd(events, context) {
20499
20414
  ["enter", label, context]
20500
20415
  ];
20501
20416
  media = push(media, events.slice(open + 1, open + offset2 + 3));
20502
- media = push(media, [["enter", text4, context]]);
20417
+ media = push(media, [["enter", text5, context]]);
20503
20418
  media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + offset2 + 4, close - 3), context));
20504
20419
  media = push(media, [
20505
- ["exit", text4, context],
20420
+ ["exit", text5, context],
20506
20421
  events[close - 2],
20507
20422
  events[close - 1],
20508
20423
  ["exit", label, context]
@@ -20862,7 +20777,7 @@ var setextUnderline = {
20862
20777
  function resolveToSetextUnderline(events, context) {
20863
20778
  let index2 = events.length;
20864
20779
  let content3;
20865
- let text4;
20780
+ let text5;
20866
20781
  let definition3;
20867
20782
  while (index2--) {
20868
20783
  if (events[index2][0] === "enter") {
@@ -20871,7 +20786,7 @@ function resolveToSetextUnderline(events, context) {
20871
20786
  break;
20872
20787
  }
20873
20788
  if (events[index2][1].type === "paragraph") {
20874
- text4 = index2;
20789
+ text5 = index2;
20875
20790
  }
20876
20791
  } else {
20877
20792
  if (events[index2][1].type === "content") {
@@ -20884,12 +20799,12 @@ function resolveToSetextUnderline(events, context) {
20884
20799
  }
20885
20800
  const heading2 = {
20886
20801
  type: "setextHeading",
20887
- start: Object.assign({}, events[text4][1].start),
20802
+ start: Object.assign({}, events[text5][1].start),
20888
20803
  end: Object.assign({}, events[events.length - 1][1].end)
20889
20804
  };
20890
- events[text4][1].type = "setextHeadingText";
20805
+ events[text5][1].type = "setextHeadingText";
20891
20806
  if (definition3) {
20892
- events.splice(text4, 0, ["enter", heading2, context]);
20807
+ events.splice(text5, 0, ["enter", heading2, context]);
20893
20808
  events.splice(definition3 + 1, 0, ["exit", events[content3][1], context]);
20894
20809
  events[content3][1].end = Object.assign({}, events[definition3][1].end);
20895
20810
  } else {
@@ -20982,10 +20897,10 @@ function initializeFactory(field) {
20982
20897
  function initializeText(effects) {
20983
20898
  const self2 = this;
20984
20899
  const constructs2 = this.parser.constructs[field];
20985
- const text4 = effects.attempt(constructs2, start3, notText);
20900
+ const text5 = effects.attempt(constructs2, start3, notText);
20986
20901
  return start3;
20987
20902
  function start3(code2) {
20988
- return atBreak(code2) ? text4(code2) : notText(code2);
20903
+ return atBreak(code2) ? text5(code2) : notText(code2);
20989
20904
  }
20990
20905
  function notText(code2) {
20991
20906
  if (code2 === null) {
@@ -20999,7 +20914,7 @@ function initializeFactory(field) {
20999
20914
  function data2(code2) {
21000
20915
  if (atBreak(code2)) {
21001
20916
  effects.exit("data");
21002
- return text4(code2);
20917
+ return text5(code2);
21003
20918
  }
21004
20919
  effects.consume(code2);
21005
20920
  return data2;
@@ -21393,14 +21308,14 @@ __export(constructs_exports, {
21393
21308
  attentionMarkers: () => attentionMarkers,
21394
21309
  contentInitial: () => contentInitial,
21395
21310
  disable: () => disable,
21396
- document: () => document3,
21311
+ document: () => document2,
21397
21312
  flow: () => flow2,
21398
21313
  flowInitial: () => flowInitial,
21399
21314
  insideSpan: () => insideSpan,
21400
21315
  string: () => string2,
21401
21316
  text: () => text2
21402
21317
  });
21403
- var document3 = {
21318
+ var document2 = {
21404
21319
  [42]: list,
21405
21320
  [43]: list,
21406
21321
  [45]: list,
@@ -21470,7 +21385,7 @@ function parse(options = {}) {
21470
21385
  lazy: {},
21471
21386
  constructs: constructs2,
21472
21387
  content: create(content),
21473
- document: create(document2),
21388
+ document: create(document),
21474
21389
  flow: create(flow),
21475
21390
  string: create(string),
21476
21391
  text: create(text)
@@ -21991,7 +21906,7 @@ function compiler(options = {}) {
21991
21906
  const parent = this.stack[this.stack.length - 1];
21992
21907
  let tail = parent.children[parent.children.length - 1];
21993
21908
  if (!tail || tail.type !== "text") {
21994
- tail = text4();
21909
+ tail = text5();
21995
21910
  tail.position = {
21996
21911
  start: point2(token.start)
21997
21912
  };
@@ -22226,7 +22141,7 @@ function compiler(options = {}) {
22226
22141
  children: []
22227
22142
  };
22228
22143
  }
22229
- function text4() {
22144
+ function text5() {
22230
22145
  return {
22231
22146
  type: "text",
22232
22147
  value: ""
@@ -23173,12 +23088,12 @@ function linkReference(node, _, context, safeOptions) {
23173
23088
  let subexit = context.enter("label");
23174
23089
  const tracker = track(safeOptions);
23175
23090
  let value = tracker.move("[");
23176
- const text4 = containerPhrasing(node, context, {
23091
+ const text5 = containerPhrasing(node, context, {
23177
23092
  before: value,
23178
23093
  after: "]",
23179
23094
  ...tracker.current()
23180
23095
  });
23181
- value += tracker.move(text4 + "][");
23096
+ value += tracker.move(text5 + "][");
23182
23097
  subexit();
23183
23098
  const stack = context.stack;
23184
23099
  context.stack = [];
@@ -23191,7 +23106,7 @@ function linkReference(node, _, context, safeOptions) {
23191
23106
  subexit();
23192
23107
  context.stack = stack;
23193
23108
  exit2();
23194
- if (type === "full" || !text4 || text4 !== reference) {
23109
+ if (type === "full" || !text5 || text5 !== reference) {
23195
23110
  value += tracker.move(reference + "]");
23196
23111
  } else if (type === "shortcut") {
23197
23112
  value = value.slice(0, -1);
@@ -23909,10 +23824,10 @@ function getOptions(opts) {
23909
23824
  return options;
23910
23825
  }
23911
23826
  function pushComment(options, array) {
23912
- return function(block, text4, start3, end, startLoc, endLoc) {
23827
+ return function(block, text5, start3, end, startLoc, endLoc) {
23913
23828
  var comment = {
23914
23829
  type: block ? "Block" : "Line",
23915
- value: text4,
23830
+ value: text5,
23916
23831
  start: start3,
23917
23832
  end
23918
23833
  };
@@ -24736,16 +24651,16 @@ pp$8.parseClass = function(node, isStatement) {
24736
24651
  classBody.body = [];
24737
24652
  this.expect(types$1.braceL);
24738
24653
  while (this.type !== types$1.braceR) {
24739
- var element2 = this.parseClassElement(node.superClass !== null);
24740
- if (element2) {
24741
- classBody.body.push(element2);
24742
- if (element2.type === "MethodDefinition" && element2.kind === "constructor") {
24654
+ var element = this.parseClassElement(node.superClass !== null);
24655
+ if (element) {
24656
+ classBody.body.push(element);
24657
+ if (element.type === "MethodDefinition" && element.kind === "constructor") {
24743
24658
  if (hadConstructor) {
24744
- this.raise(element2.start, "Duplicate constructor in the same class");
24659
+ this.raise(element.start, "Duplicate constructor in the same class");
24745
24660
  }
24746
24661
  hadConstructor = true;
24747
- } else if (element2.key && element2.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element2)) {
24748
- this.raiseRecoverable(element2.key.start, "Identifier '#" + element2.key.name + "' has already been declared");
24662
+ } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
24663
+ this.raiseRecoverable(element.key.start, "Identifier '#" + element.key.name + "' has already been declared");
24749
24664
  }
24750
24665
  }
24751
24666
  }
@@ -24822,15 +24737,15 @@ pp$8.parseClassElement = function(constructorAllowsSuper) {
24822
24737
  pp$8.isClassElementNameStart = function() {
24823
24738
  return this.type === types$1.name || this.type === types$1.privateId || this.type === types$1.num || this.type === types$1.string || this.type === types$1.bracketL || this.type.keyword;
24824
24739
  };
24825
- pp$8.parseClassElementName = function(element2) {
24740
+ pp$8.parseClassElementName = function(element) {
24826
24741
  if (this.type === types$1.privateId) {
24827
24742
  if (this.value === "constructor") {
24828
24743
  this.raise(this.start, "Classes can't have an element named '#constructor'");
24829
24744
  }
24830
- element2.computed = false;
24831
- element2.key = this.parsePrivateIdent();
24745
+ element.computed = false;
24746
+ element.key = this.parsePrivateIdent();
24832
24747
  } else {
24833
- this.parsePropertyName(element2);
24748
+ this.parsePropertyName(element);
24834
24749
  }
24835
24750
  };
24836
24751
  pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
@@ -24906,9 +24821,9 @@ pp$8.parseClassSuper = function(node) {
24906
24821
  node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(false) : null;
24907
24822
  };
24908
24823
  pp$8.enterClassBody = function() {
24909
- var element2 = { declared: Object.create(null), used: [] };
24910
- this.privateNameStack.push(element2);
24911
- return element2.declared;
24824
+ var element = { declared: Object.create(null), used: [] };
24825
+ this.privateNameStack.push(element);
24826
+ return element.declared;
24912
24827
  };
24913
24828
  pp$8.exitClassBody = function() {
24914
24829
  var ref2 = this.privateNameStack.pop();
@@ -24927,12 +24842,12 @@ pp$8.exitClassBody = function() {
24927
24842
  }
24928
24843
  }
24929
24844
  };
24930
- function isPrivateNameConflicted(privateNameMap, element2) {
24931
- var name = element2.key.name;
24845
+ function isPrivateNameConflicted(privateNameMap, element) {
24846
+ var name = element.key.name;
24932
24847
  var curr = privateNameMap[name];
24933
24848
  var next = "true";
24934
- if (element2.type === "MethodDefinition" && (element2.kind === "get" || element2.kind === "set")) {
24935
- next = (element2.static ? "s" : "i") + element2.kind;
24849
+ if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
24850
+ next = (element.static ? "s" : "i") + element.kind;
24936
24851
  }
24937
24852
  if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") {
24938
24853
  privateNameMap[name] = "true";
@@ -25811,19 +25726,19 @@ pp$5.parseSubscripts = function(base2, startPos, startLoc, noCalls, forInit) {
25811
25726
  var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base2.type === "Identifier" && base2.name === "async" && this.lastTokEnd === base2.end && !this.canInsertSemicolon() && base2.end - base2.start === 5 && this.potentialArrowAt === base2.start;
25812
25727
  var optionalChained = false;
25813
25728
  while (true) {
25814
- var element2 = this.parseSubscript(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
25815
- if (element2.optional) {
25729
+ var element = this.parseSubscript(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
25730
+ if (element.optional) {
25816
25731
  optionalChained = true;
25817
25732
  }
25818
- if (element2 === base2 || element2.type === "ArrowFunctionExpression") {
25733
+ if (element === base2 || element.type === "ArrowFunctionExpression") {
25819
25734
  if (optionalChained) {
25820
25735
  var chainNode = this.startNodeAt(startPos, startLoc);
25821
- chainNode.expression = element2;
25822
- element2 = this.finishNode(chainNode, "ChainExpression");
25736
+ chainNode.expression = element;
25737
+ element = this.finishNode(chainNode, "ChainExpression");
25823
25738
  }
25824
- return element2;
25739
+ return element;
25825
25740
  }
25826
- base2 = element2;
25741
+ base2 = element;
25827
25742
  }
25828
25743
  };
25829
25744
  pp$5.parseSubscript = function(base2, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
@@ -30204,8 +30119,135 @@ function remarkMdx(options = {}) {
30204
30119
  }
30205
30120
  }
30206
30121
 
30207
- // src/parse/remarkToPlate.ts
30208
- var import_lodash = __toModule(require_lodash());
30122
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
30123
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
30124
+ var freeGlobal_default = freeGlobal;
30125
+
30126
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
30127
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
30128
+ var root2 = freeGlobal_default || freeSelf || Function("return this")();
30129
+ var root_default = root2;
30130
+
30131
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
30132
+ var Symbol2 = root_default.Symbol;
30133
+ var Symbol_default = Symbol2;
30134
+
30135
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
30136
+ var objectProto = Object.prototype;
30137
+ var hasOwnProperty3 = objectProto.hasOwnProperty;
30138
+ var nativeObjectToString = objectProto.toString;
30139
+ var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
30140
+ function getRawTag(value) {
30141
+ var isOwn = hasOwnProperty3.call(value, symToStringTag), tag = value[symToStringTag];
30142
+ try {
30143
+ value[symToStringTag] = void 0;
30144
+ var unmasked = true;
30145
+ } catch (e) {
30146
+ }
30147
+ var result = nativeObjectToString.call(value);
30148
+ if (unmasked) {
30149
+ if (isOwn) {
30150
+ value[symToStringTag] = tag;
30151
+ } else {
30152
+ delete value[symToStringTag];
30153
+ }
30154
+ }
30155
+ return result;
30156
+ }
30157
+ var getRawTag_default = getRawTag;
30158
+
30159
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
30160
+ var objectProto2 = Object.prototype;
30161
+ var nativeObjectToString2 = objectProto2.toString;
30162
+ function objectToString(value) {
30163
+ return nativeObjectToString2.call(value);
30164
+ }
30165
+ var objectToString_default = objectToString;
30166
+
30167
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
30168
+ var nullTag = "[object Null]";
30169
+ var undefinedTag = "[object Undefined]";
30170
+ var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
30171
+ function baseGetTag(value) {
30172
+ if (value == null) {
30173
+ return value === void 0 ? undefinedTag : nullTag;
30174
+ }
30175
+ return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
30176
+ }
30177
+ var baseGetTag_default = baseGetTag;
30178
+
30179
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObjectLike.js
30180
+ function isObjectLike(value) {
30181
+ return value != null && typeof value == "object";
30182
+ }
30183
+ var isObjectLike_default = isObjectLike;
30184
+
30185
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isArray.js
30186
+ var isArray2 = Array.isArray;
30187
+ var isArray_default = isArray2;
30188
+
30189
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsArguments.js
30190
+ var argsTag = "[object Arguments]";
30191
+ function baseIsArguments(value) {
30192
+ return isObjectLike_default(value) && baseGetTag_default(value) == argsTag;
30193
+ }
30194
+ var baseIsArguments_default = baseIsArguments;
30195
+
30196
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isArguments.js
30197
+ var objectProto3 = Object.prototype;
30198
+ var hasOwnProperty4 = objectProto3.hasOwnProperty;
30199
+ var propertyIsEnumerable = objectProto3.propertyIsEnumerable;
30200
+ var isArguments = baseIsArguments_default(function() {
30201
+ return arguments;
30202
+ }()) ? baseIsArguments_default : function(value) {
30203
+ return isObjectLike_default(value) && hasOwnProperty4.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
30204
+ };
30205
+ var isArguments_default = isArguments;
30206
+
30207
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayPush.js
30208
+ function arrayPush(array, values) {
30209
+ var index2 = -1, length = values.length, offset2 = array.length;
30210
+ while (++index2 < length) {
30211
+ array[offset2 + index2] = values[index2];
30212
+ }
30213
+ return array;
30214
+ }
30215
+ var arrayPush_default = arrayPush;
30216
+
30217
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_isFlattenable.js
30218
+ var spreadableSymbol = Symbol_default ? Symbol_default.isConcatSpreadable : void 0;
30219
+ function isFlattenable(value) {
30220
+ return isArray_default(value) || isArguments_default(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
30221
+ }
30222
+ var isFlattenable_default = isFlattenable;
30223
+
30224
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseFlatten.js
30225
+ function baseFlatten(array, depth, predicate, isStrict, result) {
30226
+ var index2 = -1, length = array.length;
30227
+ predicate || (predicate = isFlattenable_default);
30228
+ result || (result = []);
30229
+ while (++index2 < length) {
30230
+ var value = array[index2];
30231
+ if (depth > 0 && predicate(value)) {
30232
+ if (depth > 1) {
30233
+ baseFlatten(value, depth - 1, predicate, isStrict, result);
30234
+ } else {
30235
+ arrayPush_default(result, value);
30236
+ }
30237
+ } else if (!isStrict) {
30238
+ result[result.length] = value;
30239
+ }
30240
+ }
30241
+ return result;
30242
+ }
30243
+ var baseFlatten_default = baseFlatten;
30244
+
30245
+ // ../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/flatten.js
30246
+ function flatten(array) {
30247
+ var length = array == null ? 0 : array.length;
30248
+ return length ? baseFlatten_default(array, 1) : [];
30249
+ }
30250
+ var flatten_default = flatten;
30209
30251
 
30210
30252
  // src/parse/acorn.ts
30211
30253
  var extractAttributes = (attributes, fields, imageCallback) => {
@@ -30216,7 +30258,14 @@ var extractAttributes = (attributes, fields, imageCallback) => {
30216
30258
  if (!field) {
30217
30259
  throw new Error(`Unable to find field definition for property "${attribute.name}"`);
30218
30260
  }
30219
- properties[attribute.name] = extractAttribute(attribute, field, imageCallback);
30261
+ try {
30262
+ properties[attribute.name] = extractAttribute(attribute, field, imageCallback);
30263
+ } catch (e) {
30264
+ if (e instanceof Error) {
30265
+ throw new Error(`Unable to parse field value for field "${field.name}" (type: ${field.type}). ${e.message}`);
30266
+ }
30267
+ throw e;
30268
+ }
30220
30269
  });
30221
30270
  return properties;
30222
30271
  };
@@ -30235,9 +30284,7 @@ var extractAttribute = (attribute, field, imageCallback) => {
30235
30284
  case "image":
30236
30285
  if (field.list) {
30237
30286
  const values = extractScalar(extractExpression(attribute), field);
30238
- if (typeof values === "string") {
30239
- return values.split(",").map((value) => imageCallback(value));
30240
- }
30287
+ return values.split(",").map((value) => imageCallback(value));
30241
30288
  } else {
30242
30289
  const value = extractString(attribute, field);
30243
30290
  return imageCallback(value);
@@ -30252,7 +30299,11 @@ var extractAttribute = (attribute, field, imageCallback) => {
30252
30299
  return extractObject(extractExpression(attribute), field);
30253
30300
  case "rich-text":
30254
30301
  const JSXString = extractJSXFragment(extractExpression(attribute), attribute, field);
30255
- return parseMDX(JSXString, field);
30302
+ if (JSXString) {
30303
+ return parseMDX(JSXString, field, imageCallback);
30304
+ } else {
30305
+ return {};
30306
+ }
30256
30307
  default:
30257
30308
  throw new Error(`Extract attribute: Unhandled field type ${field.type}`);
30258
30309
  }
@@ -30260,10 +30311,10 @@ var extractAttribute = (attribute, field, imageCallback) => {
30260
30311
  var extractScalar = (attribute, field) => {
30261
30312
  if (field.list) {
30262
30313
  assertType(attribute.expression, "ArrayExpression");
30263
- return attribute.expression.elements.map((element2) => {
30264
- assertHasType(element2);
30265
- assertType(element2, "Literal");
30266
- return element2.value;
30314
+ return attribute.expression.elements.map((element) => {
30315
+ assertHasType(element);
30316
+ assertType(element, "Literal");
30317
+ return element.value;
30267
30318
  });
30268
30319
  } else {
30269
30320
  assertType(attribute.expression, "Literal");
@@ -30273,10 +30324,10 @@ var extractScalar = (attribute, field) => {
30273
30324
  var extractObject = (attribute, field) => {
30274
30325
  if (field.list) {
30275
30326
  assertType(attribute.expression, "ArrayExpression");
30276
- return attribute.expression.elements.map((element2) => {
30277
- assertHasType(element2);
30278
- assertType(element2, "ObjectExpression");
30279
- return extractObjectExpression(element2, field);
30327
+ return attribute.expression.elements.map((element) => {
30328
+ assertHasType(element);
30329
+ assertType(element, "ObjectExpression");
30330
+ return extractObjectExpression(element, field);
30280
30331
  });
30281
30332
  } else {
30282
30333
  assertType(attribute.expression, "ObjectExpression");
@@ -30301,14 +30352,16 @@ var getField = (objectField, name) => {
30301
30352
  }
30302
30353
  };
30303
30354
  var extractJSXFragment = (attribute, baseAttribute, field) => {
30304
- var _a;
30305
30355
  if (field.list) {
30306
30356
  } else {
30307
30357
  if (attribute.expression.type === "JSXFragment") {
30308
- assertHasType(attribute.expression.children[0]);
30309
- return attribute.expression.children[0].value.trim();
30310
- if (typeof baseAttribute.value !== "string") {
30311
- return (_a = baseAttribute.value) == null ? void 0 : _a.value;
30358
+ assertHasType(attribute.expression);
30359
+ if (attribute.expression.children[0]) {
30360
+ const firstChild = attribute.expression.children[0];
30361
+ if (attribute.expression.children[0].type === "JSXText") {
30362
+ const child = firstChild;
30363
+ return child.value.trim();
30364
+ }
30312
30365
  }
30313
30366
  }
30314
30367
  }
@@ -30321,10 +30374,10 @@ var extractKeyValue = (property, parentField) => {
30321
30374
  if ((field == null ? void 0 : field.type) === "object") {
30322
30375
  if (field.list) {
30323
30376
  assertType(property.value, "ArrayExpression");
30324
- const value = property.value.elements.map((element2) => {
30325
- assertHasType(element2);
30326
- assertType(element2, "ObjectExpression");
30327
- return extractObjectExpression(element2, field);
30377
+ const value = property.value.elements.map((element) => {
30378
+ assertHasType(element);
30379
+ assertType(element, "ObjectExpression");
30380
+ return extractObjectExpression(element, field);
30328
30381
  });
30329
30382
  return { key, value };
30330
30383
  } else {
@@ -30364,7 +30417,7 @@ var extractExpression = (attribute) => {
30364
30417
  };
30365
30418
  function assertType(val, type) {
30366
30419
  if (val.type !== type) {
30367
- throw new Error(`Expected type to be ${type} but received ${val.type}`);
30420
+ throw new Error(`Expected type to be ${type} but received ${val.type}. ${MDX_PARSE_ERROR_MSG}`);
30368
30421
  }
30369
30422
  }
30370
30423
  function assertHasType(val) {
@@ -30382,58 +30435,71 @@ var throwError = (field) => {
30382
30435
  // src/parse/mdx.ts
30383
30436
  function mdxJsxElement(node, field, imageCallback) {
30384
30437
  var _a;
30385
- const template = (_a = field.templates) == null ? void 0 : _a.find((template2) => {
30386
- const templateName = typeof template2 === "string" ? template2 : template2.name;
30387
- return templateName === node.name;
30388
- });
30389
- if (typeof template === "string") {
30390
- throw new Error("Global templates not yet supported");
30391
- }
30392
- if (!template) {
30393
- const string3 = toMarkdown({ type: "root", children: [node] }, {
30394
- extensions: [mdxJsxToMarkdown()],
30395
- listItemIndent: "one"
30438
+ try {
30439
+ const template = (_a = field.templates) == null ? void 0 : _a.find((template2) => {
30440
+ const templateName = typeof template2 === "string" ? template2 : template2.name;
30441
+ return templateName === node.name;
30396
30442
  });
30397
- return {
30398
- type: node.type === "mdxJsxFlowElement" ? "html" : "html_inline",
30399
- value: string3.trim(),
30400
- children: [{ type: "text", text: "" }]
30401
- };
30402
- }
30403
- if (template.match) {
30404
- const value = node.children[0].value;
30405
- if (node.type === "mdxJsxFlowElement") {
30406
- return {
30407
- type: node.type,
30408
- name: node.name,
30409
- children: [{ type: "text", text: "" }],
30410
- props: { text: value }
30411
- };
30412
- } else {
30443
+ if (typeof template === "string") {
30444
+ throw new Error("Global templates not yet supported");
30445
+ }
30446
+ if (!template) {
30447
+ const string3 = toMarkdown({ type: "root", children: [node] }, {
30448
+ extensions: [mdxJsxToMarkdown()],
30449
+ listItemIndent: "one"
30450
+ });
30413
30451
  return {
30414
- type: node.type,
30415
- name: node.name,
30416
- children: [{ type: "text", text: "" }],
30417
- props: { text: value }
30452
+ type: node.type === "mdxJsxFlowElement" ? "html" : "html_inline",
30453
+ value: string3.trim(),
30454
+ children: [{ type: "text", text: "" }]
30418
30455
  };
30419
30456
  }
30457
+ if (template.match) {
30458
+ const firstChild = node == null ? void 0 : node.children[0];
30459
+ if ((firstChild == null ? void 0 : firstChild.type) === "inlineCode") {
30460
+ const value = firstChild.value;
30461
+ if (node.type === "mdxJsxFlowElement") {
30462
+ return {
30463
+ type: node.type,
30464
+ name: node.name,
30465
+ children: [{ type: "text", text: "" }],
30466
+ props: { text: value }
30467
+ };
30468
+ } else {
30469
+ return {
30470
+ type: node.type,
30471
+ name: node.name,
30472
+ children: [{ type: "text", text: "" }],
30473
+ props: { text: value }
30474
+ };
30475
+ }
30476
+ } else {
30477
+ throw new Error(`Unable to parse value for template match pattern - start: ${template.match.start}, end: ${template.match.end}`);
30478
+ }
30479
+ }
30480
+ const props = extractAttributes(node.attributes, template.fields, imageCallback);
30481
+ const childField = template.fields.find((field2) => field2.name === "children");
30482
+ if (childField) {
30483
+ if (childField.type === "rich-text") {
30484
+ props.children = remarkToSlate(node, childField, imageCallback);
30485
+ }
30486
+ }
30487
+ return {
30488
+ type: node.type,
30489
+ name: node.name,
30490
+ children: [{ type: "text", text: "" }],
30491
+ props
30492
+ };
30493
+ } catch (e) {
30494
+ if (e instanceof Error) {
30495
+ throw new RichTextParseError(e.message, node.position);
30496
+ }
30497
+ throw e;
30420
30498
  }
30421
- const props = extractAttributes(node.attributes, template.fields, imageCallback);
30422
- const childField = template.fields.find((field2) => field2.name === "children");
30423
- if (childField) {
30424
- const childProps = remarkToSlate(node, childField, imageCallback);
30425
- props.children = childProps;
30426
- }
30427
- return {
30428
- type: node.type,
30429
- name: node.name,
30430
- children: [{ type: "text", text: "" }],
30431
- props
30432
- };
30433
30499
  }
30434
30500
 
30435
30501
  // src/parse/remarkToPlate.ts
30436
- var remarkToSlate = (root2, field, imageCallback) => {
30502
+ var remarkToSlate = (root3, field, imageCallback) => {
30437
30503
  const content3 = (content4) => {
30438
30504
  switch (content4.type) {
30439
30505
  case "blockquote":
@@ -30467,23 +30533,31 @@ var remarkToSlate = (root2, field, imageCallback) => {
30467
30533
  children: [
30468
30534
  {
30469
30535
  type: "lic",
30470
- children: content4.children.map((child) => blockContent(child))
30536
+ children: flatten_default(content4.children.map((child) => unwrapBlockContent(child)))
30471
30537
  }
30472
30538
  ]
30473
30539
  };
30474
30540
  case "list":
30475
30541
  return list3(content4);
30476
30542
  case "html":
30477
- return html2(content4, true);
30478
- case "text":
30479
- return text4(content4);
30543
+ return html2(content4);
30544
+ case "mdxFlowExpression":
30545
+ case "mdxjsEsm":
30546
+ throw new RichTextParseError(`Unexpected expression ${content4.value}.`, content4.position);
30480
30547
  default:
30481
- throw new Error(`Content: ${content4.type} is not yet supported`);
30548
+ throw new RichTextParseError(`Content: ${content4.type} is not yet supported`, content4.position);
30482
30549
  }
30483
30550
  };
30484
- const html2 = (content4, block) => {
30551
+ const html2 = (content4) => {
30485
30552
  return {
30486
- type: block ? "html" : "html_inline",
30553
+ type: "html",
30554
+ value: content4.value,
30555
+ children: [{ type: "text", text: "" }]
30556
+ };
30557
+ };
30558
+ const html_inline = (content4) => {
30559
+ return {
30560
+ type: "html_inline",
30487
30561
  value: content4.value,
30488
30562
  children: [{ type: "text", text: "" }]
30489
30563
  };
@@ -30494,9 +30568,6 @@ var remarkToSlate = (root2, field, imageCallback) => {
30494
30568
  children: content4.children.map((child) => listItem2(child))
30495
30569
  };
30496
30570
  };
30497
- const toArray = (item) => {
30498
- return Array.isArray(item) ? item : [item];
30499
- };
30500
30571
  const listItem2 = (content4) => {
30501
30572
  return {
30502
30573
  type: "li",
@@ -30508,7 +30579,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30508
30579
  case "paragraph":
30509
30580
  return {
30510
30581
  type: "lic",
30511
- children: (0, import_lodash.default)(child.children.map((child2) => phrasingContent(child2)))
30582
+ children: flatten_default(child.children.map((child2) => phrasingContent(child2)))
30512
30583
  };
30513
30584
  case "blockquote": {
30514
30585
  return __spreadProps(__spreadValues({}, blockquote2(child)), {
@@ -30536,7 +30607,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30536
30607
  const unwrapBlockContent = (content4) => {
30537
30608
  const flattenPhrasingContent = (children) => {
30538
30609
  const children2 = children.map((child) => phrasingContent(child));
30539
- return (0, import_lodash.default)(Array.isArray(children2) ? children2 : [children2]);
30610
+ return flatten_default(Array.isArray(children2) ? children2 : [children2]);
30540
30611
  };
30541
30612
  switch (content4.type) {
30542
30613
  case "heading":
@@ -30547,25 +30618,28 @@ var remarkToSlate = (root2, field, imageCallback) => {
30547
30618
  }
30548
30619
  };
30549
30620
  const code2 = (content4) => {
30550
- return {
30551
- type: "code_block",
30552
- lang: content4.lang,
30621
+ const extra = {};
30622
+ if (content4.lang)
30623
+ extra["lang"] = content4.lang;
30624
+ return __spreadProps(__spreadValues({
30625
+ type: "code_block"
30626
+ }, extra), {
30553
30627
  value: content4.value,
30554
30628
  children: [{ type: "text", text: "" }]
30555
- };
30629
+ });
30556
30630
  };
30557
30631
  const link2 = (content4) => {
30558
30632
  return {
30559
30633
  type: "a",
30560
30634
  url: content4.url,
30561
30635
  title: content4.title,
30562
- children: (0, import_lodash.default)(content4.children.map((child) => staticPhrasingContent(child)))
30636
+ children: flatten_default(content4.children.map((child) => staticPhrasingContent(child)))
30563
30637
  };
30564
30638
  };
30565
30639
  const heading2 = (content4) => {
30566
30640
  return {
30567
30641
  type: ["h1", "h2", "h3", "h4", "h5", "h6"][content4.depth - 1],
30568
- children: (0, import_lodash.default)(content4.children.map(phrasingContent))
30642
+ children: flatten_default(content4.children.map(phrasingContent))
30569
30643
  };
30570
30644
  };
30571
30645
  const staticPhrasingContent = (content4) => {
@@ -30573,7 +30647,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30573
30647
  case "mdxJsxTextElement":
30574
30648
  return mdxJsxElement(content4, field, imageCallback);
30575
30649
  case "text":
30576
- return text4(content4);
30650
+ return text5(content4);
30577
30651
  case "inlineCode":
30578
30652
  case "emphasis":
30579
30653
  case "image":
@@ -30586,7 +30660,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30586
30660
  const phrasingContent = (content4) => {
30587
30661
  switch (content4.type) {
30588
30662
  case "text":
30589
- return text4(content4);
30663
+ return text5(content4);
30590
30664
  case "link":
30591
30665
  return link2(content4);
30592
30666
  case "image":
@@ -30602,7 +30676,9 @@ var remarkToSlate = (root2, field, imageCallback) => {
30602
30676
  case "inlineCode":
30603
30677
  return phrashingMark(content4);
30604
30678
  case "html":
30605
- return html2(content4);
30679
+ return html_inline(content4);
30680
+ case "mdxTextExpression":
30681
+ throw new RichTextParseError(`Unexpected expression ${content4.value}.`, content4.position);
30606
30682
  default:
30607
30683
  throw new Error(`PhrasingContent: ${content4.type} is not yet supported`);
30608
30684
  }
@@ -30622,7 +30698,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30622
30698
  const accum = [];
30623
30699
  switch (node.type) {
30624
30700
  case "emphasis": {
30625
- const children = (0, import_lodash.default)(node.children.map((child) => phrashingMark(child, [...marks, "italic"])));
30701
+ const children = flatten_default(node.children.map((child) => phrashingMark(child, [...marks, "italic"])));
30626
30702
  children.forEach((child) => {
30627
30703
  accum.push(child);
30628
30704
  });
@@ -30639,7 +30715,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30639
30715
  break;
30640
30716
  }
30641
30717
  case "strong": {
30642
- const children = (0, import_lodash.default)(node.children.map((child) => phrashingMark(child, [...marks, "bold"])));
30718
+ const children = flatten_default(node.children.map((child) => phrashingMark(child, [...marks, "bold"])));
30643
30719
  children.forEach((child) => {
30644
30720
  accum.push(child);
30645
30721
  });
@@ -30650,7 +30726,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30650
30726
  break;
30651
30727
  }
30652
30728
  case "link": {
30653
- const children = (0, import_lodash.default)(node.children.map((child) => phrashingMark(child, marks)));
30729
+ const children = flatten_default(node.children.map((child) => phrashingMark(child, marks)));
30654
30730
  accum.push({ type: "a", url: node.url, title: node.title, children });
30655
30731
  break;
30656
30732
  }
@@ -30673,7 +30749,7 @@ var remarkToSlate = (root2, field, imageCallback) => {
30673
30749
  children: [{ type: "text", text: "" }]
30674
30750
  };
30675
30751
  };
30676
- const text4 = (content4) => {
30752
+ const text5 = (content4) => {
30677
30753
  return {
30678
30754
  type: "text",
30679
30755
  text: content4.value
@@ -30693,12 +30769,14 @@ var remarkToSlate = (root2, field, imageCallback) => {
30693
30769
  };
30694
30770
  };
30695
30771
  const paragraph2 = (content4) => {
30696
- const children = (0, import_lodash.default)(content4.children.map(phrasingContent));
30772
+ const children = flatten_default(content4.children.map(phrasingContent));
30697
30773
  if (children.length === 1) {
30698
- if (children[0].type === "html_inline") {
30699
- return __spreadProps(__spreadValues({}, children[0]), {
30700
- type: "html"
30701
- });
30774
+ if (children[0]) {
30775
+ if (children[0].type === "html_inline") {
30776
+ return __spreadProps(__spreadValues({}, children[0]), {
30777
+ type: "html"
30778
+ });
30779
+ }
30702
30780
  }
30703
30781
  }
30704
30782
  return {
@@ -30706,65 +30784,89 @@ var remarkToSlate = (root2, field, imageCallback) => {
30706
30784
  children
30707
30785
  };
30708
30786
  };
30709
- const blockContent = (content4) => {
30710
- switch (content4.type) {
30711
- case "blockquote":
30712
- return blockquote2(content4);
30713
- case "paragraph":
30714
- return paragraph2(content4);
30715
- case "thematicBreak":
30716
- return {
30717
- type: "hr",
30718
- children: [{ type: "text", text: "" }]
30719
- };
30720
- case "code":
30721
- case "heading":
30722
- case "html":
30723
- case "list":
30724
- case "table":
30725
- default:
30726
- throw new Error(`BlockContent: ${content4.type} is not yet supported`);
30727
- }
30728
- };
30729
30787
  return {
30730
30788
  type: "root",
30731
- children: root2.children.map((child) => content3(child))
30789
+ children: root3.children.map((child) => {
30790
+ return content3(child);
30791
+ })
30732
30792
  };
30733
30793
  };
30794
+ var RichTextParseError = class extends Error {
30795
+ constructor(message, position2) {
30796
+ super(message);
30797
+ if (Error.captureStackTrace) {
30798
+ Error.captureStackTrace(this, RichTextParseError);
30799
+ }
30800
+ this.name = "RichTextParseError";
30801
+ this.position = position2;
30802
+ }
30803
+ };
30734
30804
 
30735
30805
  // src/parse/index.ts
30736
- var markdownToAst = (value, skipMDX, field) => {
30806
+ var markdownToAst = (value, field) => {
30737
30807
  var _a;
30738
- try {
30739
- const templatesWithMatchers = (_a = field.templates) == null ? void 0 : _a.filter((template) => template.match);
30740
- let preprocessedString = value;
30741
- templatesWithMatchers == null ? void 0 : templatesWithMatchers.forEach((template) => {
30808
+ const templatesWithMatchers = (_a = field.templates) == null ? void 0 : _a.filter((template) => template.match);
30809
+ let preprocessedString = value;
30810
+ templatesWithMatchers == null ? void 0 : templatesWithMatchers.forEach((template) => {
30811
+ if (typeof template === "string") {
30812
+ throw new Error("Global templates are not supported");
30813
+ }
30814
+ if (template.match) {
30742
30815
  preprocessedString = preprocessedString.replaceAll(template.match.start, `<${template.name}>\``);
30743
30816
  preprocessedString = preprocessedString.replaceAll(template.match.end, `\`</${template.name}>`);
30744
- });
30817
+ }
30818
+ });
30819
+ try {
30745
30820
  const tree = remark().use(remarkMdx).parse(preprocessedString);
30746
30821
  if (!tree) {
30747
30822
  throw new Error("Error parsing markdown");
30748
30823
  }
30749
- visit(tree, (node) => {
30750
- delete node.position;
30751
- });
30752
30824
  return tree;
30753
30825
  } catch (e) {
30754
- console.log(e);
30826
+ throw new RichTextParseError(e, e.position);
30827
+ }
30828
+ };
30829
+ var MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/editing/mdx/#differences-from-other-mdx-implementations";
30830
+ var parseMDX = (value, field, imageCallback) => {
30831
+ let tree;
30832
+ try {
30833
+ tree = markdownToAst(value, field);
30834
+ if (tree) {
30835
+ return remarkToSlate(tree, field, imageCallback);
30836
+ } else {
30837
+ return { type: "root", children: [] };
30838
+ }
30839
+ } catch (e) {
30840
+ if (e instanceof RichTextParseError) {
30841
+ return invalidMarkdown(e, value);
30842
+ }
30843
+ throw e;
30755
30844
  }
30756
30845
  };
30757
- var parseMDX = (value, field, imageCallback, skipMDX) => {
30758
- const tree = markdownToAst(value, skipMDX, field);
30759
- return remarkToSlate(tree, field, imageCallback);
30846
+ var invalidMarkdown = (e, value) => {
30847
+ const extra = {};
30848
+ if (e.position && Object.keys(e.position).length) {
30849
+ extra["position"] = e.position;
30850
+ }
30851
+ return {
30852
+ type: "root",
30853
+ children: [
30854
+ __spreadValues({
30855
+ type: "invalid_markdown",
30856
+ value,
30857
+ message: e.message || `Error parsing markdown ${MDX_PARSE_ERROR_MSG}`,
30858
+ children: [{ type: "text", text: "" }]
30859
+ }, extra)
30860
+ ]
30861
+ };
30760
30862
  };
30761
30863
 
30762
30864
  // src/stringify/acorn.ts
30763
30865
  var import_prettier = __toModule(require_standalone());
30764
- var stringifyPropsInline = (element2, field, imageCallback) => {
30765
- return stringifyProps(element2, field, true, imageCallback);
30866
+ var stringifyPropsInline = (element, field, imageCallback) => {
30867
+ return stringifyProps(element, field, true, imageCallback);
30766
30868
  };
30767
- var stringifyProps = (element2, parentField, flatten2, imageCallback) => {
30869
+ function stringifyProps(element, parentField, flatten2, imageCallback) {
30768
30870
  var _a;
30769
30871
  const attributes = [];
30770
30872
  const children = [];
@@ -30772,12 +30874,12 @@ var stringifyProps = (element2, parentField, flatten2, imageCallback) => {
30772
30874
  if (typeof template2 === "string") {
30773
30875
  throw new Error("Global templates not supported");
30774
30876
  }
30775
- return template2.name === element2.name;
30877
+ return template2.name === element.name;
30776
30878
  });
30777
30879
  if (!template || typeof template === "string") {
30778
- throw new Error(`Unable to find template for JSX element ${element2.name}`);
30880
+ throw new Error(`Unable to find template for JSX element ${element.name}`);
30779
30881
  }
30780
- Object.entries(element2.props).forEach(([name, value]) => {
30882
+ Object.entries(element.props).forEach(([name, value]) => {
30781
30883
  const field = template.fields.find((field2) => field2.name === name);
30782
30884
  if (!field) {
30783
30885
  if (name === "children") {
@@ -30788,69 +30890,91 @@ var stringifyProps = (element2, parentField, flatten2, imageCallback) => {
30788
30890
  switch (field.type) {
30789
30891
  case "reference":
30790
30892
  if (field.list) {
30791
- attributes.push({
30792
- type: "mdxJsxAttribute",
30793
- name,
30794
- value: {
30795
- type: "mdxJsxAttributeValueExpression",
30796
- value: `[${value.map((item) => `"${item}"`).join(", ")}]`
30797
- }
30798
- });
30893
+ if (Array.isArray(value)) {
30894
+ attributes.push({
30895
+ type: "mdxJsxAttribute",
30896
+ name,
30897
+ value: {
30898
+ type: "mdxJsxAttributeValueExpression",
30899
+ value: `[${value.map((item) => `"${item}"`).join(", ")}]`
30900
+ }
30901
+ });
30902
+ }
30799
30903
  } else {
30800
- attributes.push({
30801
- type: "mdxJsxAttribute",
30802
- name,
30803
- value
30804
- });
30904
+ if (typeof value === "string") {
30905
+ attributes.push({
30906
+ type: "mdxJsxAttribute",
30907
+ name,
30908
+ value
30909
+ });
30910
+ }
30805
30911
  }
30806
30912
  break;
30807
30913
  case "datetime":
30808
30914
  case "string":
30809
30915
  if (field.list) {
30810
- attributes.push({
30811
- type: "mdxJsxAttribute",
30812
- name,
30813
- value: {
30814
- type: "mdxJsxAttributeValueExpression",
30815
- value: `[${value.map((item) => `"${item}"`).join(", ")}]`
30816
- }
30817
- });
30916
+ if (Array.isArray(value)) {
30917
+ attributes.push({
30918
+ type: "mdxJsxAttribute",
30919
+ name,
30920
+ value: {
30921
+ type: "mdxJsxAttributeValueExpression",
30922
+ value: `[${value.map((item) => `"${item}"`).join(", ")}]`
30923
+ }
30924
+ });
30925
+ }
30818
30926
  } else {
30819
- attributes.push({
30820
- type: "mdxJsxAttribute",
30821
- name,
30822
- value
30823
- });
30927
+ if (typeof value === "string") {
30928
+ attributes.push({
30929
+ type: "mdxJsxAttribute",
30930
+ name,
30931
+ value
30932
+ });
30933
+ } else {
30934
+ throw new Error(`Expected string for attribute on field ${field.name}`);
30935
+ }
30824
30936
  }
30825
30937
  break;
30826
30938
  case "image":
30827
30939
  if (field.list) {
30828
- attributes.push({
30829
- type: "mdxJsxAttribute",
30830
- name,
30831
- value: {
30832
- type: "mdxJsxAttributeValueExpression",
30833
- value: `[${value.map((item) => `"${imageCallback(item)}"`).join(", ")}]`
30834
- }
30835
- });
30940
+ if (Array.isArray(value)) {
30941
+ attributes.push({
30942
+ type: "mdxJsxAttribute",
30943
+ name,
30944
+ value: {
30945
+ type: "mdxJsxAttributeValueExpression",
30946
+ value: `[${value.map((item) => `"${imageCallback(item)}"`).join(", ")}]`
30947
+ }
30948
+ });
30949
+ }
30836
30950
  } else {
30837
30951
  attributes.push({
30838
30952
  type: "mdxJsxAttribute",
30839
30953
  name,
30840
- value: imageCallback(value)
30954
+ value: imageCallback(String(value))
30841
30955
  });
30842
30956
  }
30843
30957
  break;
30844
30958
  case "number":
30845
30959
  case "boolean":
30846
30960
  if (field.list) {
30961
+ if (Array.isArray(value)) {
30962
+ attributes.push({
30963
+ type: "mdxJsxAttribute",
30964
+ name,
30965
+ value: {
30966
+ type: "mdxJsxAttributeValueExpression",
30967
+ value: `[${value.map((item) => `${item}`).join(", ")}]`
30968
+ }
30969
+ });
30970
+ }
30847
30971
  } else {
30848
30972
  attributes.push({
30849
30973
  type: "mdxJsxAttribute",
30850
30974
  name,
30851
30975
  value: {
30852
30976
  type: "mdxJsxAttributeValueExpression",
30853
- value
30977
+ value: String(value)
30854
30978
  }
30855
30979
  });
30856
30980
  }
@@ -30874,14 +30998,15 @@ var stringifyProps = (element2, parentField, flatten2, imageCallback) => {
30874
30998
  } else {
30875
30999
  const joiner = flatten2 ? " " : "\n";
30876
31000
  let val = "";
31001
+ assertShape(value, (value2) => value2.type === "root" && Array.isArray(value2.children), `Nested rich-text element is not a valid shape for field ${field.name}`);
30877
31002
  if (field.name === "children") {
30878
- const root2 = rootElement(value, field, imageCallback);
30879
- root2.children.forEach((child) => {
31003
+ const root3 = rootElement(value, field, imageCallback);
31004
+ root3.children.forEach((child) => {
30880
31005
  children.push(child);
30881
31006
  });
30882
31007
  return;
30883
31008
  } else {
30884
- const stringValue = stringifyMDX(value, field);
31009
+ const stringValue = stringifyMDX(value, field, imageCallback);
30885
31010
  val = stringValue.trim().split("\n").map((str) => ` ${str.trim()}`).join(joiner);
30886
31011
  }
30887
31012
  if (flatten2) {
@@ -30911,16 +31036,34 @@ ${val}
30911
31036
  throw new Error(`Stringify props: ${field.type} not yet supported`);
30912
31037
  }
30913
31038
  });
31039
+ if (template.match) {
31040
+ if (attributes[0] && typeof attributes[0].value === "string") {
31041
+ return {
31042
+ attributes: [],
31043
+ children: [{ type: "inlineCode", value: attributes[0].value }]
31044
+ };
31045
+ }
31046
+ }
30914
31047
  return { attributes, children };
30915
- };
31048
+ }
30916
31049
  function stringifyObj(obj, flatten2) {
30917
- const dummyFunc = `const dummyFunc = `;
30918
- const res = (0, import_prettier.format)(`${dummyFunc}${JSON.stringify(obj)}`, {
30919
- parser: "acorn",
30920
- trailingComma: "none",
30921
- semi: false
30922
- }).trim().replace(dummyFunc, "");
30923
- return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
31050
+ if (typeof obj === "object" && obj !== null) {
31051
+ const dummyFunc = `const dummyFunc = `;
31052
+ const res = (0, import_prettier.format)(`${dummyFunc}${JSON.stringify(obj)}`, {
31053
+ parser: "acorn",
31054
+ trailingComma: "none",
31055
+ semi: false
31056
+ }).trim().replace(dummyFunc, "");
31057
+ return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
31058
+ } else {
31059
+ console.log(obj);
31060
+ throw new Error(`stringifyObj must be passed an object or an array of objects, received ${typeof obj}`);
31061
+ }
31062
+ }
31063
+ function assertShape(value, callback, errorMessage) {
31064
+ if (!callback(value)) {
31065
+ throw new Error(errorMessage || `Failed to assert shape`);
31066
+ }
30924
31067
  }
30925
31068
 
30926
31069
  // src/stringify/marks.ts
@@ -30940,12 +31083,7 @@ var replaceLinksWithTextNodes = (content3) => {
30940
31083
  type: "link",
30941
31084
  url: item.url,
30942
31085
  title: item.title,
30943
- children: [
30944
- {
30945
- type: "text",
30946
- value: a.value
30947
- }
30948
- ]
31086
+ children: [text4({ text: a.value })]
30949
31087
  };
30950
31088
  }
30951
31089
  }));
@@ -30978,15 +31116,6 @@ var inlineElementExceptLink = (content3, field, imageCallback) => {
30978
31116
  };
30979
31117
  case "mdxJsxTextElement": {
30980
31118
  const { attributes, children } = stringifyPropsInline(content3, field, imageCallback);
30981
- const template = field.templates.find((template2) => template2.name === content3.name);
30982
- if (template.match) {
30983
- return {
30984
- type: "mdxJsxTextElement",
30985
- name: content3.name,
30986
- attributes: [],
30987
- children: [{ type: "inlineCode", value: attributes[0].value }]
30988
- };
30989
- }
30990
31119
  return {
30991
31120
  type: "mdxJsxTextElement",
30992
31121
  name: content3.name,
@@ -31002,14 +31131,17 @@ var inlineElementExceptLink = (content3, field, imageCallback) => {
31002
31131
  }
31003
31132
  default:
31004
31133
  if (!content3.type && typeof content3.text === "string") {
31005
- return {
31006
- type: "text",
31007
- value: content3.text
31008
- };
31134
+ return text4(content3);
31009
31135
  }
31010
- throw new Error(`InlineElement: ${content3.type} is not yet supported`);
31136
+ throw new Error(`InlineElement: ${content3.type} is not supported`);
31011
31137
  }
31012
31138
  };
31139
+ var text4 = (content3) => {
31140
+ return {
31141
+ type: "text",
31142
+ value: content3.text
31143
+ };
31144
+ };
31013
31145
  var eat2 = (c, field, imageCallback) => {
31014
31146
  const content3 = replaceLinksWithTextNodes(c);
31015
31147
  const first = content3[0];
@@ -31026,14 +31158,11 @@ var eat2 = (c, field, imageCallback) => {
31026
31158
  if (marks.length === 0) {
31027
31159
  if (first.linkifyTextNode) {
31028
31160
  return [
31029
- first.linkifyTextNode({ type: "text", value: first.text }),
31161
+ first.linkifyTextNode(text4(first)),
31030
31162
  ...eat2(content3.slice(1), field, imageCallback)
31031
31163
  ];
31032
31164
  } else {
31033
- return [
31034
- { type: "text", value: first.text },
31035
- ...eat2(content3.slice(1), field, imageCallback)
31036
- ];
31165
+ return [text4(first), ...eat2(content3.slice(1), field, imageCallback)];
31037
31166
  }
31038
31167
  }
31039
31168
  let nonMatchingSiblingIndex = 0;
@@ -31069,13 +31198,7 @@ var eat2 = (c, field, imageCallback) => {
31069
31198
  }
31070
31199
  });
31071
31200
  if (!markToProcess) {
31072
- return [
31073
- {
31074
- type: "text",
31075
- value: first.text
31076
- },
31077
- ...eat2(content3.slice(1), field, imageCallback)
31078
- ];
31201
+ return [text4(first), ...eat2(content3.slice(1), field, imageCallback)];
31079
31202
  }
31080
31203
  if (markToProcess === "inlineCode") {
31081
31204
  if (nonMatchingSiblingIndex) {
@@ -31123,6 +31246,11 @@ var cleanNode = (node, mark) => {
31123
31246
  // src/stringify/index.ts
31124
31247
  var stringifyMDX = (value, field, imageCallback) => {
31125
31248
  var _a;
31249
+ if (value == null ? void 0 : value.children[0]) {
31250
+ if ((value == null ? void 0 : value.children[0].type) === "invalid_markdown") {
31251
+ return value.children[0].value;
31252
+ }
31253
+ }
31126
31254
  const res = toMarkdown(rootElement(value, field, imageCallback), {
31127
31255
  extensions: [mdxJsxToMarkdown()],
31128
31256
  listItemIndent: "one"
@@ -31130,15 +31258,20 @@ var stringifyMDX = (value, field, imageCallback) => {
31130
31258
  const templatesWithMatchers = (_a = field.templates) == null ? void 0 : _a.filter((template) => template.match);
31131
31259
  let preprocessedString = res;
31132
31260
  templatesWithMatchers == null ? void 0 : templatesWithMatchers.forEach((template) => {
31133
- preprocessedString = preprocessedString.replaceAll(`<${template.name}>\``, `${template.match.start} `);
31134
- preprocessedString = preprocessedString.replaceAll(`\`</${template.name}>`, ` ${template.match.end}`);
31261
+ if (typeof template === "string") {
31262
+ throw new Error("Global templates are not supported");
31263
+ }
31264
+ if (template.match) {
31265
+ preprocessedString = preprocessedString.replaceAll(`<${template.name}>\``, `${template.match.start} `);
31266
+ preprocessedString = preprocessedString.replaceAll(`\`</${template.name}>`, ` ${template.match.end}`);
31267
+ }
31135
31268
  });
31136
31269
  return preprocessedString;
31137
31270
  };
31138
31271
  var rootElement = (content3, field, imageCallback) => {
31139
31272
  const children = [];
31140
31273
  content3.children.forEach((child) => {
31141
- const value = blockElement2(child, field, imageCallback);
31274
+ const value = blockElement(child, field, imageCallback);
31142
31275
  if (value) {
31143
31276
  children.push(value);
31144
31277
  }
@@ -31148,7 +31281,7 @@ var rootElement = (content3, field, imageCallback) => {
31148
31281
  children
31149
31282
  };
31150
31283
  };
31151
- var blockElement2 = (content3, field, imageCallback) => {
31284
+ var blockElement = (content3, field, imageCallback) => {
31152
31285
  switch (content3.type) {
31153
31286
  case "h1":
31154
31287
  case "h2":
@@ -31208,14 +31341,12 @@ var blockElement2 = (content3, field, imageCallback) => {
31208
31341
  spread: false,
31209
31342
  children: content3.children.map((child) => listItemElement(child, field, imageCallback))
31210
31343
  };
31211
- case "html":
31212
- {
31213
- return {
31214
- type: "html",
31215
- value: content3.value
31216
- };
31217
- }
31218
- break;
31344
+ case "html": {
31345
+ return {
31346
+ type: "html",
31347
+ value: content3.value
31348
+ };
31349
+ }
31219
31350
  default:
31220
31351
  throw new Error(`BlockElement: ${content3.type} is not yet supported`);
31221
31352
  }
@@ -31285,3 +31416,12 @@ export {
31285
31416
  * @author Feross Aboukhadijeh <https://feross.org>
31286
31417
  * @license MIT
31287
31418
  */
31419
+ /**
31420
+ * @license
31421
+ * Lodash (Custom Build) <https://lodash.com/>
31422
+ * Build: `lodash modularize exports="es" -o ./`
31423
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
31424
+ * Released under MIT license <https://lodash.com/license>
31425
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
31426
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
31427
+ */