@tinacms/graphql 0.0.0-20218161139 → 0.0.0-2021816214827
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/CHANGELOG.md +3 -3
- package/dist/index.js +11 -688
- package/dist/primitives/ast-builder/index.d.ts +0 -1
- package/dist/primitives/spec/setup.d.ts +4 -8
- package/dist/primitives/types.d.ts +1 -17
- package/package.json +5 -23
- package/dist/index.es.js +0 -3403
- package/dist/primitives/mdx/index.d.ts +0 -21
- package/dist/primitives/mdx/parse.d.ts +0 -194
- package/dist/primitives/mdx/stringify.d.ts +0 -22
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -489,7 +489,6 @@ var astBuilder = {
|
|
|
489
489
|
ID: "ID",
|
|
490
490
|
SystemInfo: "SystemInfo",
|
|
491
491
|
Boolean: "Boolean",
|
|
492
|
-
JSON: "JSON",
|
|
493
492
|
Node: "Node",
|
|
494
493
|
PageInfo: "PageInfo",
|
|
495
494
|
Connection: "Connection",
|
|
@@ -1154,12 +1153,6 @@ var Builder = class {
|
|
|
1154
1153
|
list: field.list,
|
|
1155
1154
|
type: yield this._updateCollectionDocumentMutationType(field)
|
|
1156
1155
|
});
|
|
1157
|
-
case "rich-text":
|
|
1158
|
-
return astBuilder.InputValueDefinition({
|
|
1159
|
-
name: field.name,
|
|
1160
|
-
list: field.list,
|
|
1161
|
-
type: astBuilder.TYPES.JSON
|
|
1162
|
-
});
|
|
1163
1156
|
case "reference":
|
|
1164
1157
|
return astBuilder.InputValueDefinition({
|
|
1165
1158
|
name: field.name,
|
|
@@ -1268,13 +1261,6 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
1268
1261
|
required: field.required,
|
|
1269
1262
|
type: yield this._buildObjectOrUnionData(this.tinaSchema.getTemplatesForCollectable(field))
|
|
1270
1263
|
});
|
|
1271
|
-
case "rich-text":
|
|
1272
|
-
return astBuilder.FieldDefinition({
|
|
1273
|
-
name: field.name,
|
|
1274
|
-
list: field.list,
|
|
1275
|
-
required: field.required,
|
|
1276
|
-
type: astBuilder.TYPES.JSON
|
|
1277
|
-
});
|
|
1278
1264
|
case "reference":
|
|
1279
1265
|
const name = NAMER.documentTypeName(field.namespace);
|
|
1280
1266
|
if (field.list) {
|
|
@@ -1546,636 +1532,6 @@ var import_graphql3 = __toModule(require("graphql"));
|
|
|
1546
1532
|
var import_lodash5 = __toModule(require("lodash"));
|
|
1547
1533
|
var import_path2 = __toModule(require("path"));
|
|
1548
1534
|
var import_isValid = __toModule(require("date-fns/isValid"));
|
|
1549
|
-
|
|
1550
|
-
// ../graphql/src/primitives/mdx/parse.ts
|
|
1551
|
-
var import_unified = __toModule(require("unified"));
|
|
1552
|
-
var import_remark_parse = __toModule(require("remark-parse"));
|
|
1553
|
-
var import_remark_mdx = __toModule(require("remark-mdx"));
|
|
1554
|
-
var import_unist_util_visit = __toModule(require("unist-util-visit"));
|
|
1555
|
-
var parseMDX = (value, field) => {
|
|
1556
|
-
const tree = (0, import_unified.unified)().use(import_remark_parse.default).use(import_remark_mdx.default).parse(value);
|
|
1557
|
-
return parseMDXInner(tree, field);
|
|
1558
|
-
};
|
|
1559
|
-
var parseMDXInner = (tree, field) => {
|
|
1560
|
-
(0, import_unist_util_visit.visit)(tree, (node) => {
|
|
1561
|
-
delete node.position;
|
|
1562
|
-
});
|
|
1563
|
-
(0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
|
|
1564
|
-
var _a;
|
|
1565
|
-
let props = {};
|
|
1566
|
-
if (!node.name) {
|
|
1567
|
-
props = parseMDXInner({ type: "root", children: node.children }, field);
|
|
1568
|
-
}
|
|
1569
|
-
const template = (_a = field.templates) == null ? void 0 : _a.find((template2) => {
|
|
1570
|
-
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
1571
|
-
return templateName === node.name;
|
|
1572
|
-
});
|
|
1573
|
-
if (node.children.length > 0) {
|
|
1574
|
-
node.attributes.push({
|
|
1575
|
-
value: node.children,
|
|
1576
|
-
name: "children",
|
|
1577
|
-
type: "mdxJsxAttribute"
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
node.children = null;
|
|
1581
|
-
node.attributes.forEach((attribute) => {
|
|
1582
|
-
if (attribute.type === "mdxJsxAttribute") {
|
|
1583
|
-
if (typeof template === "string") {
|
|
1584
|
-
throw new Error("Global templates not yet supported");
|
|
1585
|
-
}
|
|
1586
|
-
if (!template) {
|
|
1587
|
-
} else {
|
|
1588
|
-
const field2 = template.fields.find((field3) => field3.name === attribute.name);
|
|
1589
|
-
if (!field2) {
|
|
1590
|
-
throw new Error(`Unknown property '${attribute.name}' for embedded structure '${node.name}'`);
|
|
1591
|
-
}
|
|
1592
|
-
parseField(attribute, field2, props);
|
|
1593
|
-
}
|
|
1594
|
-
} else {
|
|
1595
|
-
console.log(`Not sure what this is, type: ${attribute.type}`);
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
delete node.attributes;
|
|
1599
|
-
node.props = props;
|
|
1600
|
-
});
|
|
1601
|
-
const slateTree = tree.children.map(remarkToSlate);
|
|
1602
|
-
return { type: "root", children: slateTree };
|
|
1603
|
-
};
|
|
1604
|
-
var parseField = (attribute, field, props) => {
|
|
1605
|
-
var _a, _b;
|
|
1606
|
-
switch (field.type) {
|
|
1607
|
-
case "boolean":
|
|
1608
|
-
case "datetime":
|
|
1609
|
-
case "image":
|
|
1610
|
-
case "number":
|
|
1611
|
-
case "string":
|
|
1612
|
-
if (field.list) {
|
|
1613
|
-
if (((_a = attribute.value) == null ? void 0 : _a.type) === "mdxJsxAttributeValueExpression") {
|
|
1614
|
-
attribute.value.data.estree.body.forEach((item) => {
|
|
1615
|
-
if (item.type === "ExpressionStatement") {
|
|
1616
|
-
if (item.expression.type === "ArrayExpression") {
|
|
1617
|
-
props[field.name] = item.expression.elements.map((element) => {
|
|
1618
|
-
if (element.type === "Literal") {
|
|
1619
|
-
return element.value;
|
|
1620
|
-
} else {
|
|
1621
|
-
throw new Error(`Only literals are supported for array expressions`);
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
} else {
|
|
1629
|
-
if (attribute.type === "Property") {
|
|
1630
|
-
if (attribute.value.type === "Literal") {
|
|
1631
|
-
props[attribute.key.name] = attribute.value.value;
|
|
1632
|
-
}
|
|
1633
|
-
} else if (((_b = attribute.value) == null ? void 0 : _b.type) === "mdxJsxAttributeValueExpression") {
|
|
1634
|
-
attribute.value.data.estree.body.forEach((item) => {
|
|
1635
|
-
if (item.type === "ExpressionStatement") {
|
|
1636
|
-
if (item.expression.type === "Literal") {
|
|
1637
|
-
props[field.name] = item.expression.value;
|
|
1638
|
-
}
|
|
1639
|
-
if (item.expression.type === "ArrayExpression") {
|
|
1640
|
-
throw new Error(`Unexpected array expression for non-list field ${field.name}`);
|
|
1641
|
-
}
|
|
1642
|
-
if (item.expression.type === "TemplateLiteral") {
|
|
1643
|
-
throw new Error(`Template literals are not yet supported`);
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
} else {
|
|
1648
|
-
props[field.name] = attribute.value;
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
break;
|
|
1652
|
-
case "object":
|
|
1653
|
-
if (attribute.type === "mdxJsxAttribute") {
|
|
1654
|
-
if (attribute.value.type === "mdxJsxAttributeValueExpression") {
|
|
1655
|
-
attribute.value.data.estree.body.forEach((item) => {
|
|
1656
|
-
if (item.type === "ExpressionStatement") {
|
|
1657
|
-
if (item.expression.type === "ObjectExpression") {
|
|
1658
|
-
const objectProps = {};
|
|
1659
|
-
item.expression.properties.forEach((property) => {
|
|
1660
|
-
if (property.key.type !== "Identifier") {
|
|
1661
|
-
throw new Error(`Unexptected key type ${property.key.type}`);
|
|
1662
|
-
}
|
|
1663
|
-
if (property.value.type !== "Literal") {
|
|
1664
|
-
throw new Error(`Unexptected value type ${property.value.type}`);
|
|
1665
|
-
}
|
|
1666
|
-
if (field.fields) {
|
|
1667
|
-
if (typeof field.fields === "string") {
|
|
1668
|
-
throw new Error(`Global fields not supported at this time`);
|
|
1669
|
-
}
|
|
1670
|
-
field.fields.forEach((field2) => {
|
|
1671
|
-
parseField(property, field2, objectProps);
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
props[field.name] = objectProps;
|
|
1676
|
-
} else if (item.expression.type === "ArrayExpression") {
|
|
1677
|
-
const objectArrayProps = [];
|
|
1678
|
-
item.expression.elements.forEach((element) => {
|
|
1679
|
-
if (element.type === "ObjectExpression") {
|
|
1680
|
-
const objectProps = {};
|
|
1681
|
-
element.properties.forEach((property) => {
|
|
1682
|
-
if (property.key.type !== "Identifier") {
|
|
1683
|
-
throw new Error(`Unexptected key type ${property.key.type}`);
|
|
1684
|
-
}
|
|
1685
|
-
if (property.value.type !== "Literal") {
|
|
1686
|
-
throw new Error(`Unexptected value type ${property.value.type}`);
|
|
1687
|
-
}
|
|
1688
|
-
if (field.fields) {
|
|
1689
|
-
if (typeof field.fields === "string") {
|
|
1690
|
-
throw new Error(`Global fields not supported at this time`);
|
|
1691
|
-
}
|
|
1692
|
-
field.fields.forEach((field2) => {
|
|
1693
|
-
parseField(property, field2, objectProps);
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
if (field.templates) {
|
|
1697
|
-
field.templates.forEach((fieldTemplate) => {
|
|
1698
|
-
if (typeof fieldTemplate === "string") {
|
|
1699
|
-
throw new Error(`Global fields not supported at this time`);
|
|
1700
|
-
}
|
|
1701
|
-
fieldTemplate.fields.forEach((field2) => {
|
|
1702
|
-
parseField(property, field2, objectProps);
|
|
1703
|
-
});
|
|
1704
|
-
});
|
|
1705
|
-
}
|
|
1706
|
-
});
|
|
1707
|
-
objectArrayProps.push(objectProps);
|
|
1708
|
-
} else {
|
|
1709
|
-
throw new Error(`Unexpected expression type ${element.type}`);
|
|
1710
|
-
}
|
|
1711
|
-
props[field.name] = objectArrayProps;
|
|
1712
|
-
});
|
|
1713
|
-
} else {
|
|
1714
|
-
throw new Error("Only object expressions are supported");
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
break;
|
|
1721
|
-
case "rich-text":
|
|
1722
|
-
if (attribute.value) {
|
|
1723
|
-
if (field.name === "children") {
|
|
1724
|
-
if (Array.isArray(attribute.value)) {
|
|
1725
|
-
props[field.name] = parseMDXInner({ type: "root", children: attribute.value }, field);
|
|
1726
|
-
} else {
|
|
1727
|
-
throw Error(`Expected an array of MDX strings for rich-text field with the special name 'children'`);
|
|
1728
|
-
}
|
|
1729
|
-
} else {
|
|
1730
|
-
try {
|
|
1731
|
-
const mdx2 = parseMDX(attribute.value.value, field);
|
|
1732
|
-
props[field.name] = mdx2.children[0].props;
|
|
1733
|
-
} catch (e) {
|
|
1734
|
-
console.log(e);
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
} else {
|
|
1738
|
-
console.log("nothing", field.name, import_remark_mdx.default);
|
|
1739
|
-
}
|
|
1740
|
-
break;
|
|
1741
|
-
}
|
|
1742
|
-
};
|
|
1743
|
-
var defaultNodeTypes = {
|
|
1744
|
-
paragraph: "paragraph",
|
|
1745
|
-
block_quote: "block_quote",
|
|
1746
|
-
code_block: "code_block",
|
|
1747
|
-
link: "link",
|
|
1748
|
-
ul_list: "ul_list",
|
|
1749
|
-
ol_list: "ol_list",
|
|
1750
|
-
listItem: "list_item",
|
|
1751
|
-
heading: {
|
|
1752
|
-
1: "heading_one",
|
|
1753
|
-
2: "heading_two",
|
|
1754
|
-
3: "heading_three",
|
|
1755
|
-
4: "heading_four",
|
|
1756
|
-
5: "heading_five",
|
|
1757
|
-
6: "heading_six"
|
|
1758
|
-
},
|
|
1759
|
-
emphasis_mark: "italic",
|
|
1760
|
-
strong_mark: "bold",
|
|
1761
|
-
delete_mark: "strikeThrough",
|
|
1762
|
-
inline_code_mark: "code",
|
|
1763
|
-
thematic_break: "thematic_break",
|
|
1764
|
-
image: "image"
|
|
1765
|
-
};
|
|
1766
|
-
function remarkToSlate(node) {
|
|
1767
|
-
const types = __spreadProps(__spreadValues({}, defaultNodeTypes), {
|
|
1768
|
-
heading: __spreadValues({}, defaultNodeTypes.heading)
|
|
1769
|
-
});
|
|
1770
|
-
switch (node.type) {
|
|
1771
|
-
case "heading":
|
|
1772
|
-
return {
|
|
1773
|
-
type: types.heading[node.depth || 1],
|
|
1774
|
-
children: node.children.map(remarkToSlate)
|
|
1775
|
-
};
|
|
1776
|
-
case "list":
|
|
1777
|
-
return {
|
|
1778
|
-
type: node.ordered ? types.ol_list : types.ul_list,
|
|
1779
|
-
children: node.children.map(remarkToSlate)
|
|
1780
|
-
};
|
|
1781
|
-
case "listItem":
|
|
1782
|
-
return {
|
|
1783
|
-
type: types.listItem,
|
|
1784
|
-
children: node.children.map(remarkToSlate)
|
|
1785
|
-
};
|
|
1786
|
-
case "paragraph":
|
|
1787
|
-
return {
|
|
1788
|
-
type: types.paragraph,
|
|
1789
|
-
children: node.children.map(remarkToSlate)
|
|
1790
|
-
};
|
|
1791
|
-
case "link":
|
|
1792
|
-
return {
|
|
1793
|
-
type: types.link,
|
|
1794
|
-
link: node.url,
|
|
1795
|
-
children: node.children.map(remarkToSlate)
|
|
1796
|
-
};
|
|
1797
|
-
case "image":
|
|
1798
|
-
return {
|
|
1799
|
-
type: types.image,
|
|
1800
|
-
link: node.url,
|
|
1801
|
-
caption: node.alt
|
|
1802
|
-
};
|
|
1803
|
-
case "blockquote":
|
|
1804
|
-
return {
|
|
1805
|
-
type: types.block_quote,
|
|
1806
|
-
children: node.children.map(remarkToSlate)
|
|
1807
|
-
};
|
|
1808
|
-
case "code":
|
|
1809
|
-
return {
|
|
1810
|
-
type: types.code_block,
|
|
1811
|
-
language: node.lang,
|
|
1812
|
-
children: [{ type: "text", text: node.value }]
|
|
1813
|
-
};
|
|
1814
|
-
case "emphasis":
|
|
1815
|
-
return __spreadValues(__spreadValues({
|
|
1816
|
-
[types.emphasis_mark]: true
|
|
1817
|
-
}, forceLeafNode(node.children)), persistLeafFormats(node.children));
|
|
1818
|
-
case "strong":
|
|
1819
|
-
return __spreadValues(__spreadValues({
|
|
1820
|
-
[types.strong_mark]: true
|
|
1821
|
-
}, forceLeafNode(node.children)), persistLeafFormats(node.children));
|
|
1822
|
-
case "delete":
|
|
1823
|
-
return __spreadValues(__spreadValues({
|
|
1824
|
-
[types.delete_mark]: true
|
|
1825
|
-
}, forceLeafNode(node.children)), persistLeafFormats(node.children));
|
|
1826
|
-
case "inlineCode":
|
|
1827
|
-
return {
|
|
1828
|
-
[types.inline_code_mark]: true,
|
|
1829
|
-
text: node.value
|
|
1830
|
-
};
|
|
1831
|
-
case "thematicBreak":
|
|
1832
|
-
return {
|
|
1833
|
-
type: types.thematic_break,
|
|
1834
|
-
children: [{ type: "text", text: "" }]
|
|
1835
|
-
};
|
|
1836
|
-
case "text":
|
|
1837
|
-
return { type: "text", text: node.value || "" };
|
|
1838
|
-
case "mdxJsxFlowElement":
|
|
1839
|
-
case "mdxJsxTextElement":
|
|
1840
|
-
return __spreadProps(__spreadValues({}, node), {
|
|
1841
|
-
children: void 0
|
|
1842
|
-
});
|
|
1843
|
-
default:
|
|
1844
|
-
console.log("unknown", node);
|
|
1845
|
-
return { type: "text", text: "" };
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
var forceLeafNode = (children) => {
|
|
1849
|
-
const extraProps = {};
|
|
1850
|
-
const text = [];
|
|
1851
|
-
children.forEach((k) => {
|
|
1852
|
-
switch (k.type) {
|
|
1853
|
-
case "text":
|
|
1854
|
-
return text.push(k.value || "");
|
|
1855
|
-
case "strong":
|
|
1856
|
-
case "emphasis":
|
|
1857
|
-
case "code":
|
|
1858
|
-
const format = { strong: "bold", em: "italic", code: "code" };
|
|
1859
|
-
extraProps[format[k.type]] = true;
|
|
1860
|
-
return k.children.forEach((item) => {
|
|
1861
|
-
text.push(item.value);
|
|
1862
|
-
});
|
|
1863
|
-
default:
|
|
1864
|
-
throw new Error(`Not sure, this should be flattened to the same node`);
|
|
1865
|
-
}
|
|
1866
|
-
});
|
|
1867
|
-
return __spreadValues({
|
|
1868
|
-
type: "text",
|
|
1869
|
-
text: text.join("")
|
|
1870
|
-
}, extraProps);
|
|
1871
|
-
};
|
|
1872
|
-
function persistLeafFormats(children) {
|
|
1873
|
-
return children.reduce((acc, node) => {
|
|
1874
|
-
Object.keys(node).forEach(function(key) {
|
|
1875
|
-
if (key === "children" || key === "type" || key === "text")
|
|
1876
|
-
return;
|
|
1877
|
-
acc[key] = node[key];
|
|
1878
|
-
});
|
|
1879
|
-
return acc;
|
|
1880
|
-
}, {});
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
// ../graphql/src/primitives/mdx/stringify.ts
|
|
1884
|
-
var import_mdast_util_to_markdown = __toModule(require("mdast-util-to-markdown"));
|
|
1885
|
-
var import_mdast_util_mdx = __toModule(require("mdast-util-mdx"));
|
|
1886
|
-
var stringifyMDX = (value, field) => {
|
|
1887
|
-
const slateTree = value.children;
|
|
1888
|
-
try {
|
|
1889
|
-
const tree = slateTree.map((item) => stringify(item, field));
|
|
1890
|
-
const out = (0, import_mdast_util_to_markdown.toMarkdown)({
|
|
1891
|
-
type: "root",
|
|
1892
|
-
children: tree
|
|
1893
|
-
}, {
|
|
1894
|
-
extensions: [import_mdast_util_mdx.mdxToMarkdown]
|
|
1895
|
-
});
|
|
1896
|
-
return out.replace(/"/g, `"`);
|
|
1897
|
-
} catch (e) {
|
|
1898
|
-
console.log(e);
|
|
1899
|
-
}
|
|
1900
|
-
};
|
|
1901
|
-
var stringify = (node, field) => {
|
|
1902
|
-
var _a;
|
|
1903
|
-
if (!node.type) {
|
|
1904
|
-
return {
|
|
1905
|
-
type: "text",
|
|
1906
|
-
value: node.text || ""
|
|
1907
|
-
};
|
|
1908
|
-
}
|
|
1909
|
-
switch (node.type) {
|
|
1910
|
-
case "heading_one":
|
|
1911
|
-
return {
|
|
1912
|
-
type: "heading",
|
|
1913
|
-
depth: 1,
|
|
1914
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1915
|
-
};
|
|
1916
|
-
case "heading_two":
|
|
1917
|
-
return {
|
|
1918
|
-
type: "heading",
|
|
1919
|
-
depth: 2,
|
|
1920
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1921
|
-
};
|
|
1922
|
-
case "heading_three":
|
|
1923
|
-
return {
|
|
1924
|
-
type: "heading",
|
|
1925
|
-
depth: 3,
|
|
1926
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1927
|
-
};
|
|
1928
|
-
case "heading_four":
|
|
1929
|
-
return {
|
|
1930
|
-
type: "heading",
|
|
1931
|
-
depth: 4,
|
|
1932
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1933
|
-
};
|
|
1934
|
-
case "heading_five":
|
|
1935
|
-
return {
|
|
1936
|
-
type: "heading",
|
|
1937
|
-
depth: 5,
|
|
1938
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1939
|
-
};
|
|
1940
|
-
case "heading_six":
|
|
1941
|
-
return {
|
|
1942
|
-
type: "heading",
|
|
1943
|
-
depth: 6,
|
|
1944
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1945
|
-
};
|
|
1946
|
-
case "paragraph":
|
|
1947
|
-
return {
|
|
1948
|
-
type: "paragraph",
|
|
1949
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1950
|
-
};
|
|
1951
|
-
case "link":
|
|
1952
|
-
return {
|
|
1953
|
-
type: "link",
|
|
1954
|
-
url: node.link,
|
|
1955
|
-
children: node.children.map((child) => stringify(child, field))
|
|
1956
|
-
};
|
|
1957
|
-
case "mdxJsxTextElement":
|
|
1958
|
-
case "mdxJsxFlowElement":
|
|
1959
|
-
try {
|
|
1960
|
-
let children = [];
|
|
1961
|
-
const atts = [];
|
|
1962
|
-
const template = (_a = field.templates) == null ? void 0 : _a.find((fieldTemplate) => {
|
|
1963
|
-
if (typeof fieldTemplate === "string") {
|
|
1964
|
-
throw new Error(`Global templates not yet supported`);
|
|
1965
|
-
} else {
|
|
1966
|
-
return fieldTemplate.name === node.name;
|
|
1967
|
-
}
|
|
1968
|
-
});
|
|
1969
|
-
if (typeof template === "string") {
|
|
1970
|
-
throw new Error(`Global templates not yet supported`);
|
|
1971
|
-
}
|
|
1972
|
-
Object.entries(node.props).map(([key, value]) => {
|
|
1973
|
-
if (template.fields) {
|
|
1974
|
-
const field2 = template.fields.find((field3) => field3.name === key);
|
|
1975
|
-
if (!field2) {
|
|
1976
|
-
throw new Error(`Unknown field for key ${key}`);
|
|
1977
|
-
}
|
|
1978
|
-
switch (field2.type) {
|
|
1979
|
-
case "boolean":
|
|
1980
|
-
case "datetime":
|
|
1981
|
-
case "image":
|
|
1982
|
-
case "number":
|
|
1983
|
-
case "string":
|
|
1984
|
-
if (field2.list) {
|
|
1985
|
-
const v = {
|
|
1986
|
-
type: "mdxJsxAttributeValueExpression",
|
|
1987
|
-
value: `[${value.map((item) => {
|
|
1988
|
-
switch (field2.type) {
|
|
1989
|
-
case "boolean":
|
|
1990
|
-
case "number":
|
|
1991
|
-
return `${item}`;
|
|
1992
|
-
case "image":
|
|
1993
|
-
case "datetime":
|
|
1994
|
-
case "string":
|
|
1995
|
-
return `"${item}"`;
|
|
1996
|
-
}
|
|
1997
|
-
})}]`
|
|
1998
|
-
};
|
|
1999
|
-
atts.push({ type: "mdxJsxAttribute", name: key, value: v });
|
|
2000
|
-
} else {
|
|
2001
|
-
atts.push({
|
|
2002
|
-
type: "mdxJsxAttribute",
|
|
2003
|
-
name: key,
|
|
2004
|
-
value: `${value}`
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
break;
|
|
2008
|
-
case "object":
|
|
2009
|
-
if (field2.list) {
|
|
2010
|
-
const values = [];
|
|
2011
|
-
value.forEach((item) => {
|
|
2012
|
-
if (field2.fields) {
|
|
2013
|
-
const v = {};
|
|
2014
|
-
if (typeof field2.fields === "string") {
|
|
2015
|
-
throw new Error(`Global templates not yet supported for rich text`);
|
|
2016
|
-
}
|
|
2017
|
-
field2.fields.forEach((field3) => {
|
|
2018
|
-
const fieldValue = item[field3.name];
|
|
2019
|
-
if (fieldValue) {
|
|
2020
|
-
switch (field3.type) {
|
|
2021
|
-
case "boolean":
|
|
2022
|
-
case "number":
|
|
2023
|
-
v[field3.name] = `${fieldValue}`;
|
|
2024
|
-
break;
|
|
2025
|
-
case "image":
|
|
2026
|
-
case "datetime":
|
|
2027
|
-
case "string":
|
|
2028
|
-
v[field3.name] = `"${fieldValue}"`;
|
|
2029
|
-
break;
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
values.push(v);
|
|
2033
|
-
});
|
|
2034
|
-
} else {
|
|
2035
|
-
value.forEach((item2) => {
|
|
2036
|
-
const [itemTemplateName, itemValues] = Object.entries(item2)[0];
|
|
2037
|
-
const template2 = field2.templates.find((template3) => {
|
|
2038
|
-
const templateName = typeof template3 === "string" ? template3 : template3.name;
|
|
2039
|
-
return templateName === itemTemplateName;
|
|
2040
|
-
});
|
|
2041
|
-
if (typeof template2 === "string") {
|
|
2042
|
-
throw new Error(`Global templates not yet supported for rich text`);
|
|
2043
|
-
}
|
|
2044
|
-
if (!template2) {
|
|
2045
|
-
throw new Error(`Unable to find template for field ${field2.name}`);
|
|
2046
|
-
}
|
|
2047
|
-
const v = {};
|
|
2048
|
-
template2.fields.forEach((field3) => {
|
|
2049
|
-
const fieldValue = itemValues[field3.name];
|
|
2050
|
-
if (fieldValue) {
|
|
2051
|
-
switch (field3.type) {
|
|
2052
|
-
case "boolean":
|
|
2053
|
-
case "number":
|
|
2054
|
-
v[field3.name] = `${fieldValue}`;
|
|
2055
|
-
break;
|
|
2056
|
-
case "image":
|
|
2057
|
-
case "datetime":
|
|
2058
|
-
case "string":
|
|
2059
|
-
v[field3.name] = `"${fieldValue}"`;
|
|
2060
|
-
break;
|
|
2061
|
-
}
|
|
2062
|
-
v["_template"] = `"${template2.name}"`;
|
|
2063
|
-
}
|
|
2064
|
-
});
|
|
2065
|
-
values.push(v);
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
});
|
|
2069
|
-
if (values.length > 0) {
|
|
2070
|
-
const ast = {
|
|
2071
|
-
type: "mdxJsxAttributeValueExpression",
|
|
2072
|
-
name: key,
|
|
2073
|
-
value: {
|
|
2074
|
-
value: `[${values.map((item) => {
|
|
2075
|
-
return `{${Object.entries(item).map(([key2, value2]) => {
|
|
2076
|
-
return `${key2}: ${value2}`;
|
|
2077
|
-
}).join(", ")}}`;
|
|
2078
|
-
}).join(", ")}]`
|
|
2079
|
-
}
|
|
2080
|
-
};
|
|
2081
|
-
atts.push(__spreadValues({ name: key }, ast));
|
|
2082
|
-
}
|
|
2083
|
-
} else {
|
|
2084
|
-
if (field2.fields) {
|
|
2085
|
-
const v = {};
|
|
2086
|
-
if (typeof field2.fields === "string") {
|
|
2087
|
-
throw new Error(`Global templates not yet supported for rich text`);
|
|
2088
|
-
}
|
|
2089
|
-
field2.fields.forEach((field3) => {
|
|
2090
|
-
const fieldValue = value[field3.name];
|
|
2091
|
-
switch (field3.type) {
|
|
2092
|
-
case "boolean":
|
|
2093
|
-
case "number":
|
|
2094
|
-
v[field3.name] = `${fieldValue}`;
|
|
2095
|
-
break;
|
|
2096
|
-
case "image":
|
|
2097
|
-
case "datetime":
|
|
2098
|
-
case "string":
|
|
2099
|
-
v[field3.name] = `"${fieldValue}"`;
|
|
2100
|
-
break;
|
|
2101
|
-
}
|
|
2102
|
-
});
|
|
2103
|
-
const ast = {
|
|
2104
|
-
type: "mdxJsxAttributeValueExpression",
|
|
2105
|
-
name: key,
|
|
2106
|
-
value: {
|
|
2107
|
-
value: `{${Object.entries(v).map(([key2, value2]) => {
|
|
2108
|
-
return `${key2}: ${value2}`;
|
|
2109
|
-
}).join(", ")}}`
|
|
2110
|
-
}
|
|
2111
|
-
};
|
|
2112
|
-
atts.push(__spreadValues({ name: key }, ast));
|
|
2113
|
-
} else {
|
|
2114
|
-
throw new Error("Templates not yet");
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
break;
|
|
2118
|
-
case "rich-text":
|
|
2119
|
-
const tree = value.children.map((item) => stringify(item, field2)).filter((item) => {
|
|
2120
|
-
if (item.type === "text" && !item.text) {
|
|
2121
|
-
return false;
|
|
2122
|
-
}
|
|
2123
|
-
return true;
|
|
2124
|
-
});
|
|
2125
|
-
if (field2.name === "children") {
|
|
2126
|
-
children = tree;
|
|
2127
|
-
} else {
|
|
2128
|
-
const out = (0, import_mdast_util_to_markdown.toMarkdown)({
|
|
2129
|
-
type: "root",
|
|
2130
|
-
children: tree
|
|
2131
|
-
}, { extensions: [import_mdast_util_mdx.mdxToMarkdown] });
|
|
2132
|
-
if (out) {
|
|
2133
|
-
atts.push({
|
|
2134
|
-
type: "mdxJsxAttribute",
|
|
2135
|
-
name: key,
|
|
2136
|
-
value: {
|
|
2137
|
-
value: `
|
|
2138
|
-
<>
|
|
2139
|
-
${out}
|
|
2140
|
-
</>
|
|
2141
|
-
`
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
break;
|
|
2147
|
-
default:
|
|
2148
|
-
atts.push({
|
|
2149
|
-
type: "mdxJsxAttribute",
|
|
2150
|
-
name: key,
|
|
2151
|
-
value: "not yet"
|
|
2152
|
-
});
|
|
2153
|
-
break;
|
|
2154
|
-
}
|
|
2155
|
-
} else {
|
|
2156
|
-
throw new Error(`Templates not yet supported`);
|
|
2157
|
-
}
|
|
2158
|
-
});
|
|
2159
|
-
return __spreadProps(__spreadValues({}, node), {
|
|
2160
|
-
children,
|
|
2161
|
-
attributes: atts
|
|
2162
|
-
});
|
|
2163
|
-
} catch (e) {
|
|
2164
|
-
console.log(e);
|
|
2165
|
-
}
|
|
2166
|
-
case "text":
|
|
2167
|
-
return {
|
|
2168
|
-
type: "text",
|
|
2169
|
-
value: node.text || ""
|
|
2170
|
-
};
|
|
2171
|
-
default:
|
|
2172
|
-
console.log(`Unrecognized field type: ${node.type}`);
|
|
2173
|
-
break;
|
|
2174
|
-
}
|
|
2175
|
-
return { type: "text", value: "" };
|
|
2176
|
-
};
|
|
2177
|
-
|
|
2178
|
-
// ../graphql/src/primitives/resolver/index.ts
|
|
2179
1535
|
var createResolver = (args) => {
|
|
2180
1536
|
return new Resolver(args);
|
|
2181
1537
|
};
|
|
@@ -2240,7 +1596,6 @@ var Resolver = class {
|
|
|
2240
1596
|
};
|
|
2241
1597
|
} catch (e) {
|
|
2242
1598
|
if (e instanceof TinaError) {
|
|
2243
|
-
console.log(e);
|
|
2244
1599
|
throw new TinaError(e.message, __spreadValues({
|
|
2245
1600
|
requestedDocument: fullPath
|
|
2246
1601
|
}, e.extensions));
|
|
@@ -2397,9 +1752,6 @@ var Resolver = class {
|
|
|
2397
1752
|
}
|
|
2398
1753
|
break;
|
|
2399
1754
|
}
|
|
2400
|
-
case "rich-text":
|
|
2401
|
-
accum[fieldName] = stringifyMDX(fieldValue, field);
|
|
2402
|
-
break;
|
|
2403
1755
|
case "reference":
|
|
2404
1756
|
accum[fieldName] = fieldValue;
|
|
2405
1757
|
break;
|
|
@@ -2425,10 +1777,6 @@ var Resolver = class {
|
|
|
2425
1777
|
case "image":
|
|
2426
1778
|
accumulator[field.name] = value;
|
|
2427
1779
|
break;
|
|
2428
|
-
case "rich-text":
|
|
2429
|
-
const tree = parseMDX(value, field);
|
|
2430
|
-
accumulator[field.name] = tree;
|
|
2431
|
-
break;
|
|
2432
1780
|
case "object":
|
|
2433
1781
|
if (field.list) {
|
|
2434
1782
|
if (!value) {
|
|
@@ -2552,13 +1900,13 @@ var Resolver = class {
|
|
|
2552
1900
|
}))
|
|
2553
1901
|
}), extraFields);
|
|
2554
1902
|
} else if (templateInfo.type === "union") {
|
|
2555
|
-
const
|
|
2556
|
-
const
|
|
1903
|
+
const templates = {};
|
|
1904
|
+
const typeMap = {};
|
|
2557
1905
|
yield sequential(templateInfo.templates, (template) => __async(this, null, function* () {
|
|
2558
1906
|
const extraFields2 = template.ui || {};
|
|
2559
1907
|
const templateName = lastItem(template.namespace);
|
|
2560
|
-
|
|
2561
|
-
|
|
1908
|
+
typeMap[templateName] = NAMER.dataTypeName(template.namespace);
|
|
1909
|
+
templates[lastItem(template.namespace)] = __spreadValues({
|
|
2562
1910
|
label: template.label || templateName,
|
|
2563
1911
|
key: templateName,
|
|
2564
1912
|
fields: yield sequential(template.fields, (field2) => __async(this, null, function* () {
|
|
@@ -2568,35 +1916,13 @@ var Resolver = class {
|
|
|
2568
1916
|
return true;
|
|
2569
1917
|
}));
|
|
2570
1918
|
return __spreadValues(__spreadProps(__spreadValues({}, field), {
|
|
2571
|
-
typeMap
|
|
1919
|
+
typeMap,
|
|
2572
1920
|
component: field.list ? "blocks" : "not-implemented",
|
|
2573
|
-
templates
|
|
1921
|
+
templates
|
|
2574
1922
|
}), extraFields);
|
|
2575
1923
|
} else {
|
|
2576
1924
|
throw new Error(`Unknown object for resolveField function`);
|
|
2577
1925
|
}
|
|
2578
|
-
case "rich-text":
|
|
2579
|
-
const templates = {};
|
|
2580
|
-
const typeMap = {};
|
|
2581
|
-
yield sequential(field.templates, (template) => __async(this, null, function* () {
|
|
2582
|
-
const extraFields2 = template.ui || {};
|
|
2583
|
-
const templateName = lastItem(template.namespace);
|
|
2584
|
-
typeMap[templateName] = NAMER.dataTypeName(template.namespace);
|
|
2585
|
-
templates[lastItem(template.namespace)] = __spreadValues({
|
|
2586
|
-
label: template.label || templateName,
|
|
2587
|
-
key: templateName,
|
|
2588
|
-
inline: template.inline,
|
|
2589
|
-
name: templateName,
|
|
2590
|
-
fields: yield sequential(template.fields, (field2) => __async(this, null, function* () {
|
|
2591
|
-
return yield this.resolveField(field2);
|
|
2592
|
-
}))
|
|
2593
|
-
}, extraFields2);
|
|
2594
|
-
return true;
|
|
2595
|
-
}));
|
|
2596
|
-
return __spreadValues(__spreadProps(__spreadValues({}, field), {
|
|
2597
|
-
templates: Object.values(templates),
|
|
2598
|
-
component: "rich-text"
|
|
2599
|
-
}), extraFields);
|
|
2600
1926
|
case "reference":
|
|
2601
1927
|
const documents = import_lodash5.default.flatten(yield sequential(field.collections, (collectionName) => __async(this, null, function* () {
|
|
2602
1928
|
return this.database.getDocumentsForCollection(collectionName);
|
|
@@ -3125,7 +2451,7 @@ var Database = class {
|
|
|
3125
2451
|
const templateName = hasOwnProperty(contentObject, "_template") && typeof contentObject._template === "string" ? contentObject._template : void 0;
|
|
3126
2452
|
const { collection, template } = yield tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
|
|
3127
2453
|
const field = template.fields.find((field2) => {
|
|
3128
|
-
if (field2.type === "string"
|
|
2454
|
+
if (field2.type === "string") {
|
|
3129
2455
|
if (field2.isBody) {
|
|
3130
2456
|
return true;
|
|
3131
2457
|
}
|
|
@@ -3133,7 +2459,7 @@ var Database = class {
|
|
|
3133
2459
|
return false;
|
|
3134
2460
|
});
|
|
3135
2461
|
let data = contentObject;
|
|
3136
|
-
if (
|
|
2462
|
+
if (extension === ".md" && field) {
|
|
3137
2463
|
if (hasOwnProperty(contentObject, "$_body")) {
|
|
3138
2464
|
const _b = contentObject, { $_body } = _b, rest = __objRest(_b, ["$_body"]);
|
|
3139
2465
|
data = rest;
|
|
@@ -3170,7 +2496,7 @@ var Database = class {
|
|
|
3170
2496
|
throw new Error(`Unable to determine template`);
|
|
3171
2497
|
}
|
|
3172
2498
|
const field = template.fields.find((field2) => {
|
|
3173
|
-
if (field2.type === "string"
|
|
2499
|
+
if (field2.type === "string") {
|
|
3174
2500
|
if (field2.isBody) {
|
|
3175
2501
|
return true;
|
|
3176
2502
|
}
|
|
@@ -3178,7 +2504,7 @@ var Database = class {
|
|
|
3178
2504
|
return false;
|
|
3179
2505
|
});
|
|
3180
2506
|
let payload = {};
|
|
3181
|
-
if (
|
|
2507
|
+
if (collection.format === "md" && field) {
|
|
3182
2508
|
Object.entries(data).forEach(([key, value]) => {
|
|
3183
2509
|
if (key !== field.name) {
|
|
3184
2510
|
payload[key] = value;
|
|
@@ -3259,15 +2585,13 @@ var Database = class {
|
|
|
3259
2585
|
this.stringifyFile = (content, format, keepTemplateKey) => {
|
|
3260
2586
|
switch (format) {
|
|
3261
2587
|
case ".markdown":
|
|
3262
|
-
case ".mdx":
|
|
3263
2588
|
case ".md":
|
|
3264
2589
|
const _a = content, { _id, _template, _collection, $_body } = _a, rest = __objRest(_a, ["_id", "_template", "_collection", "$_body"]);
|
|
3265
2590
|
const extra = {};
|
|
3266
2591
|
if (keepTemplateKey) {
|
|
3267
2592
|
extra["_template"] = _template;
|
|
3268
2593
|
}
|
|
3269
|
-
return import_gray_matter.default.stringify(
|
|
3270
|
-
${$_body}` || "\n", __spreadValues(__spreadValues({}, rest), extra));
|
|
2594
|
+
return import_gray_matter.default.stringify($_body || "", __spreadValues(__spreadValues({}, rest), extra));
|
|
3271
2595
|
case ".json":
|
|
3272
2596
|
return JSON.stringify(content, null, 2);
|
|
3273
2597
|
default:
|
|
@@ -3277,7 +2601,6 @@ ${$_body}` || "\n", __spreadValues(__spreadValues({}, rest), extra));
|
|
|
3277
2601
|
this.parseFile = (content, format, yupSchema) => {
|
|
3278
2602
|
switch (format) {
|
|
3279
2603
|
case ".markdown":
|
|
3280
|
-
case ".mdx":
|
|
3281
2604
|
case ".md":
|
|
3282
2605
|
const contentJSON = (0, import_gray_matter.default)(content || "");
|
|
3283
2606
|
const markdownData = __spreadProps(__spreadValues({}, contentJSON.data), {
|