@tinacms/mdx 0.61.16 → 0.61.17
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 +31 -21
- package/dist/parse/acorn.d.ts +1 -0
- package/dist/parse/acorn.test.d.ts +1 -0
- package/dist/tests/autotest/autoformat mdx with deeply nested rich-text elements.test.d.ts +1 -0
- package/dist/tests/autotest/mdx with deeply nested rich-text elements.test.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -210126,7 +210126,7 @@ ${fromBody}`;
|
|
|
210126
210126
|
const regex = makeRegex(pattern, ignoreCase);
|
|
210127
210127
|
return new IgnoreRule(origin, pattern, negative, regex);
|
|
210128
210128
|
};
|
|
210129
|
-
var
|
|
210129
|
+
var throwError = (message, Ctor) => {
|
|
210130
210130
|
throw new Ctor(message);
|
|
210131
210131
|
};
|
|
210132
210132
|
var checkPath = (path, originalPath, doThrow) => {
|
|
@@ -210207,7 +210207,7 @@ ${fromBody}`;
|
|
|
210207
210207
|
}
|
|
210208
210208
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
210209
210209
|
const path = originalPath && checkPath.convert(originalPath);
|
|
210210
|
-
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE :
|
|
210210
|
+
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
|
|
210211
210211
|
return this._t(path, cache, checkUnignored, slices);
|
|
210212
210212
|
}
|
|
210213
210213
|
_t(path, cache, checkUnignored, slices) {
|
|
@@ -244207,7 +244207,7 @@ var extractAttribute = (attribute, field, imageCallback) => {
|
|
|
244207
244207
|
case "object":
|
|
244208
244208
|
return extractObject(extractExpression(attribute), field);
|
|
244209
244209
|
case "rich-text":
|
|
244210
|
-
const JSXString =
|
|
244210
|
+
const JSXString = extractRaw(attribute);
|
|
244211
244211
|
if (JSXString) {
|
|
244212
244212
|
return parseMDX(JSXString, field, imageCallback);
|
|
244213
244213
|
} else {
|
|
@@ -244260,22 +244260,6 @@ var getField = (objectField, name) => {
|
|
|
244260
244260
|
return objectField.fields.find((f) => f.name === name);
|
|
244261
244261
|
}
|
|
244262
244262
|
};
|
|
244263
|
-
var extractJSXFragment = (attribute, baseAttribute, field) => {
|
|
244264
|
-
if (field.list) {
|
|
244265
|
-
} else {
|
|
244266
|
-
if (attribute.expression.type === "JSXFragment") {
|
|
244267
|
-
assertHasType(attribute.expression);
|
|
244268
|
-
if (attribute.expression.children[0]) {
|
|
244269
|
-
const firstChild = attribute.expression.children[0];
|
|
244270
|
-
if (attribute.expression.children[0].type === "JSXText") {
|
|
244271
|
-
const child = firstChild;
|
|
244272
|
-
return child.value.trim();
|
|
244273
|
-
}
|
|
244274
|
-
}
|
|
244275
|
-
}
|
|
244276
|
-
}
|
|
244277
|
-
throwError(field);
|
|
244278
|
-
};
|
|
244279
244263
|
var extractKeyValue = (property, parentField) => {
|
|
244280
244264
|
assertType(property.key, "Identifier");
|
|
244281
244265
|
const key = property.key.name;
|
|
@@ -244324,6 +244308,13 @@ var extractExpression = (attribute) => {
|
|
|
244324
244308
|
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
244325
244309
|
return extractStatement(attribute.value);
|
|
244326
244310
|
};
|
|
244311
|
+
var extractRaw = (attribute) => {
|
|
244312
|
+
assertType(attribute, "mdxJsxAttribute");
|
|
244313
|
+
assertHasType(attribute.value);
|
|
244314
|
+
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
244315
|
+
const rawValue = attribute.value.value;
|
|
244316
|
+
return trimFragments(rawValue);
|
|
244317
|
+
};
|
|
244327
244318
|
function assertType(val, type) {
|
|
244328
244319
|
if (val.type !== type) {
|
|
244329
244320
|
throw new Error(`Expected type to be ${type} but received ${val.type}. ${MDX_PARSE_ERROR_MSG}`);
|
|
@@ -244337,8 +244328,27 @@ function assertHasType(val) {
|
|
|
244337
244328
|
}
|
|
244338
244329
|
throw new Error(`Expect value to be an object with property "type"`);
|
|
244339
244330
|
}
|
|
244340
|
-
var
|
|
244341
|
-
|
|
244331
|
+
var trimFragments = (string3) => {
|
|
244332
|
+
const rawArr = string3.split("\n");
|
|
244333
|
+
let openingFragmentIndex = null;
|
|
244334
|
+
let closingFragmentIndex = null;
|
|
244335
|
+
rawArr.forEach((item, index2) => {
|
|
244336
|
+
if (item.trim() === "<>") {
|
|
244337
|
+
if (!openingFragmentIndex) {
|
|
244338
|
+
openingFragmentIndex = index2 + 1;
|
|
244339
|
+
}
|
|
244340
|
+
}
|
|
244341
|
+
});
|
|
244342
|
+
rawArr.reverse().forEach((item, index2) => {
|
|
244343
|
+
if (item.trim() === "</>") {
|
|
244344
|
+
const length = rawArr.length - 1;
|
|
244345
|
+
if (!closingFragmentIndex) {
|
|
244346
|
+
closingFragmentIndex = length - index2;
|
|
244347
|
+
}
|
|
244348
|
+
}
|
|
244349
|
+
});
|
|
244350
|
+
const value = rawArr.reverse().slice(openingFragmentIndex || 0, closingFragmentIndex || rawArr.length - 1).join("\n");
|
|
244351
|
+
return value;
|
|
244342
244352
|
};
|
|
244343
244353
|
|
|
244344
244354
|
// src/parse/mdx.ts
|
package/dist/parse/acorn.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ limitations under the License.
|
|
|
18
18
|
import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
|
|
19
19
|
import type { TinaFieldBase } from '@tinacms/schema-tools';
|
|
20
20
|
export declare const extractAttributes: (attributes: (MdxJsxAttribute | MdxJsxExpressionAttribute)[], fields: TinaFieldBase[], imageCallback: (image: string) => string) => Record<string, unknown>;
|
|
21
|
+
export declare const trimFragments: (string: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/mdx",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.17",
|
|
4
4
|
"typings": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
]
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tinacms/schema-tools": "0.2.
|
|
22
|
+
"@tinacms/schema-tools": "0.2.2",
|
|
23
23
|
"acorn": "^8.7.1",
|
|
24
24
|
"lodash-es": "^4.17.21",
|
|
25
25
|
"mdast-util-mdx-jsx": "^2.0.1",
|