@comet/admin-generator 9.0.0-canary-20251211112608 → 9.0.0-canary-20251222112948

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.
@@ -52,6 +52,20 @@ const supportedInlineCodePaths = [
52
52
  //support in up to 5 levels of nested fields (eg. fieldSet)
53
53
  ...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.validate`),
54
54
  ];
55
+ const supportedFormattedMessagePaths = [
56
+ "[type=grid].newEntryText",
57
+ "[type=grid].columns.headerName",
58
+ "[type=grid].columns.headerInfoTooltip",
59
+ //staticSelect
60
+ "[type=grid].columns.values.label",
61
+ "[type=grid].columns.values.label.primaryText",
62
+ "[type=grid].columns.values.label.secondaryText",
63
+ //support in up to 5 levels of nested fields (eg. fieldSet)
64
+ ...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.label`),
65
+ ...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.helperText`),
66
+ ...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.checkboxLabel`),
67
+ ...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.title`), // fieldSet title
68
+ ];
55
69
  // transform the config file to replace all imports and inline code with a { code, imports } object
56
70
  // this is needed to be able to execute the config file in a node environment
57
71
  function transformConfigFile(fileName, sourceText) {
@@ -112,6 +126,26 @@ function transformConfigFile(fileName, sourceText) {
112
126
  }
113
127
  }
114
128
  }
129
+ else if (ts.isJsxSelfClosingElement(node)) {
130
+ if (node.tagName.getText() == "FormattedMessage") {
131
+ if (!supportedFormattedMessagePaths.includes(path)) {
132
+ throw new Error(`FormattedMessage is not supported in this context: ${path}`);
133
+ }
134
+ return ts.factory.createObjectLiteralExpression(node.attributes.properties.map((attr) => {
135
+ var _a;
136
+ if (!ts.isJsxAttribute(attr)) {
137
+ throw new Error(`Only JsxAttributes are supported in FormattedMessage in this context: ${path}`);
138
+ }
139
+ let name = (_a = attr.name) === null || _a === void 0 ? void 0 : _a.getText();
140
+ if (name === "id")
141
+ name = "formattedMessageId"; // rename to identify as formattedMessage
142
+ if (!attr.initializer || !ts.isStringLiteral(attr.initializer)) {
143
+ throw new Error(`Only string literals are supported in FormattedMessage in this context: ${path}.${name}`);
144
+ }
145
+ return ts.factory.createPropertyAssignment(name, ts.factory.createStringLiteral(attr.initializer.text));
146
+ }));
147
+ }
148
+ }
115
149
  const transformKinds = [
116
150
  ts.SyntaxKind.Identifier,
117
151
  ts.SyntaxKind.ArrayLiteralExpression,
@@ -6,9 +6,11 @@ import { type IconProps } from "@mui/material";
6
6
  import { type GridCellParams, type GridFilterItem, type GridFilterOperator, type GridRenderCellParams, type GridSortDirection, type GridValidRowModel } from "@mui/x-data-grid";
7
7
  import { Command } from "commander";
8
8
  import { type FieldValidator, type FormApi } from "final-form";
9
- import { type ComponentType } from "react";
9
+ import type { ComponentType, ReactElement } from "react";
10
+ import type { FormattedMessage, MessageDescriptor } from "react-intl";
10
11
  import { type UsableFields, type UsableFormFields } from "./generateGrid/usableFields";
11
12
  import { type ColumnVisibleOption } from "./utils/columnVisibility";
13
+ export type FormattedMessageElement = ReactElement<MessageDescriptor, typeof FormattedMessage>;
12
14
  type IconObject = Pick<IconProps, "color" | "fontSize"> & {
13
15
  name: IconName;
14
16
  };
@@ -143,23 +145,23 @@ export type FormFieldConfig<T> = (({
143
145
  maxFiles?: number;
144
146
  download?: boolean;
145
147
  } & Pick<Partial<FinalFormFileUploadProps<true>>, "maxFileSize" | "readOnly" | "layout" | "accept">)) & {
146
- label?: string;
148
+ label?: string | FormattedMessageElement;
147
149
  required?: boolean;
148
150
  validate?: FieldValidator<unknown>;
149
- helperText?: string;
151
+ helperText?: string | FormattedMessageElement;
150
152
  readOnly?: boolean;
151
153
  };
152
154
  export declare function isFormFieldConfig<T>(arg: any): arg is FormFieldConfig<T>;
153
155
  type OptionalNestedFieldsConfig<T> = {
154
156
  type: "optionalNestedFields";
155
157
  name: UsableFormFields<T>;
156
- checkboxLabel?: string;
158
+ checkboxLabel?: string | FormattedMessageElement;
157
159
  fields: FormFieldConfig<any>[];
158
160
  };
159
161
  export type FormLayoutConfig<T> = {
160
162
  type: "fieldSet";
161
163
  name: string;
162
- title?: string;
164
+ title?: string | FormattedMessageElement;
163
165
  supportText?: string;
164
166
  collapsible?: boolean;
165
167
  initiallyExpanded?: boolean;
@@ -194,19 +196,20 @@ export type InjectedFormVariables = {
194
196
  scope: ContentScope;
195
197
  };
196
198
  export declare function injectFormVariables<T>(fn: (injectedVariables: InjectedFormVariables) => T): T;
197
- type BaseColumnConfig = Pick<GridColDef, "headerName" | "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
198
- headerInfoTooltip?: string;
199
+ type BaseColumnConfig = Pick<GridColDef, "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
200
+ headerName?: string | FormattedMessageElement;
201
+ headerInfoTooltip?: string | FormattedMessageElement;
199
202
  visible?: ColumnVisibleOption;
200
203
  fieldName?: string;
201
204
  };
202
205
  export type GridColumnStaticSelectLabelCellContent = {
203
- primaryText?: string;
204
- secondaryText?: string;
206
+ primaryText?: string | FormattedMessageElement;
207
+ secondaryText?: string | FormattedMessageElement;
205
208
  icon?: Icon;
206
209
  };
207
210
  export type GridColumnStaticSelectValue = StaticSelectValue | {
208
211
  value: string | number | boolean;
209
- label: string | GridColumnStaticSelectLabelCellContent;
212
+ label: string | FormattedMessageElement | GridColumnStaticSelectLabelCellContent;
210
213
  } | number | boolean;
211
214
  export type GridColumnConfig<T extends GridValidRowModel> = ({
212
215
  type: "text";
@@ -294,7 +297,7 @@ export type GridConfig<T extends {
294
297
  filterProp?: boolean;
295
298
  toolbar?: boolean;
296
299
  toolbarActionProp?: boolean;
297
- newEntryText?: string;
300
+ newEntryText?: string | FormattedMessageElement;
298
301
  rowActionProp?: boolean;
299
302
  selectionProps?: "multiSelect" | "singleSelect";
300
303
  rowReordering?: {
@@ -307,6 +310,9 @@ export type GridConfig<T extends {
307
310
  */
308
311
  scopeAsProp?: boolean;
309
312
  density?: "comfortable" | "compact" | "standard";
313
+ crudContextMenu?: {
314
+ deleteText?: string;
315
+ };
310
316
  };
311
317
  export type GeneratorConfig<T extends {
312
318
  __typename?: string;
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.buildFormFieldOptions = buildFormFieldOptions;
15
15
  const camelCaseToHumanReadable_1 = require("../../utils/camelCaseToHumanReadable");
16
16
  const convertConfigImport_1 = require("../../utils/convertConfigImport");
17
+ const intl_1 = require("../../utils/intl");
17
18
  const runtimeTypeGuards_1 = require("../../utils/runtimeTypeGuards");
18
19
  const buildAdornmentData = ({ adornmentData }) => {
19
20
  let adornmentString = "";
@@ -52,12 +53,15 @@ const buildAdornmentData = ({ adornmentData }) => {
52
53
  * Helper function that builds various options needed for generating form fields.
53
54
  */
54
55
  function buildFormFieldOptions({ config, formConfig, }) {
55
- var _a;
56
56
  const rootGqlType = formConfig.gqlType;
57
57
  const name = String(config.name);
58
- const label = (_a = config.label) !== null && _a !== void 0 ? _a : (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(name);
59
58
  const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
60
- const fieldLabel = `<FormattedMessage id="${formattedMessageRootId}.${name}" defaultMessage="${label}" />`;
59
+ const fieldLabel = (0, intl_1.generateFormattedMessage)({
60
+ config: config.label,
61
+ id: `${formattedMessageRootId}.${name}`,
62
+ defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(name),
63
+ type: "jsx",
64
+ });
61
65
  const imports = [];
62
66
  let startAdornment = { adornmentString: "" };
63
67
  let endAdornment = { adornmentString: "" };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFormField = generateFormField;
4
4
  const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
5
5
  const convertConfigImport_1 = require("../utils/convertConfigImport");
6
+ const intl_1 = require("../utils/intl");
6
7
  const isFieldOptional_1 = require("../utils/isFieldOptional");
7
8
  const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
8
9
  const generateAsyncSelect_1 = require("./asyncSelect/generateAsyncSelect");
@@ -57,9 +58,11 @@ function generateFormField({ gqlIntrospection, baseOutputFilename, config, formC
57
58
  ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
58
59
  ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
59
60
  ${config.helperText
60
- ? `helperText={<FormattedMessage id=` +
61
- `"${formattedMessageRootId}.${name}.helperText" ` +
62
- `defaultMessage="${config.helperText}" />}`
61
+ ? `helperText={${(0, intl_1.generateFormattedMessage)({
62
+ config: config.helperText,
63
+ id: `${formattedMessageRootId}.${name}.helperText`,
64
+ type: "jsx",
65
+ })}}`
63
66
  : ""}
64
67
  ${validateCode}
65
68
  />`;
