@tinacms/mdx 0.0.0-20220718185604 → 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 (89) hide show
  1. package/dist/index.cjs +887 -738
  2. package/dist/index.es.js +546 -406
  3. package/dist/{parse/plate-spec.d.ts → index.js} +4 -2
  4. package/dist/mdx.es.js +1092 -0
  5. package/dist/mdx.umd.js +1097 -0
  6. package/dist/parse/acorn.d.ts +2 -3
  7. package/dist/parse/acorn.js +201 -0
  8. package/dist/parse/index.d.ts +8 -2
  9. package/dist/parse/index.js +144 -0
  10. package/dist/parse/mdx.js +75 -0
  11. package/dist/parse/plate.d.ts +15 -2
  12. package/dist/parse/plate.js +1 -0
  13. package/dist/parse/remarkToPlate.d.ts +16 -1
  14. package/dist/parse/remarkToPlate.js +380 -0
  15. package/dist/stringify/acorn.d.ts +7 -2
  16. package/dist/stringify/acorn.js +241 -0
  17. package/dist/stringify/index.d.ts +15 -0
  18. package/dist/stringify/index.js +195 -0
  19. package/dist/stringify/marks.js +250 -0
  20. package/dist/tests/autotest/_config.d.ts +4 -0
  21. package/dist/tests/autotest/_config.js +159 -0
  22. package/dist/tests/autotest/_runner.test.d.ts +1 -0
  23. package/dist/tests/autotest/_runner.test.js +77 -0
  24. package/dist/tests/autotest/autoformat block elements in list items.test.d.ts +1 -0
  25. package/dist/tests/autotest/autoformat block elements in list items.test.js +33 -0
  26. package/dist/tests/autotest/autoformat blockquote.result.test.d.ts +1 -0
  27. package/dist/tests/autotest/autoformat blockquote.result.test.js +18 -0
  28. package/dist/tests/autotest/autoformat blockquote.test.d.ts +1 -0
  29. package/dist/tests/autotest/autoformat blockquote.test.js +18 -0
  30. package/dist/tests/autotest/autoformat list item.test.d.ts +1 -0
  31. package/dist/tests/autotest/autoformat list item.test.js +31 -0
  32. package/dist/tests/autotest/autoformat mdx with nested null children.test.d.ts +1 -0
  33. package/dist/tests/autotest/autoformat mdx with nested null children.test.js +23 -0
  34. package/dist/tests/autotest/autoformat syntax changes.test.d.ts +1 -0
  35. package/dist/tests/autotest/autoformat syntax changes.test.js +90 -0
  36. package/dist/tests/autotest/blockquote.test.d.ts +1 -0
  37. package/dist/tests/autotest/blockquote.test.js +17 -0
  38. package/dist/tests/autotest/break.test.d.ts +1 -0
  39. package/dist/tests/autotest/break.test.js +26 -0
  40. package/dist/tests/autotest/code block.test.d.ts +1 -0
  41. package/dist/tests/autotest/code block.test.js +27 -0
  42. package/dist/tests/autotest/image.test.d.ts +1 -0
  43. package/dist/tests/autotest/image.test.js +52 -0
  44. package/dist/tests/autotest/invalid mdx with a closing tag.test.d.ts +1 -0
  45. package/dist/tests/autotest/invalid mdx with a closing tag.test.js +27 -0
  46. package/dist/tests/autotest/invalid mdx with a const expression.test.d.ts +1 -0
  47. package/dist/tests/autotest/invalid mdx with a const expression.test.js +27 -0
  48. package/dist/tests/autotest/invalid mdx with an expression {{}}.test.d.ts +1 -0
  49. package/dist/tests/autotest/invalid mdx with an expression {{}}.test.js +27 -0
  50. package/dist/tests/autotest/invalid mdx with an expression.test.d.ts +1 -0
  51. package/dist/tests/autotest/invalid mdx with an expression.test.js +27 -0
  52. package/dist/tests/autotest/invalid mdx with an import statment.test.d.ts +1 -0
  53. package/dist/tests/autotest/invalid mdx with an import statment.test.js +27 -0
  54. package/dist/tests/autotest/kitchen sink.test.d.ts +1 -0
  55. package/dist/tests/autotest/kitchen sink.test.js +144 -0
  56. package/dist/tests/autotest/links.test.d.ts +1 -0
  57. package/dist/tests/autotest/links.test.js +29 -0
  58. package/dist/tests/autotest/lists.test.d.ts +1 -0
  59. package/dist/tests/autotest/lists.test.js +110 -0
  60. package/dist/tests/autotest/marks.test.d.ts +1 -0
  61. package/dist/tests/autotest/marks.test.js +102 -0
  62. package/dist/tests/autotest/mdx field with a scalar field as a list.test.d.ts +1 -0
  63. package/dist/tests/autotest/mdx field with a scalar field as a list.test.js +22 -0
  64. package/dist/tests/autotest/mdx which hasnt been registered returns html.test.d.ts +1 -0
  65. package/dist/tests/autotest/mdx which hasnt been registered returns html.test.js +26 -0
  66. package/dist/tests/autotest/mdx with a boolean field.test.d.ts +1 -0
  67. package/dist/tests/autotest/mdx with a boolean field.test.js +22 -0
  68. package/dist/tests/autotest/mdx with a number field.test.d.ts +1 -0
  69. package/dist/tests/autotest/mdx with a number field.test.js +22 -0
  70. package/dist/tests/autotest/mdx with a srtring field.test.d.ts +1 -0
  71. package/dist/tests/autotest/mdx with a srtring field.test.js +28 -0
  72. package/dist/tests/autotest/mdx with multiple rich-text fields.test.d.ts +1 -0
  73. package/dist/tests/autotest/mdx with multiple rich-text fields.test.js +53 -0
  74. package/dist/tests/autotest/mdx with nested children.test.d.ts +1 -0
  75. package/dist/tests/autotest/mdx with nested children.test.js +35 -0
  76. package/dist/tests/autotest/mdx with nested null children.test.d.ts +1 -0
  77. package/dist/tests/autotest/mdx with nested null children.test.js +23 -0
  78. package/dist/tests/autotest/mdx with number list field.test.d.ts +1 -0
  79. package/dist/tests/autotest/mdx with number list field.test.js +22 -0
  80. package/dist/tests/autotest/mdx with object list field.test.d.ts +1 -0
  81. package/dist/tests/autotest/mdx with object list field.test.js +25 -0
  82. package/dist/tests/autotest/mdx with object with templates.test.d.ts +1 -0
  83. package/dist/tests/autotest/mdx with object with templates.test.js +41 -0
  84. package/dist/tests/autotest/shortcodes.test.d.ts +1 -0
  85. package/dist/tests/autotest/shortcodes.test.js +51 -0
  86. package/dist/tests/setup.d.ts +14 -0
  87. package/dist/tests/setup.js +70 -0
  88. package/package.json +13 -14
  89. package/dist/stringify/mdx.d.ts +0 -38
