@tinacms/app 0.0.24 → 0.0.25

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.
@@ -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>
@@ -368,11 +368,16 @@ export const queryMachine =
368
368
  }
369
369
  })
370
370
  if (context.cms) {
371
- context.cms.events.subscribe(`forms:fields:onChange`, () => {
372
- callback({ type: 'FIELD_CHANGE' })
371
+ context.cms.events.subscribe(`forms:fields:onChange`, (event) => {
372
+ // Nested forms from rich-text also trigger this event
373
+ if (Object.keys(context.documentMap).includes(event.formId)) {
374
+ callback({ type: 'FIELD_CHANGE' })
375
+ }
373
376
  })
374
- context.cms.events.subscribe(`forms:reset`, () => {
375
- callback({ type: 'FIELD_CHANGE' })
377
+ context.cms.events.subscribe(`forms:reset`, (event) => {
378
+ if (Object.keys(context.documentMap).includes(event.formId)) {
379
+ callback({ type: 'FIELD_CHANGE' })
380
+ }
376
381
  })
377
382
  }
378
383
  },
package/dist/index.js CHANGED
@@ -398,11 +398,11 @@ var viteBuild = async ({
398
398
  },
399
399
  logLevel: "silent"
400
400
  };
401
- if (true) {
402
- await import_fs_extra.default.copy(appCopyPath, appRootPath);
401
+ if (process.env.MONOREPO_DEV) {
402
+ console.warn("Using monorepo dev mode, source files will be symlinked");
403
+ await import_fs_extra.default.createSymlink(appCopyPath, appRootPath, "dir");
403
404
  } else {
404
- await import_fs_extra.default.createSymlink(import_path2.default.join(appCopyPath, "src"), import_path2.default.join(appRootPath, "src"), "dir");
405
- await import_fs_extra.default.createSymlink(import_path2.default.join(appCopyPath, "package.json"), import_path2.default.join(appRootPath, "package.json"), "file");
405
+ await import_fs_extra.default.copy(appCopyPath, appRootPath);
406
406
  }
407
407
  await execShellCommand(`npm --prefix ${appRootPath} i --legacy-peer-deps --omit=dev --no-package-lock`);
408
408
  await import_fs_extra.default.outputFile(import_path2.default.join(outputPath, ".gitignore"), `index.html
@@ -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.24",
3
+ "version": "0.0.25",
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.69.19",
40
+ "tinacms": "0.69.21",
41
+ "@tinacms/mdx": "0.61.14",
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": "^3.1.3"
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",