@tinacms/mdx 0.0.0-c852462-20250131014229 → 0.0.0-c965b5f-20250426163441

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.
@@ -23382,7 +23382,9 @@ function mdxJsxFromMarkdown2({ patterns }) {
23382
23382
  if (attribute.name === "") {
23383
23383
  attribute.name = "_value";
23384
23384
  }
23385
- attribute.value = parseEntities(this.resume(), { nonTerminated: false });
23385
+ attribute.value = parseEntities(this.resume(), {
23386
+ nonTerminated: false
23387
+ });
23386
23388
  }
23387
23389
  }
23388
23390
  };
@@ -23634,7 +23636,9 @@ var mdxJsxToMarkdown2 = function(options) {
23634
23636
  if (!emptyChildren) {
23635
23637
  tracker.shift(2);
23636
23638
  value += tracker.move("\n");
23637
- value += tracker.move(containerFlow(node2, context, tracker.current()));
23639
+ value += tracker.move(
23640
+ containerFlow(node2, context, tracker.current())
23641
+ );
23638
23642
  value += tracker.move("\n");
23639
23643
  }
23640
23644
  } else {
@@ -38154,22 +38158,10 @@ var Xh = Q({ "src/language-js/parse/acorn-and-espree.js"(a, u) {
38154
38158
  var mc = Xh();
38155
38159
 
38156
38160
  // src/stringify/acorn.ts
38157
- function generateRandom6LetterString() {
38158
- const characters = "abcdefghijklmnopqrstuvwxyz";
38159
- let result = "";
38160
- for (let i = 0; i < 6; i++) {
38161
- const randomIndex = Math.floor(Math.random() * characters.length);
38162
- result += characters[randomIndex];
38163
- }
38164
- return result;
38165
- }
38166
- function isMultiline(input) {
38167
- return input.includes("\n") || input.includes("\r");
38168
- }
38169
- var stringifyPropsInline = (element2, field, imageCallback, context) => {
38170
- return stringifyProps(element2, field, true, imageCallback, context || {});
38161
+ var stringifyPropsInline = (element2, field, imageCallback) => {
38162
+ return stringifyProps(element2, field, true, imageCallback);
38171
38163
  };
38172
- function stringifyProps(element2, parentField, flatten2, imageCallback, context) {
38164
+ function stringifyProps(element2, parentField, flatten2, imageCallback) {
38173
38165
  const attributes2 = [];
38174
38166
  const children = [];
38175
38167
  let template;
@@ -38193,16 +38185,6 @@ function stringifyProps(element2, parentField, flatten2, imageCallback, context)
38193
38185
  if (template.fields.find((f) => f.name === "children")) {
38194
38186
  directiveType = "block";
38195
38187
  }
38196
- const embedCodes = {};
38197
- for (const [embedKey, value] of Object.entries(element2.props)) {
38198
- if (embedKey.startsWith("_tinaEmbeds")) {
38199
- const key = embedKey.replace("_tinaEmbeds.", "");
38200
- embedCodes[key] = value;
38201
- }
38202
- }
38203
- for (const key of Object.keys(embedCodes)) {
38204
- delete element2.props[`_tinaEmbeds.${key}`];
38205
- }
38206
38188
  useDirective = !!template.match;
38207
38189
  Object.entries(element2.props).forEach(([name2, value]) => {
38208
38190
  if (typeof template === "string") {
@@ -38253,22 +38235,11 @@ function stringifyProps(element2, parentField, flatten2, imageCallback, context)
38253
38235
  }
38254
38236
  } else {
38255
38237
  if (typeof value === "string") {
38256
- if (isMultiline(value)) {
38257
- const code3 = embedCodes[name2] || generateRandom6LetterString();
38258
- context._tinaEmbeds = context._tinaEmbeds || {};
38259
- context._tinaEmbeds[code3] = value;
38260
- attributes2.push({
38261
- type: "mdxJsxAttribute",
38262
- name: name2,
38263
- value: `_tinaEmbeds.${code3}`
38264
- });
38265
- } else {
38266
- attributes2.push({
38267
- type: "mdxJsxAttribute",
38268
- name: name2,
38269
- value
38270
- });
38271
- }
38238
+ attributes2.push({
38239
+ type: "mdxJsxAttribute",
38240
+ name: name2,
38241
+ value
38242
+ });
38272
38243
  } else {
38273
38244
  throw new Error(
38274
38245
  `Expected string for attribute on field ${field.name}`
@@ -38354,23 +38325,39 @@ function stringifyProps(element2, parentField, flatten2, imageCallback, context)
38354
38325
  (value2) => value2.type === "root" && Array.isArray(value2.children),
38355
38326
  `Nested rich-text element is not a valid shape for field ${field.name}`
38356
38327
  );
38357
- const code3 = value.embedCode || generateRandom6LetterString();
38358
38328
  if (field.name === "children") {
38359
- const root2 = rootElement(value, field, imageCallback, context);
38329
+ const root2 = rootElement(value, field, imageCallback);
38360
38330
  root2.children.forEach((child) => {
38361
38331
  children.push(child);
38362
38332
  });
38363
38333
  return;
38364
38334
  } else {
38365
38335
  const stringValue = stringifyMDX(value, field, imageCallback);
38366
- context._tinaEmbeds = context._tinaEmbeds || {};
38367
- context._tinaEmbeds[code3] = stringValue;
38336
+ if (stringValue) {
38337
+ val = stringValue.trim().split("\n").map((str) => ` ${str.trim()}`).join(joiner);
38338
+ }
38339
+ }
38340
+ if (flatten2) {
38341
+ attributes2.push({
38342
+ type: "mdxJsxAttribute",
38343
+ name: name2,
38344
+ value: {
38345
+ type: "mdxJsxAttributeValueExpression",
38346
+ value: `<>${val.trim()}</>`
38347
+ }
38348
+ });
38349
+ } else {
38350
+ attributes2.push({
38351
+ type: "mdxJsxAttribute",
38352
+ name: name2,
38353
+ value: {
38354
+ type: "mdxJsxAttributeValueExpression",
38355
+ value: `<>
38356
+ ${val}
38357
+ </>`
38358
+ }
38359
+ });
38368
38360
  }
38369
- attributes2.push({
38370
- type: "mdxJsxAttribute",
38371
- name: name2,
38372
- value: `_tinaEmbeds.${code3}`
38373
- });
38374
38361
  }
38375
38362
  break;
38376
38363
  default:
@@ -38635,7 +38622,7 @@ var eat2 = (c, field, imageCallback) => {
38635
38622
  }
38636
38623
  if (markToProcess === "inlineCode") {
38637
38624
  if (nonMatchingSiblingIndex) {
38638
- throw new Error(`Marks inside inline code are not supported`);
38625
+ throw new Error("Marks inside inline code are not supported");
38639
38626
  }
38640
38627
  const node2 = {
38641
38628
  type: markToProcess,
@@ -38670,7 +38657,8 @@ var cleanNode = (node2, mark) => {
38670
38657
  const markToClear = {
38671
38658
  strong: "bold",
38672
38659
  emphasis: "italic",
38673
- inlineCode: "code"
38660
+ inlineCode: "code",
38661
+ delete: "strikethrough"
38674
38662
  }[mark];
38675
38663
  Object.entries(node2).map(([key, value]) => {
38676
38664
  if (key !== markToClear) {
@@ -38807,7 +38795,7 @@ ${match.start} /${match.name || template.name} ${match.end}`;
38807
38795
  }
38808
38796
 
38809
38797
  // src/stringify/index.ts
38810
- var stringifyMDX = (value, field, imageCallback, context = {}) => {
38798
+ var stringifyMDX = (value, field, imageCallback) => {
38811
38799
  if (field.parser?.type === "markdown") {
38812
38800
  return stringifyMDX2(value, field, imageCallback);
38813
38801
  }
@@ -38822,7 +38810,7 @@ var stringifyMDX = (value, field, imageCallback, context = {}) => {
38822
38810
  return value.children[0].value;
38823
38811
  }
38824
38812
  }
38825
- const tree = rootElement(value, field, imageCallback, context);
38813
+ const tree = rootElement(value, field, imageCallback);
38826
38814
  const res = toTinaMarkdown2(tree, field);
38827
38815
  const templatesWithMatchers = field.templates?.filter(
38828
38816
  (template) => template.match
@@ -38883,10 +38871,10 @@ var toTinaMarkdown2 = (tree, field) => {
38883
38871
  handlers
38884
38872
  });
38885
38873
  };
38886
- var rootElement = (content3, field, imageCallback, context) => {
38874
+ var rootElement = (content3, field, imageCallback) => {
38887
38875
  const children = [];
38888
38876
  content3.children?.forEach((child) => {
38889
- const value = blockElement(child, field, imageCallback, context);
38877
+ const value = blockElement(child, field, imageCallback);
38890
38878
  if (value) {
38891
38879
  children.push(value);
38892
38880
  }
@@ -38896,7 +38884,7 @@ var rootElement = (content3, field, imageCallback, context) => {
38896
38884
  children
38897
38885
  };
38898
38886
  };
38899
- var blockElement = (content3, field, imageCallback, context) => {
38887
+ var blockElement = (content3, field, imageCallback) => {
38900
38888
  switch (content3.type) {
38901
38889
  case "h1":
38902
38890
  case "h2":
@@ -38958,7 +38946,7 @@ var blockElement = (content3, field, imageCallback, context) => {
38958
38946
  })
38959
38947
  };
38960
38948
  }
38961
- const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback, context);
38949
+ const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback);
38962
38950
  if (useDirective) {
38963
38951
  const name2 = content3.name;
38964
38952
  if (!name2) {
@@ -39128,6 +39116,9 @@ var getMarks = (content3) => {
39128
39116
  if (content3.code) {
39129
39117
  marks.push("inlineCode");
39130
39118
  }
39119
+ if (content3.strikethrough) {
39120
+ marks.push("delete");
39121
+ }
39131
39122
  return marks;
39132
39123
  };
39133
39124
 
@@ -39572,7 +39563,8 @@ var cleanNode2 = (node2, mark) => {
39572
39563
  const markToClear = {
39573
39564
  strong: "bold",
39574
39565
  emphasis: "italic",
39575
- inlineCode: "code"
39566
+ inlineCode: "code",
39567
+ delete: "strikethrough"
39576
39568
  }[mark];
39577
39569
  Object.entries(node2).map(([key, value]) => {
39578
39570
  if (key !== markToClear) {
@@ -42048,7 +42040,9 @@ function mdxJsx2(options = {}) {
42048
42040
  { locations: true }
42049
42041
  );
42050
42042
  } else if (options.acornOptions || options.addResult) {
42051
- throw new Error("Expected an `acorn` instance passed in as `options.acorn`");
42043
+ throw new Error(
42044
+ "Expected an `acorn` instance passed in as `options.acorn`"
42045
+ );
42052
42046
  }
42053
42047
  const patterns = options.patterns || [];
42054
42048
  const flowRules = {};
@@ -42125,7 +42119,7 @@ function compact(tree) {
42125
42119
  var import_lodash = __toESM(require_lodash());
42126
42120
 
42127
42121
  // src/parse/acorn.ts
42128
- var extractAttributes = (attributes2, fields, imageCallback, context) => {
42122
+ var extractAttributes = (attributes2, fields, imageCallback) => {
42129
42123
  const properties = {};
42130
42124
  attributes2?.forEach((attribute) => {
42131
42125
  assertType(attribute, "mdxJsxAttribute");
@@ -42139,9 +42133,7 @@ var extractAttributes = (attributes2, fields, imageCallback, context) => {
42139
42133
  properties[attribute.name] = extractAttribute(
42140
42134
  attribute,
42141
42135
  field,
42142
- imageCallback,
42143
- context,
42144
- (name2, value) => properties[name2] = value
42136
+ imageCallback
42145
42137
  );
42146
42138
  } catch (e) {
42147
42139
  if (e instanceof Error) {
@@ -42154,7 +42146,7 @@ var extractAttributes = (attributes2, fields, imageCallback, context) => {
42154
42146
  });
42155
42147
  return properties;
42156
42148
  };
42157
- var extractAttribute = (attribute, field, imageCallback, context, addProperty) => {
42149
+ var extractAttribute = (attribute, field, imageCallback) => {
42158
42150
  switch (field.type) {
42159
42151
  case "boolean":
42160
42152
  case "number":
@@ -42164,7 +42156,7 @@ var extractAttribute = (attribute, field, imageCallback, context, addProperty) =
42164
42156
  if (field.list) {
42165
42157
  return extractScalar(extractExpression(attribute), field);
42166
42158
  } else {
42167
- return extractString(attribute, field, context, addProperty);
42159
+ return extractString(attribute, field);
42168
42160
  }
42169
42161
  case "image":
42170
42162
  if (field.list) {
@@ -42174,35 +42166,18 @@ var extractAttribute = (attribute, field, imageCallback, context, addProperty) =
42174
42166
  );
42175
42167
  return values2.split(",").map((value) => imageCallback(value));
42176
42168
  } else {
42177
- const value = extractString(attribute, field, context, addProperty);
42169
+ const value = extractString(attribute, field);
42178
42170
  return imageCallback(value);
42179
42171
  }
42180
42172
  case "reference":
42181
42173
  if (field.list) {
42182
42174
  return extractScalar(extractExpression(attribute), field);
42183
42175
  } else {
42184
- return extractString(attribute, field, context, addProperty);
42176
+ return extractString(attribute, field);
42185
42177
  }
42186
42178
  case "object":
42187
42179
  return extractObject(extractExpression(attribute), field, imageCallback);
42188
42180
  case "rich-text":
42189
- if (attribute.type === "mdxJsxAttribute") {
42190
- if (typeof attribute.value === "string") {
42191
- if (attribute.value.startsWith("_tinaEmbeds")) {
42192
- const embedValue = context?._tinaEmbeds;
42193
- const key = attribute.value.split(".")[1];
42194
- if (typeof key !== "string") {
42195
- throw new Error(`Unable to extract key from embed value`);
42196
- }
42197
- const value = embedValue[key];
42198
- if (typeof value === "string") {
42199
- const ast = parseMDX(value, field, imageCallback, context);
42200
- ast.embedCode = attribute.value.split(".")[1];
42201
- return ast;
42202
- }
42203
- }
42204
- }
42205
- }
42206
42181
  const JSXString = extractRaw(attribute);
42207
42182
  if (JSXString) {
42208
42183
  return parseMDX(JSXString, field, imageCallback);
@@ -42308,21 +42283,9 @@ var extractStatement = (attribute) => {
42308
42283
  }
42309
42284
  throw new Error(`Unable to extract body from expression`);
42310
42285
  };
42311
- var extractString = (attribute, field, context, addProperty) => {
42286
+ var extractString = (attribute, field) => {
42312
42287
  if (attribute.type === "mdxJsxAttribute") {
42313
42288
  if (typeof attribute.value === "string") {
42314
- if (attribute.value.startsWith("_tinaEmbeds")) {
42315
- const embedValue = context?._tinaEmbeds;
42316
- const key = attribute.value.split(".")[1];
42317
- if (typeof key !== "string") {
42318
- throw new Error(`Unable to extract key from embed value`);
42319
- }
42320
- const value = embedValue[key];
42321
- if (typeof value === "string") {
42322
- addProperty?.(`_tinaEmbeds.${attribute.name}`, key);
42323
- return value;
42324
- }
42325
- }
42326
42289
  return attribute.value;
42327
42290
  }
42328
42291
  }
@@ -42447,7 +42410,7 @@ function source(value, file) {
42447
42410
  }
42448
42411
 
42449
42412
  // src/parse/mdx.ts
42450
- function mdxJsxElement(node2, field, imageCallback, context) {
42413
+ function mdxJsxElement(node2, field, imageCallback) {
42451
42414
  try {
42452
42415
  const template = field.templates?.find((template2) => {
42453
42416
  const templateName = typeof template2 === "string" ? template2 : template2.name;
@@ -42467,8 +42430,7 @@ function mdxJsxElement(node2, field, imageCallback, context) {
42467
42430
  const props = extractAttributes(
42468
42431
  node2.attributes,
42469
42432
  template.fields,
42470
- imageCallback,
42471
- context
42433
+ imageCallback
42472
42434
  );
42473
42435
  const childField = template.fields.find(
42474
42436
  (field2) => field2.name === "children"
@@ -42536,7 +42498,7 @@ var directiveElement = (node2, field, imageCallback, raw) => {
42536
42498
  };
42537
42499
 
42538
42500
  // src/parse/remarkToPlate.ts
42539
- var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context) => {
42501
+ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
42540
42502
  const mdxJsxElement2 = skipMDXProcess ? (node2) => node2 : mdxJsxElement;
42541
42503
  const content3 = (content4) => {
42542
42504
  switch (content4.type) {
@@ -42587,7 +42549,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42587
42549
  case "paragraph":
42588
42550
  return paragraph2(content4);
42589
42551
  case "mdxJsxFlowElement":
42590
- return mdxJsxElement2(content4, field, imageCallback, context);
42552
+ return mdxJsxElement2(content4, field, imageCallback);
42591
42553
  case "thematicBreak":
42592
42554
  return {
42593
42555
  type: "hr",
@@ -42683,8 +42645,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42683
42645
  mdxJsxElement2(
42684
42646
  { ...child, type: "mdxJsxTextElement" },
42685
42647
  field,
42686
- imageCallback,
42687
- context
42648
+ imageCallback
42688
42649
  )
42689
42650
  ]
42690
42651
  };
@@ -42797,7 +42758,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42797
42758
  const staticPhrasingContent = (content4) => {
42798
42759
  switch (content4.type) {
42799
42760
  case "mdxJsxTextElement":
42800
- return mdxJsxElement2(content4, field, imageCallback, context);
42761
+ return mdxJsxElement2(content4, field, imageCallback);
42801
42762
  case "text":
42802
42763
  return text7(content4);
42803
42764
  case "inlineCode":
@@ -42817,12 +42778,14 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42817
42778
  switch (content4.type) {
42818
42779
  case "text":
42819
42780
  return text7(content4);
42781
+ case "delete":
42782
+ return phrashingMark(content4);
42820
42783
  case "link":
42821
42784
  return link2(content4);
42822
42785
  case "image":
42823
42786
  return image2(content4);
42824
42787
  case "mdxJsxTextElement":
42825
- return mdxJsxElement2(content4, field, imageCallback, context);
42788
+ return mdxJsxElement2(content4, field, imageCallback);
42826
42789
  case "emphasis":
42827
42790
  return phrashingMark(content4);
42828
42791
  case "strong":
@@ -42842,7 +42805,9 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42842
42805
  content4.position
42843
42806
  );
42844
42807
  default:
42845
- throw new Error(`PhrasingContent: ${content4.type} is not yet supported`);
42808
+ throw new Error(
42809
+ `PhrasingContent: ${content4.type} is not yet supported`
42810
+ );
42846
42811
  }
42847
42812
  };
42848
42813
  const breakContent = () => {
@@ -42881,6 +42846,17 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context)
42881
42846
  });
42882
42847
  break;
42883
42848
  }
42849
+ case "delete": {
42850
+ const children = (0, import_lodash.default)(
42851
+ node2.children.map(
42852
+ (child) => phrashingMark(child, [...marks, "strikethrough"])
42853
+ )
42854
+ );
42855
+ children.forEach((child) => {
42856
+ accum.push(child);
42857
+ });
42858
+ break;
42859
+ }
42884
42860
  case "strong": {
42885
42861
  const children = (0, import_lodash.default)(
42886
42862
  node2.children.map((child) => phrashingMark(child, [...marks, "bold"]))
@@ -43084,7 +43060,7 @@ var mdxToAst = (value) => {
43084
43060
  return remark().use(remarkMdx).use(remarkGfm).parse(value);
43085
43061
  };
43086
43062
  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";
43087
- var parseMDX = (value, field, imageCallback, context) => {
43063
+ var parseMDX = (value, field, imageCallback) => {
43088
43064
  if (!value) {
43089
43065
  return { type: "root", children: [] };
43090
43066
  }
@@ -43109,7 +43085,7 @@ var parseMDX = (value, field, imageCallback, context) => {
43109
43085
  });
43110
43086
  tree = mdxToAst(preprocessedString);
43111
43087
  if (tree) {
43112
- return remarkToSlate(tree, field, imageCallback, value, false, context);
43088
+ return remarkToSlate(tree, field, imageCallback, value);
43113
43089
  } else {
43114
43090
  return { type: "root", children: [] };
43115
43091
  }
package/dist/index.d.ts CHANGED
@@ -1,10 +1 @@
1
- /**
2
-
3
-
4
-
5
- */
6
- import { parseMDX } from './parse';
7
- import { stringifyMDX } from './stringify';
8
- export * from './parse/plate';
9
- export { parseMDX };
10
- export { stringifyMDX };
1
+ export * from "../src/index"