@comet/admin-generator 8.13.0-canary-20260128160441 → 8.13.0-canary-20260129094054

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.
@@ -187,6 +187,11 @@ export type FormConfig<T extends {
187
187
  * @default true
188
188
  */
189
189
  navigateOnCreate?: boolean;
190
+ /**
191
+ * If true, the generated form will have an initialValues prop to set initial form values.
192
+ * @default false
193
+ */
194
+ initialValuesAsProp?: boolean;
190
195
  };
191
196
  export type InjectedFormVariables = {
192
197
  id?: string;
@@ -4,6 +4,7 @@ export type Prop = {
4
4
  type: string;
5
5
  optional: boolean;
6
6
  name: string;
7
+ localAliasName?: string;
7
8
  };
8
9
  export declare function generateForm({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, }: {
9
10
  exportName: string;
@@ -29,7 +29,7 @@ function generateFormPropsCode(props) {
29
29
  formPropsTypeCode: `interface FormProps {
30
30
  ${uniqueProps.map((prop) => `${prop.name}${prop.optional ? `?` : ``}: ${prop.type};`).join("\n")}
31
31
  }`,
32
- formPropsParamsCode: `{${uniqueProps.map((prop) => prop.name).join(", ")}}: FormProps`,
32
+ formPropsParamsCode: `{${uniqueProps.map((prop) => prop.name + (prop.localAliasName ? `: ${prop.localAliasName}` : "")).join(", ")}}: FormProps`,
33
33
  };
34
34
  }
35
35
  function generateForm({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, },
@@ -160,6 +160,14 @@ config) {
160
160
  optional: true,
161
161
  type: `(id: string) => void`,
162
162
  });
163
+ if (config.initialValuesAsProp) {
164
+ formProps.push({
165
+ name: "initialValues",
166
+ localAliasName: "passedInitialValues",
167
+ optional: true,
168
+ type: `Partial<FormValues>`,
169
+ });
170
+ }
163
171
  const { formPropsTypeCode, formPropsParamsCode } = generateFormPropsCode(formProps);
164
172
  gqlDocuments[`${instanceGqlType}FormFragment`] = {
165
173
  document: (0, generateFragmentByFormFragmentFields_1.generateFragmentByFormFragmentFields)({ formFragmentName, gqlType, formFragmentFields }),
@@ -308,7 +316,7 @@ config) {
308
316
  `
309
317
  : ""}
310
318
 
311
- ${(0, generateFormValues_1.generateInitialValues)({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType })}
319
+ ${(0, generateFormValues_1.generateInitialValues)({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, initialValuesAsProp: !!config.initialValuesAsProp })}
312
320
 
313
321
 
314
322
  ${editMode
@@ -19,12 +19,13 @@ export declare function generateFormValuesType({ formValuesConfig, filterByFragm
19
19
  gqlIntrospection: IntrospectionQuery;
20
20
  gqlType: string;
21
21
  }): string;
22
- export declare function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, }: {
22
+ export declare function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, initialValuesAsProp, }: {
23
23
  mode: "all" | "edit" | "add";
24
24
  formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
25
25
  filterByFragmentType: string;
26
26
  gqlIntrospection: IntrospectionQuery;
27
27
  gqlType: string;
28
+ initialValuesAsProp: boolean;
28
29
  }): string;
29
30
  export declare function generateDestructFormValueForInput({ formValuesConfig, gqlIntrospection, gqlType, }: {
30
31
  formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
@@ -84,9 +84,9 @@ function generateInitialValuesFromTree(tree, dataObject, generationType) {
84
84
  let code = "";
85
85
  for (const [key, value] of Object.entries(tree)) {
86
86
  if (Object.keys(value.children).length > 0) {
87
- let childCode = generateInitialValuesFromTree(value.children, `${dataObject}.${key}`, generationType);
87
+ let childCode = generateInitialValuesFromTree(value.children, dataObject ? `${dataObject}.${key}` : null, generationType);
88
88
  if (childCode.length) {
89
- if (generationType == "initializationCode") {
89
+ if (dataObject) {
90
90
  childCode = `{ ...${dataObject}.${key}, ${childCode} }`;
91
91
  if (value.nullable) {
92
92
  code += `${key}: ${dataObject}.${key} ? ${childCode} : undefined, `;
@@ -111,7 +111,7 @@ function generateInitialValuesFromTree(tree, dataObject, generationType) {
111
111
  }
112
112
  return code;
113
113
  }
114
- function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, }) {
114
+ function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, initialValuesAsProp, }) {
115
115
  const instanceGqlType = gqlType[0].toLowerCase() + gqlType.substring(1);
116
116
  const editMode = mode === "edit" || mode == "all";
117
117
  const tree = formValuesConfigToTree({ formValuesConfig, gqlIntrospection, gqlType });
@@ -122,13 +122,15 @@ function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, g
122
122
  ${generateInitialValuesFromTree(tree, `data.${instanceGqlType}`, "initializationCode")}
123
123
  }
124
124
  : {
125
- ${generateInitialValuesFromTree(tree, `data.${instanceGqlType}`, "defaultInitializationCode")}
125
+ ${generateInitialValuesFromTree(tree, initialValuesAsProp ? `passedInitialValues` : null, "defaultInitializationCode")}
126
+ ${initialValuesAsProp ? `...passedInitialValues,` : ""}
126
127
  }
127
128
  , [data]);`;
128
129
  }
129
130
  else {
130
131
  return `const initialValues = {
131
- ${generateInitialValuesFromTree(tree, `data.${instanceGqlType}`, "defaultInitializationCode")}
132
+ ${generateInitialValuesFromTree(tree, initialValuesAsProp ? `passedInitialValues` : null, "defaultInitializationCode")}
133
+ ${initialValuesAsProp ? `...passedInitialValues,` : ""}
132
134
  };`;
133
135
  }
134
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/admin-generator",
3
- "version": "8.13.0-canary-20260128160441",
3
+ "version": "8.13.0-canary-20260129094054",
4
4
  "description": "Comet Admin Generator CLI tool",
5
5
  "repository": {
6
6
  "directory": "packages/admin/admin-generator",
@@ -46,10 +46,10 @@
46
46
  "rimraf": "^6.1.2",
47
47
  "typescript": "5.9.3",
48
48
  "vitest": "^4.0.16",
49
- "@comet/admin": "8.13.0-canary-20260128160441",
50
- "@comet/admin-icons": "8.13.0-canary-20260128160441",
51
- "@comet/cms-admin": "8.13.0-canary-20260128160441",
52
- "@comet/eslint-config": "8.13.0-canary-20260128160441"
49
+ "@comet/admin": "8.13.0-canary-20260129094054",
50
+ "@comet/admin-icons": "8.13.0-canary-20260129094054",
51
+ "@comet/cms-admin": "8.13.0-canary-20260129094054",
52
+ "@comet/eslint-config": "8.13.0-canary-20260129094054"
53
53
  },
54
54
  "engines": {
55
55
  "node": ">=22.0.0"