eddev 0.2.65 → 0.2.67-beta1
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/admin/components/ImageWell.d.ts +2 -3
- package/admin/components/ImageWell.js +39 -51
- package/admin/defineField.d.ts +2 -2
- package/admin/defineWidget.d.ts +1 -1
- package/admin/defineWidget.js +2 -2
- package/admin/index.js +5 -1
- package/admin/installFieldTypes.js +26 -26
- package/admin/runWidgets.js +17 -28
- package/admin/selectMedia.d.ts +2 -2
- package/admin/selectMedia.js +1 -1
- package/blocks/ContentBlocks.d.ts +6 -6
- package/blocks/ContentBlocks.js +58 -66
- package/blocks/ErrorBoundaryEditor.d.ts +1 -1
- package/blocks/ErrorBoundaryEditor.js +16 -45
- package/blocks/ErrorBoundaryFrontend.d.ts +1 -1
- package/blocks/ErrorBoundaryFrontend.js +16 -45
- package/blocks/InspectorControls.d.ts +1 -1
- package/blocks/InspectorControls.js +3 -3
- package/blocks/blockAttributes.d.ts +2 -2
- package/blocks/blockAttributes.js +24 -44
- package/blocks/index.js +5 -1
- package/blocks/inlineEditing.d.ts +7 -7
- package/blocks/inlineEditing.js +36 -55
- package/blocks/installGutenbergHooks.js +48 -68
- package/build/babel/plugin-name-defined-components.js +15 -16
- package/build/build-favicon.js +11 -62
- package/build/clean.js +5 -52
- package/build/create-codegen-worker.js +78 -33
- package/build/create-serverless-dev-worker.js +61 -39
- package/build/create-webpack-worker.js +65 -33
- package/build/file-tree.d.ts +2 -2
- package/build/file-tree.js +12 -12
- package/build/get-webpack-config.js +341 -395
- package/build/graphql-codegen/graphql-codegen-files.js +31 -25
- package/build/graphql-codegen/graphql-codegen-no-duplicates.js +4 -4
- package/build/graphql-codegen/graphql-codegen-queries.js +102 -99
- package/build/manifests/manifest-blocks.d.ts +1 -1
- package/build/manifests/manifest-blocks.js +37 -29
- package/build/manifests/manifest-fields.d.ts +1 -1
- package/build/manifests/manifest-fields.js +23 -21
- package/build/manifests/manifest-views.d.ts +1 -1
- package/build/manifests/manifest-views.js +32 -25
- package/build/manifests/manifest-widgets.d.ts +1 -1
- package/build/manifests/manifest-widgets.js +22 -20
- package/build/manifests/manifest.d.ts +2 -2
- package/build/manifests/manifest.js +30 -90
- package/build/reporter.d.ts +1 -1
- package/build/reporter.js +29 -32
- package/build/serverless/create-next-app.d.ts +1 -1
- package/build/serverless/create-next-app.js +245 -467
- package/build/state/codegen-state.d.ts +4 -4
- package/build/state/compiler-state.d.ts +5 -5
- package/build/state/serverless-state.d.ts +3 -3
- package/build/workers/codegen-worker-script.js +392 -507
- package/build/workers/serverless-worker-dev-script.js +4 -4
- package/build/workers/webpack-worker-script.js +89 -150
- package/cli/build.dev.d.ts +1 -1
- package/cli/build.dev.js +79 -126
- package/cli/build.prod.d.ts +1 -1
- package/cli/build.prod.js +42 -98
- package/cli/cli.js +16 -55
- package/cli/display/components/BundleDisplay.d.ts +1 -2
- package/cli/display/components/BundleDisplay.js +13 -24
- package/cli/display/components/CodegenDisplay.d.ts +1 -2
- package/cli/display/components/CodegenDisplay.js +14 -25
- package/cli/display/components/DevCLIDisplay.d.ts +2 -3
- package/cli/display/components/DevCLIDisplay.js +14 -25
- package/cli/display/components/Fullscreen.js +9 -20
- package/cli/display/components/ServerlessDisplay.d.ts +2 -3
- package/cli/display/components/ServerlessDisplay.js +15 -26
- package/cli/display/components/StatusIcon.d.ts +2 -3
- package/cli/display/components/StatusIcon.js +3 -3
- package/cli/preinstall.js +4 -5
- package/cli/setup.js +25 -73
- package/components/AdminBar.d.ts +1 -2
- package/components/AdminBar.js +37 -3
- package/components/BrowserRouter.d.ts +2 -2
- package/components/BrowserRouter.js +41 -54
- package/components/InlinePage.d.ts +2 -2
- package/components/InlinePage.js +17 -29
- package/components/NextRouter.d.ts +2 -2
- package/components/NextRouter.js +20 -29
- package/components/index.js +5 -1
- package/config/config-schema.d.ts +1 -1
- package/config/config-schema.js +1 -1
- package/config/create-schema-file.js +6 -6
- package/config/get-config.js +10 -13
- package/config/index.js +5 -1
- package/config/parse-config.js +1 -1
- package/config/print-zod-errors.js +3 -3
- package/dev-ui/components/BreakpointColumnHeader.d.ts +2 -3
- package/dev-ui/components/BreakpointColumnHeader.js +7 -18
- package/dev-ui/components/BreakpointIndicator.d.ts +1 -2
- package/dev-ui/components/BreakpointIndicator.js +25 -32
- package/dev-ui/components/DevUI.d.ts +1 -2
- package/dev-ui/components/DevUI.js +13 -13
- package/dev-ui/components/Launcher.d.ts +2 -2
- package/dev-ui/components/Launcher.js +13 -25
- package/dev-ui/components/PanelWrapper.d.ts +2 -2
- package/dev-ui/components/PanelWrapper.js +8 -8
- package/dev-ui/components/ResponsiveLerpControl.d.ts +2 -3
- package/dev-ui/components/ResponsiveLerpControl.js +27 -38
- package/dev-ui/components/ResponsiveScaleEditor.d.ts +4 -5
- package/dev-ui/components/ResponsiveScaleEditor.js +64 -78
- package/dev-ui/components/atoms/Button.js +1 -1
- package/dev-ui/components/atoms/Dropdown.d.ts +3 -3
- package/dev-ui/components/atoms/Dropdown.js +8 -9
- package/dev-ui/components/atoms/NumberField.d.ts +2 -3
- package/dev-ui/components/atoms/NumberField.js +29 -42
- package/dev-ui/components/atoms/Spacer.js +1 -1
- package/dev-ui/components/atoms/Text.js +1 -1
- package/dev-ui/components/atoms/ToggleButton.d.ts +2 -2
- package/dev-ui/components/atoms/ToggleButton.js +5 -16
- package/dev-ui/components/atoms/Tooltip.d.ts +2 -2
- package/dev-ui/components/atoms/Tooltip.js +8 -20
- package/dev-ui/components/panels/AppDataDebugger.d.ts +1 -2
- package/dev-ui/components/panels/AppDataDebugger.js +8 -19
- package/dev-ui/components/panels/ColorEditor.d.ts +1 -2
- package/dev-ui/components/panels/ColorEditor.js +35 -42
- package/dev-ui/components/panels/PageDataDebugger.d.ts +1 -2
- package/dev-ui/components/panels/PageDataDebugger.js +8 -20
- package/dev-ui/components/panels/QueryDebugger.d.ts +1 -2
- package/dev-ui/components/panels/QueryDebugger.js +12 -24
- package/dev-ui/components/panels/SpacingEditor.d.ts +1 -2
- package/dev-ui/components/panels/SpacingEditor.js +34 -48
- package/dev-ui/components/panels/TypographyEditor.d.ts +1 -2
- package/dev-ui/components/panels/TypographyEditor.js +38 -46
- package/dev-ui/hooks/useBreakpoint.d.ts +1 -1
- package/dev-ui/hooks/useBreakpoint.js +13 -13
- package/dev-ui/hooks/usePersistState.js +6 -7
- package/dev-ui/hooks/useStylesheet.js +6 -6
- package/dev-ui/icons.d.ts +15 -16
- package/dev-ui/icons.js +16 -27
- package/dev-ui/index.js +5 -1
- package/dev-ui/loader.d.ts +1 -2
- package/dev-ui/loader.js +13 -9
- package/dev-ui/panels.d.ts +2 -2
- package/dev-ui/panels.js +7 -7
- package/dev-ui/theme.d.ts +96 -70
- package/dev-ui/theme.js +3 -3
- package/dynamic/dynamic-component.d.ts +1 -10
- package/dynamic/dynamic-component.js +1 -1
- package/dynamic/index.js +5 -1
- package/entry/Root.d.ts +2 -3
- package/entry/Root.js +16 -26
- package/entry/entry.admin.dev.js +4 -4
- package/entry/entry.admin.prod.js +4 -4
- package/entry/entry.monolith.dev.js +5 -5
- package/entry/entry.monolith.prod.js +5 -5
- package/gravityforms/gravity-forms.d.ts +2 -2
- package/gravityforms/index.js +5 -1
- package/gravityforms/useGravityForm.d.ts +2 -2
- package/gravityforms/useGravityForm.js +126 -130
- package/hooks/index.js +5 -1
- package/hooks/queryUtils.d.ts +14 -14
- package/hooks/queryUtils.js +101 -192
- package/hooks/useAppData.d.ts +2 -2
- package/hooks/useAppData.js +9 -9
- package/hooks/usePageLoad.js +4 -4
- package/hooks/useQueryDebug.d.ts +1 -1
- package/hooks/useQueryDebug.js +7 -7
- package/hooks/useRPC.d.ts +4 -4
- package/hooks/useRPC.js +3 -3
- package/package.json +7 -7
- package/routing/index.js +5 -1
- package/routing/remoteProps.d.ts +1 -1
- package/routing/remoteProps.js +31 -72
- package/routing/routing.d.ts +15 -15
- package/routing/routing.js +108 -170
- package/routing/updateEditLink.js +1 -1
- package/serverless/define-api.d.ts +1 -1
- package/serverless/define-rpc-router.js +8 -4
- package/serverless/index.js +6 -2
- package/serverless-template/_utils/fetch-wordpress-props.ts +0 -4
- package/serverless-template/_utils/fetch-wp.ts +0 -1
- package/style/createStitches.d.ts +375 -783
- package/style/createStitches.js +164 -142
- package/style/index.js +5 -1
- package/tsconfig.json +1 -1
- package/utils/Observable.d.ts +2 -2
- package/utils/Observable.js +12 -15
- package/utils/getRepoName.js +3 -3
- package/utils/promptIfRepoNameIncorrect.js +18 -64
- package/utils/refreshOverlayInterop.js +1 -1
- package/utils/reportErrorStack.d.ts +1 -1
- package/utils/reportErrorStack.js +1 -1
- package/utils/serverlessAppContext.js +1 -1
- package/utils/updateEnvFile.js +19 -69
- package/utils/useObservable.js +3 -3
- package/views/index.js +5 -1
|
@@ -3,22 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const glob_promise_1 = require("glob-promise");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
8
|
module.exports = {
|
|
9
|
-
plugin:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
plugin: (schema, documents, config, info) => {
|
|
10
|
+
const folder = path_1.default.resolve(config.rootDir, config.folderName);
|
|
11
|
+
const imports = [];
|
|
12
|
+
const items = [];
|
|
13
|
+
const files = glob_promise_1.glob.sync(folder + "/**/*.tsx");
|
|
14
|
+
const filesFound = {};
|
|
15
|
+
const additionalTypes = config.additionalTypes || {};
|
|
16
16
|
// const additionalTypes: Record<string, string> = {
|
|
17
17
|
// "_html.tsx": `{ "template": string, "htmlContent": string }`,
|
|
18
18
|
// }
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const getRelative = (path) => path_1.default.relative(folder, path);
|
|
20
|
+
const typeForFile = (file, baseType) => {
|
|
21
|
+
const types = [];
|
|
22
22
|
if (baseType)
|
|
23
23
|
types.push(baseType);
|
|
24
24
|
if (additionalTypes[file]) {
|
|
@@ -31,34 +31,40 @@ module.exports = {
|
|
|
31
31
|
return types.join(" & ");
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
documents.forEach(
|
|
35
|
-
var _a;
|
|
34
|
+
documents.forEach((doc) => {
|
|
36
35
|
if (!doc.location.startsWith(folder))
|
|
37
36
|
return;
|
|
38
37
|
filesFound[doc.location.replace(/\.graphql/, "")] = true;
|
|
39
|
-
|
|
38
|
+
const relative = getRelative(doc.location);
|
|
40
39
|
// const docsNames = doc.document.definitions.map(
|
|
41
40
|
// (def: any) => def.name.value
|
|
42
41
|
// )
|
|
43
42
|
if (relative && doc.document.definitions.length) {
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
let importedName = doc.document.definitions[0].name.value + "Query";
|
|
44
|
+
let typeName = config.getType?.(importedName, doc.document.definitions[0]) || importedName;
|
|
46
45
|
imports.push(importedName);
|
|
47
|
-
|
|
48
|
-
items.push(
|
|
46
|
+
const key = relative.replace(/\.graphql/, "");
|
|
47
|
+
items.push(`${JSON.stringify(key)}: ${typeForFile(key, typeName)}`);
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
|
-
for (
|
|
52
|
-
var file = files_1[_i];
|
|
50
|
+
for (const file of files) {
|
|
53
51
|
if (!filesFound[file.replace(/\.tsx/, "")]) {
|
|
54
|
-
|
|
55
|
-
items.push(
|
|
52
|
+
const key = getRelative(file).replace(/\.tsx$/, "");
|
|
53
|
+
items.push(`${JSON.stringify(key)}: ${typeForFile(key, "")}`);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
if (imports.length === 0) {
|
|
59
57
|
process.exit();
|
|
60
|
-
return
|
|
58
|
+
return `export { };`;
|
|
61
59
|
}
|
|
62
|
-
return
|
|
60
|
+
return `import { ${imports.sort().join(", ")} } from "./types.graphql"
|
|
61
|
+
export { };
|
|
62
|
+
|
|
63
|
+
declare global {
|
|
64
|
+
type ${config.globalName} = {
|
|
65
|
+
${items.sort().join(",\n")}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
63
69
|
},
|
|
64
70
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
module.exports = {
|
|
4
|
-
plugin:
|
|
5
|
-
validate:
|
|
6
|
-
documents.forEach(
|
|
4
|
+
plugin: () => { },
|
|
5
|
+
validate: (schema, documents, config, info) => {
|
|
6
|
+
documents.forEach((doc) => {
|
|
7
7
|
if (doc.document.definitions.length === 0) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error(`GraphQL file '${doc.location}' does not contain any uniquely named operations.`);
|
|
9
9
|
process.exit();
|
|
10
10
|
}
|
|
11
11
|
});
|
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const path_1 = require("path");
|
|
14
5
|
module.exports = {
|
|
15
|
-
plugin:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
documents.forEach(
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
plugin: (schema, documents, config, info) => {
|
|
7
|
+
const hooks = {};
|
|
8
|
+
const importTypes = [];
|
|
9
|
+
const importUtils = {};
|
|
10
|
+
documents.forEach((doc) => {
|
|
11
|
+
const fullFileName = doc.location;
|
|
12
|
+
const fileName = doc.location.replace(config.rootDir, "");
|
|
22
13
|
if (doc.document.definitions.length) {
|
|
23
|
-
|
|
24
|
-
doc.document.definitions.forEach(
|
|
25
|
-
var _a, _b, _c;
|
|
14
|
+
let foundQueryOperation = false;
|
|
15
|
+
doc.document.definitions.forEach((item) => {
|
|
26
16
|
// We only care about 'operations'
|
|
27
17
|
if (item.kind !== "OperationDefinition" || !item.name)
|
|
28
18
|
return;
|
|
29
19
|
function throwErrorAtLocation(loc, message) {
|
|
30
|
-
|
|
20
|
+
let printedSource = "";
|
|
31
21
|
if (loc && loc.source) {
|
|
32
22
|
loc.source.name = fileName;
|
|
33
23
|
printedSource = (0, graphql_1.printSourceLocation)(loc.source, {
|
|
@@ -35,45 +25,45 @@ module.exports = {
|
|
|
35
25
|
column: loc.startToken.column,
|
|
36
26
|
});
|
|
37
27
|
}
|
|
38
|
-
|
|
28
|
+
let fullMessage = message;
|
|
39
29
|
if (printedSource) {
|
|
40
30
|
fullMessage += ":\n\n" + printedSource;
|
|
41
31
|
}
|
|
42
32
|
else {
|
|
43
|
-
fullMessage +=
|
|
33
|
+
fullMessage += ` (in ${fileName})`;
|
|
44
34
|
}
|
|
45
|
-
|
|
35
|
+
const err = new Error(fullMessage);
|
|
46
36
|
err.name = "QueryError";
|
|
47
37
|
throw err;
|
|
48
38
|
}
|
|
49
39
|
// Ensure only ONE operation per query file
|
|
50
|
-
if (
|
|
40
|
+
if (foundQueryOperation) {
|
|
51
41
|
throwErrorAtLocation(item.loc, "Only one operation is allowed in each queries/*.graphql file");
|
|
52
42
|
}
|
|
53
|
-
|
|
43
|
+
foundQueryOperation = true;
|
|
54
44
|
/**
|
|
55
45
|
* Determine the 'hook type'
|
|
56
46
|
* - 'mutation' if the operation starts with 'mutation' instead of 'query'
|
|
57
47
|
* - 'infinite' if the operation contains the word 'infinite'
|
|
58
48
|
* - 'normal' otherwise
|
|
59
49
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const type = item.operation === "mutation" ? "mutation" : item.name.value.match(/infinite/i) ? "infinite" : "normal";
|
|
51
|
+
const name = item.name.value;
|
|
52
|
+
const hookName = "use" + name.replace(/^use/i, "").replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
53
|
+
const variablesTypeName = item.variableDefinitions?.length
|
|
64
54
|
? type === "mutation"
|
|
65
55
|
? name + "MutationVariables"
|
|
66
56
|
: name + "QueryVariables"
|
|
67
57
|
: null;
|
|
68
|
-
|
|
58
|
+
const resultTypeName = name + (type === "mutation" ? "Mutation" : "Query");
|
|
69
59
|
// For conventions sake, the name of the operation should start with 'Use'
|
|
70
60
|
if (!name.match(/^Use/)) {
|
|
71
|
-
throwErrorAtLocation(item.name.loc,
|
|
61
|
+
throwErrorAtLocation(item.name.loc, `Expected your query name to start with 'Use', but found '${name}'. Did you mean 'Use${name}'`);
|
|
72
62
|
}
|
|
73
63
|
// Another convention, the query name and file name should be the same
|
|
74
|
-
|
|
64
|
+
const baseName = (0, path_1.basename)(fileName);
|
|
75
65
|
if (baseName.replace(".graphql", "") !== name) {
|
|
76
|
-
throwErrorAtLocation(item.name.loc,
|
|
66
|
+
throwErrorAtLocation(item.name.loc, `Expected your query name and file name to match, for conventions sake (eg. '${baseName}' should be '${name}.graphql')`);
|
|
77
67
|
}
|
|
78
68
|
// Only import variables if the operation has variables
|
|
79
69
|
if (variablesTypeName) {
|
|
@@ -83,165 +73,178 @@ module.exports = {
|
|
|
83
73
|
if (type === "normal") {
|
|
84
74
|
// Just a normal query!
|
|
85
75
|
importUtils["createUseQuery"] = true;
|
|
86
|
-
hooks[hookName] =
|
|
76
|
+
hooks[hookName] = `
|
|
77
|
+
createUseQuery<${resultTypeName}, ${variablesTypeName || "undefined"}>({
|
|
78
|
+
name: ${JSON.stringify(name)}
|
|
79
|
+
})
|
|
80
|
+
`;
|
|
87
81
|
}
|
|
88
82
|
else if (type === "mutation") {
|
|
89
83
|
// A triggerable mutation
|
|
90
84
|
importUtils["createUseMutation"] = true;
|
|
91
|
-
hooks[hookName] =
|
|
85
|
+
hooks[hookName] = `
|
|
86
|
+
createUseMutation<${resultTypeName}, ${variablesTypeName || "undefined"}>({
|
|
87
|
+
name: ${JSON.stringify(name)}
|
|
88
|
+
})
|
|
89
|
+
`;
|
|
92
90
|
}
|
|
93
91
|
else if (type === "infinite") {
|
|
94
92
|
// Ensure the query has 'limit' and 'cursor' variables
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (((_a = variable === null || variable === void 0 ? void 0 : variable.name) === null || _a === void 0 ? void 0 : _a.value) === "limit") {
|
|
93
|
+
let limitVariableIsValid = false;
|
|
94
|
+
let cursorVariableIsValid = false;
|
|
95
|
+
let defaultLimit = 0;
|
|
96
|
+
item.variableDefinitions?.forEach((item) => {
|
|
97
|
+
const { variable, type, loc, defaultValue } = item;
|
|
98
|
+
if (variable?.name?.value === "limit") {
|
|
102
99
|
// Found 'limit', but make sure it's an Int, and has a default value
|
|
103
100
|
if (type.kind === "NamedType" && type.name.value === "Int") {
|
|
104
101
|
if (defaultValue && defaultValue.kind === "IntValue") {
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
limitVariableIsValid = true;
|
|
103
|
+
defaultLimit = Number(defaultValue.value);
|
|
107
104
|
}
|
|
108
105
|
else {
|
|
109
|
-
throwErrorAtLocation(loc,
|
|
106
|
+
throwErrorAtLocation(loc, `For infinite queries, be sure to give the '$limit' variable a default value!\nFor example: posts($limit: Int = 10, $cursor: String)\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
else {
|
|
113
110
|
// @ts-ignore
|
|
114
|
-
|
|
115
|
-
throwErrorAtLocation(loc,
|
|
111
|
+
const wrongType = type?.name?.value;
|
|
112
|
+
throwErrorAtLocation(loc, `For infinite queries, the '$limit' variable is expected to be an 'Int' type, but you've used '${wrongType}' instead!\nFor example: posts($limit: Int = 10, $cursor: String)\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
else if (variable.name.value === "cursor") {
|
|
119
116
|
// Found 'cursor', but make sure it's a string
|
|
120
117
|
if (type.kind === "NamedType") {
|
|
121
118
|
if (type.name.value === "String") {
|
|
122
|
-
|
|
119
|
+
cursorVariableIsValid = true;
|
|
123
120
|
}
|
|
124
121
|
else {
|
|
125
|
-
throwErrorAtLocation(loc,
|
|
122
|
+
throwErrorAtLocation(loc, `For infinite queries, the required '$cursor' variable must be an optional String.\nFor example: posts($limit: Int = 10, $cursor: String)\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
});
|
|
130
127
|
// Check that both the 'limit' and 'cursor' variables are present!
|
|
131
|
-
if (!
|
|
132
|
-
throwErrorAtLocation(item.loc,
|
|
128
|
+
if (!cursorVariableIsValid || !limitVariableIsValid) {
|
|
129
|
+
throwErrorAtLocation(item.loc, `For infinite queries, you must supply and use the '$limit' and '$cursor' variables\nFor example: posts($limit: Int = 10, $cursor: String) ${cursorVariableIsValid} ${limitVariableIsValid}\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
133
130
|
}
|
|
134
131
|
// Finally, ensure that pageInfo is queried somewhere
|
|
135
132
|
// We actually want the selection path for a whole bunch of fields, so that we can extract pagination info, and the list of data
|
|
136
|
-
|
|
133
|
+
const pageInfo = {
|
|
137
134
|
nodesPath: null,
|
|
138
135
|
pageInfoPath: null,
|
|
139
136
|
endCursorPath: null,
|
|
140
137
|
hasNextPagePath: null,
|
|
141
138
|
};
|
|
142
|
-
|
|
139
|
+
let nodesPaths = [];
|
|
143
140
|
// To do this, we use the visitor pattern to find the pageInfo field selection
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
let lookingAtPageInfo = true;
|
|
142
|
+
let lookupPath = [];
|
|
143
|
+
let parentNode;
|
|
147
144
|
(0, graphql_1.visit)(item.selectionSet, {
|
|
148
|
-
enter
|
|
145
|
+
enter(node, key, parent, path, ancestors) {
|
|
149
146
|
if (node.kind === "Field") {
|
|
150
|
-
|
|
147
|
+
lookupPath = [...lookupPath, node.name.value];
|
|
151
148
|
if (node.name.value === "pageInfo") {
|
|
152
|
-
|
|
149
|
+
parentNode = ancestors[ancestors.length - 2];
|
|
153
150
|
// parentNode = ancestors
|
|
154
|
-
if (
|
|
151
|
+
if (pageInfo.pageInfoPath) {
|
|
155
152
|
// Detected multiple pageInfo fields in the query — confusing!
|
|
156
|
-
throwErrorAtLocation(node.loc,
|
|
153
|
+
throwErrorAtLocation(node.loc, `For infinite queries, be sure to only use 'pageInfo' once. Multiple 'pageInfo' fields were selected in your query!`);
|
|
157
154
|
}
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
lookingAtPageInfo = true;
|
|
156
|
+
pageInfo.pageInfoPath = lookupPath;
|
|
160
157
|
}
|
|
161
158
|
else if (node.name.value === "nodes") {
|
|
162
|
-
|
|
159
|
+
nodesPaths.push(lookupPath);
|
|
163
160
|
}
|
|
164
|
-
else if (
|
|
161
|
+
else if (lookingAtPageInfo) {
|
|
165
162
|
if (node.name.value === "endCursor") {
|
|
166
|
-
|
|
163
|
+
pageInfo.endCursorPath = lookupPath;
|
|
167
164
|
}
|
|
168
165
|
else if (node.name.value === "hasNextPage") {
|
|
169
|
-
|
|
166
|
+
pageInfo.hasNextPagePath = lookupPath;
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
170
|
},
|
|
174
|
-
leave
|
|
171
|
+
leave(node, key, parent, path, ancestors) {
|
|
175
172
|
if (node.kind === "Field") {
|
|
176
|
-
|
|
173
|
+
lookupPath = lookupPath.slice(0, -1);
|
|
177
174
|
if (node.name.value === "pageInfo") {
|
|
178
|
-
|
|
175
|
+
lookingAtPageInfo = false;
|
|
179
176
|
}
|
|
180
177
|
}
|
|
181
178
|
},
|
|
182
179
|
});
|
|
183
180
|
// Make sure we found pageInfo { endCursor, hasNextPage }
|
|
184
|
-
if (!
|
|
185
|
-
throwErrorAtLocation(undefined,
|
|
181
|
+
if (!pageInfo.pageInfoPath || !pageInfo.endCursorPath || !pageInfo.hasNextPagePath) {
|
|
182
|
+
throwErrorAtLocation(undefined, `For infinite queries, you need to ensure you select the 'pageInfo' field and it's child 'hasNextPage' and 'endCursor' fields\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
186
183
|
}
|
|
187
184
|
// Look for a nodes path which shares the same parent as the pageInfo path
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return testPath ===
|
|
185
|
+
const expectedNodesPath = pageInfo.pageInfoPath.slice(0, -1).join(",");
|
|
186
|
+
pageInfo.nodesPath = nodesPaths.find((path) => {
|
|
187
|
+
const testPath = path.slice(0, -1).join(",");
|
|
188
|
+
return testPath === expectedNodesPath;
|
|
192
189
|
});
|
|
193
|
-
if (!
|
|
194
|
-
throwErrorAtLocation(undefined,
|
|
190
|
+
if (!pageInfo.nodesPath || !parentNode) {
|
|
191
|
+
throwErrorAtLocation(undefined, `For infinite queries, be sure to select some nodes using the 'nodes' field, adjacent to the 'pageInfo' field which has been selected.\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
195
192
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
let firstArgumentIsValid = false;
|
|
194
|
+
let afterArgumentIsValid = false;
|
|
195
|
+
parentNode?.arguments?.forEach((arg) => {
|
|
199
196
|
if (arg.kind === "Argument") {
|
|
200
197
|
if (arg.name.value === "first") {
|
|
201
198
|
if (arg.value.kind === "Variable") {
|
|
202
199
|
if (arg.value.name.value === "limit") {
|
|
203
|
-
|
|
200
|
+
firstArgumentIsValid = true;
|
|
204
201
|
}
|
|
205
202
|
}
|
|
206
203
|
}
|
|
207
204
|
if (arg.name.value === "after") {
|
|
208
205
|
if (arg.value.kind === "Variable") {
|
|
209
206
|
if (arg.value.name.value === "cursor") {
|
|
210
|
-
|
|
207
|
+
afterArgumentIsValid = true;
|
|
211
208
|
}
|
|
212
209
|
}
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
212
|
});
|
|
216
|
-
if (
|
|
217
|
-
throwErrorAtLocation(
|
|
213
|
+
if (parentNode && (!firstArgumentIsValid || !afterArgumentIsValid)) {
|
|
214
|
+
throwErrorAtLocation(parentNode.loc, `You must use the arguments (first: $limit, after: $cursor) when using infinite queries.\nRead more -> https://eddev.ed.studio/docs/graphql/query-hooks`);
|
|
218
215
|
}
|
|
219
216
|
// Drill down to the path type
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
217
|
+
let finalResultTypeName = resultTypeName;
|
|
218
|
+
pageInfo.nodesPath.forEach((key) => {
|
|
219
|
+
finalResultTypeName = `Exclude<${finalResultTypeName}[${JSON.stringify(key)}], undefined | null>`;
|
|
223
220
|
});
|
|
224
221
|
importUtils["createUseInfiniteQuery"] = true;
|
|
225
|
-
hooks[hookName] =
|
|
222
|
+
hooks[hookName] = `
|
|
223
|
+
createUseInfiniteQuery<Exclude<${finalResultTypeName}[0], undefined | null>, Omit<${variablesTypeName || "undefined"}, 'limit' | 'cursor'>>({
|
|
224
|
+
name: ${JSON.stringify(name)},
|
|
225
|
+
defaultLimit: ${defaultLimit},
|
|
226
|
+
paths: ${JSON.stringify(pageInfo)}
|
|
227
|
+
})
|
|
228
|
+
`;
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
}
|
|
229
232
|
});
|
|
230
|
-
|
|
233
|
+
const utilsToImport = Object.keys(importUtils);
|
|
231
234
|
if (!utilsToImport)
|
|
232
|
-
return
|
|
233
|
-
|
|
235
|
+
return `export {}`;
|
|
236
|
+
const codeBlocks = [];
|
|
234
237
|
// Import required utility functions
|
|
235
238
|
if (utilsToImport.length) {
|
|
236
|
-
codeBlocks.push(
|
|
239
|
+
codeBlocks.push(`import { ${utilsToImport.join(", ")} } from 'eddev/hooks/queryUtils'`);
|
|
237
240
|
}
|
|
238
241
|
// Import types from types.graphql
|
|
239
242
|
if (importTypes.length) {
|
|
240
|
-
codeBlocks.push(
|
|
243
|
+
codeBlocks.push(`import { ${importTypes} } from '../types.graphql'`);
|
|
241
244
|
}
|
|
242
|
-
for (
|
|
243
|
-
|
|
244
|
-
codeBlocks.push(
|
|
245
|
+
for (const hookName in hooks) {
|
|
246
|
+
const hookCode = hooks[hookName];
|
|
247
|
+
codeBlocks.push(`export const ${hookName} = ${hookCode}`);
|
|
245
248
|
}
|
|
246
249
|
return codeBlocks.join("\n\n");
|
|
247
250
|
},
|
|
@@ -4,57 +4,65 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createBlockManifestGenerator = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const manifest_1 = require("./manifest");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const change_case_1 = require("change-case");
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const JSX = /\.(jsx|tsx|ts|js)$/i;
|
|
12
12
|
function createBlockManifestGenerator(opts) {
|
|
13
13
|
return (0, manifest_1.createManifestGenerator)({
|
|
14
14
|
glob: path_1.default.join(opts.baseDirectory, "/blocks/**/*.tsx"),
|
|
15
15
|
onGenerate: opts.onGenerate,
|
|
16
16
|
watch: opts.watch,
|
|
17
|
-
generate
|
|
18
|
-
|
|
19
|
-
.filter(
|
|
20
|
-
.map(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
generate(fileNames) {
|
|
18
|
+
const files = fileNames
|
|
19
|
+
.filter((file) => !file.includes("/_core"))
|
|
20
|
+
.map((file) => {
|
|
21
|
+
const relative = path_1.default.relative(opts.baseDirectory, file).replace(JSX, "");
|
|
22
|
+
const name = path_1.default.basename(file).replace(JSX, "");
|
|
23
|
+
const module = JSON.stringify("./" + relative).replace(JSX, "");
|
|
24
|
+
const componentName = (0, change_case_1.pascalCase)(name);
|
|
25
25
|
// Test if the block has Dynamic: true in the header
|
|
26
|
-
|
|
26
|
+
const dynamic = !opts.isAdmin &&
|
|
27
27
|
!!(0, fs_1.readFileSync)(file)
|
|
28
28
|
.toString()
|
|
29
29
|
.match(/\*[\s]*dynamic: true/i);
|
|
30
|
-
return { relative
|
|
30
|
+
return { relative, name, module, componentName, dynamic };
|
|
31
31
|
});
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
return `
|
|
33
|
+
import coreBlocks from './blocks/_core'
|
|
34
|
+
import { dynamic } from 'eddev/dynamic';
|
|
35
|
+
|
|
36
|
+
${files
|
|
37
|
+
.map(({ relative, componentName, module, dynamic }) => {
|
|
38
|
+
const parts = relative.replace(/\.tsx$/, "").split("/");
|
|
39
|
+
const blockName = "acf/" + parts.slice(1).join("-");
|
|
37
40
|
if (dynamic) {
|
|
38
41
|
return null;
|
|
39
42
|
}
|
|
40
43
|
else {
|
|
41
|
-
return
|
|
44
|
+
return `import ${componentName} from ${module}`;
|
|
42
45
|
}
|
|
43
46
|
})
|
|
44
47
|
.filter(Boolean)
|
|
45
|
-
.join("\n")
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
.join("\n")}
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
...coreBlocks,
|
|
52
|
+
${files
|
|
53
|
+
.map(({ relative, componentName, module, dynamic }) => {
|
|
54
|
+
const parts = relative.replace(/\.tsx$/, "").split("/");
|
|
55
|
+
const blockName = "acf/" + parts.slice(1).join("-");
|
|
50
56
|
if (dynamic) {
|
|
51
|
-
return "
|
|
57
|
+
return `"${blockName}": dynamic(() => import(${module}))`;
|
|
52
58
|
}
|
|
53
59
|
else {
|
|
54
|
-
return "
|
|
60
|
+
return `"${blockName}": ${componentName}`;
|
|
55
61
|
}
|
|
56
62
|
})
|
|
57
|
-
.join(",\n")
|
|
63
|
+
.join(",\n")}
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
58
66
|
},
|
|
59
67
|
});
|
|
60
68
|
}
|