@comet/admin-generator 8.7.0-canary-20251113120441 → 8.7.0-canary-20251113135204
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/lib/commands/generate/config/transformConfig.d.ts +6 -0
- package/lib/commands/generate/config/transformConfig.js +36 -8
- package/lib/commands/generate/generate-command.d.ts +11 -2
- package/lib/commands/generate/generate-command.js +5 -0
- package/lib/commands/generate/utils/convertConfigImport.d.ts +1 -0
- package/lib/commands/generate/utils/convertConfigImport.js +1 -1
- package/lib/commands/generate/utils/generateImportsCode.d.ts +1 -0
- package/lib/commands/generate/utils/generateImportsCode.js +6 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/package.json +6 -5
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.transformConfigFile = transformConfigFile;
|
|
37
|
+
exports.collectImports = collectImports;
|
|
37
38
|
const ts = __importStar(require("typescript"));
|
|
38
39
|
const supportedImportPaths = [
|
|
39
40
|
"[type=grid].columns.filterOperators",
|
|
@@ -60,6 +61,21 @@ function transformConfigFile(fileName, sourceText) {
|
|
|
60
61
|
function configTransformer() {
|
|
61
62
|
return (context) => {
|
|
62
63
|
const visit = (node, path) => {
|
|
64
|
+
if (ts.isCallExpression(node)) {
|
|
65
|
+
if (node.expression.getText() === "injectFormVariables") {
|
|
66
|
+
if (!path.startsWith("[type=form].fields")) {
|
|
67
|
+
throw new Error(`injectFormVariables can only be used in form field definitions: ${path}`);
|
|
68
|
+
}
|
|
69
|
+
if (node.arguments.length !== 1) {
|
|
70
|
+
throw new Error(`injectFormVariables expects exactly one argument`);
|
|
71
|
+
}
|
|
72
|
+
const injectFormVariablesArg = node.arguments[0];
|
|
73
|
+
if (!ts.isArrowFunction(injectFormVariablesArg)) {
|
|
74
|
+
throw new Error(`injectFormVariables expects an arrow function as its argument`);
|
|
75
|
+
}
|
|
76
|
+
node = injectFormVariablesArg.body;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
63
79
|
if (ts.isArrowFunction(node)) {
|
|
64
80
|
if (supportedInlineCodePaths.includes(path)) {
|
|
65
81
|
let code = node.getText();
|
|
@@ -73,6 +89,9 @@ function transformConfigFile(fileName, sourceText) {
|
|
|
73
89
|
return ts.factory.createObjectLiteralExpression([
|
|
74
90
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(imprt.name)),
|
|
75
91
|
ts.factory.createPropertyAssignment("import", ts.factory.createStringLiteral(imprt.import)),
|
|
92
|
+
...(imprt.defaultImport
|
|
93
|
+
? [ts.factory.createPropertyAssignment("defaultImport", ts.factory.createTrue())]
|
|
94
|
+
: []),
|
|
76
95
|
]);
|
|
77
96
|
}))),
|
|
78
97
|
], true);
|
|
@@ -193,16 +212,25 @@ function getTypePropertyFromObjectLiteral(node) {
|
|
|
193
212
|
function collectImports(rootNode) {
|
|
194
213
|
const importedIdentifiers = new Map();
|
|
195
214
|
function visit(node) {
|
|
196
|
-
if (ts.isImportDeclaration(node) &&
|
|
197
|
-
node.importClause &&
|
|
198
|
-
node.importClause.namedBindings &&
|
|
199
|
-
ts.isNamedImports(node.importClause.namedBindings)) {
|
|
215
|
+
if (ts.isImportDeclaration(node) && node.importClause) {
|
|
200
216
|
const moduleSpecifier = node.moduleSpecifier.text;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
217
|
+
if (node.importClause.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {
|
|
218
|
+
//named import
|
|
219
|
+
for (const element of node.importClause.namedBindings.elements) {
|
|
220
|
+
const localName = element.name.text;
|
|
221
|
+
const originalName = element.propertyName ? element.propertyName.text : localName;
|
|
222
|
+
importedIdentifiers.set(localName, {
|
|
223
|
+
name: originalName,
|
|
224
|
+
import: moduleSpecifier,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (node.importClause.name && ts.isIdentifier(node.importClause.name)) {
|
|
229
|
+
//default import
|
|
230
|
+
const localName = node.importClause.name.text;
|
|
204
231
|
importedIdentifiers.set(localName, {
|
|
205
|
-
|
|
232
|
+
defaultImport: true,
|
|
233
|
+
name: localName,
|
|
206
234
|
import: moduleSpecifier,
|
|
207
235
|
});
|
|
208
236
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type ApolloClient } from "@apollo/client";
|
|
1
2
|
import { type GridColDef } from "@comet/admin";
|
|
2
3
|
import { type IconName } from "@comet/admin-icons";
|
|
3
|
-
import { type BlockInterface, type FinalFormFileUploadProps } from "@comet/cms-admin";
|
|
4
|
+
import { type BlockInterface, type ContentScope, type FinalFormFileUploadProps } from "@comet/cms-admin";
|
|
4
5
|
import { type IconProps } from "@mui/material";
|
|
5
6
|
import { type GridCellParams, type GridFilterItem, type GridFilterOperator, type GridRenderCellParams, type GridSortDirection, type GridValidRowModel } from "@mui/x-data-grid";
|
|
6
7
|
import { Command } from "commander";
|
|
7
|
-
import { type FieldValidator } from "final-form";
|
|
8
|
+
import { type FieldValidator, type FormApi } from "final-form";
|
|
8
9
|
import { type ComponentType } from "react";
|
|
9
10
|
import { type UsableFields, type UsableFormFields } from "./generateGrid/usableFields";
|
|
10
11
|
import { type ColumnVisibleOption } from "./utils/columnVisibility";
|
|
@@ -175,6 +176,14 @@ export type FormConfig<T extends {
|
|
|
175
176
|
*/
|
|
176
177
|
navigateOnCreate?: boolean;
|
|
177
178
|
};
|
|
179
|
+
export type InjectedFormVariables = {
|
|
180
|
+
id?: string;
|
|
181
|
+
mode?: "edit" | "add";
|
|
182
|
+
client: ApolloClient<object>;
|
|
183
|
+
formApi: FormApi<unknown, Partial<unknown>>;
|
|
184
|
+
scope: ContentScope;
|
|
185
|
+
};
|
|
186
|
+
export declare function injectFormVariables<T>(fn: (injectedVariables: InjectedFormVariables) => T): T;
|
|
178
187
|
type BaseColumnConfig = Pick<GridColDef, "headerName" | "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
|
|
179
188
|
headerInfoTooltip?: string;
|
|
180
189
|
visible?: ColumnVisibleOption;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.generateCommand = void 0;
|
|
13
13
|
exports.isFormFieldConfig = isFormFieldConfig;
|
|
14
14
|
exports.isFormLayoutConfig = isFormLayoutConfig;
|
|
15
|
+
exports.injectFormVariables = injectFormVariables;
|
|
15
16
|
exports.defineConfig = defineConfig;
|
|
16
17
|
const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
17
18
|
const load_1 = require("@graphql-tools/load");
|
|
@@ -33,6 +34,10 @@ function isFormFieldConfig(arg) {
|
|
|
33
34
|
function isFormLayoutConfig(arg) {
|
|
34
35
|
return arg.type !== undefined && ["fieldSet", "optionalNestedFields"].includes(arg.type);
|
|
35
36
|
}
|
|
37
|
+
function injectFormVariables(fn) {
|
|
38
|
+
// this function is only used in config but never called at runtime
|
|
39
|
+
return fn({});
|
|
40
|
+
}
|
|
36
41
|
function defineConfig(config) {
|
|
37
42
|
return config;
|
|
38
43
|
}
|
|
@@ -19,7 +19,12 @@ function generateImportsCode(imports) {
|
|
|
19
19
|
});
|
|
20
20
|
const importsString = filteredImports
|
|
21
21
|
.map((imp) => {
|
|
22
|
-
|
|
22
|
+
if (imp.defaultImport) {
|
|
23
|
+
return `import ${imp.name} from "${imp.importPath}";`;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return `import { ${imp.name} } from "${imp.importPath}";`;
|
|
27
|
+
}
|
|
23
28
|
})
|
|
24
29
|
.join("\n");
|
|
25
30
|
return importsString;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { FormConfig, FormFieldConfig, GeneratorConfig, GridColumnConfig, GridColumnStaticSelectValue, GridConfig, StaticSelectValue, } from "./commands/generate/generate-command";
|
|
2
|
-
export { defineConfig } from "./commands/generate/generate-command";
|
|
1
|
+
export type { FormConfig, FormFieldConfig, GeneratorConfig, GridColumnConfig, GridColumnStaticSelectValue, GridConfig, InjectedFormVariables, StaticSelectValue, } from "./commands/generate/generate-command";
|
|
2
|
+
export { defineConfig, injectFormVariables } from "./commands/generate/generate-command";
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineConfig = void 0;
|
|
3
|
+
exports.injectFormVariables = exports.defineConfig = void 0;
|
|
4
4
|
var generate_command_1 = require("./commands/generate/generate-command");
|
|
5
5
|
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return generate_command_1.defineConfig; } });
|
|
6
|
+
Object.defineProperty(exports, "injectFormVariables", { enumerable: true, get: function () { return generate_command_1.injectFormVariables; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/admin-generator",
|
|
3
|
-
"version": "8.7.0-canary-
|
|
3
|
+
"version": "8.7.0-canary-20251113135204",
|
|
4
4
|
"description": "Comet Admin Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/admin/admin-generator",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"ts-node": "^10.9.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@apollo/client": "^3.7.0",
|
|
33
34
|
"@mui/material": "^7.2.0",
|
|
34
35
|
"@mui/x-data-grid": "^7.29.8",
|
|
35
36
|
"@types/jest": "^29.5.14",
|
|
@@ -47,10 +48,10 @@
|
|
|
47
48
|
"rimraf": "^6.0.1",
|
|
48
49
|
"ts-jest": "^29.4.0",
|
|
49
50
|
"typescript": "5.8.3",
|
|
50
|
-
"@comet/admin": "8.7.0-canary-
|
|
51
|
-
"@comet/admin-icons": "8.7.0-canary-
|
|
52
|
-
"@comet/cms-admin": "8.7.0-canary-
|
|
53
|
-
"@comet/eslint-config": "8.7.0-canary-
|
|
51
|
+
"@comet/admin": "8.7.0-canary-20251113135204",
|
|
52
|
+
"@comet/admin-icons": "8.7.0-canary-20251113135204",
|
|
53
|
+
"@comet/cms-admin": "8.7.0-canary-20251113135204",
|
|
54
|
+
"@comet/eslint-config": "8.7.0-canary-20251113135204"
|
|
54
55
|
},
|
|
55
56
|
"engines": {
|
|
56
57
|
"node": ">=22.0.0"
|