@@ -0,0 +1,195 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import { toMarkdown } from 'mdast-util-to-markdown';
19
+ import { mdxJsxToMarkdown, } from 'mdast-util-mdx-jsx';
20
+ import { eat } from './marks';
21
+ import { stringifyProps } from './acorn';
22
+ export var stringifyMDX = function (value, field, imageCallback) {
23
+ var _a;
24
+ if (value === null || value === void 0 ? void 0 : value.children[0]) {
25
+ if ((value === null || value === void 0 ? void 0 : value.children[0].type) === 'invalid_markdown') {
26
+ return value.children[0].value;
27
+ }
28
+ }
29
+ var res = toMarkdown(rootElement(value, field, imageCallback), {
30
+ extensions: [mdxJsxToMarkdown()],
31
+ listItemIndent: 'one'
32
+ });
33
+ var templatesWithMatchers = (_a = field.templates) === null || _a === void 0 ? void 0 : _a.filter(function (template) { return template.match; });
34
+ var preprocessedString = res;
35
+ templatesWithMatchers === null || templatesWithMatchers === void 0 ? void 0 : templatesWithMatchers.forEach(function (template) {
36
+ if (typeof template === 'string') {
37
+ throw new Error('Global templates are not supported');
38
+ }
39
+ if (template.match) {
40
+ preprocessedString = preprocessedString.replaceAll("<" + template.name + ">`", template.match.start + " ");
41
+ preprocessedString = preprocessedString.replaceAll("`</" + template.name + ">", " " + template.match.end);
42
+ }
43
+ });
44
+ return preprocessedString;
45
+ };
46
+ export var rootElement = function (content, field, imageCallback) {
47
+ var children = [];
48
+ content.children.forEach(function (child) {
49
+ var value = blockElement(child, field, imageCallback);
50
+ if (value) {
51
+ children.push(value);
52
+ }
53
+ });
54
+ return {
55
+ type: 'root',
56
+ children: children
57
+ };
58
+ };
59
+ export var blockElement = function (content, field, imageCallback) {
60
+ switch (content.type) {
61
+ case 'h1':
62
+ case 'h2':
63
+ case 'h3':
64
+ case 'h4':
65
+ case 'h5':
66
+ case 'h6':
67
+ return {
68
+ type: 'heading',
69
+ // @ts-ignore Type 'number' is not assignable to type '1 | 2 | 3 | 4 | 5 | 6'
70
+ depth: { h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6 }[content.type],
71
+ children: eat(content.children, field, imageCallback)
72
+ };
73
+ case 'p':
74
+ // Ignore empty blocks
75
+ if (content.children.length === 1) {
76
+ var onlyChild = content.children[0];
77
+ if (onlyChild && onlyChild.type === 'text' && onlyChild.text === '') {
78
+ return null;
79
+ }
80
+ }
81
+ return {
82
+ type: 'paragraph',
83
+ children: eat(content.children, field, imageCallback)
84
+ };
85
+ case 'code_block':
86
+ return {
87
+ type: 'code',
88
+ lang: content.lang,
89
+ value: content.value
90
+ };
91
+ case 'mdxJsxFlowElement':
92
+ var _a = stringifyProps(content, field, false, imageCallback), children = _a.children, attributes = _a.attributes;
93
+ return {
94
+ type: 'mdxJsxFlowElement',
95
+ name: content.name,
96
+ attributes: attributes,
97
+ children: children
98
+ };
99
+ case 'blockquote':
100
+ return {
101
+ type: 'blockquote',
102
+ children: [
103
+ {
104
+ type: 'paragraph',
105
+ children: eat(content.children, field, imageCallback)
106
+ },
107
+ ]
108
+ };
109
+ case 'hr':
110
+ return {
111
+ type: 'thematicBreak'
112
+ };
113
+ case 'ol':
114
+ case 'ul':
115
+ return {
116
+ type: 'list',
117
+ ordered: content.type === 'ol',
118
+ spread: false,
119
+ children: content.children.map(function (child) {
120
+ return listItemElement(child, field, imageCallback);
121
+ })
122
+ };
123
+ case 'html': {
124
+ return {
125
+ type: 'html',
126
+ value: content.value
127
+ };
128
+ }
129
+ default:
130
+ throw new Error("BlockElement: " + content.type + " is not yet supported");
131
+ }
132
+ };
133
+ var listItemElement = function (content, field, imageCallback) {
134
+ return {
135
+ type: 'listItem',
136
+ // spread is always false since we don't support block elements in list items
137
+ // good explanation of the difference: https://stackoverflow.com/questions/43503528/extra-lines-appearing-between-list-items-in-github-markdown
138
+ spread: false,
139
+ children: content.children.map(function (child) {
140
+ if (child.type === 'lic') {
141
+ return {
142
+ type: 'paragraph',
143
+ children: eat(child.children, field, imageCallback)
144
+ };
145
+ }
146
+ return blockContentElement(child, field, imageCallback);
147
+ })
148
+ };
149
+ };
150
+ var blockContentElement = function (content, field, imageCallback) {
151
+ switch (content.type) {
152
+ case 'blockquote':
153
+ return {
154
+ type: 'blockquote',
155
+ children: content.children.map(function (child) {
156
+ // FIXME: text nodes are probably passed in here by the rich text editor
157
+ // @ts-ignore
158
+ return blockContentElement(child, field, imageCallback);
159
+ })
160
+ };
161
+ case 'p':
162
+ return {
163
+ type: 'paragraph',
164
+ children: eat(content.children, field, imageCallback)
165
+ };
166
+ case 'ol':
167
+ case 'ul':
168
+ return {
169
+ type: 'list',
170
+ ordered: content.type === 'ol',
171
+ spread: false,
172
+ children: content.children.map(function (child) {
173
+ return listItemElement(child, field, imageCallback);
174
+ })
175
+ };
176
+ default:
177
+ throw new Error("BlockContentElement: " + content.type + " is not yet supported");
178
+ }
179
+ };
180
+ export var getMarks = function (content) {
181
+ var marks = [];
182
+ if (content.type !== 'text') {
183
+ return [];
184
+ }
185
+ if (content.bold) {
186
+ marks.push('strong');
187
+ }
188
+ if (content.italic) {
189
+ marks.push('emphasis');
190
+ }
191
+ if (content.code) {
192
+ marks.push('inlineCode');
193
+ }
194
+ return marks;
195
+ };
@@ -0,0 +1,250 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ var __assign = (this && this.__assign) || function () {
19
+ __assign = Object.assign || function(t) {
20
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
21
+ s = arguments[i];
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23
+ t[p] = s[p];
24
+ }
25
+ return t;
26
+ };
27
+ return __assign.apply(this, arguments);
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
+ to[j] = from[i];
32
+ return to;
33
+ };
34
+ import { getMarks } from './index';
35
+ import { stringifyPropsInline } from './acorn';
36
+ var matches = function (a, b) {
37
+ return a.some(function (v) { return b.includes(v); });
38
+ };
39
+ /**
40
+ *
41
+ * Links can contain marks inside them, and in the scenario that there is a link with a single
42
+ * child with a mark on it, we want to possibly merge those marks with adjacent ones:
43
+ * ```markdown
44
+ * *Hello [world](https://example.com)*
45
+ * ```
46
+ * Without "flattening" text nodes like this, this shape:
47
+ * ```js
48
+ * [
49
+ * {
50
+ * type: 'text',
51
+ * text: 'Hello',
52
+ * italic: true
53
+ * },
54
+ * {
55
+ * type: 'link',
56
+ * url: 'https://example.com',
57
+ * children: [{
58
+ * type: 'text',
59
+ * text: 'world',
60
+ * italic: true
61
+ * }]
62
+ * }
63
+ * ]
64
+ * ```
65
+ * Would result in this markdown:
66
+ * ```markdown
67
+ * *Hello **[world](https://example.com)*
68
+ * ```
69
+ * So instead we place a callback on the text node, treat is any other text node,
70
+ * and at the end we replace it with it's callback value (inside cleanNodes)
71
+ */
72
+ var replaceLinksWithTextNodes = function (content) {
73
+ var newItems = [];
74
+ content.forEach(function (item) {
75
+ if (item.type === 'a') {
76
+ if (item.children.length === 1) {
77
+ var firstChild = item.children[0];
78
+ if ((firstChild === null || firstChild === void 0 ? void 0 : firstChild.type) === 'text') {
79
+ newItems.push(__assign(__assign({}, firstChild), { linkifyTextNode: function (a) {
80
+ return {
81
+ type: 'link',
82
+ url: item.url,
83
+ title: item.title,
84
+ children: [text({ text: a.value })]
85
+ };
86
+ } }));
87
+ }
88
+ else {
89
+ newItems.push(item);
90
+ }
91
+ }
92
+ else {
93
+ newItems.push(item);
94
+ }
95
+ }
96
+ else {
97
+ newItems.push(item);
98
+ }
99
+ });
100
+ return newItems;
101
+ };
102
+ /**
103
+ * Links should be processed via 'linkifyTextNode', otherwise handle phrasing content
104
+ */
105
+ var inlineElementExceptLink = function (content, field, imageCallback) {
106
+ switch (content.type) {
107
+ case 'a':
108
+ throw new Error("Unexpected node of type \"a\", link elements should be processed after all inline elements have resolved");
109
+ case 'img':
110
+ return {
111
+ type: 'image',
112
+ url: imageCallback(content.url),
113
+ alt: content.alt,
114
+ title: content.caption
115
+ };
116
+ case 'break':
117
+ return {
118
+ type: 'break'
119
+ };
120
+ case 'mdxJsxTextElement': {
121
+ var _a = stringifyPropsInline(content, field, imageCallback), attributes = _a.attributes, children = _a.children;
122
+ return {
123
+ type: 'mdxJsxTextElement',
124
+ name: content.name,
125
+ attributes: attributes,
126
+ children: children
127
+ };
128
+ }
129
+ case 'html_inline': {
130
+ return {
131
+ type: 'html',
132
+ value: content.value
133
+ };
134
+ }
135
+ default:
136
+ // @ts-expect-error type is 'never'
137
+ if (!content.type && typeof content.text === 'string') {
138
+ return text(content);
139
+ }
140
+ throw new Error("InlineElement: " + content.type + " is not supported");
141
+ }
142
+ };
143
+ var text = function (content) {
144
+ return {
145
+ type: 'text',
146
+ value: content.text
147
+ };
148
+ };
149
+ export var eat = function (c, field, imageCallback) {
150
+ var content = replaceLinksWithTextNodes(c);
151
+ var first = content[0];
152
+ if (!first) {
153
+ return [];
154
+ }
155
+ if (first && (first === null || first === void 0 ? void 0 : first.type) !== 'text') {
156
+ // non-text nodes can't be merged. Eg. img, break. So process them and move on to the rest
157
+ return __spreadArray([
158
+ inlineElementExceptLink(first, field, imageCallback)
159
+ ], eat(content.slice(1), field, imageCallback));
160
+ }
161
+ var marks = getMarks(first);
162
+ if (marks.length === 0) {
163
+ if (first.linkifyTextNode) {
164
+ return __spreadArray([
165
+ first.linkifyTextNode(text(first))
166
+ ], eat(content.slice(1), field, imageCallback));
167
+ }
168
+ else {
169
+ return __spreadArray([text(first)], eat(content.slice(1), field, imageCallback));
170
+ }
171
+ }
172
+ var nonMatchingSiblingIndex = 0;
173
+ if (content.slice(1).every(function (content, index) {
174
+ if (matches(marks, getMarks(content))) {
175
+ return true;
176
+ }
177
+ else {
178
+ nonMatchingSiblingIndex = index;
179
+ return false;
180
+ }
181
+ })) {
182
+ // Every sibling matches, so capture all of them in this node
183
+ nonMatchingSiblingIndex = content.length - 1;
184
+ }
185
+ var matchingSiblings = content.slice(1, nonMatchingSiblingIndex + 1);
186
+ var markCounts = {};
187
+ marks.forEach(function (mark) {
188
+ var count = 1;
189
+ matchingSiblings.every(function (sibling, index) {
190
+ if (getMarks(sibling).includes(mark)) {
191
+ count = index + 1;
192
+ return true;
193
+ }
194
+ });
195
+ markCounts[mark] = count;
196
+ });
197
+ var count = 0;
198
+ var markToProcess = null;
199
+ Object.entries(markCounts).forEach(function (_a) {
200
+ var mark = _a[0], markCount = _a[1];
201
+ var m = mark;
202
+ if (markCount > count) {
203
+ count = markCount;
204
+ markToProcess = m;
205
+ }
206
+ });
207
+ if (!markToProcess) {
208
+ return __spreadArray([text(first)], eat(content.slice(1), field, imageCallback));
209
+ }
210
+ if (markToProcess === 'inlineCode') {
211
+ if (nonMatchingSiblingIndex) {
212
+ throw new Error("Marks inside inline code are not supported");
213
+ }
214
+ return __spreadArray([
215
+ {
216
+ type: markToProcess,
217
+ value: first.text
218
+ }
219
+ ], eat(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback));
220
+ }
221
+ return __spreadArray([
222
+ {
223
+ type: markToProcess,
224
+ children: eat(__spreadArray([], __spreadArray([first], matchingSiblings).map(function (sibling) {
225
+ return cleanNode(sibling, markToProcess);
226
+ })), field, imageCallback)
227
+ }
228
+ ], eat(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback));
229
+ };
230
+ var cleanNode = function (node, mark) {
231
+ if (!mark) {
232
+ return node;
233
+ }
234
+ var cleanedNode = {};
235
+ var markToClear = {
236
+ strong: 'bold',
237
+ emphasis: 'italic',
238
+ inlineCode: 'code'
239
+ }[mark];
240
+ Object.entries(node).map(function (_a) {
241
+ var key = _a[0], value = _a[1];
242
+ if (key !== markToClear) {
243
+ cleanedNode[key] = value;
244
+ }
245
+ });
246
+ if (node.linkifyTextNode) {
247
+ cleanedNode.callback = node.linkifyTextNode;
248
+ }
249
+ return cleanedNode;
250
+ };
@@ -0,0 +1,4 @@
1
+ import type { RichTypeInner } from '@tinacms/schema-tools';
2
+ export { output } from '../setup';
3
+ export { parseMDX, stringifyMDX } from '../..';
4
+ export declare const field: RichTypeInner;
@@ -0,0 +1,159 @@
1
+ export { output } from '../setup';
2
+ export { parseMDX, stringifyMDX } from '../..';
3
+ export var field = {
4
+ name: 'body',
5
+ type: 'rich-text',
6
+ templates: [
7
+ {
8
+ name: 'Greeting',
9
+ label: 'Greeting',
10
+ inline: true,
11
+ fields: [{ type: 'string', name: 'message' }]
12
+ },
13
+ {
14
+ name: 'Blockquote',
15
+ label: 'Blockquote',
16
+ fields: [
17
+ { type: 'string', name: 'author' },
18
+ { type: 'rich-text', name: 'children' },
19
+ ]
20
+ },
21
+ {
22
+ name: 'Cta',
23
+ label: 'Call-to-action',
24
+ fields: [
25
+ { type: 'rich-text', name: 'description' },
26
+ { type: 'rich-text', name: 'children' },
27
+ ]
28
+ },
29
+ {
30
+ name: 'MaybeShow',
31
+ label: 'Maybe Show',
32
+ fields: [{ type: 'boolean', name: 'toggle' }]
33
+ },
34
+ {
35
+ name: 'Count',
36
+ label: 'Count',
37
+ fields: [{ type: 'number', name: 'number' }]
38
+ },
39
+ {
40
+ name: 'Tags',
41
+ label: 'Tags',
42
+ fields: [{ type: 'string', name: 'items', list: true }]
43
+ },
44
+ {
45
+ name: 'Date',
46
+ label: 'Date',
47
+ fields: [{ type: 'datetime', name: 'here' }]
48
+ },
49
+ {
50
+ name: 'Ratings',
51
+ label: 'Ratings',
52
+ fields: [{ type: 'number', name: 'value', list: true }]
53
+ },
54
+ {
55
+ name: 'Playground',
56
+ label: 'Playground',
57
+ fields: [
58
+ { type: 'string', name: 'code' },
59
+ {
60
+ name: 'config',
61
+ type: 'object',
62
+ list: true,
63
+ fields: [
64
+ {
65
+ type: 'string',
66
+ name: 'key'
67
+ },
68
+ {
69
+ type: 'string',
70
+ name: 'value'
71
+ },
72
+ ]
73
+ },
74
+ ]
75
+ },
76
+ {
77
+ name: 'Action',
78
+ label: 'Action',
79
+ fields: [
80
+ {
81
+ type: 'object',
82
+ name: 'action',
83
+ templates: [
84
+ {
85
+ label: 'Popup',
86
+ name: 'popup',
87
+ fields: [
88
+ {
89
+ type: 'string',
90
+ name: 'title'
91
+ },
92
+ {
93
+ type: 'string',
94
+ name: 'descrption'
95
+ },
96
+ ]
97
+ },
98
+ {
99
+ label: 'Link',
100
+ name: 'link',
101
+ fields: [
102
+ {
103
+ type: 'string',
104
+ name: 'title'
105
+ },
106
+ {
107
+ type: 'string',
108
+ name: 'url'
109
+ },
110
+ ]
111
+ },
112
+ ]
113
+ },
114
+ ]
115
+ },
116
+ {
117
+ name: 'Shortcode1',
118
+ label: 'Shortcode 1',
119
+ inline: true,
120
+ match: {
121
+ start: '{{<',
122
+ end: '>}}'
123
+ },
124
+ fields: [
125
+ {
126
+ name: 'text',
127
+ label: 'Text',
128
+ type: 'string',
129
+ required: true,
130
+ isTitle: true,
131
+ ui: {
132
+ component: 'textarea'
133
+ }
134
+ },
135
+ ]
136
+ },
137
+ {
138
+ name: 'Shortcode2',
139
+ label: 'Shortcode 2',
140
+ inline: true,
141
+ match: {
142
+ start: '{{%',
143
+ end: '%}}'
144
+ },
145
+ fields: [
146
+ {
147
+ name: 'text',
148
+ required: true,
149
+ isTitle: true,
150
+ label: 'Text',
151
+ type: 'string',
152
+ ui: {
153
+ component: 'textarea'
154
+ }
155
+ },
156
+ ]
157
+ },
158
+ ]
159
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { describe, expect, it } from 'vitest';
38
+ import { field, parseMDX, stringifyMDX } from './_config';
39
+ import { setupNewTests, writeAutoformatFile, writeTestFile } from '../setup';
40
+ var content = import.meta.glob('./*.md', { as: 'raw' });
41
+ var outputString = import.meta.glob('./*.ts', { as: 'raw' });
42
+ setupNewTests(content, outputString, function (_a) {
43
+ var name = _a.name, markdownContent = _a.markdownContent;
44
+ describe("setting up " + name, function () {
45
+ it("verifies that stringifying the parsed output will match the original string", function () { return __awaiter(void 0, void 0, void 0, function () {
46
+ var markdownString, astResult, stringResult;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4 /*yield*/, markdownContent()];
50
+ case 1:
51
+ markdownString = _a.sent();
52
+ astResult = parseMDX(markdownString, field, function (v) { return v; });
53
+ stringResult = stringifyMDX(astResult, field, function (v) { return v; });
54
+ try {
55
+ expect(stringResult).toEqual(markdownString);
56
+ // If `expect` doesn't throw, save the file
57
+ writeTestFile(__dirname, name, astResult);
58
+ }
59
+ catch (e) {
60
+ if (name.startsWith('./autoformat')) {
61
+ console.log('we shoud write another file', stringResult);
62
+ writeTestFile(__dirname, name, astResult, true);
63
+ writeAutoformatFile(__dirname, name, stringResult);
64
+ }
65
+ else {
66
+ throw e;
67
+ }
68
+ }
69
+ return [2 /*return*/];
70
+ }
71
+ });
72
+ }); });
73
+ });
74
+ });
75
+ it("true is true", function () {
76
+ expect(true).toBe(true);
77
+ });