@@ -89,22 +92,9 @@ function generateFormField({ gqlIntrospection, baseOutputFilename, config, formC
89
92
  : ""}
90
93
  ${validateCode}
91
94
  />`;
92
- //TODO MUI suggest not using type=number https://mui.com/material-ui/react-text-field/#type-quot-number-quot
93
- let assignment = `parseFloat($fieldName)`;
94
- if ((0, isFieldOptional_1.isFieldOptional)({ config, gqlIntrospection: gqlIntrospection, gqlType: gqlType })) {
95
- assignment = `$fieldName ? ${assignment} : null`;
96
- }
97
- formValueConfig.formValueToGqlInputCode = `${assignment}`;
98
- let initializationAssignment = `String(data.${dataRootName}.${nameWithPrefix})`;
99
- if (!required) {
100
- initializationAssignment = `data.${dataRootName}.${nameWithPrefix} ? ${initializationAssignment} : undefined`;
95
+ if (!required && !config.readOnly) {
96
+ formValueConfig.formValueToGqlInputCode = `$fieldName ?? null`;
101
97
  }
102
- formValueConfig.omitFromFragmentType = true;
103
- formValueConfig.typeCode = {
104
- nullable: !required,
105
- type: "string",
106
- };
107
- formValueConfig.initializationCode = `${initializationAssignment}`;
108
98
  if (config.initialValue !== undefined) {
109
99
  formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
110
100
  }
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFormLayout = generateFormLayout;
4
4
  const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
5
+ const intl_1 = require("../utils/intl");
5
6
  const findIntrospectionFieldType_1 = require("./formField/findIntrospectionFieldType");
6
7
  const generateFields_1 = require("./generateFields");
7
8
  function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }) {
8
- var _a, _b, _c, _d, _e;
9
+ var _a, _b, _c;
9
10
  const rootGqlType = formConfig.gqlType;
10
11
  const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
11
12
  const dataRootName = rootGqlType[0].toLowerCase() + rootGqlType.substring(1); // TODO should probably be deteced via query
@@ -18,7 +19,6 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
18
19
  const formValuesConfig = [];
19
20
  const finalFormConfig = { subscription: {}, renderProps: {} };
20
21
  if (config.type === "fieldSet") {
21
- const title = (_a = config.title) !== null && _a !== void 0 ? _a : (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(config.name);
22
22
  const generatedFields = (0, generateFields_1.generateFields)({
23
23
  gqlIntrospection,
24
24
  baseOutputFilename,
@@ -36,10 +36,10 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
36
36
  imports.push(...generatedFields.imports);
37
37
  formProps.push(...generatedFields.formProps);
38
38
  formValuesConfig.push(...generatedFields.formValuesConfig);
39
- finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (_b = generatedFields.finalFormConfig) === null || _b === void 0 ? void 0 : _b.subscription);
40
- finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (_c = generatedFields.finalFormConfig) === null || _c === void 0 ? void 0 : _c.renderProps);
39
+ finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (_a = generatedFields.finalFormConfig) === null || _a === void 0 ? void 0 : _a.subscription);
40
+ finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (_b = generatedFields.finalFormConfig) === null || _b === void 0 ? void 0 : _b.renderProps);
41
41
  imports.push({ name: "FieldSet", importPath: "@comet/admin" });
42
- const supportPlaceholder = (_d = config.supportText) === null || _d === void 0 ? void 0 : _d.includes("{");
42
+ const supportPlaceholder = (_c = config.supportText) === null || _c === void 0 ? void 0 : _c.includes("{");
43
43
  if (supportPlaceholder) {
44
44
  imports.push({ name: "FormSpy", importPath: "react-final-form" });
45
45
  }
@@ -47,7 +47,12 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
47
47
  <FieldSet
48
48
  ${config.collapsible === undefined || config.collapsible ? `collapsible` : ``}
49
49
  ${config.initiallyExpanded != null ? `initiallyExpanded={${config.initiallyExpanded}}` : ``}
50
- title={<FormattedMessage id="${formattedMessageRootId}.${config.name}.title" defaultMessage="${title}" />}
50
+ title={${(0, intl_1.generateFormattedMessage)({
51
+ config: config.title,
52
+ id: `${formattedMessageRootId}.${config.name}.title`,
53
+ defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(config.name),
54
+ type: "jsx",
55
+ })}}
51
56
  ${config.supportText
52
57
  ? `supportText={
53
58
  ${supportPlaceholder ? `mode === "edit" && (<FormSpy subscription={{ values: true }}>{({ values }) => (` : ``}
@@ -70,7 +75,6 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
70
75
  throw new Error(`field ${name} in gql introspection type ${gqlType} not found`);
71
76
  if (introspectionFieldType.kind !== "OBJECT")
72
77
  throw new Error(`field ${name} in gql introspection type ${gqlType} has to be OBJECT`);
73
- const checkboxLabel = (_e = config.checkboxLabel) !== null && _e !== void 0 ? _e : `Enable ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(String(config.name))}`;
74
78
  const generatedFields = (0, generateFields_1.generateFields)({
75
79
  gqlIntrospection,
76
80
  baseOutputFilename,
@@ -110,7 +114,12 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
110
114
  fullWidth
111
115
  name="${String(config.name)}Enabled"
112
116
  type="checkbox"
113
- label={<FormattedMessage id="${formattedMessageRootId}.${String(config.name)}.${String(config.name)}Enabled" defaultMessage="${checkboxLabel}" />}
117
+ label={${(0, intl_1.generateFormattedMessage)({
118
+ config: config.checkboxLabel,
119
+ id: `${formattedMessageRootId}.${String(config.name)}.${String(config.name)}Enabled`,
120
+ defaultMessage: `Enable ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(String(config.name))}`,
121
+ type: "jsx",
122
+ })}}
114
123
  >
115
124
  {(props) => (
116
125
  <FormControlLabel
@@ -20,6 +20,7 @@ const findQueryType_1 = require("../utils/findQueryType");
20
20
  const findRootBlocks_1 = require("../utils/findRootBlocks");
21
21
  const generateGqlOperation_1 = require("../utils/generateGqlOperation");
22
22
  const generateImportsCode_1 = require("../utils/generateImportsCode");
23
+ const intl_1 = require("../utils/intl");
23
24
  const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
24
25
  const detectMuiXVersion_1 = require("./detectMuiXVersion");
25
26
  const findInputObjectType_1 = require("./findInputObjectType");
@@ -73,37 +74,59 @@ const getSortByValue = (sortBy) => {
73
74
  return sortBy;
74
75
  };
75
76
  const getValueOptionsLabelData = (messageId, label) => {
76
- if (typeof label === "string") {
77
+ if (typeof label === "string" || (0, runtimeTypeGuards_1.isGeneratorConfigFormattedMessage)(label)) {
77
78
  return {
78
- textLabel: `intl.formatMessage({ id: "${messageId}", defaultMessage: "${label}" })`,
79
+ textLabel: (0, intl_1.generateFormattedMessage)({
80
+ config: label,
81
+ id: messageId,
82
+ type: "intlCall",
83
+ }),
79
84
  };
80
85
  }
81
86
  const textLabelParts = [];
82
87
  const gridCellContentProps = {};
83
- if (label.primaryText) {
88
+ if ("primaryText" in label && label.primaryText) {
84
89
  const primaryMessageId = `${messageId}.primary`;
85
- textLabelParts.push(`intl.formatMessage({ id: "${primaryMessageId}", defaultMessage: "${label.primaryText}" })`);
86
- gridCellContentProps.primaryText = `<FormattedMessage id="${primaryMessageId}" defaultMessage="${label.primaryText}" />`;
90
+ textLabelParts.push((0, intl_1.generateFormattedMessage)({
91
+ config: label.primaryText,
92
+ id: primaryMessageId,
93
+ type: "intlCall",
94
+ }));
95
+ gridCellContentProps.primaryText = (0, intl_1.generateFormattedMessage)({
96
+ config: label.primaryText,
97
+ id: primaryMessageId,
98
+ type: "jsx",
99
+ });
87
100
  }
88
- if (label.secondaryText) {
101
+ if ("secondaryText" in label && label.secondaryText) {
89
102
  const secondaryMessageId = `${messageId}.secondary`;
90
- textLabelParts.push(`intl.formatMessage({ id: "${secondaryMessageId}", defaultMessage: "${label.secondaryText}" })`);
91
- gridCellContentProps.secondaryText = `<FormattedMessage id="${secondaryMessageId}" defaultMessage="${label.secondaryText}" />`;
92
- }
93
- if (typeof label.icon === "string") {
94
- gridCellContentProps.icon = `<${label.icon}Icon />`;
103
+ textLabelParts.push((0, intl_1.generateFormattedMessage)({
104
+ config: label.secondaryText,
105
+ id: secondaryMessageId,
106
+ type: "intlCall",
107
+ }));
108
+ gridCellContentProps.secondaryText = (0, intl_1.generateFormattedMessage)({
109
+ config: label.secondaryText,
110
+ id: secondaryMessageId,
111
+ type: "jsx",
112
+ });
95
113
  }
96
- else if (typeof label.icon === "object") {
97
- if ("import" in label.icon) {
98
- gridCellContentProps.icon = `<${label.icon.name} />`;
114
+ if ("icon" in label) {
115
+ if (typeof label.icon === "string") {
116
+ gridCellContentProps.icon = `<${label.icon}Icon />`;
99
117
  }
100
- else {
101
- const _a = label.icon, { name } = _a, iconProps = __rest(_a, ["name"]);
102
- gridCellContentProps.icon = `<${name}Icon
118
+ else if (typeof label.icon === "object") {
119
+ if ("import" in label.icon) {
120
+ gridCellContentProps.icon = `<${label.icon.name} />`;
121
+ }
122
+ else {
123
+ const _a = label.icon, { name } = _a, iconProps = __rest(_a, ["name"]);
124
+ gridCellContentProps.icon = `<${name}Icon
103
125
  ${Object.entries(iconProps)
104
- .map(([key, value]) => `${key}="${value}"`)
105
- .join("\n")}
126
+ .map(([key, value]) => `${key}="${value}"`)
127
+ .join("\n")}
106
128
  />`;
129
+ }
107
130
  }
108
131
  }
109
132
  const gridCellContent = `<GridCellContent
@@ -117,7 +140,7 @@ const getValueOptionsLabelData = (messageId, label) => {
117
140
  };
118
141
  };
119
142
  function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, }, config) {
120
- var _a, _b, _c, _d, _e, _f, _g, _h;
143
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
121
144
  const gqlType = config.gqlType;
122
145
  if (!gqlType) {
123
146
  throw new Error("gqlType is required in grid config");
@@ -312,10 +335,10 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
312
335
  if (!schemaEntity)
313
336
  throw new Error("didn't find entity in schema types");
314
337
  const actionsColumnConfig = config.columns.find((column) => column.type === "actions");
315
- const _j = actionsColumnConfig !== null && actionsColumnConfig !== void 0 ? actionsColumnConfig : {}, { component: actionsColumnComponent, type: actionsColumnType, headerName: actionsColumnHeaderName, pinned: actionsColumnPinned = "right", width: actionsColumnWidth = defaultActionsColumnWidth, visible: actionsColumnVisible = undefined,
338
+ const _k = actionsColumnConfig !== null && actionsColumnConfig !== void 0 ? actionsColumnConfig : {}, { component: actionsColumnComponent, type: actionsColumnType, headerName: actionsColumnHeaderName, pinned: actionsColumnPinned = "right", width: actionsColumnWidth = defaultActionsColumnWidth, visible: actionsColumnVisible = undefined,
316
339
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
317
- queryFields: actionsColumnQueryFields = [] } = _j, // not needed here, but needs to be removed from restActionsColumnConfig because it's directly used in to generate component props in tsCodeRecordToString
318
- restActionsColumnConfig = __rest(_j, ["component", "type", "headerName", "pinned", "width", "visible", "queryFields"]);
340
+ queryFields: actionsColumnQueryFields = [] } = _k, // not needed here, but needs to be removed from restActionsColumnConfig because it's directly used in to generate component props in tsCodeRecordToString
341
+ restActionsColumnConfig = __rest(_k, ["component", "type", "headerName", "pinned", "width", "visible", "queryFields"]);
319
342
  if (actionsColumnComponent) {
320
343
  if (!(0, runtimeTypeGuards_1.isGeneratorConfigImport)(actionsColumnComponent)) {
321
344
  throw new Error("Unsupported actionsColumnComponent, only imports are supported");
@@ -380,7 +403,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
380
403
  const enumType = gqlIntrospection.__schema.types.find((t) => t.kind === "ENUM" && t.name === introspectionFieldType.name);
381
404
  (_a = column.values) === null || _a === void 0 ? void 0 : _a.forEach((value) => {
382
405
  var _a;
383
- if (typeof value === "object" && typeof value.label === "object" && typeof value.label.icon !== "undefined") {
406
+ if (typeof value === "object" && typeof value.label === "object" && "icon" in value.label) {
384
407
  if (typeof value.label.icon === "string") {
385
408
  iconsToImport.push(value.label.icon);
386
409
  }
@@ -677,10 +700,19 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
677
700
  renderHeader: column.headerInfoTooltip
678
701
  ? `() => (
679
702
  <>
680
- <GridColumnHeaderTitle label={intl.formatMessage({ id: "${instanceGqlType}.${column.name}", defaultMessage: "${column.headerName || (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name)}"})} columnWidth= {${tooltipColumnWidth}}
703
+ <GridColumnHeaderTitle label={${(0, intl_1.generateFormattedMessage)({
704
+ config: column.headerName,
705
+ id: `${instanceGqlType}.${column.name}`,
706
+ defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name),
707
+ type: "intlCall",
708
+ })}} columnWidth= {${tooltipColumnWidth}}
681
709
  />
682
710
  <Tooltip
683
- title={<FormattedMessage id="${instanceGqlType}.${column.name}.tooltip" defaultMessage="${column.headerInfoTooltip}" />}
711
+ title={${(0, intl_1.generateFormattedMessage)({
712
+ config: column.headerInfoTooltip,
713
+ id: `${instanceGqlType}.${column.name}.tooltip`,
714
+ type: "jsx",
715
+ })}}
684
716
  >
685
717
  <InfoIcon sx={{ marginLeft: 1 }} />
686
718
  </Tooltip>
@@ -689,7 +721,12 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
689
721
  : undefined,
690
722
  headerName: column.headerName === ""
691
723
  ? `""`
692
- : `intl.formatMessage({ id: "${instanceGqlType}.${column.name}", defaultMessage: "${column.headerName || (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name)}" })`,
724
+ : (0, intl_1.generateFormattedMessage)({
725
+ config: column.headerName,
726
+ id: `${instanceGqlType}.${column.name}`,
727
+ defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name),
728
+ type: "intlCall",
729
+ }),
693
730
  type: column.gridType ? `"${column.gridType}"` : undefined,
694
731
  filterable: (!column.filterOperators && !filterFields.includes(column.name)) || allowRowReordering ? `false` : undefined,
695
732
  sortable: (!sortFields.includes(column.name) || allowRowReordering) && !column.sortBy ? `false` : undefined,
@@ -717,8 +754,18 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
717
754
  .join(",\n")},
718
755
  ${showActionsColumn
719
756
  ? tsCodeRecordToString(Object.assign(Object.assign({ field: '"actions"', headerName: actionsColumnHeaderName
720
- ? `intl.formatMessage({ id: "${instanceGqlType}.actions", defaultMessage: "${actionsColumnHeaderName}" })`
721
- : `""`, sortable: "false", filterable: "false", type: '"actions"', align: '"right"', pinned: `"${actionsColumnPinned}"`, width: forwardRowAction ? "actionsColumnWidth" : actionsColumnWidth, visible: actionsColumnVisible && `theme.breakpoints.${actionsColumnVisible}` }, restActionsColumnConfig), { disableExport: config.excelExport ? "true" : undefined, renderCell: `(params) => {
757
+ ? (0, intl_1.generateFormattedMessage)({
758
+ config: actionsColumnHeaderName,
759
+ id: `${instanceGqlType}.actions`,
760
+ type: "intlCall",
761
+ })
762
+ : `""`, sortable: "false", filterable: "false", type: '"actions"', align: '"right"', pinned: `"${actionsColumnPinned}"`, width: forwardRowAction ? "actionsColumnWidth" : actionsColumnWidth, visible: actionsColumnVisible && `theme.breakpoints.${actionsColumnVisible}` }, restActionsColumnConfig), { headerInfoTooltip: restActionsColumnConfig.headerInfoTooltip
763
+ ? (0, intl_1.generateFormattedMessage)({
764
+ config: restActionsColumnConfig.headerInfoTooltip,
765
+ id: `${instanceGqlType}.actions`,
766
+ type: "intlCall",
767
+ })
768
+ : undefined, disableExport: config.excelExport ? "true" : undefined, renderCell: `(params) => {
722
769
  return (
723
770
  <>
724
771
  ${(actionsColumnComponent === null || actionsColumnComponent === void 0 ? void 0 : actionsColumnComponent.name) ? `<${actionsColumnComponent.name} {...params} />` : ""}${allowEditing
@@ -742,6 +789,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
742
789
  `
743
790
  : ""}
744
791
  refetchQueries={[${instanceGqlTypePlural}Query]}
792
+ ${((_h = config.crudContextMenu) === null || _h === void 0 ? void 0 : _h.deleteText) ? `messagesMapping={{ delete: <FormattedMessage id="${instanceGqlType}.crudContextMenu.delete" defaultMessage="${config.crudContextMenu.deleteText}" /> }}` : ""}
745
793
  />
746
794
  `
747
795
  : ""}
@@ -783,7 +831,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
783
831
  });
784
832
  const rowCount = useBufferedRowCount(data?.${gridQuery}.totalCount);
785
833
  if (error) throw error;
786
- const rows = ${!allowRowReordering ? `data?.${gridQuery}.nodes` : generateRowReorderingRows(gridQuery, fieldList, (_h = config.rowReordering) === null || _h === void 0 ? void 0 : _h.dragPreviewField)} ?? [];
834
+ const rows = ${!allowRowReordering ? `data?.${gridQuery}.nodes` : generateRowReorderingRows(gridQuery, fieldList, (_j = config.rowReordering) === null || _j === void 0 ? void 0 : _j.dragPreviewField)} ?? [];
787
835
 
788
836
  ${generateGridExportApi(config.excelExport, gqlTypePlural, instanceGqlTypePlural, gridQuery, gqlArgs)}
789
837
 
@@ -1,3 +1,4 @@
1
+ import { type FormattedMessageElement } from "../generate-command";
1
2
  type Options = {
2
3
  componentName: string;
3
4
  forwardToolbarAction: boolean | undefined;
@@ -7,7 +8,7 @@ type Options = {
7
8
  allowAdding: boolean;
8
9
  instanceGqlType: string;
9
10
  gqlType: string;
10
- newEntryText: string | undefined;
11
+ newEntryText: string | FormattedMessageElement | undefined;
11
12
  fragmentName: string;
12
13
  };
13
14
  export declare const generateGridToolbar: ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }: Options) => string;
@@ -14,7 +14,12 @@ const generateGridToolbar = ({ componentName, forwardToolbarAction, hasSearch, h
14
14
  <FillSpace />
15
15
  ${renderToolbarActions({
16
16
  forwardToolbarAction,
17
- addItemText: (0, intl_1.getFormattedMessageNode)(`${instanceGqlType}.${(0, change_case_1.camelCase)(fragmentName)}.newEntry`, newEntryText !== null && newEntryText !== void 0 ? newEntryText : `New ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(gqlType)}`),
17
+ addItemText: (0, intl_1.generateFormattedMessage)({
18
+ config: newEntryText,
19
+ id: `${instanceGqlType}.${(0, change_case_1.camelCase)(fragmentName)}.newEntry`,
20
+ defaultMessage: `New ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(gqlType)}`,
21
+ type: "jsx",
22
+ }),
18
23
  excelExport,
19
24
  allowAdding,
20
25
  })}
@@ -1 +1,17 @@
1
- export declare const getFormattedMessageNode: (id: string, defaultMessage?: string, values?: string) => string;
1
+ import { type FormattedMessageElement } from "../generate-command";
2
+ type GenerateFormattedMessageOptions = ({
3
+ config: string | FormattedMessageElement | undefined;
4
+ defaultMessage: string;
5
+ } | {
6
+ config: string | FormattedMessageElement;
7
+ }) & {
8
+ id: string;
9
+ type: "jsx" | "intlCall";
10
+ };
11
+ /**
12
+ * Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
13
+ *
14
+ * either config or defaultMessage is required
15
+ */
16
+ export declare const generateFormattedMessage: (options: GenerateFormattedMessageOptions) => string;
17
+ export {};
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFormattedMessageNode = void 0;
4
- const getFormattedMessageNode = (id, defaultMessage = "", values) => {
5
- return `<FormattedMessage id="${id}" defaultMessage={\`${defaultMessage}\`} ${values ? `values={${values}}` : ""} />`;
3
+ exports.generateFormattedMessage = void 0;
4
+ const runtimeTypeGuards_1 = require("./runtimeTypeGuards");
5
+ /**
6
+ * Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
7
+ *
8
+ * either config or defaultMessage is required
9
+ */
10
+ const generateFormattedMessage = (options) => {
11
+ let id = options.id;
12
+ let defaultMessage = "";
13
+ if ("defaultMessage" in options) {
14
+ defaultMessage = options.defaultMessage;
15
+ }
16
+ if ((0, runtimeTypeGuards_1.isGeneratorConfigFormattedMessage)(options.config)) {
17
+ id = options.config.formattedMessageId;
18
+ defaultMessage = options.config.defaultMessage;
19
+ }
20
+ else if (typeof options.config === "string") {
21
+ defaultMessage = options.config;
22
+ }
23
+ if (options.type === "jsx") {
24
+ return `<FormattedMessage id=${JSON.stringify(id)} defaultMessage=${JSON.stringify(defaultMessage)} />`;
25
+ }
26
+ else {
27
+ return `intl.formatMessage({ id: ${JSON.stringify(id)}, defaultMessage: ${JSON.stringify(defaultMessage)} })`;
28
+ }
6
29
  };
7
- exports.getFormattedMessageNode = getFormattedMessageNode;
30
+ exports.generateFormattedMessage = generateFormattedMessage;
@@ -17,4 +17,12 @@ type GeneratorConfigCode = {
17
17
  * Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
18
18
  */
19
19
  export declare function isGeneratorConfigCode(value: unknown): value is GeneratorConfigCode;
20
+ type GeneratorConfigFormattedMessage = {
21
+ formattedMessageId: string;
22
+ defaultMessage: string;
23
+ };
24
+ /**
25
+ * Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
26
+ */
27
+ export declare function isGeneratorConfigFormattedMessage(value: unknown): value is GeneratorConfigFormattedMessage;
20
28
  export {};
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isGeneratorConfigImport = isGeneratorConfigImport;
4
4
  exports.isGeneratorConfigCode = isGeneratorConfigCode;
5
+ exports.isGeneratorConfigFormattedMessage = isGeneratorConfigFormattedMessage;
5
6
  /**
6
7
  * Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
7
8
  */
@@ -20,3 +21,12 @@ function isGeneratorConfigCode(value) {
20
21
  }
21
22
  return false;
22
23
  }
24
+ /**
25
+ * Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
26
+ */
27
+ function isGeneratorConfigFormattedMessage(value) {
28
+ if (value && typeof value === "object" && "formattedMessageId" in value) {
29
+ return true;
30
+ }
31
+ return false;
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/admin-generator",
3
- "version": "9.0.0-canary-20251211112608",
3
+ "version": "9.0.0-canary-20251222112948",
4
4
  "description": "Comet Admin Generator CLI tool",
5
5
  "repository": {
6
6
  "directory": "packages/admin/admin-generator",
@@ -37,7 +37,7 @@
37
37
  "@types/node": "^24.9.1",
38
38
  "@types/object-path": "^0.11.4",
39
39
  "@types/pluralize": "^0.0.33",
40
- "@types/react": "^18.3.23",
40
+ "@types/react": "^18.3.27",
41
41
  "@types/react-dom": "^18.3.7",
42
42
  "eslint": "^9.30.1",
43
43
  "final-form": "^4.20.10",
@@ -50,10 +50,10 @@
50
50
  "rimraf": "^6.1.2",
51
51
  "ts-jest": "^29.4.0",
52
52
  "typescript": "5.9.3",
53
- "@comet/admin": "9.0.0-canary-20251211112608",
54
- "@comet/admin-icons": "9.0.0-canary-20251211112608",
55
- "@comet/cms-admin": "9.0.0-canary-20251211112608",
56
- "@comet/eslint-config": "9.0.0-canary-20251211112608"
53
+ "@comet/admin": "9.0.0-canary-20251222112948",
54
+ "@comet/admin-icons": "9.0.0-canary-20251222112948",
55
+ "@comet/cms-admin": "9.0.0-canary-20251222112948",
56
+ "@comet/eslint-config": "9.0.0-canary-20251222112948"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22.0.0"