@tinacms/mdx 1.6.2 → 1.6.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.
- package/dist/index.js +60 -89
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -25144,9 +25144,8 @@ function mdxJsxFromMarkdown2({ patterns }) {
|
|
|
25144
25144
|
this.buffer();
|
|
25145
25145
|
};
|
|
25146
25146
|
const data2 = function(token) {
|
|
25147
|
-
|
|
25148
|
-
|
|
25149
|
-
(_f = (_e = (_d2 = this.config) == null ? void 0 : _d2.exit) == null ? void 0 : _e.data) == null ? void 0 : _f.call(this, token);
|
|
25147
|
+
this.config?.enter?.data?.call(this, token);
|
|
25148
|
+
this.config?.exit?.data?.call(this, token);
|
|
25150
25149
|
};
|
|
25151
25150
|
const enterMdxJsxTag = function(token) {
|
|
25152
25151
|
const tag = {
|
|
@@ -25164,7 +25163,7 @@ function mdxJsxFromMarkdown2({ patterns }) {
|
|
|
25164
25163
|
const enterMdxJsxTagClosingMarker = function(token) {
|
|
25165
25164
|
const stack = this.getData("mdxJsxTagStack");
|
|
25166
25165
|
const tag = this.getData("mdxJsxTag");
|
|
25167
|
-
if (
|
|
25166
|
+
if (stack?.length === 0) {
|
|
25168
25167
|
if (tag) {
|
|
25169
25168
|
tag.shouldFallback = true;
|
|
25170
25169
|
}
|
|
@@ -25175,7 +25174,7 @@ function mdxJsxFromMarkdown2({ patterns }) {
|
|
|
25175
25174
|
};
|
|
25176
25175
|
const enterMdxJsxTagSelfClosingMarker = function(token) {
|
|
25177
25176
|
const tag = this.getData("mdxJsxTag");
|
|
25178
|
-
if (tag
|
|
25177
|
+
if (tag?.close) {
|
|
25179
25178
|
throw new VFileMessage(
|
|
25180
25179
|
"Unexpected self-closing slash `/` in closing tag, expected the end of the tag",
|
|
25181
25180
|
{ start: token.start, end: token.end },
|
|
@@ -25307,7 +25306,7 @@ function mdxJsxFromMarkdown2({ patterns }) {
|
|
|
25307
25306
|
stack.pop();
|
|
25308
25307
|
} else {
|
|
25309
25308
|
const pattern = patterns.find((pattern2) => pattern2.name === tag.name);
|
|
25310
|
-
const tagName =
|
|
25309
|
+
const tagName = pattern?.templateName || tag.name;
|
|
25311
25310
|
this.enter(
|
|
25312
25311
|
{
|
|
25313
25312
|
type: token.type === "mdxJsxTextTag" ? "mdxJsxTextElement" : "mdxJsxFlowElement",
|
|
@@ -25437,12 +25436,11 @@ var mdxJsxToMarkdown2 = function(options) {
|
|
|
25437
25436
|
);
|
|
25438
25437
|
}
|
|
25439
25438
|
const mdxElement = function(node2, _, context, safeOptions) {
|
|
25440
|
-
var _a3, _b;
|
|
25441
25439
|
const pattern = patterns.find((p) => p.templateName === node2.name);
|
|
25442
25440
|
if (!pattern) {
|
|
25443
25441
|
return "";
|
|
25444
25442
|
}
|
|
25445
|
-
const patternName = pattern.name ||
|
|
25443
|
+
const patternName = pattern.name || pattern?.templateName;
|
|
25446
25444
|
const tracker = track(safeOptions);
|
|
25447
25445
|
const selfClosing = pattern.leaf;
|
|
25448
25446
|
const exit3 = context.enter(node2.type);
|
|
@@ -25456,10 +25454,10 @@ var mdxJsxToMarkdown2 = function(options) {
|
|
|
25456
25454
|
while (++index2 < node2.attributes.length) {
|
|
25457
25455
|
const attribute = node2.attributes[index2];
|
|
25458
25456
|
let result;
|
|
25459
|
-
if (
|
|
25457
|
+
if (attribute?.type === "mdxJsxExpressionAttribute") {
|
|
25460
25458
|
result = "{" + (attribute.value || "") + "}";
|
|
25461
25459
|
} else {
|
|
25462
|
-
if (!
|
|
25460
|
+
if (!attribute?.name) {
|
|
25463
25461
|
throw new Error("Cannot serialize attribute w/o name");
|
|
25464
25462
|
}
|
|
25465
25463
|
const value2 = attribute.value;
|
|
@@ -25512,7 +25510,7 @@ var mdxJsxToMarkdown2 = function(options) {
|
|
|
25512
25510
|
value += tracker.move(" " + pattern.end);
|
|
25513
25511
|
if (node2.children) {
|
|
25514
25512
|
if (node2.type === "mdxJsxFlowElement") {
|
|
25515
|
-
const emptyChildren = node2.children.length === 1 &&
|
|
25513
|
+
const emptyChildren = node2.children.length === 1 && node2.children[0]?.type === "paragraph" && node2.children[0].children[0]?.type === "text" && node2.children[0].children[0].value === "";
|
|
25516
25514
|
if (!emptyChildren) {
|
|
25517
25515
|
tracker.shift(2);
|
|
25518
25516
|
value += tracker.move("\n");
|
|
@@ -25567,7 +25565,7 @@ var getFieldPatterns = (field) => {
|
|
|
25567
25565
|
const patterns = [];
|
|
25568
25566
|
const templates = [];
|
|
25569
25567
|
hoistAllTemplates(field, templates);
|
|
25570
|
-
templates
|
|
25568
|
+
templates?.forEach((template) => {
|
|
25571
25569
|
if (typeof template === "string") {
|
|
25572
25570
|
throw new Error("Global templates not supported");
|
|
25573
25571
|
}
|
|
@@ -25585,8 +25583,7 @@ var getFieldPatterns = (field) => {
|
|
|
25585
25583
|
return patterns;
|
|
25586
25584
|
};
|
|
25587
25585
|
var hoistAllTemplates = (field, templates = []) => {
|
|
25588
|
-
|
|
25589
|
-
(_a3 = field.templates) == null ? void 0 : _a3.forEach((template) => {
|
|
25586
|
+
field.templates?.forEach((template) => {
|
|
25590
25587
|
if (typeof template === "string") {
|
|
25591
25588
|
throw new Error("Global templates not supported");
|
|
25592
25589
|
}
|
|
@@ -25605,14 +25602,13 @@ var toTinaMarkdown = (tree, field) => {
|
|
|
25605
25602
|
const patterns = getFieldPatterns(field);
|
|
25606
25603
|
const handlers = {};
|
|
25607
25604
|
handlers["text"] = (node2, parent, context, safeOptions) => {
|
|
25608
|
-
var _a3;
|
|
25609
25605
|
context.unsafe = context.unsafe.filter((unsafeItem) => {
|
|
25610
25606
|
if (unsafeItem.character === " " && unsafeItem.inConstruct === "phrasing") {
|
|
25611
25607
|
return false;
|
|
25612
25608
|
}
|
|
25613
25609
|
return true;
|
|
25614
25610
|
});
|
|
25615
|
-
if (
|
|
25611
|
+
if (field.parser?.type === "markdown") {
|
|
25616
25612
|
if (field.parser.skipEscaping === "all") {
|
|
25617
25613
|
return node2.value;
|
|
25618
25614
|
}
|
|
@@ -40044,22 +40040,20 @@ var stringifyPropsInline = (element, field, imageCallback) => {
|
|
|
40044
40040
|
return stringifyProps(element, field, true, imageCallback);
|
|
40045
40041
|
};
|
|
40046
40042
|
function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
40047
|
-
var _a3, _b;
|
|
40048
40043
|
const attributes2 = [];
|
|
40049
40044
|
const children = [];
|
|
40050
40045
|
let template;
|
|
40051
40046
|
let useDirective = false;
|
|
40052
40047
|
let directiveType = "leaf";
|
|
40053
|
-
template =
|
|
40048
|
+
template = parentField.templates?.find((template2) => {
|
|
40054
40049
|
if (typeof template2 === "string") {
|
|
40055
40050
|
throw new Error("Global templates not supported");
|
|
40056
40051
|
}
|
|
40057
40052
|
return template2.name === element.name;
|
|
40058
40053
|
});
|
|
40059
40054
|
if (!template) {
|
|
40060
|
-
template =
|
|
40061
|
-
|
|
40062
|
-
const templateName = (_a4 = template2 == null ? void 0 : template2.match) == null ? void 0 : _a4.name;
|
|
40055
|
+
template = parentField.templates?.find((template2) => {
|
|
40056
|
+
const templateName = template2?.match?.name;
|
|
40063
40057
|
return templateName === element.name;
|
|
40064
40058
|
});
|
|
40065
40059
|
}
|
|
@@ -40071,11 +40065,10 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
40071
40065
|
}
|
|
40072
40066
|
useDirective = !!template.match;
|
|
40073
40067
|
Object.entries(element.props).forEach(([name2, value]) => {
|
|
40074
|
-
var _a4;
|
|
40075
40068
|
if (typeof template === "string") {
|
|
40076
40069
|
throw new Error(`Unable to find template for JSX element ${name2}`);
|
|
40077
40070
|
}
|
|
40078
|
-
const field =
|
|
40071
|
+
const field = template?.fields?.find((field2) => field2.name === name2);
|
|
40079
40072
|
if (!field) {
|
|
40080
40073
|
if (name2 === "children") {
|
|
40081
40074
|
return;
|
|
@@ -40355,11 +40348,11 @@ var matches = (a, b) => {
|
|
|
40355
40348
|
};
|
|
40356
40349
|
var replaceLinksWithTextNodes = (content3) => {
|
|
40357
40350
|
const newItems = [];
|
|
40358
|
-
content3
|
|
40351
|
+
content3?.forEach((item) => {
|
|
40359
40352
|
if (item.type === "a") {
|
|
40360
40353
|
if (item.children.length === 1) {
|
|
40361
40354
|
const firstChild = item.children[0];
|
|
40362
|
-
if (
|
|
40355
|
+
if (firstChild?.type === "text") {
|
|
40363
40356
|
newItems.push({
|
|
40364
40357
|
...firstChild,
|
|
40365
40358
|
linkifyTextNode: (a) => {
|
|
@@ -40433,13 +40426,12 @@ var text5 = (content3) => {
|
|
|
40433
40426
|
};
|
|
40434
40427
|
};
|
|
40435
40428
|
var eat2 = (c, field, imageCallback) => {
|
|
40436
|
-
var _a3, _b;
|
|
40437
40429
|
const content3 = replaceLinksWithTextNodes(c);
|
|
40438
40430
|
const first = content3[0];
|
|
40439
40431
|
if (!first) {
|
|
40440
40432
|
return [];
|
|
40441
40433
|
}
|
|
40442
|
-
if (first &&
|
|
40434
|
+
if (first && first?.type !== "text") {
|
|
40443
40435
|
if (first.type === "a") {
|
|
40444
40436
|
return [
|
|
40445
40437
|
{
|
|
@@ -40515,7 +40507,7 @@ var eat2 = (c, field, imageCallback) => {
|
|
|
40515
40507
|
value: first.text
|
|
40516
40508
|
};
|
|
40517
40509
|
return [
|
|
40518
|
-
|
|
40510
|
+
first.linkifyTextNode?.(node2) ?? node2,
|
|
40519
40511
|
...eat2(content3.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
40520
40512
|
];
|
|
40521
40513
|
}
|
|
@@ -40682,8 +40674,7 @@ ${match.start} /${match.name || template.name} ${match.end}`;
|
|
|
40682
40674
|
|
|
40683
40675
|
// src/stringify/index.ts
|
|
40684
40676
|
var stringifyMDX = (value, field, imageCallback) => {
|
|
40685
|
-
|
|
40686
|
-
if (((_a3 = field.parser) == null ? void 0 : _a3.type) === "markdown") {
|
|
40677
|
+
if (field.parser?.type === "markdown") {
|
|
40687
40678
|
return stringifyMDX2(value, field, imageCallback);
|
|
40688
40679
|
}
|
|
40689
40680
|
if (!value) {
|
|
@@ -40692,18 +40683,18 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
40692
40683
|
if (typeof value === "string") {
|
|
40693
40684
|
throw new Error("Expected an object to stringify, but received a string");
|
|
40694
40685
|
}
|
|
40695
|
-
if (value
|
|
40696
|
-
if (
|
|
40686
|
+
if (value?.children[0]) {
|
|
40687
|
+
if (value?.children[0].type === "invalid_markdown") {
|
|
40697
40688
|
return value.children[0].value;
|
|
40698
40689
|
}
|
|
40699
40690
|
}
|
|
40700
40691
|
const tree = rootElement(value, field, imageCallback);
|
|
40701
40692
|
const res = toTinaMarkdown2(tree, field);
|
|
40702
|
-
const templatesWithMatchers =
|
|
40693
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
40703
40694
|
(template) => template.match
|
|
40704
40695
|
);
|
|
40705
40696
|
let preprocessedString = res;
|
|
40706
|
-
templatesWithMatchers
|
|
40697
|
+
templatesWithMatchers?.forEach((template) => {
|
|
40707
40698
|
if (typeof template === "string") {
|
|
40708
40699
|
throw new Error("Global templates are not supported");
|
|
40709
40700
|
}
|
|
@@ -40714,9 +40705,8 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
40714
40705
|
return preprocessedString;
|
|
40715
40706
|
};
|
|
40716
40707
|
var toTinaMarkdown2 = (tree, field) => {
|
|
40717
|
-
var _a3;
|
|
40718
40708
|
const patterns = [];
|
|
40719
|
-
|
|
40709
|
+
field.templates?.forEach((template) => {
|
|
40720
40710
|
if (typeof template === "string") {
|
|
40721
40711
|
return;
|
|
40722
40712
|
}
|
|
@@ -40728,14 +40718,13 @@ var toTinaMarkdown2 = (tree, field) => {
|
|
|
40728
40718
|
});
|
|
40729
40719
|
const handlers = {};
|
|
40730
40720
|
handlers["text"] = (node2, parent, context, safeOptions) => {
|
|
40731
|
-
var _a4;
|
|
40732
40721
|
context.unsafe = context.unsafe.filter((unsafeItem) => {
|
|
40733
40722
|
if (unsafeItem.character === " " && unsafeItem.inConstruct === "phrasing") {
|
|
40734
40723
|
return false;
|
|
40735
40724
|
}
|
|
40736
40725
|
return true;
|
|
40737
40726
|
});
|
|
40738
|
-
if (
|
|
40727
|
+
if (field.parser?.type === "markdown") {
|
|
40739
40728
|
if (field.parser.skipEscaping === "all") {
|
|
40740
40729
|
return node2.value;
|
|
40741
40730
|
}
|
|
@@ -40761,9 +40750,8 @@ var toTinaMarkdown2 = (tree, field) => {
|
|
|
40761
40750
|
});
|
|
40762
40751
|
};
|
|
40763
40752
|
var rootElement = (content3, field, imageCallback) => {
|
|
40764
|
-
var _a3;
|
|
40765
40753
|
const children = [];
|
|
40766
|
-
|
|
40754
|
+
content3.children?.forEach((child) => {
|
|
40767
40755
|
const value = blockElement(child, field, imageCallback);
|
|
40768
40756
|
if (value) {
|
|
40769
40757
|
children.push(value);
|
|
@@ -40822,11 +40810,10 @@ var blockElement = (content3, field, imageCallback) => {
|
|
|
40822
40810
|
const tr2 = {
|
|
40823
40811
|
type: "tableRow",
|
|
40824
40812
|
children: tableRow.tableCells.map(({ value }) => {
|
|
40825
|
-
var _a3, _b;
|
|
40826
40813
|
return {
|
|
40827
40814
|
type: "tableCell",
|
|
40828
40815
|
children: eat2(
|
|
40829
|
-
|
|
40816
|
+
value?.children?.at(0)?.children || [],
|
|
40830
40817
|
field,
|
|
40831
40818
|
imageCallback
|
|
40832
40819
|
)
|
|
@@ -40846,7 +40833,7 @@ var blockElement = (content3, field, imageCallback) => {
|
|
|
40846
40833
|
);
|
|
40847
40834
|
}
|
|
40848
40835
|
const directiveAttributes = {};
|
|
40849
|
-
attributes2
|
|
40836
|
+
attributes2?.forEach((att) => {
|
|
40850
40837
|
if (att.value && typeof att.value === "string") {
|
|
40851
40838
|
directiveAttributes[att.name] = att.value;
|
|
40852
40839
|
}
|
|
@@ -40921,16 +40908,15 @@ var blockElement = (content3, field, imageCallback) => {
|
|
|
40921
40908
|
const table = content3.props;
|
|
40922
40909
|
return {
|
|
40923
40910
|
type: "table",
|
|
40924
|
-
align: table
|
|
40911
|
+
align: table?.align,
|
|
40925
40912
|
children: content3.children.map((tableRow) => {
|
|
40926
40913
|
return {
|
|
40927
40914
|
type: "tableRow",
|
|
40928
40915
|
children: tableRow.children.map((tableCell) => {
|
|
40929
|
-
var _a3, _b;
|
|
40930
40916
|
return {
|
|
40931
40917
|
type: "tableCell",
|
|
40932
40918
|
children: eat2(
|
|
40933
|
-
|
|
40919
|
+
tableCell.children?.at(0)?.children || [],
|
|
40934
40920
|
field,
|
|
40935
40921
|
imageCallback
|
|
40936
40922
|
)
|
|
@@ -41019,22 +41005,20 @@ var stringifyPropsInline2 = (element, field, imageCallback) => {
|
|
|
41019
41005
|
return stringifyProps2(element, field, true, imageCallback);
|
|
41020
41006
|
};
|
|
41021
41007
|
function stringifyProps2(element, parentField, flatten2, imageCallback) {
|
|
41022
|
-
var _a3, _b;
|
|
41023
41008
|
const attributes2 = [];
|
|
41024
41009
|
const children = [];
|
|
41025
41010
|
let template;
|
|
41026
41011
|
let useDirective = false;
|
|
41027
41012
|
let directiveType = "leaf";
|
|
41028
|
-
template =
|
|
41013
|
+
template = parentField.templates?.find((template2) => {
|
|
41029
41014
|
if (typeof template2 === "string") {
|
|
41030
41015
|
throw new Error("Global templates not supported");
|
|
41031
41016
|
}
|
|
41032
41017
|
return template2.name === element.name;
|
|
41033
41018
|
});
|
|
41034
41019
|
if (!template) {
|
|
41035
|
-
template =
|
|
41036
|
-
|
|
41037
|
-
const templateName = (_a4 = template2 == null ? void 0 : template2.match) == null ? void 0 : _a4.name;
|
|
41020
|
+
template = parentField.templates?.find((template2) => {
|
|
41021
|
+
const templateName = template2?.match?.name;
|
|
41038
41022
|
return templateName === element.name;
|
|
41039
41023
|
});
|
|
41040
41024
|
}
|
|
@@ -41046,11 +41030,10 @@ function stringifyProps2(element, parentField, flatten2, imageCallback) {
|
|
|
41046
41030
|
}
|
|
41047
41031
|
useDirective = !!template.match;
|
|
41048
41032
|
Object.entries(element.props).forEach(([name2, value]) => {
|
|
41049
|
-
var _a4;
|
|
41050
41033
|
if (typeof template === "string") {
|
|
41051
41034
|
throw new Error(`Unable to find template for JSX element ${name2}`);
|
|
41052
41035
|
}
|
|
41053
|
-
const field =
|
|
41036
|
+
const field = template?.fields?.find((field2) => field2.name === name2);
|
|
41054
41037
|
if (!field) {
|
|
41055
41038
|
if (name2 === "children") {
|
|
41056
41039
|
return;
|
|
@@ -41264,11 +41247,11 @@ var matches2 = (a, b) => {
|
|
|
41264
41247
|
};
|
|
41265
41248
|
var replaceLinksWithTextNodes2 = (content3) => {
|
|
41266
41249
|
const newItems = [];
|
|
41267
|
-
content3
|
|
41250
|
+
content3?.forEach((item) => {
|
|
41268
41251
|
if (item.type === "a") {
|
|
41269
41252
|
if (item.children.length === 1) {
|
|
41270
41253
|
const firstChild = item.children[0];
|
|
41271
|
-
if (
|
|
41254
|
+
if (firstChild?.type === "text") {
|
|
41272
41255
|
newItems.push({
|
|
41273
41256
|
...firstChild,
|
|
41274
41257
|
linkifyTextNode: (a) => {
|
|
@@ -41349,13 +41332,12 @@ var text6 = (content3) => {
|
|
|
41349
41332
|
};
|
|
41350
41333
|
};
|
|
41351
41334
|
var eat3 = (c, field, imageCallback) => {
|
|
41352
|
-
var _a3, _b;
|
|
41353
41335
|
const content3 = replaceLinksWithTextNodes2(c);
|
|
41354
41336
|
const first = content3[0];
|
|
41355
41337
|
if (!first) {
|
|
41356
41338
|
return [];
|
|
41357
41339
|
}
|
|
41358
|
-
if (first &&
|
|
41340
|
+
if (first && first?.type !== "text") {
|
|
41359
41341
|
if (first.type === "a") {
|
|
41360
41342
|
return [
|
|
41361
41343
|
{
|
|
@@ -41431,7 +41413,7 @@ var eat3 = (c, field, imageCallback) => {
|
|
|
41431
41413
|
value: first.text
|
|
41432
41414
|
};
|
|
41433
41415
|
return [
|
|
41434
|
-
|
|
41416
|
+
first.linkifyTextNode?.(node2) ?? node2,
|
|
41435
41417
|
...eat3(content3.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
41436
41418
|
];
|
|
41437
41419
|
}
|
|
@@ -41479,9 +41461,8 @@ var preProcess = (tree, field, imageCallback) => {
|
|
|
41479
41461
|
return ast;
|
|
41480
41462
|
};
|
|
41481
41463
|
var rootElement2 = (content3, field, imageCallback) => {
|
|
41482
|
-
var _a3;
|
|
41483
41464
|
const children = [];
|
|
41484
|
-
|
|
41465
|
+
content3.children?.forEach((child) => {
|
|
41485
41466
|
const value = blockElement2(child, field, imageCallback);
|
|
41486
41467
|
if (value) {
|
|
41487
41468
|
children.push(value);
|
|
@@ -41540,11 +41521,10 @@ var blockElement2 = (content3, field, imageCallback) => {
|
|
|
41540
41521
|
const tr2 = {
|
|
41541
41522
|
type: "tableRow",
|
|
41542
41523
|
children: tableRow.tableCells.map(({ value }) => {
|
|
41543
|
-
var _a3, _b;
|
|
41544
41524
|
return {
|
|
41545
41525
|
type: "tableCell",
|
|
41546
41526
|
children: eat3(
|
|
41547
|
-
|
|
41527
|
+
value?.children?.at(0)?.children || [],
|
|
41548
41528
|
field,
|
|
41549
41529
|
imageCallback
|
|
41550
41530
|
)
|
|
@@ -41608,16 +41588,15 @@ var blockElement2 = (content3, field, imageCallback) => {
|
|
|
41608
41588
|
const table = content3.props;
|
|
41609
41589
|
return {
|
|
41610
41590
|
type: "table",
|
|
41611
|
-
align: table
|
|
41591
|
+
align: table?.align,
|
|
41612
41592
|
children: content3.children.map((tableRow) => {
|
|
41613
41593
|
return {
|
|
41614
41594
|
type: "tableRow",
|
|
41615
41595
|
children: tableRow.children.map((tableCell) => {
|
|
41616
|
-
var _a3, _b;
|
|
41617
41596
|
return {
|
|
41618
41597
|
type: "tableCell",
|
|
41619
41598
|
children: eat3(
|
|
41620
|
-
|
|
41599
|
+
tableCell.children?.at(0)?.children || [],
|
|
41621
41600
|
field,
|
|
41622
41601
|
imageCallback
|
|
41623
41602
|
)
|
|
@@ -43947,8 +43926,7 @@ function mdxJsx2(options = {}) {
|
|
|
43947
43926
|
const flowRules = {};
|
|
43948
43927
|
const textRules = {};
|
|
43949
43928
|
patterns.forEach((pattern) => {
|
|
43950
|
-
|
|
43951
|
-
const firstCharacter = (_a3 = findCode(pattern.start[0])) == null ? void 0 : _a3.toString();
|
|
43929
|
+
const firstCharacter = findCode(pattern.start[0])?.toString();
|
|
43952
43930
|
if (!firstCharacter) {
|
|
43953
43931
|
return;
|
|
43954
43932
|
}
|
|
@@ -44021,7 +43999,7 @@ var import_lodash = __toESM(require_lodash());
|
|
|
44021
43999
|
// src/parse/acorn.ts
|
|
44022
44000
|
var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
44023
44001
|
const properties = {};
|
|
44024
|
-
attributes2
|
|
44002
|
+
attributes2?.forEach((attribute) => {
|
|
44025
44003
|
assertType(attribute, "mdxJsxAttribute");
|
|
44026
44004
|
const field = fields.find((field2) => field2.name === attribute.name);
|
|
44027
44005
|
if (!field) {
|
|
@@ -44115,9 +44093,8 @@ var extractObject = (attribute, field, imageCallback) => {
|
|
|
44115
44093
|
}
|
|
44116
44094
|
};
|
|
44117
44095
|
var extractObjectExpression = (expression, field, imageCallback) => {
|
|
44118
|
-
var _a3;
|
|
44119
44096
|
const properties = {};
|
|
44120
|
-
|
|
44097
|
+
expression.properties?.forEach((property) => {
|
|
44121
44098
|
assertType(property, "Property");
|
|
44122
44099
|
const { key, value } = extractKeyValue(property, field, imageCallback);
|
|
44123
44100
|
properties[key] = value;
|
|
@@ -44136,7 +44113,7 @@ var extractKeyValue = (property, parentField, imageCallback) => {
|
|
|
44136
44113
|
assertType(property.key, "Identifier");
|
|
44137
44114
|
const key = property.key.name;
|
|
44138
44115
|
const field = getField(parentField, key);
|
|
44139
|
-
if (
|
|
44116
|
+
if (field?.type === "object") {
|
|
44140
44117
|
if (field.list) {
|
|
44141
44118
|
assertType(property.value, "ArrayExpression");
|
|
44142
44119
|
const value = property.value.elements.map((element) => {
|
|
@@ -44154,7 +44131,7 @@ var extractKeyValue = (property, parentField, imageCallback) => {
|
|
|
44154
44131
|
);
|
|
44155
44132
|
return { key, value };
|
|
44156
44133
|
}
|
|
44157
|
-
} else if (field
|
|
44134
|
+
} else if (field?.list) {
|
|
44158
44135
|
assertType(property.value, "ArrayExpression");
|
|
44159
44136
|
const value = property.value.elements.map((element) => {
|
|
44160
44137
|
assertHasType(element);
|
|
@@ -44162,7 +44139,7 @@ var extractKeyValue = (property, parentField, imageCallback) => {
|
|
|
44162
44139
|
return element.value;
|
|
44163
44140
|
});
|
|
44164
44141
|
return { key, value };
|
|
44165
|
-
} else if (
|
|
44142
|
+
} else if (field?.type === "rich-text") {
|
|
44166
44143
|
assertType(property.value, "Literal");
|
|
44167
44144
|
const raw = property.value.value;
|
|
44168
44145
|
if (typeof raw === "string") {
|
|
@@ -44175,8 +44152,7 @@ var extractKeyValue = (property, parentField, imageCallback) => {
|
|
|
44175
44152
|
}
|
|
44176
44153
|
};
|
|
44177
44154
|
var extractStatement = (attribute) => {
|
|
44178
|
-
|
|
44179
|
-
const body = (_b = (_a3 = attribute.data) == null ? void 0 : _a3.estree) == null ? void 0 : _b.body;
|
|
44155
|
+
const body = attribute.data?.estree?.body;
|
|
44180
44156
|
if (body) {
|
|
44181
44157
|
if (body[0]) {
|
|
44182
44158
|
assertType(body[0], "ExpressionStatement");
|
|
@@ -44313,9 +44289,8 @@ function source(value, file) {
|
|
|
44313
44289
|
|
|
44314
44290
|
// src/parse/mdx.ts
|
|
44315
44291
|
function mdxJsxElement(node2, field, imageCallback) {
|
|
44316
|
-
var _a3;
|
|
44317
44292
|
try {
|
|
44318
|
-
const template =
|
|
44293
|
+
const template = field.templates?.find((template2) => {
|
|
44319
44294
|
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
44320
44295
|
return templateName === node2.name;
|
|
44321
44296
|
});
|
|
@@ -44360,9 +44335,8 @@ function mdxJsxElement(node2, field, imageCallback) {
|
|
|
44360
44335
|
}
|
|
44361
44336
|
}
|
|
44362
44337
|
var directiveElement = (node2, field, imageCallback, raw) => {
|
|
44363
|
-
var _a3, _b;
|
|
44364
44338
|
let template;
|
|
44365
|
-
template =
|
|
44339
|
+
template = field.templates?.find((template2) => {
|
|
44366
44340
|
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
44367
44341
|
return templateName === node2.name;
|
|
44368
44342
|
});
|
|
@@ -44370,9 +44344,8 @@ var directiveElement = (node2, field, imageCallback, raw) => {
|
|
|
44370
44344
|
throw new Error("Global templates not yet supported");
|
|
44371
44345
|
}
|
|
44372
44346
|
if (!template) {
|
|
44373
|
-
template =
|
|
44374
|
-
|
|
44375
|
-
const templateName = (_a4 = template2 == null ? void 0 : template2.match) == null ? void 0 : _a4.name;
|
|
44347
|
+
template = field.templates?.find((template2) => {
|
|
44348
|
+
const templateName = template2?.match?.name;
|
|
44376
44349
|
return templateName === node2.name;
|
|
44377
44350
|
});
|
|
44378
44351
|
}
|
|
@@ -44406,7 +44379,6 @@ var directiveElement = (node2, field, imageCallback, raw) => {
|
|
|
44406
44379
|
var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
44407
44380
|
const mdxJsxElement2 = skipMDXProcess ? (node2) => node2 : mdxJsxElement;
|
|
44408
44381
|
const content3 = (content4) => {
|
|
44409
|
-
var _a3;
|
|
44410
44382
|
switch (content4.type) {
|
|
44411
44383
|
case "table": {
|
|
44412
44384
|
return {
|
|
@@ -44432,7 +44404,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44432
44404
|
};
|
|
44433
44405
|
}),
|
|
44434
44406
|
props: {
|
|
44435
|
-
align:
|
|
44407
|
+
align: content4.align?.filter((item) => !!item)
|
|
44436
44408
|
}
|
|
44437
44409
|
};
|
|
44438
44410
|
}
|
|
@@ -44806,7 +44778,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44806
44778
|
throw new RichTextParseError(
|
|
44807
44779
|
`Unexpected inline element of type ${node2.type}`,
|
|
44808
44780
|
// @ts-ignore
|
|
44809
|
-
node2
|
|
44781
|
+
node2?.position
|
|
44810
44782
|
);
|
|
44811
44783
|
}
|
|
44812
44784
|
return accum;
|
|
@@ -44967,20 +44939,19 @@ var mdxToAst = (value) => {
|
|
|
44967
44939
|
};
|
|
44968
44940
|
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";
|
|
44969
44941
|
var parseMDX = (value, field, imageCallback) => {
|
|
44970
|
-
var _a3, _b;
|
|
44971
44942
|
if (!value) {
|
|
44972
44943
|
return { type: "root", children: [] };
|
|
44973
44944
|
}
|
|
44974
44945
|
let tree;
|
|
44975
44946
|
try {
|
|
44976
|
-
if (
|
|
44947
|
+
if (field.parser?.type === "markdown") {
|
|
44977
44948
|
return parseMDX2(value, field, imageCallback);
|
|
44978
44949
|
}
|
|
44979
44950
|
let preprocessedString = value;
|
|
44980
|
-
const templatesWithMatchers =
|
|
44951
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
44981
44952
|
(template) => template.match
|
|
44982
44953
|
);
|
|
44983
|
-
templatesWithMatchers
|
|
44954
|
+
templatesWithMatchers?.forEach((template) => {
|
|
44984
44955
|
if (typeof template === "string") {
|
|
44985
44956
|
throw new Error("Global templates are not supported");
|
|
44986
44957
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/mdx",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"typings": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/index.browser.mjs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"unist-util-visit": "4.1.2",
|
|
57
57
|
"uvu": "0.5.6",
|
|
58
58
|
"vfile-message": "3.1.4",
|
|
59
|
-
"@tinacms/schema-tools": "1.7.
|
|
59
|
+
"@tinacms/schema-tools": "1.7.4"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"registry": "https://registry.npmjs.org"
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"typescript": "^5.7.3",
|
|
81
81
|
"vite": "^4.5.9",
|
|
82
82
|
"vitest": "^0.32.4",
|
|
83
|
-
"@tinacms/scripts": "1.3.
|
|
83
|
+
"@tinacms/scripts": "1.3.5"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"types": "tsc",
|