@tinacms/graphql 0.60.5 → 0.60.6
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 +16 -0
- package/dist/ast-builder/index.d.ts +3 -1
- package/dist/index.js +294 -60
- package/dist/mdx/parse.d.ts +4 -4
- package/dist/mdx/stringify.d.ts +3 -3
- package/dist/resolver/media-utils.d.ts +29 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# tina-graphql
|
|
2
2
|
|
|
3
|
+
## 0.60.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e2aafcd93: Add more GraphQL variables to the generated queries.
|
|
8
|
+
- a20fed8b7: Resolve Cloud URLs to Relative URLs when saving TinaCloud's media
|
|
9
|
+
|
|
10
|
+
Introduces a pair of functions (inside `media-utils.ts`) for handling URLs provided by TinaCloud (`resolveMediaCloudToRelative` and `resolveMediaRelativeToCloud`).
|
|
11
|
+
|
|
12
|
+
These are used in conjuction with two pairs of functions:
|
|
13
|
+
|
|
14
|
+
- When providing data to the preview: `resolveFieldData` and `parseMDX`
|
|
15
|
+
- When saving data to the document: `buildFieldMutations` and `stringifyMDX`
|
|
16
|
+
|
|
17
|
+
I also introduced tests around `media-utils.ts` (`media-utils.test.ts`).
|
|
18
|
+
|
|
3
19
|
## 0.60.5
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -126,9 +126,11 @@ export declare const astBuilder: {
|
|
|
126
126
|
queryName: string;
|
|
127
127
|
fragName: string;
|
|
128
128
|
}) => OperationDefinitionNode;
|
|
129
|
-
ListQueryOperationDefinition: ({ queryName, fragName, }: {
|
|
129
|
+
ListQueryOperationDefinition: ({ queryName, fragName, filterType, dataLayer, }: {
|
|
130
130
|
queryName: string;
|
|
131
131
|
fragName: string;
|
|
132
|
+
filterType: string;
|
|
133
|
+
dataLayer: boolean;
|
|
132
134
|
}) => OperationDefinitionNode;
|
|
133
135
|
toGraphQLAst: (ast: {
|
|
134
136
|
globalTemplates: TypeDefinitionNode[];
|
package/dist/index.js
CHANGED
|
@@ -10954,8 +10954,208 @@ var astBuilder = {
|
|
|
10954
10954
|
},
|
|
10955
10955
|
ListQueryOperationDefinition: ({
|
|
10956
10956
|
queryName,
|
|
10957
|
-
fragName
|
|
10957
|
+
fragName,
|
|
10958
|
+
filterType,
|
|
10959
|
+
dataLayer
|
|
10958
10960
|
}) => {
|
|
10961
|
+
const variableDefinitions = [
|
|
10962
|
+
{
|
|
10963
|
+
kind: "VariableDefinition",
|
|
10964
|
+
variable: {
|
|
10965
|
+
kind: "Variable",
|
|
10966
|
+
name: {
|
|
10967
|
+
kind: "Name",
|
|
10968
|
+
value: "before"
|
|
10969
|
+
}
|
|
10970
|
+
},
|
|
10971
|
+
type: {
|
|
10972
|
+
kind: "NamedType",
|
|
10973
|
+
name: {
|
|
10974
|
+
kind: "Name",
|
|
10975
|
+
value: "String"
|
|
10976
|
+
}
|
|
10977
|
+
},
|
|
10978
|
+
directives: []
|
|
10979
|
+
},
|
|
10980
|
+
{
|
|
10981
|
+
kind: "VariableDefinition",
|
|
10982
|
+
variable: {
|
|
10983
|
+
kind: "Variable",
|
|
10984
|
+
name: {
|
|
10985
|
+
kind: "Name",
|
|
10986
|
+
value: "after"
|
|
10987
|
+
}
|
|
10988
|
+
},
|
|
10989
|
+
type: {
|
|
10990
|
+
kind: "NamedType",
|
|
10991
|
+
name: {
|
|
10992
|
+
kind: "Name",
|
|
10993
|
+
value: "String"
|
|
10994
|
+
}
|
|
10995
|
+
},
|
|
10996
|
+
directives: []
|
|
10997
|
+
},
|
|
10998
|
+
{
|
|
10999
|
+
kind: "VariableDefinition",
|
|
11000
|
+
variable: {
|
|
11001
|
+
kind: "Variable",
|
|
11002
|
+
name: {
|
|
11003
|
+
kind: "Name",
|
|
11004
|
+
value: "first"
|
|
11005
|
+
}
|
|
11006
|
+
},
|
|
11007
|
+
type: {
|
|
11008
|
+
kind: "NamedType",
|
|
11009
|
+
name: {
|
|
11010
|
+
kind: "Name",
|
|
11011
|
+
value: "Float"
|
|
11012
|
+
}
|
|
11013
|
+
},
|
|
11014
|
+
directives: []
|
|
11015
|
+
},
|
|
11016
|
+
{
|
|
11017
|
+
kind: "VariableDefinition",
|
|
11018
|
+
variable: {
|
|
11019
|
+
kind: "Variable",
|
|
11020
|
+
name: {
|
|
11021
|
+
kind: "Name",
|
|
11022
|
+
value: "last"
|
|
11023
|
+
}
|
|
11024
|
+
},
|
|
11025
|
+
type: {
|
|
11026
|
+
kind: "NamedType",
|
|
11027
|
+
name: {
|
|
11028
|
+
kind: "Name",
|
|
11029
|
+
value: "Float"
|
|
11030
|
+
}
|
|
11031
|
+
},
|
|
11032
|
+
directives: []
|
|
11033
|
+
},
|
|
11034
|
+
{
|
|
11035
|
+
kind: "VariableDefinition",
|
|
11036
|
+
variable: {
|
|
11037
|
+
kind: "Variable",
|
|
11038
|
+
name: {
|
|
11039
|
+
kind: "Name",
|
|
11040
|
+
value: "sort"
|
|
11041
|
+
}
|
|
11042
|
+
},
|
|
11043
|
+
type: {
|
|
11044
|
+
kind: "NamedType",
|
|
11045
|
+
name: {
|
|
11046
|
+
kind: "Name",
|
|
11047
|
+
value: "String"
|
|
11048
|
+
}
|
|
11049
|
+
},
|
|
11050
|
+
directives: []
|
|
11051
|
+
}
|
|
11052
|
+
];
|
|
11053
|
+
const queryArguments = [
|
|
11054
|
+
{
|
|
11055
|
+
kind: "Argument",
|
|
11056
|
+
name: {
|
|
11057
|
+
kind: "Name",
|
|
11058
|
+
value: "before"
|
|
11059
|
+
},
|
|
11060
|
+
value: {
|
|
11061
|
+
kind: "Variable",
|
|
11062
|
+
name: {
|
|
11063
|
+
kind: "Name",
|
|
11064
|
+
value: "before"
|
|
11065
|
+
}
|
|
11066
|
+
}
|
|
11067
|
+
},
|
|
11068
|
+
{
|
|
11069
|
+
kind: "Argument",
|
|
11070
|
+
name: {
|
|
11071
|
+
kind: "Name",
|
|
11072
|
+
value: "after"
|
|
11073
|
+
},
|
|
11074
|
+
value: {
|
|
11075
|
+
kind: "Variable",
|
|
11076
|
+
name: {
|
|
11077
|
+
kind: "Name",
|
|
11078
|
+
value: "after"
|
|
11079
|
+
}
|
|
11080
|
+
}
|
|
11081
|
+
},
|
|
11082
|
+
{
|
|
11083
|
+
kind: "Argument",
|
|
11084
|
+
name: {
|
|
11085
|
+
kind: "Name",
|
|
11086
|
+
value: "first"
|
|
11087
|
+
},
|
|
11088
|
+
value: {
|
|
11089
|
+
kind: "Variable",
|
|
11090
|
+
name: {
|
|
11091
|
+
kind: "Name",
|
|
11092
|
+
value: "first"
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
},
|
|
11096
|
+
{
|
|
11097
|
+
kind: "Argument",
|
|
11098
|
+
name: {
|
|
11099
|
+
kind: "Name",
|
|
11100
|
+
value: "last"
|
|
11101
|
+
},
|
|
11102
|
+
value: {
|
|
11103
|
+
kind: "Variable",
|
|
11104
|
+
name: {
|
|
11105
|
+
kind: "Name",
|
|
11106
|
+
value: "last"
|
|
11107
|
+
}
|
|
11108
|
+
}
|
|
11109
|
+
},
|
|
11110
|
+
{
|
|
11111
|
+
kind: "Argument",
|
|
11112
|
+
name: {
|
|
11113
|
+
kind: "Name",
|
|
11114
|
+
value: "sort"
|
|
11115
|
+
},
|
|
11116
|
+
value: {
|
|
11117
|
+
kind: "Variable",
|
|
11118
|
+
name: {
|
|
11119
|
+
kind: "Name",
|
|
11120
|
+
value: "sort"
|
|
11121
|
+
}
|
|
11122
|
+
}
|
|
11123
|
+
}
|
|
11124
|
+
];
|
|
11125
|
+
if (dataLayer) {
|
|
11126
|
+
queryArguments.push({
|
|
11127
|
+
kind: "Argument",
|
|
11128
|
+
name: {
|
|
11129
|
+
kind: "Name",
|
|
11130
|
+
value: "filter"
|
|
11131
|
+
},
|
|
11132
|
+
value: {
|
|
11133
|
+
kind: "Variable",
|
|
11134
|
+
name: {
|
|
11135
|
+
kind: "Name",
|
|
11136
|
+
value: "filter"
|
|
11137
|
+
}
|
|
11138
|
+
}
|
|
11139
|
+
});
|
|
11140
|
+
variableDefinitions.push({
|
|
11141
|
+
kind: "VariableDefinition",
|
|
11142
|
+
variable: {
|
|
11143
|
+
kind: "Variable",
|
|
11144
|
+
name: {
|
|
11145
|
+
kind: "Name",
|
|
11146
|
+
value: "filter"
|
|
11147
|
+
}
|
|
11148
|
+
},
|
|
11149
|
+
type: {
|
|
11150
|
+
kind: "NamedType",
|
|
11151
|
+
name: {
|
|
11152
|
+
kind: "Name",
|
|
11153
|
+
value: filterType
|
|
11154
|
+
}
|
|
11155
|
+
},
|
|
11156
|
+
directives: []
|
|
11157
|
+
});
|
|
11158
|
+
}
|
|
10959
11159
|
return {
|
|
10960
11160
|
kind: "OperationDefinition",
|
|
10961
11161
|
operation: "query",
|
|
@@ -10963,7 +11163,7 @@ var astBuilder = {
|
|
|
10963
11163
|
kind: "Name",
|
|
10964
11164
|
value: queryName
|
|
10965
11165
|
},
|
|
10966
|
-
variableDefinitions
|
|
11166
|
+
variableDefinitions,
|
|
10967
11167
|
directives: [],
|
|
10968
11168
|
selectionSet: {
|
|
10969
11169
|
kind: "SelectionSet",
|
|
@@ -10974,7 +11174,7 @@ var astBuilder = {
|
|
|
10974
11174
|
kind: "Name",
|
|
10975
11175
|
value: queryName
|
|
10976
11176
|
},
|
|
10977
|
-
arguments:
|
|
11177
|
+
arguments: queryArguments,
|
|
10978
11178
|
directives: [],
|
|
10979
11179
|
selectionSet: {
|
|
10980
11180
|
kind: "SelectionSet",
|
|
@@ -12480,7 +12680,7 @@ var validateField = async (field) => {
|
|
|
12480
12680
|
|
|
12481
12681
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
|
|
12482
12682
|
var name = "@tinacms/graphql";
|
|
12483
|
-
var version = "0.60.
|
|
12683
|
+
var version = "0.60.6";
|
|
12484
12684
|
var main = "dist/index.js";
|
|
12485
12685
|
var typings = "dist/index.d.ts";
|
|
12486
12686
|
var files = [
|
|
@@ -12850,13 +13050,17 @@ var _buildQueries = async (builder, tinaSchema, rootPath) => {
|
|
|
12850
13050
|
const operationsDefinitions = [];
|
|
12851
13051
|
const collections = tinaSchema.getCollections();
|
|
12852
13052
|
await sequential(collections, async (collection) => {
|
|
13053
|
+
var _a, _b, _c;
|
|
12853
13054
|
const queryName = NAMER.queryName(collection.namespace);
|
|
12854
13055
|
const queryListName = NAMER.generateQueryListName(collection.namespace);
|
|
13056
|
+
const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
|
|
12855
13057
|
const fragName = NAMER.fragmentName(collection.namespace);
|
|
12856
13058
|
operationsDefinitions.push(astBuilder.QueryOperationDefinition({ fragName, queryName }));
|
|
12857
13059
|
operationsDefinitions.push(astBuilder.ListQueryOperationDefinition({
|
|
12858
13060
|
fragName,
|
|
12859
|
-
queryName: queryListName
|
|
13061
|
+
queryName: queryListName,
|
|
13062
|
+
filterType: queryFilterTypeName,
|
|
13063
|
+
dataLayer: Boolean((_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData"))
|
|
12860
13064
|
}));
|
|
12861
13065
|
});
|
|
12862
13066
|
const queryDoc = {
|
|
@@ -20222,11 +20426,42 @@ var visit = function(tree, test, visitor, reverse) {
|
|
|
20222
20426
|
|
|
20223
20427
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/mdx/parse.ts
|
|
20224
20428
|
var import_lodash4 = __toModule(require("lodash"));
|
|
20225
|
-
|
|
20429
|
+
|
|
20430
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/media-utils.ts
|
|
20431
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }) => {
|
|
20432
|
+
if (config && value) {
|
|
20433
|
+
if (config.useRelativeMedia === true) {
|
|
20434
|
+
return value;
|
|
20435
|
+
} else {
|
|
20436
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
20437
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
20438
|
+
return value.replace(assetsURL, "");
|
|
20439
|
+
} else {
|
|
20440
|
+
return value;
|
|
20441
|
+
}
|
|
20442
|
+
}
|
|
20443
|
+
} else {
|
|
20444
|
+
return value;
|
|
20445
|
+
}
|
|
20446
|
+
};
|
|
20447
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }) => {
|
|
20448
|
+
if (config && value) {
|
|
20449
|
+
if (config.useRelativeMedia === true) {
|
|
20450
|
+
return value;
|
|
20451
|
+
} else {
|
|
20452
|
+
return `https://${config.assetsHost}/${config.clientId}${value}`;
|
|
20453
|
+
}
|
|
20454
|
+
} else {
|
|
20455
|
+
return value;
|
|
20456
|
+
}
|
|
20457
|
+
};
|
|
20458
|
+
|
|
20459
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/mdx/parse.ts
|
|
20460
|
+
var parseMDX = (value, field, graphQLconfig) => {
|
|
20226
20461
|
const tree = unified().use(remark_parse_default).use(import_remark_mdx.default).parse(value);
|
|
20227
|
-
return parseMDXInner(tree, field);
|
|
20462
|
+
return parseMDXInner(tree, field, graphQLconfig);
|
|
20228
20463
|
};
|
|
20229
|
-
var parseMDXInner = (tree, field) => {
|
|
20464
|
+
var parseMDXInner = (tree, field, graphQLconfig) => {
|
|
20230
20465
|
visit(tree, (node) => {
|
|
20231
20466
|
delete node.position;
|
|
20232
20467
|
});
|
|
@@ -20234,7 +20469,7 @@ var parseMDXInner = (tree, field) => {
|
|
|
20234
20469
|
var _a;
|
|
20235
20470
|
let props = {};
|
|
20236
20471
|
if (!node.name) {
|
|
20237
|
-
props = parseMDXInner({ type: "root", children: node.children }, field);
|
|
20472
|
+
props = parseMDXInner({ type: "root", children: node.children }, field, graphQLconfig);
|
|
20238
20473
|
}
|
|
20239
20474
|
const template = (_a = field.templates) == null ? void 0 : _a.find((template2) => {
|
|
20240
20475
|
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
@@ -20265,7 +20500,7 @@ var parseMDXInner = (tree, field) => {
|
|
|
20265
20500
|
if (!field2) {
|
|
20266
20501
|
throw new Error(`Unknown property '${attribute.name}' for embedded structure '${node.name}'`);
|
|
20267
20502
|
}
|
|
20268
|
-
parseField(attribute, field2, props);
|
|
20503
|
+
parseField(attribute, field2, props, graphQLconfig);
|
|
20269
20504
|
}
|
|
20270
20505
|
} else {
|
|
20271
20506
|
console.log(`Not sure what this is, type: ${attribute.type}`);
|
|
@@ -20274,15 +20509,19 @@ var parseMDXInner = (tree, field) => {
|
|
|
20274
20509
|
delete node.attributes;
|
|
20275
20510
|
node.props = props;
|
|
20276
20511
|
});
|
|
20277
|
-
const slateTree = tree.children.map(remarkToSlate);
|
|
20512
|
+
const slateTree = tree.children.map((node) => remarkToSlate(node, graphQLconfig));
|
|
20278
20513
|
return { type: "root", children: slateTree };
|
|
20279
20514
|
};
|
|
20280
|
-
var parseField = (attribute, field, props) => {
|
|
20515
|
+
var parseField = (attribute, field, props, graphQLconfig) => {
|
|
20281
20516
|
var _a, _b;
|
|
20282
20517
|
switch (field.type) {
|
|
20283
20518
|
case "boolean":
|
|
20284
20519
|
case "datetime":
|
|
20520
|
+
props[field.name] = attribute.value;
|
|
20521
|
+
break;
|
|
20285
20522
|
case "image":
|
|
20523
|
+
props[field.name] = resolveMediaRelativeToCloud(attribute.value, graphQLconfig);
|
|
20524
|
+
break;
|
|
20286
20525
|
case "number":
|
|
20287
20526
|
case "string":
|
|
20288
20527
|
if (field.list) {
|
|
@@ -20344,7 +20583,7 @@ var parseField = (attribute, field, props) => {
|
|
|
20344
20583
|
throw new Error(`Global fields not supported at this time`);
|
|
20345
20584
|
}
|
|
20346
20585
|
field.fields.forEach((field2) => {
|
|
20347
|
-
parseField(property, field2, objectProps);
|
|
20586
|
+
parseField(property, field2, objectProps, graphQLconfig);
|
|
20348
20587
|
});
|
|
20349
20588
|
}
|
|
20350
20589
|
});
|
|
@@ -20366,7 +20605,7 @@ var parseField = (attribute, field, props) => {
|
|
|
20366
20605
|
throw new Error(`Global fields not supported at this time`);
|
|
20367
20606
|
}
|
|
20368
20607
|
field.fields.forEach((field2) => {
|
|
20369
|
-
parseField(property, field2, objectProps);
|
|
20608
|
+
parseField(property, field2, objectProps, graphQLconfig);
|
|
20370
20609
|
});
|
|
20371
20610
|
}
|
|
20372
20611
|
if (field.templates) {
|
|
@@ -20375,7 +20614,7 @@ var parseField = (attribute, field, props) => {
|
|
|
20375
20614
|
throw new Error(`Global fields not supported at this time`);
|
|
20376
20615
|
}
|
|
20377
20616
|
fieldTemplate.fields.forEach((field2) => {
|
|
20378
|
-
parseField(property, field2, objectProps);
|
|
20617
|
+
parseField(property, field2, objectProps, graphQLconfig);
|
|
20379
20618
|
});
|
|
20380
20619
|
});
|
|
20381
20620
|
}
|
|
@@ -20398,13 +20637,13 @@ var parseField = (attribute, field, props) => {
|
|
|
20398
20637
|
if (attribute.value) {
|
|
20399
20638
|
if (field.name === "children") {
|
|
20400
20639
|
if (Array.isArray(attribute.value)) {
|
|
20401
|
-
props[field.name] = parseMDXInner({ type: "root", children: attribute.value }, field);
|
|
20640
|
+
props[field.name] = parseMDXInner({ type: "root", children: attribute.value }, field, graphQLconfig);
|
|
20402
20641
|
} else {
|
|
20403
20642
|
throw Error(`Expected an array of MDX strings for rich-text field with the special name 'children'`);
|
|
20404
20643
|
}
|
|
20405
20644
|
} else {
|
|
20406
20645
|
try {
|
|
20407
|
-
const mdx2 = parseMDX(attribute.value.value, field);
|
|
20646
|
+
const mdx2 = parseMDX(attribute.value.value, field, graphQLconfig);
|
|
20408
20647
|
props[field.name] = mdx2.children[0].props;
|
|
20409
20648
|
} catch (e) {
|
|
20410
20649
|
console.log(e);
|
|
@@ -20475,7 +20714,7 @@ var defaultNodeTypes = {
|
|
|
20475
20714
|
break: "break",
|
|
20476
20715
|
image: plateElements.ELEMENT_IMAGE
|
|
20477
20716
|
};
|
|
20478
|
-
function remarkToSlate(node) {
|
|
20717
|
+
function remarkToSlate(node, graphQLconfig) {
|
|
20479
20718
|
const types = __spreadProps(__spreadValues({}, defaultNodeTypes), {
|
|
20480
20719
|
heading: __spreadValues({}, defaultNodeTypes.heading)
|
|
20481
20720
|
});
|
|
@@ -20483,12 +20722,12 @@ function remarkToSlate(node) {
|
|
|
20483
20722
|
case "heading":
|
|
20484
20723
|
return {
|
|
20485
20724
|
type: types.heading[node.depth],
|
|
20486
|
-
children: node.children.map(remarkToSlate)
|
|
20725
|
+
children: node.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20487
20726
|
};
|
|
20488
20727
|
case "list":
|
|
20489
20728
|
return {
|
|
20490
20729
|
type: node.ordered ? types.ol_list : types.ul_list,
|
|
20491
|
-
children: node.children.map(remarkToSlate)
|
|
20730
|
+
children: node.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20492
20731
|
};
|
|
20493
20732
|
case "listItem":
|
|
20494
20733
|
const realChildren = [];
|
|
@@ -20496,12 +20735,12 @@ function remarkToSlate(node) {
|
|
|
20496
20735
|
if (child.type === "list") {
|
|
20497
20736
|
realChildren.push({
|
|
20498
20737
|
type: child.ordered ? types.ol_list : types.ul_list,
|
|
20499
|
-
children: child.children.map(remarkToSlate)
|
|
20738
|
+
children: child.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20500
20739
|
});
|
|
20501
20740
|
} else {
|
|
20502
20741
|
realChildren.push({
|
|
20503
20742
|
type: plateElements.ELEMENT_LIC,
|
|
20504
|
-
children: child.children.map(remarkToSlate)
|
|
20743
|
+
children: child.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20505
20744
|
});
|
|
20506
20745
|
}
|
|
20507
20746
|
});
|
|
@@ -20512,25 +20751,26 @@ function remarkToSlate(node) {
|
|
|
20512
20751
|
case "paragraph":
|
|
20513
20752
|
return {
|
|
20514
20753
|
type: types.paragraph,
|
|
20515
|
-
children: node.children.map(remarkToSlate)
|
|
20754
|
+
children: node.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20516
20755
|
};
|
|
20517
20756
|
case "link":
|
|
20518
20757
|
return {
|
|
20519
20758
|
type: types.link,
|
|
20520
20759
|
url: node.url,
|
|
20521
|
-
children: node.children.map(remarkToSlate)
|
|
20760
|
+
children: node.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20522
20761
|
};
|
|
20523
20762
|
case "image":
|
|
20763
|
+
const url = resolveMediaRelativeToCloud(node.url, graphQLconfig);
|
|
20524
20764
|
return {
|
|
20525
20765
|
type: types.image,
|
|
20526
|
-
url
|
|
20766
|
+
url,
|
|
20527
20767
|
alt: node.alt,
|
|
20528
20768
|
caption: node.title
|
|
20529
20769
|
};
|
|
20530
20770
|
case "blockquote":
|
|
20531
20771
|
return {
|
|
20532
20772
|
type: types.block_quote,
|
|
20533
|
-
children: node.children.map(remarkToSlate)
|
|
20773
|
+
children: node.children.map((node2) => remarkToSlate(node2, graphQLconfig))
|
|
20534
20774
|
};
|
|
20535
20775
|
case "code":
|
|
20536
20776
|
return {
|
|
@@ -21991,10 +22231,10 @@ var mdxToMarkdown = {
|
|
|
21991
22231
|
};
|
|
21992
22232
|
|
|
21993
22233
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/mdx/stringify.ts
|
|
21994
|
-
var stringifyMDX = (value, field) => {
|
|
22234
|
+
var stringifyMDX = (value, field, graphQLconfig) => {
|
|
21995
22235
|
const slateTree = value.children;
|
|
21996
22236
|
try {
|
|
21997
|
-
const tree = stringifyChildren(slateTree, field);
|
|
22237
|
+
const tree = stringifyChildren(slateTree, field, graphQLconfig);
|
|
21998
22238
|
const out = toMarkdown({
|
|
21999
22239
|
type: "root",
|
|
22000
22240
|
children: tree
|
|
@@ -22012,13 +22252,13 @@ var allChildrenEmpty = (children) => {
|
|
|
22012
22252
|
}
|
|
22013
22253
|
return false;
|
|
22014
22254
|
};
|
|
22015
|
-
var stringifyChildren = (children, field) => {
|
|
22255
|
+
var stringifyChildren = (children, field, graphQLconfig) => {
|
|
22016
22256
|
if (!children) {
|
|
22017
22257
|
return [];
|
|
22018
22258
|
}
|
|
22019
|
-
return children.map((child) => stringify(child, field)).filter(Boolean);
|
|
22259
|
+
return children.map((child) => stringify(child, field, graphQLconfig)).filter(Boolean);
|
|
22020
22260
|
};
|
|
22021
|
-
var stringify = (node, field) => {
|
|
22261
|
+
var stringify = (node, field, graphQLconfig) => {
|
|
22022
22262
|
var _a;
|
|
22023
22263
|
if (!node.type) {
|
|
22024
22264
|
if (node == null ? void 0 : node.code) {
|
|
@@ -22044,40 +22284,40 @@ var stringify = (node, field) => {
|
|
|
22044
22284
|
return {
|
|
22045
22285
|
type: "heading",
|
|
22046
22286
|
depth: 1,
|
|
22047
|
-
children: stringifyChildren(node.children, field)
|
|
22287
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22048
22288
|
};
|
|
22049
22289
|
case plateElements.ELEMENT_H2:
|
|
22050
22290
|
return {
|
|
22051
22291
|
type: "heading",
|
|
22052
22292
|
depth: 2,
|
|
22053
|
-
children: stringifyChildren(node.children, field)
|
|
22293
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22054
22294
|
};
|
|
22055
22295
|
case plateElements.ELEMENT_H3:
|
|
22056
22296
|
return {
|
|
22057
22297
|
type: "heading",
|
|
22058
22298
|
depth: 3,
|
|
22059
|
-
children: stringifyChildren(node.children, field)
|
|
22299
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22060
22300
|
};
|
|
22061
22301
|
case plateElements.ELEMENT_H4:
|
|
22062
22302
|
return {
|
|
22063
22303
|
type: "heading",
|
|
22064
22304
|
depth: 4,
|
|
22065
|
-
children: stringifyChildren(node.children, field)
|
|
22305
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22066
22306
|
};
|
|
22067
22307
|
case plateElements.ELEMENT_H5:
|
|
22068
22308
|
return {
|
|
22069
22309
|
type: "heading",
|
|
22070
22310
|
depth: 5,
|
|
22071
|
-
children: stringifyChildren(node.children, field)
|
|
22311
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22072
22312
|
};
|
|
22073
22313
|
case plateElements.ELEMENT_H6:
|
|
22074
22314
|
return {
|
|
22075
22315
|
type: "heading",
|
|
22076
22316
|
depth: 6,
|
|
22077
|
-
children: stringifyChildren(node.children, field)
|
|
22317
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22078
22318
|
};
|
|
22079
22319
|
case plateElements.ELEMENT_PARAGRAPH:
|
|
22080
|
-
const children = stringifyChildren(node.children, field);
|
|
22320
|
+
const children = stringifyChildren(node.children, field, graphQLconfig);
|
|
22081
22321
|
if (allChildrenEmpty(children)) {
|
|
22082
22322
|
return false;
|
|
22083
22323
|
}
|
|
@@ -22097,7 +22337,7 @@ var stringify = (node, field) => {
|
|
|
22097
22337
|
ordered: false,
|
|
22098
22338
|
spread: false,
|
|
22099
22339
|
check: null,
|
|
22100
|
-
children: stringifyChildren(node.children, field)
|
|
22340
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22101
22341
|
};
|
|
22102
22342
|
case plateElements.ELEMENT_OL:
|
|
22103
22343
|
return {
|
|
@@ -22105,7 +22345,7 @@ var stringify = (node, field) => {
|
|
|
22105
22345
|
ordered: true,
|
|
22106
22346
|
spread: false,
|
|
22107
22347
|
check: null,
|
|
22108
|
-
children: stringifyChildren(node.children, field)
|
|
22348
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22109
22349
|
};
|
|
22110
22350
|
case plateElements.ELEMENT_LI:
|
|
22111
22351
|
const realChildren = [];
|
|
@@ -22128,21 +22368,22 @@ var stringify = (node, field) => {
|
|
|
22128
22368
|
spread: false,
|
|
22129
22369
|
check: null,
|
|
22130
22370
|
children: [
|
|
22131
|
-
...stringifyChildren([p], field),
|
|
22132
|
-
...stringifyChildren(extraChildren, field)
|
|
22371
|
+
...stringifyChildren([p], field, graphQLconfig),
|
|
22372
|
+
...stringifyChildren(extraChildren, field, graphQLconfig)
|
|
22133
22373
|
]
|
|
22134
22374
|
};
|
|
22135
22375
|
case plateElements.ELEMENT_LIC:
|
|
22136
22376
|
return {
|
|
22137
22377
|
type: "paragraph",
|
|
22138
|
-
children: stringifyChildren(node.children, field)
|
|
22378
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22139
22379
|
};
|
|
22140
22380
|
case plateElements.ELEMENT_IMAGE:
|
|
22381
|
+
const url = resolveMediaCloudToRelative(node.url, graphQLconfig);
|
|
22141
22382
|
return {
|
|
22142
22383
|
type: "image",
|
|
22143
22384
|
title: node.caption,
|
|
22144
22385
|
alt: node.alt,
|
|
22145
|
-
url
|
|
22386
|
+
url
|
|
22146
22387
|
};
|
|
22147
22388
|
case plateElements.ELEMENT_HR:
|
|
22148
22389
|
return {
|
|
@@ -22153,12 +22394,12 @@ var stringify = (node, field) => {
|
|
|
22153
22394
|
type: "link",
|
|
22154
22395
|
url: node.url,
|
|
22155
22396
|
title: node.title,
|
|
22156
|
-
children: stringifyChildren(node.children, field)
|
|
22397
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22157
22398
|
};
|
|
22158
22399
|
case plateElements.ELEMENT_BLOCKQUOTE:
|
|
22159
22400
|
return {
|
|
22160
22401
|
type: "blockquote",
|
|
22161
|
-
children: stringifyChildren(node.children, field)
|
|
22402
|
+
children: stringifyChildren(node.children, field, graphQLconfig)
|
|
22162
22403
|
};
|
|
22163
22404
|
case "mdxJsxTextElement":
|
|
22164
22405
|
case "mdxJsxFlowElement":
|
|
@@ -22323,7 +22564,7 @@ var stringify = (node, field) => {
|
|
|
22323
22564
|
}
|
|
22324
22565
|
break;
|
|
22325
22566
|
case "rich-text":
|
|
22326
|
-
const tree = stringifyChildren(value.children, field2);
|
|
22567
|
+
const tree = stringifyChildren(value.children, field2, graphQLconfig);
|
|
22327
22568
|
if (field2.name === "children") {
|
|
22328
22569
|
children2 = tree;
|
|
22329
22570
|
} else {
|
|
@@ -22844,15 +23085,16 @@ var Resolver = class {
|
|
|
22844
23085
|
case "string":
|
|
22845
23086
|
case "boolean":
|
|
22846
23087
|
case "number":
|
|
22847
|
-
case "image":
|
|
22848
23088
|
accum[fieldName] = fieldValue;
|
|
22849
23089
|
break;
|
|
23090
|
+
case "image":
|
|
23091
|
+
accum[fieldName] = resolveMediaCloudToRelative(fieldValue, this.config);
|
|
23092
|
+
break;
|
|
22850
23093
|
case "object":
|
|
22851
23094
|
accum[fieldName] = this.buildObjectMutations(fieldValue, field);
|
|
22852
23095
|
break;
|
|
22853
23096
|
case "rich-text":
|
|
22854
|
-
field;
|
|
22855
|
-
accum[fieldName] = stringifyMDX(fieldValue, field);
|
|
23097
|
+
accum[fieldName] = stringifyMDX(fieldValue, field, this.config);
|
|
22856
23098
|
break;
|
|
22857
23099
|
case "reference":
|
|
22858
23100
|
accum[fieldName] = fieldValue;
|
|
@@ -22885,18 +23127,10 @@ var Resolver = class {
|
|
|
22885
23127
|
accumulator[field.name] = value;
|
|
22886
23128
|
break;
|
|
22887
23129
|
case "image":
|
|
22888
|
-
|
|
22889
|
-
if (this.config.useRelativeMedia === true) {
|
|
22890
|
-
accumulator[field.name] = value;
|
|
22891
|
-
} else {
|
|
22892
|
-
accumulator[field.name] = `https://${this.config.assetsHost}/${this.config.clientId}/${value}`;
|
|
22893
|
-
}
|
|
22894
|
-
} else {
|
|
22895
|
-
accumulator[field.name] = value;
|
|
22896
|
-
}
|
|
23130
|
+
accumulator[field.name] = resolveMediaRelativeToCloud(value, this.config);
|
|
22897
23131
|
break;
|
|
22898
23132
|
case "rich-text":
|
|
22899
|
-
const tree = parseMDX(value, field);
|
|
23133
|
+
const tree = parseMDX(value, field, this.config);
|
|
22900
23134
|
accumulator[field.name] = tree;
|
|
22901
23135
|
break;
|
|
22902
23136
|
case "object":
|
package/dist/mdx/parse.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
*/
|
|
18
18
|
import type { Content } from 'mdast';
|
|
19
|
-
import type { RichTypeInner } from '../types';
|
|
20
|
-
export declare const parseMDX: (value: string, field: RichTypeInner) => {
|
|
19
|
+
import type { GraphQLConfig, RichTypeInner } from '../types';
|
|
20
|
+
export declare const parseMDX: (value: string, field: RichTypeInner, graphQLconfig: GraphQLConfig) => {
|
|
21
21
|
type: string;
|
|
22
22
|
children: any;
|
|
23
23
|
};
|
|
@@ -70,7 +70,7 @@ export declare const parseMDX: (value: string, field: RichTypeInner) => {
|
|
|
70
70
|
* 2. We don't need to do any client-side parsing. Since TinaMarkdown and the slate editor work with the same
|
|
71
71
|
* format we can just allow Tina to do it's thing and update the form valuse with no additional work.
|
|
72
72
|
*/
|
|
73
|
-
export declare const parseMDXInner: (tree: any, field: RichTypeInner) => {
|
|
73
|
+
export declare const parseMDXInner: (tree: any, field: RichTypeInner, graphQLconfig: GraphQLConfig) => {
|
|
74
74
|
type: string;
|
|
75
75
|
children: any;
|
|
76
76
|
};
|
|
@@ -226,5 +226,5 @@ export declare const plateElements: {
|
|
|
226
226
|
MARK_UNDERLINE: string;
|
|
227
227
|
};
|
|
228
228
|
export declare const defaultNodeTypes: NodeTypes;
|
|
229
|
-
export default function remarkToSlate(node: MdxAstNode): any;
|
|
229
|
+
export default function remarkToSlate(node: MdxAstNode, graphQLconfig: GraphQLConfig): any;
|
|
230
230
|
export {};
|
package/dist/mdx/stringify.d.ts
CHANGED
|
@@ -15,10 +15,10 @@ See the License for the specific language governing permissions and
|
|
|
15
15
|
limitations under the License.
|
|
16
16
|
|
|
17
17
|
*/
|
|
18
|
-
import type { RichTypeInner } from '../types';
|
|
18
|
+
import type { GraphQLConfig, RichTypeInner } from '../types';
|
|
19
19
|
import { plateElements } from './parse';
|
|
20
20
|
import type { Content } from 'mdast';
|
|
21
|
-
export declare const stringifyMDX: (value: unknown, field: RichTypeInner) => string;
|
|
21
|
+
export declare const stringifyMDX: (value: unknown, field: RichTypeInner, graphQLconfig: GraphQLConfig) => string;
|
|
22
22
|
export declare const stringify: (node: {
|
|
23
23
|
type: typeof plateElements;
|
|
24
|
-
}, field: RichTypeInner) => Content;
|
|
24
|
+
}, field: RichTypeInner, graphQLconfig: GraphQLConfig) => Content;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright 2021 Forestry.io Holdings, Inc.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
import { GraphQLConfig } from '../types';
|
|
14
|
+
/**
|
|
15
|
+
* Strips away the Tina Cloud Asset URL from an `image` value
|
|
16
|
+
*
|
|
17
|
+
* @param {string} value
|
|
18
|
+
* @param {GraphQLConfig} config
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
export declare const resolveMediaCloudToRelative: (value: string, config?: GraphQLConfig) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Adds Tina Cloud Asset URL to an `image` value
|
|
24
|
+
*
|
|
25
|
+
* @param {string} value
|
|
26
|
+
* @param {GraphQLConfig} config
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export declare const resolveMediaRelativeToCloud: (value: string, config?: GraphQLConfig) => string;
|