@tinacms/app 0.0.24 → 0.0.26
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/appFiles/package.json +3 -1
- package/appFiles/src/App.tsx +25 -1
- package/appFiles/src/fields/rich-text/index.tsx +15 -0
- package/appFiles/src/fields/rich-text/monaco/error-message.tsx +126 -0
- package/appFiles/src/fields/rich-text/monaco/index.tsx +246 -0
- package/appFiles/src/fields/rich-text/monaco/mdx.js +31455 -0
- package/appFiles/src/fields/rich-text/monaco/use-debounce.ts +37 -0
- package/appFiles/src/lib/machines/document-machine.ts +1 -2
- package/appFiles/src/lib/machines/query-machine.ts +12 -4
- package/appFiles/src/preview.tsx +10 -3
- package/dist/index.js +27 -18
- package/dist/test-utils.d.ts +1 -0
- package/dist/test-utils.js +294 -0
- package/package.json +16 -3
|
@@ -0,0 +1,37 @@
|
|
|
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 { useState, useEffect } from 'react'
|
|
19
|
+
export function useDebounce(value, delay) {
|
|
20
|
+
const [debouncedValue, setDebouncedValue] = useState(value)
|
|
21
|
+
useEffect(
|
|
22
|
+
() => {
|
|
23
|
+
// Update debounced value after delay
|
|
24
|
+
const handler = setTimeout(() => {
|
|
25
|
+
setDebouncedValue(value)
|
|
26
|
+
}, delay)
|
|
27
|
+
// Cancel the timeout if value changes (also on delay change or unmount)
|
|
28
|
+
// This is how we prevent debounced value from updating if value is changed ...
|
|
29
|
+
// .. within the delay period. Timeout gets cleared and restarted.
|
|
30
|
+
return () => {
|
|
31
|
+
clearTimeout(handler)
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
[value, delay] // Only re-call effect if value or delay changes
|
|
35
|
+
)
|
|
36
|
+
return debouncedValue
|
|
37
|
+
}
|
|
@@ -11,14 +11,13 @@ See the License for the specific language governing permissions and
|
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
import { Client, Field, Form, FormOptions, TinaCMS } from 'tinacms'
|
|
14
|
-
import { assign, createMachine } from 'xstate'
|
|
14
|
+
import { assign, createMachine, sendParent } from 'xstate'
|
|
15
15
|
import {
|
|
16
16
|
resolveForm,
|
|
17
17
|
Templateable,
|
|
18
18
|
TinaFieldEnriched,
|
|
19
19
|
TinaSchema,
|
|
20
20
|
} from 'tinacms'
|
|
21
|
-
import { sendParent } from 'xstate/lib/actions'
|
|
22
21
|
|
|
23
22
|
export type FieldType = Field & TinaFieldEnriched
|
|
24
23
|
export type FormValues = Record<string, unknown>
|
|
@@ -120,6 +120,9 @@ export const queryMachine =
|
|
|
120
120
|
}
|
|
121
121
|
| {
|
|
122
122
|
type: 'FIELD_CHANGE'
|
|
123
|
+
}
|
|
124
|
+
| {
|
|
125
|
+
type: 'EDIT_MODE'
|
|
123
126
|
},
|
|
124
127
|
},
|
|
125
128
|
id: '(machine)',
|
|
@@ -368,11 +371,16 @@ export const queryMachine =
|
|
|
368
371
|
}
|
|
369
372
|
})
|
|
370
373
|
if (context.cms) {
|
|
371
|
-
context.cms.events.subscribe(`forms:fields:onChange`, () => {
|
|
372
|
-
|
|
374
|
+
context.cms.events.subscribe(`forms:fields:onChange`, (event) => {
|
|
375
|
+
// Nested forms from rich-text also trigger this event
|
|
376
|
+
if (Object.keys(context.documentMap).includes(event.formId)) {
|
|
377
|
+
callback({ type: 'FIELD_CHANGE' })
|
|
378
|
+
}
|
|
373
379
|
})
|
|
374
|
-
context.cms.events.subscribe(`forms:reset`, () => {
|
|
375
|
-
|
|
380
|
+
context.cms.events.subscribe(`forms:reset`, (event) => {
|
|
381
|
+
if (Object.keys(context.documentMap).includes(event.formId)) {
|
|
382
|
+
callback({ type: 'FIELD_CHANGE' })
|
|
383
|
+
}
|
|
376
384
|
})
|
|
377
385
|
}
|
|
378
386
|
},
|
package/appFiles/src/preview.tsx
CHANGED
|
@@ -13,12 +13,12 @@ limitations under the License.
|
|
|
13
13
|
import React from 'react'
|
|
14
14
|
import { useMachine } from '@xstate/react'
|
|
15
15
|
import { queryMachine, initialContext } from './lib/machines/query-machine'
|
|
16
|
-
import { useCMS,
|
|
16
|
+
import { useCMS, defineConfig } from 'tinacms'
|
|
17
17
|
|
|
18
|
-
type Config = Parameters<typeof
|
|
18
|
+
type Config = Parameters<typeof defineConfig>[0]
|
|
19
19
|
|
|
20
20
|
type PostMessage = {
|
|
21
|
-
type: 'open' | 'close'
|
|
21
|
+
type: 'open' | 'close' | 'isEditMode'
|
|
22
22
|
id: string
|
|
23
23
|
data: object
|
|
24
24
|
}
|
|
@@ -97,6 +97,13 @@ const QueryMachine = (props: {
|
|
|
97
97
|
|
|
98
98
|
React.useEffect(() => {
|
|
99
99
|
if (props.iframeRef.current) {
|
|
100
|
+
window.addEventListener('message', (event: MessageEvent<PostMessage>) => {
|
|
101
|
+
if (event?.data?.type === 'isEditMode') {
|
|
102
|
+
props.iframeRef?.current?.contentWindow?.postMessage({
|
|
103
|
+
type: 'tina:editMode',
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
})
|
|
100
107
|
send({ type: 'IFRAME_MOUNTED', value: props.iframeRef.current })
|
|
101
108
|
if (props.payload.type === 'open') {
|
|
102
109
|
send({ type: 'ADD_QUERY', value: props.payload })
|
package/dist/index.js
CHANGED
|
@@ -326,6 +326,7 @@ var prodHTML = `<!DOCTYPE html>
|
|
|
326
326
|
|
|
327
327
|
// src/index.ts
|
|
328
328
|
var server;
|
|
329
|
+
var hasCopiedFiles = false;
|
|
329
330
|
var viteBuild = async ({
|
|
330
331
|
rootPath,
|
|
331
332
|
outputFolder,
|
|
@@ -336,7 +337,7 @@ var viteBuild = async ({
|
|
|
336
337
|
const local = l;
|
|
337
338
|
const localBuild = l;
|
|
338
339
|
const node_env = JSON.stringify(process.env.NODE_ENV);
|
|
339
|
-
const generatedPath = import_path2.default.join(rootPath, ".tina
|
|
340
|
+
const generatedPath = import_path2.default.join(rootPath, ".tina", "__generated__");
|
|
340
341
|
const outputPath = import_path2.default.join(rootPath, publicFolder, outputFolder);
|
|
341
342
|
const appCopyPath = import_path2.default.join(__dirname, "..", "appFiles");
|
|
342
343
|
const appRootPath = import_path2.default.join(generatedPath, "app");
|
|
@@ -365,6 +366,10 @@ var viteBuild = async ({
|
|
|
365
366
|
},
|
|
366
367
|
logLevel: "silent"
|
|
367
368
|
};
|
|
369
|
+
if (!hasCopiedFiles) {
|
|
370
|
+
import_fs_extra.default.remove(import_path2.default.join(generatedPath, "prebuild"));
|
|
371
|
+
import_fs_extra.default.remove(import_path2.default.join(generatedPath, "app"));
|
|
372
|
+
}
|
|
368
373
|
await (0, import_vite.build)(prebuildConfig);
|
|
369
374
|
const alias = {
|
|
370
375
|
TINA_IMPORT: configPrebuildPath
|
|
@@ -398,26 +403,30 @@ var viteBuild = async ({
|
|
|
398
403
|
},
|
|
399
404
|
logLevel: "silent"
|
|
400
405
|
};
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
406
|
+
if (!hasCopiedFiles) {
|
|
407
|
+
if (process.env.MONOREPO_DEV) {
|
|
408
|
+
console.warn("Using monorepo dev mode, source files will be symlinked");
|
|
409
|
+
await import_fs_extra.default.createSymlink(appCopyPath, appRootPath, "dir");
|
|
410
|
+
} else {
|
|
411
|
+
await import_fs_extra.default.copy(appCopyPath, appRootPath);
|
|
412
|
+
}
|
|
413
|
+
await execShellCommand(`npm --prefix ${appRootPath} i --legacy-peer-deps --omit=dev --no-package-lock`);
|
|
414
|
+
await import_fs_extra.default.outputFile(import_path2.default.join(outputPath, ".gitignore"), `index.html
|
|
409
415
|
assets/`);
|
|
416
|
+
}
|
|
410
417
|
if (localBuild) {
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
+
if (!hasCopiedFiles) {
|
|
419
|
+
const replaceAll = (string, target, value) => {
|
|
420
|
+
const regex = new RegExp(target, "g");
|
|
421
|
+
return string.valueOf().replace(regex, value);
|
|
422
|
+
};
|
|
423
|
+
await import_fs_extra.default.outputFile(devHTMLPath, replaceAll(devHTML, "INSERT_OUTPUT_FOLDER_NAME", outputFolder));
|
|
424
|
+
}
|
|
425
|
+
if (!server) {
|
|
426
|
+
server = await (0, import_vite.createServer)(config);
|
|
427
|
+
await server.listen();
|
|
418
428
|
}
|
|
419
|
-
|
|
420
|
-
await server.listen();
|
|
429
|
+
hasCopiedFiles = true;
|
|
421
430
|
} else {
|
|
422
431
|
await import_fs_extra.default.outputFile(prodHTMLPath, prodHTML);
|
|
423
432
|
await (0, import_vite.build)(config);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../src/test-utils"
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
__markAsModule(target);
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __reExport = (target, module2, desc) => {
|
|
31
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(module2))
|
|
33
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
34
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
var __toModule = (module2) => {
|
|
39
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/test-utils.ts
|
|
43
|
+
__export(exports, {
|
|
44
|
+
printBlueprints: () => printBlueprints,
|
|
45
|
+
printState: () => printState
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// appFiles/src/lib/formify/index.ts
|
|
49
|
+
var G = __toModule(require("graphql"));
|
|
50
|
+
var formify = async ({
|
|
51
|
+
schema,
|
|
52
|
+
optimizedDocumentNode
|
|
53
|
+
}) => {
|
|
54
|
+
const blueprints = [];
|
|
55
|
+
const visitor = {
|
|
56
|
+
OperationDefinition: (node2) => {
|
|
57
|
+
if (!node2.name) {
|
|
58
|
+
return __spreadProps(__spreadValues({}, node2), {
|
|
59
|
+
name: {
|
|
60
|
+
kind: "Name",
|
|
61
|
+
value: `QueryOperation`
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return node2;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const documentNodeWithName = G.visit(optimizedDocumentNode, visitor);
|
|
69
|
+
const optimizedQuery = documentNodeWithName;
|
|
70
|
+
const typeInfo = new G.TypeInfo(schema);
|
|
71
|
+
const addMetaFields = (node2) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return __spreadProps(__spreadValues({}, node2), {
|
|
74
|
+
selectionSet: __spreadProps(__spreadValues({}, node2.selectionSet || {
|
|
75
|
+
kind: "SelectionSet",
|
|
76
|
+
selections: []
|
|
77
|
+
}), {
|
|
78
|
+
selections: [...((_a = node2.selectionSet) == null ? void 0 : _a.selections) || [], ...metaFields]
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const getPath = (path, node2) => {
|
|
83
|
+
let currentLevel = node2;
|
|
84
|
+
const fieldPath = [];
|
|
85
|
+
path.forEach((item) => {
|
|
86
|
+
currentLevel = currentLevel[item];
|
|
87
|
+
if (!Array.isArray(currentLevel)) {
|
|
88
|
+
if (currentLevel.kind === "Field") {
|
|
89
|
+
fieldPath.push(currentLevel.name.value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return fieldPath;
|
|
94
|
+
};
|
|
95
|
+
const addBlueprints = (node2, _key, _parent, path, ancestors) => {
|
|
96
|
+
const fieldPath = getPath(path, ancestors[0]);
|
|
97
|
+
const nextInfo = (innerNode) => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
const fields2 = [];
|
|
100
|
+
G.visit(innerNode, G.visitWithTypeInfo(typeInfo, {
|
|
101
|
+
Field: {
|
|
102
|
+
enter: (node3) => {
|
|
103
|
+
var _a2, _b2, _c;
|
|
104
|
+
typeInfo.enter(node3);
|
|
105
|
+
if (node3.name.value !== innerNode.name.value) {
|
|
106
|
+
if ((_a2 = node3.selectionSet) == null ? void 0 : _a2.selections.length) {
|
|
107
|
+
const subInfo = nextInfo(node3);
|
|
108
|
+
fields2.push({
|
|
109
|
+
name: node3.name.value,
|
|
110
|
+
alias: ((_b2 = node3.alias) == null ? void 0 : _b2.value) || node3.name.value,
|
|
111
|
+
fields: subInfo.fields
|
|
112
|
+
});
|
|
113
|
+
return false;
|
|
114
|
+
} else {
|
|
115
|
+
fields2.push({
|
|
116
|
+
name: node3.name.value,
|
|
117
|
+
alias: ((_c = node3.alias) == null ? void 0 : _c.value) || node3.name.value
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
leave: (node3) => {
|
|
123
|
+
typeInfo.leave(node3);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
if (fields2 == null ? void 0 : fields2.length) {
|
|
128
|
+
return {
|
|
129
|
+
name: innerNode.name.value,
|
|
130
|
+
alias: ((_a = innerNode.alias) == null ? void 0 : _a.value) || innerNode.name.value,
|
|
131
|
+
fields: fields2
|
|
132
|
+
};
|
|
133
|
+
} else {
|
|
134
|
+
return {
|
|
135
|
+
name: innerNode.name.value,
|
|
136
|
+
alias: ((_b = innerNode.alias) == null ? void 0 : _b.value) || innerNode.name.value
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const result = nextInfo(node2);
|
|
141
|
+
const mergeFields = (fields2) => {
|
|
142
|
+
if (!fields2) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
const groupBy = (items, key) => items.reduce((result2, item) => __spreadProps(__spreadValues({}, result2), {
|
|
146
|
+
[item[key]]: [...result2[item[key]] || [], item]
|
|
147
|
+
}), {});
|
|
148
|
+
const groups = groupBy(fields2, "alias");
|
|
149
|
+
const groupedFields = [];
|
|
150
|
+
Object.entries(groups).forEach(([name, items]) => {
|
|
151
|
+
const subFields = [];
|
|
152
|
+
items.forEach((item) => {
|
|
153
|
+
var _a;
|
|
154
|
+
(_a = item.fields) == null ? void 0 : _a.forEach((field) => subFields.push(field));
|
|
155
|
+
});
|
|
156
|
+
const fieldName = items[0].name;
|
|
157
|
+
const fieldAlias = items[0].alias;
|
|
158
|
+
if (subFields == null ? void 0 : subFields.length) {
|
|
159
|
+
groupedFields.push({
|
|
160
|
+
name: fieldName,
|
|
161
|
+
alias: fieldAlias,
|
|
162
|
+
fields: subFields
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
groupedFields.push({ name: fieldName, alias: fieldAlias });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return groupedFields;
|
|
169
|
+
};
|
|
170
|
+
const fields = mergeFields(result.fields);
|
|
171
|
+
if (false) {
|
|
172
|
+
} else {
|
|
173
|
+
if (fields == null ? void 0 : fields.length) {
|
|
174
|
+
blueprints.push({
|
|
175
|
+
name: result.name,
|
|
176
|
+
alias: result.alias,
|
|
177
|
+
fields,
|
|
178
|
+
path: fieldPath
|
|
179
|
+
});
|
|
180
|
+
} else {
|
|
181
|
+
blueprints.push({
|
|
182
|
+
name: result.name,
|
|
183
|
+
alias: result.alias,
|
|
184
|
+
path: fieldPath
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const formifyVisitor = {
|
|
190
|
+
InlineFragment: {
|
|
191
|
+
enter: (node2) => {
|
|
192
|
+
typeInfo.enter(node2);
|
|
193
|
+
},
|
|
194
|
+
leave: (node2) => {
|
|
195
|
+
typeInfo.leave(node2);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
Field: {
|
|
199
|
+
enter: (node2, key, parent, path, ancestors) => {
|
|
200
|
+
typeInfo.enter(node2);
|
|
201
|
+
const type = typeInfo.getType();
|
|
202
|
+
if (type) {
|
|
203
|
+
const namedType = G.getNamedType(type);
|
|
204
|
+
if (G.isInterfaceType(namedType)) {
|
|
205
|
+
if (namedType.name === "Node") {
|
|
206
|
+
return addMetaFields(node2, key, parent, path, ancestors);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (G.isUnionType(namedType)) {
|
|
210
|
+
const types = namedType.getTypes();
|
|
211
|
+
if (types.every((type2) => {
|
|
212
|
+
return type2.getInterfaces().some((intfc) => intfc.name === "Node");
|
|
213
|
+
})) {
|
|
214
|
+
return addMetaFields(node2, key, parent, path, ancestors);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (G.isObjectType(namedType)) {
|
|
218
|
+
if (namedType.getInterfaces().some((intfc) => intfc.name === "Node")) {
|
|
219
|
+
return addMetaFields(node2, key, parent, path, ancestors);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const blueprintVisitor = {
|
|
227
|
+
InlineFragment: {
|
|
228
|
+
enter: (node2) => {
|
|
229
|
+
typeInfo.enter(node2);
|
|
230
|
+
},
|
|
231
|
+
leave: (node2) => {
|
|
232
|
+
typeInfo.leave(node2);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
Field: {
|
|
236
|
+
enter: (node2, key, parent, path, ancestors) => {
|
|
237
|
+
typeInfo.enter(node2);
|
|
238
|
+
const type = typeInfo.getType();
|
|
239
|
+
if (type) {
|
|
240
|
+
const namedType = G.getNamedType(type);
|
|
241
|
+
if (G.isInterfaceType(namedType)) {
|
|
242
|
+
if (namedType.name === "Node") {
|
|
243
|
+
addBlueprints(node2, key, parent, path, ancestors);
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (G.isUnionType(namedType)) {
|
|
248
|
+
const types = namedType.getTypes();
|
|
249
|
+
if (types.every((type2) => {
|
|
250
|
+
return type2.getInterfaces().some((intfc) => intfc.name === "Node");
|
|
251
|
+
})) {
|
|
252
|
+
addBlueprints(node2, key, parent, path, ancestors);
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (G.isObjectType(namedType)) {
|
|
257
|
+
if (namedType.getInterfaces().some((intfc) => intfc.name === "Node")) {
|
|
258
|
+
addBlueprints(node2, key, parent, path, ancestors);
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const formifiedQuery = G.visit(optimizedQuery, G.visitWithTypeInfo(typeInfo, formifyVisitor));
|
|
267
|
+
G.visit(formifiedQuery, G.visitWithTypeInfo(typeInfo, blueprintVisitor));
|
|
268
|
+
return { formifiedQuery, blueprints };
|
|
269
|
+
};
|
|
270
|
+
var node = G.parse(`
|
|
271
|
+
query Sample {
|
|
272
|
+
...on Document {
|
|
273
|
+
_internalSys: _sys {
|
|
274
|
+
path
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}`);
|
|
278
|
+
var metaFields = node.definitions[0].selectionSet.selections;
|
|
279
|
+
|
|
280
|
+
// src/test-utils.ts
|
|
281
|
+
var printState = (obj) => {
|
|
282
|
+
return obj;
|
|
283
|
+
};
|
|
284
|
+
var printBlueprints = ({ schema, client, query }) => {
|
|
285
|
+
const optimizedQuery = client.getOptimizedQuery(query);
|
|
286
|
+
const res = formify({ schema, optimizedQuery });
|
|
287
|
+
const { formifiedQuery, blueprints } = res;
|
|
288
|
+
return { formifiedQuery, blueprints };
|
|
289
|
+
};
|
|
290
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
291
|
+
0 && (module.exports = {
|
|
292
|
+
printBlueprints,
|
|
293
|
+
printState
|
|
294
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"import": "./dist/index.es.js",
|
|
9
9
|
"require": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./dist/test-utils": {
|
|
12
|
+
"types": "./dist/test-utils.d.ts",
|
|
13
|
+
"import": "./dist/test-utils.es.js",
|
|
14
|
+
"require": "./dist/test-utils.js"
|
|
10
15
|
}
|
|
11
16
|
},
|
|
12
17
|
"files": [
|
|
@@ -20,6 +25,10 @@
|
|
|
20
25
|
{
|
|
21
26
|
"name": "src/index.ts",
|
|
22
27
|
"target": "node"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "src/test-utils.ts",
|
|
31
|
+
"target": "node"
|
|
23
32
|
}
|
|
24
33
|
]
|
|
25
34
|
},
|
|
@@ -28,7 +37,8 @@
|
|
|
28
37
|
"@types/react": "17.0.2",
|
|
29
38
|
"@types/react-dom": "17.0.2",
|
|
30
39
|
"@tinacms/scripts": "0.51.3",
|
|
31
|
-
"tinacms": "0.
|
|
40
|
+
"tinacms": "0.70.0",
|
|
41
|
+
"@tinacms/mdx": "0.61.15",
|
|
32
42
|
"jest": "^27.0.6"
|
|
33
43
|
},
|
|
34
44
|
"dependencies": {
|
|
@@ -53,7 +63,10 @@
|
|
|
53
63
|
"react-router-dom": "6.3.0",
|
|
54
64
|
"tailwindcss": "^3.1.6",
|
|
55
65
|
"typescript": "^4.6.4",
|
|
56
|
-
"vite": "
|
|
66
|
+
"vite": "3.1.8",
|
|
67
|
+
"@monaco-editor/react": "4.4.5",
|
|
68
|
+
"monaco-editor": "0.31.0",
|
|
69
|
+
"webfontloader": "1.6.28"
|
|
57
70
|
},
|
|
58
71
|
"scripts": {
|
|
59
72
|
"types": "rm dist/index.d.ts && touch dist/index.d.ts && echo \"export declare const viteBuild: (args: any) => any\" > dist/index.d.ts",
|