@tinacms/mdx 0.0.0-cef656e-20250119001929 → 0.0.0-d28d795-20250427004334

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.
package/dist/index.js CHANGED
@@ -5921,12 +5921,12 @@ var require_lodash = __commonJS({
5921
5921
  });
5922
5922
 
5923
5923
  // src/index.ts
5924
- var src_exports = {};
5925
- __export(src_exports, {
5924
+ var index_exports = {};
5925
+ __export(index_exports, {
5926
5926
  parseMDX: () => parseMDX,
5927
5927
  stringifyMDX: () => stringifyMDX
5928
5928
  });
5929
- module.exports = __toCommonJS(src_exports);
5929
+ module.exports = __toCommonJS(index_exports);
5930
5930
 
5931
5931
  // ../../../node_modules/.pnpm/bail@2.0.2/node_modules/bail/index.js
5932
5932
  function bail(error) {
@@ -25261,7 +25261,9 @@ function mdxJsxFromMarkdown2({ patterns }) {
25261
25261
  if (attribute.name === "") {
25262
25262
  attribute.name = "_value";
25263
25263
  }
25264
- attribute.value = parseEntities(this.resume(), { nonTerminated: false });
25264
+ attribute.value = parseEntities(this.resume(), {
25265
+ nonTerminated: false
25266
+ });
25265
25267
  }
25266
25268
  }
25267
25269
  };
@@ -25514,7 +25516,9 @@ var mdxJsxToMarkdown2 = function(options) {
25514
25516
  if (!emptyChildren) {
25515
25517
  tracker.shift(2);
25516
25518
  value += tracker.move("\n");
25517
- value += tracker.move(containerFlow(node2, context, tracker.current()));
25519
+ value += tracker.move(
25520
+ containerFlow(node2, context, tracker.current())
25521
+ );
25518
25522
  value += tracker.move("\n");
25519
25523
  }
25520
25524
  } else {
@@ -40036,22 +40040,10 @@ var Xh = Q({ "src/language-js/parse/acorn-and-espree.js"(a, u) {
40036
40040
  var mc = Xh();
40037
40041
 
40038
40042
  // src/stringify/acorn.ts
40039
- function generateRandom6LetterString() {
40040
- const characters = "abcdefghijklmnopqrstuvwxyz";
40041
- let result = "";
40042
- for (let i = 0; i < 6; i++) {
40043
- const randomIndex = Math.floor(Math.random() * characters.length);
40044
- result += characters[randomIndex];
40045
- }
40046
- return result;
40047
- }
40048
- function isMultiline(input) {
40049
- return input.includes("\n") || input.includes("\r");
40050
- }
40051
- var stringifyPropsInline = (element, field, imageCallback, context) => {
40052
- return stringifyProps(element, field, true, imageCallback, context || {});
40043
+ var stringifyPropsInline = (element, field, imageCallback) => {
40044
+ return stringifyProps(element, field, true, imageCallback);
40053
40045
  };
40054
- function stringifyProps(element, parentField, flatten2, imageCallback, context) {
40046
+ function stringifyProps(element, parentField, flatten2, imageCallback) {
40055
40047
  var _a3, _b;
40056
40048
  const attributes2 = [];
40057
40049
  const children = [];
@@ -40077,16 +40069,6 @@ function stringifyProps(element, parentField, flatten2, imageCallback, context)
40077
40069
  if (template.fields.find((f) => f.name === "children")) {
40078
40070
  directiveType = "block";
40079
40071
  }
40080
- const embedCodes = {};
40081
- for (const [embedKey, value] of Object.entries(element.props)) {
40082
- if (embedKey.startsWith("_tinaEmbeds")) {
40083
- const key = embedKey.replace("_tinaEmbeds.", "");
40084
- embedCodes[key] = value;
40085
- }
40086
- }
40087
- for (const key of Object.keys(embedCodes)) {
40088
- delete element.props[`_tinaEmbeds.${key}`];
40089
- }
40090
40072
  useDirective = !!template.match;
40091
40073
  Object.entries(element.props).forEach(([name2, value]) => {
40092
40074
  var _a4;
@@ -40138,22 +40120,11 @@ function stringifyProps(element, parentField, flatten2, imageCallback, context)
40138
40120
  }
40139
40121
  } else {
40140
40122
  if (typeof value === "string") {
40141
- if (isMultiline(value)) {
40142
- const code3 = embedCodes[name2] || generateRandom6LetterString();
40143
- context._tinaEmbeds = context._tinaEmbeds || {};
40144
- context._tinaEmbeds[code3] = value;
40145
- attributes2.push({
40146
- type: "mdxJsxAttribute",
40147
- name: name2,
40148
- value: `_tinaEmbeds.${code3}`
40149
- });
40150
- } else {
40151
- attributes2.push({
40152
- type: "mdxJsxAttribute",
40153
- name: name2,
40154
- value
40155
- });
40156
- }
40123
+ attributes2.push({
40124
+ type: "mdxJsxAttribute",
40125
+ name: name2,
40126
+ value
40127
+ });
40157
40128
  } else {
40158
40129
  throw new Error(
40159
40130
  `Expected string for attribute on field ${field.name}`
@@ -40239,23 +40210,39 @@ function stringifyProps(element, parentField, flatten2, imageCallback, context)
40239
40210
  (value2) => value2.type === "root" && Array.isArray(value2.children),
40240
40211
  `Nested rich-text element is not a valid shape for field ${field.name}`
40241
40212
  );
40242
- const code3 = value.embedCode || generateRandom6LetterString();
40243
40213
  if (field.name === "children") {
40244
- const root2 = rootElement(value, field, imageCallback, context);
40214
+ const root2 = rootElement(value, field, imageCallback);
40245
40215
  root2.children.forEach((child) => {
40246
40216
  children.push(child);
40247
40217
  });
40248
40218
  return;
40249
40219
  } else {
40250
40220
  const stringValue = stringifyMDX(value, field, imageCallback);
40251
- context._tinaEmbeds = context._tinaEmbeds || {};
40252
- context._tinaEmbeds[code3] = stringValue;
40221
+ if (stringValue) {
40222
+ val = stringValue.trim().split("\n").map((str) => ` ${str.trim()}`).join(joiner);
40223
+ }
40224
+ }
40225
+ if (flatten2) {
40226
+ attributes2.push({
40227
+ type: "mdxJsxAttribute",
40228
+ name: name2,
40229
+ value: {
40230
+ type: "mdxJsxAttributeValueExpression",
40231
+ value: `<>${val.trim()}</>`
40232
+ }
40233
+ });
40234
+ } else {
40235
+ attributes2.push({
40236
+ type: "mdxJsxAttribute",
40237
+ name: name2,
40238
+ value: {
40239
+ type: "mdxJsxAttributeValueExpression",
40240
+ value: `<>
40241
+ ${val}
40242
+ </>`
40243
+ }
40244
+ });
40253
40245
  }
40254
- attributes2.push({
40255
- type: "mdxJsxAttribute",
40256
- name: name2,
40257
- value: `_tinaEmbeds.${code3}`
40258
- });
40259
40246
  }
40260
40247
  break;
40261
40248
  default:
@@ -40521,7 +40508,7 @@ var eat2 = (c, field, imageCallback) => {
40521
40508
  }
40522
40509
  if (markToProcess === "inlineCode") {
40523
40510
  if (nonMatchingSiblingIndex) {
40524
- throw new Error(`Marks inside inline code are not supported`);
40511
+ throw new Error("Marks inside inline code are not supported");
40525
40512
  }
40526
40513
  const node2 = {
40527
40514
  type: markToProcess,
@@ -40556,7 +40543,8 @@ var cleanNode = (node2, mark) => {
40556
40543
  const markToClear = {
40557
40544
  strong: "bold",
40558
40545
  emphasis: "italic",
40559
- inlineCode: "code"
40546
+ inlineCode: "code",
40547
+ delete: "strikethrough"
40560
40548
  }[mark];
40561
40549
  Object.entries(node2).map(([key, value]) => {
40562
40550
  if (key !== markToClear) {
@@ -40693,7 +40681,7 @@ ${match.start} /${match.name || template.name} ${match.end}`;
40693
40681
  }
40694
40682
 
40695
40683
  // src/stringify/index.ts
40696
- var stringifyMDX = (value, field, imageCallback, context = {}) => {
40684
+ var stringifyMDX = (value, field, imageCallback) => {
40697
40685
  var _a3, _b;
40698
40686
  if (((_a3 = field.parser) == null ? void 0 : _a3.type) === "markdown") {
40699
40687
  return stringifyMDX2(value, field, imageCallback);
@@ -40709,7 +40697,7 @@ var stringifyMDX = (value, field, imageCallback, context = {}) => {
40709
40697
  return value.children[0].value;
40710
40698
  }
40711
40699
  }
40712
- const tree = rootElement(value, field, imageCallback, context);
40700
+ const tree = rootElement(value, field, imageCallback);
40713
40701
  const res = toTinaMarkdown2(tree, field);
40714
40702
  const templatesWithMatchers = (_b = field.templates) == null ? void 0 : _b.filter(
40715
40703
  (template) => template.match
@@ -40772,11 +40760,11 @@ var toTinaMarkdown2 = (tree, field) => {
40772
40760
  handlers
40773
40761
  });
40774
40762
  };
40775
- var rootElement = (content3, field, imageCallback, context) => {
40763
+ var rootElement = (content3, field, imageCallback) => {
40776
40764
  var _a3;
40777
40765
  const children = [];
40778
40766
  (_a3 = content3.children) == null ? void 0 : _a3.forEach((child) => {
40779
- const value = blockElement(child, field, imageCallback, context);
40767
+ const value = blockElement(child, field, imageCallback);
40780
40768
  if (value) {
40781
40769
  children.push(value);
40782
40770
  }
@@ -40786,7 +40774,7 @@ var rootElement = (content3, field, imageCallback, context) => {
40786
40774
  children
40787
40775
  };
40788
40776
  };
40789
- var blockElement = (content3, field, imageCallback, context) => {
40777
+ var blockElement = (content3, field, imageCallback) => {
40790
40778
  switch (content3.type) {
40791
40779
  case "h1":
40792
40780
  case "h2":
@@ -40849,7 +40837,7 @@ var blockElement = (content3, field, imageCallback, context) => {
40849
40837
  })
40850
40838
  };
40851
40839
  }
40852
- const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback, context);
40840
+ const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback);
40853
40841
  if (useDirective) {
40854
40842
  const name2 = content3.name;
40855
40843
  if (!name2) {
@@ -41020,6 +41008,9 @@ var getMarks = (content3) => {
41020
41008
  if (content3.code) {
41021
41009
  marks.push("inlineCode");
41022
41010
  }
41011
+ if (content3.strikethrough) {
41012
+ marks.push("delete");
41013
+ }
41023
41014
  return marks;
41024
41015
  };
41025
41016
 
@@ -41468,7 +41459,8 @@ var cleanNode2 = (node2, mark) => {
41468
41459
  const markToClear = {
41469
41460
  strong: "bold",
41470
41461
  emphasis: "italic",
41471
- inlineCode: "code"
41462
+ inlineCode: "code",
41463
+ delete: "strikethrough"
41472
41464
  }[mark];
41473
41465
  Object.entries(node2).map(([key, value]) => {
41474
41466
  if (key !== markToClear) {
@@ -43947,7 +43939,9 @@ function mdxJsx2(options = {}) {
43947
43939
  { locations: true }
43948
43940
  );
43949
43941
  } else if (options.acornOptions || options.addResult) {
43950
- throw new Error("Expected an `acorn` instance passed in as `options.acorn`");
43942
+ throw new Error(
43943
+ "Expected an `acorn` instance passed in as `options.acorn`"
43944
+ );
43951
43945
  }
43952
43946
  const patterns = options.patterns || [];
43953
43947
  const flowRules = {};
@@ -44025,7 +44019,7 @@ function compact(tree) {
44025
44019
  var import_lodash = __toESM(require_lodash());
44026
44020
 
44027
44021
  // src/parse/acorn.ts
44028
- var extractAttributes = (attributes2, fields, imageCallback, context) => {
44022
+ var extractAttributes = (attributes2, fields, imageCallback) => {
44029
44023
  const properties = {};
44030
44024
  attributes2 == null ? void 0 : attributes2.forEach((attribute) => {
44031
44025
  assertType(attribute, "mdxJsxAttribute");
@@ -44039,9 +44033,7 @@ var extractAttributes = (attributes2, fields, imageCallback, context) => {
44039
44033
  properties[attribute.name] = extractAttribute(
44040
44034
  attribute,
44041
44035
  field,
44042
- imageCallback,
44043
- context,
44044
- (name2, value) => properties[name2] = value
44036
+ imageCallback
44045
44037
  );
44046
44038
  } catch (e) {
44047
44039
  if (e instanceof Error) {
@@ -44054,7 +44046,7 @@ var extractAttributes = (attributes2, fields, imageCallback, context) => {
44054
44046
  });
44055
44047
  return properties;
44056
44048
  };
44057
- var extractAttribute = (attribute, field, imageCallback, context, addProperty) => {
44049
+ var extractAttribute = (attribute, field, imageCallback) => {
44058
44050
  switch (field.type) {
44059
44051
  case "boolean":
44060
44052
  case "number":
@@ -44064,7 +44056,7 @@ var extractAttribute = (attribute, field, imageCallback, context, addProperty) =
44064
44056
  if (field.list) {
44065
44057
  return extractScalar(extractExpression(attribute), field);
44066
44058
  } else {
44067
- return extractString(attribute, field, context, addProperty);
44059
+ return extractString(attribute, field);
44068
44060
  }
44069
44061
  case "image":
44070
44062
  if (field.list) {
@@ -44074,35 +44066,18 @@ var extractAttribute = (attribute, field, imageCallback, context, addProperty) =
44074
44066
  );
44075
44067
  return values2.split(",").map((value) => imageCallback(value));
44076
44068
  } else {
44077
- const value = extractString(attribute, field, context, addProperty);
44069
+ const value = extractString(attribute, field);
44078
44070
  return imageCallback(value);
44079
44071
  }
44080
44072
  case "reference":
44081
44073
  if (field.list) {
44082
44074
  return extractScalar(extractExpression(attribute), field);
44083
44075
  } else {
44084
- return extractString(attribute, field, context, addProperty);
44076
+ return extractString(attribute, field);
44085
44077
  }
44086
44078
  case "object":
44087
44079
  return extractObject(extractExpression(attribute), field, imageCallback);
44088
44080
  case "rich-text":
44089
- if (attribute.type === "mdxJsxAttribute") {
44090
- if (typeof attribute.value === "string") {
44091
- if (attribute.value.startsWith("_tinaEmbeds")) {
44092
- const embedValue = context == null ? void 0 : context._tinaEmbeds;
44093
- const key = attribute.value.split(".")[1];
44094
- if (typeof key !== "string") {
44095
- throw new Error(`Unable to extract key from embed value`);
44096
- }
44097
- const value = embedValue[key];
44098
- if (typeof value === "string") {
44099
- const ast = parseMDX(value, field, imageCallback, context);
44100
- ast.embedCode = attribute.value.split(".")[1];
44101
- return ast;
44102
- }
44103
- }
44104
- }
44105
- }
44106
44081
  const JSXString = extractRaw(attribute);
44107
44082
  if (JSXString) {
44108
44083
  return parseMDX(JSXString, field, imageCallback);
@@ -44210,21 +44185,9 @@ var extractStatement = (attribute) => {
44210
44185
  }
44211
44186
  throw new Error(`Unable to extract body from expression`);
44212
44187
  };
44213
- var extractString = (attribute, field, context, addProperty) => {
44188
+ var extractString = (attribute, field) => {
44214
44189
  if (attribute.type === "mdxJsxAttribute") {
44215
44190
  if (typeof attribute.value === "string") {
44216
- if (attribute.value.startsWith("_tinaEmbeds")) {
44217
- const embedValue = context == null ? void 0 : context._tinaEmbeds;
44218
- const key = attribute.value.split(".")[1];
44219
- if (typeof key !== "string") {
44220
- throw new Error(`Unable to extract key from embed value`);
44221
- }
44222
- const value = embedValue[key];
44223
- if (typeof value === "string") {
44224
- addProperty == null ? void 0 : addProperty(`_tinaEmbeds.${attribute.name}`, key);
44225
- return value;
44226
- }
44227
- }
44228
44191
  return attribute.value;
44229
44192
  }
44230
44193
  }
@@ -44349,7 +44312,7 @@ function source(value, file) {
44349
44312
  }
44350
44313
 
44351
44314
  // src/parse/mdx.ts
44352
- function mdxJsxElement(node2, field, imageCallback, context) {
44315
+ function mdxJsxElement(node2, field, imageCallback) {
44353
44316
  var _a3;
44354
44317
  try {
44355
44318
  const template = (_a3 = field.templates) == null ? void 0 : _a3.find((template2) => {
@@ -44370,8 +44333,7 @@ function mdxJsxElement(node2, field, imageCallback, context) {
44370
44333
  const props = extractAttributes(
44371
44334
  node2.attributes,
44372
44335
  template.fields,
44373
- imageCallback,
44374
- context
44336
+ imageCallback
44375
44337
  );
44376
44338
  const childField = template.fields.find(
44377
44339
  (field2) => field2.name === "children"
@@ -44441,7 +44403,7 @@ var directiveElement = (node2, field, imageCallback, raw) => {
44441
44403
  };
44442
44404
 
44443
44405
  // src/parse/remarkToPlate.ts
44444
- var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context) => {
44406
+ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
44445
44407
  const mdxJsxElement2 = skipMDXProcess ? (node2) => node2 : mdxJsxElement;
44446
44408
  const content3 = (content4) => {
44447
44409
  var _a3;
@@ -44493,7 +44455,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44493
44455
  case "paragraph":
44494
44456
  return paragraph2(content4);
44495
44457
  case "mdxJsxFlowElement":
44496
- return mdxJsxElement2(content4, field, imageCallback, context);
44458
+ return mdxJsxElement2(content4, field, imageCallback);
44497
44459
  case "thematicBreak":
44498
44460
  return {
44499
44461
  type: "hr",
@@ -44589,8 +44551,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44589
44551
  mdxJsxElement2(
44590
44552
  { ...child, type: "mdxJsxTextElement" },
44591
44553
  field,
44592
- imageCallback,
44593
- context
44554
+ imageCallback
44594
44555
  )
44595
44556
  ]
44596
44557
  };
@@ -44703,7 +44664,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44703
44664
  const staticPhrasingContent = (content4) => {
44704
44665
  switch (content4.type) {
44705
44666
  case "mdxJsxTextElement":
44706
- return mdxJsxElement2(content4, field, imageCallback, context);
44667
+ return mdxJsxElement2(content4, field, imageCallback);
44707
44668
  case "text":
44708
44669
  return text7(content4);
44709
44670
  case "inlineCode":
@@ -44723,12 +44684,14 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44723
44684
  switch (content4.type) {
44724
44685
  case "text":
44725
44686
  return text7(content4);
44687
+ case "delete":
44688
+ return phrashingMark(content4);
44726
44689
  case "link":
44727
44690
  return link2(content4);
44728
44691
  case "image":
44729
44692
  return image2(content4);
44730
44693
  case "mdxJsxTextElement":
44731
- return mdxJsxElement2(content4, field, imageCallback, context);
44694
+ return mdxJsxElement2(content4, field, imageCallback);
44732
44695
  case "emphasis":
44733
44696
  return phrashingMark(content4);
44734
44697
  case "strong":
@@ -44748,7 +44711,9 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44748
44711
  content4.position
44749
44712
  );
44750
44713
  default:
44751
- throw new Error(`PhrasingContent: ${content4.type} is not yet supported`);
44714
+ throw new Error(
44715
+ `PhrasingContent: ${content4.type} is not yet supported`
44716
+ );
44752
44717
  }
44753
44718
  };
44754
44719
  const breakContent = () => {
@@ -44787,6 +44752,17 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
44787
44752
  });
44788
44753
  break;
44789
44754
  }
44755
+ case "delete": {
44756
+ const children = (0, import_lodash.default)(
44757
+ node2.children.map(
44758
+ (child) => phrashingMark(child, [...marks, "strikethrough"])
44759
+ )
44760
+ );
44761
+ children.forEach((child) => {
44762
+ accum.push(child);
44763
+ });
44764
+ break;
44765
+ }
44790
44766
  case "strong": {
44791
44767
  const children = (0, import_lodash.default)(
44792
44768
  node2.children.map((child) => phrashingMark(child, [...marks, "bold"]))
@@ -44990,7 +44966,7 @@ var mdxToAst = (value) => {
44990
44966
  return remark().use(remarkMdx).use(remarkGfm).parse(value);
44991
44967
  };
44992
44968
  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";
44993
- var parseMDX = (value, field, imageCallback, context) => {
44969
+ var parseMDX = (value, field, imageCallback) => {
44994
44970
  var _a3, _b;
44995
44971
  if (!value) {
44996
44972
  return { type: "root", children: [] };
@@ -45016,7 +44992,7 @@ var parseMDX = (value, field, imageCallback, context) => {
45016
44992
  });
45017
44993
  tree = mdxToAst(preprocessedString);
45018
44994
  if (tree) {
45019
- return remarkToSlate(tree, field, imageCallback, value, false, context);
44995
+ return remarkToSlate(tree, field, imageCallback, value);
45020
44996
  } else {
45021
44997
  return { type: "root", children: [] };
45022
44998
  }