@dataverse-kit/export-engine 1.3.0 → 1.5.0

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.
Files changed (3) hide show
  1. package/dist/index.cjs +334 -42
  2. package/dist/index.mjs +334 -42
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -12810,6 +12810,7 @@ function buildV8Body(args) {
12810
12810
  handlerBlock = "",
12811
12811
  rowCommandsLiteral = "",
12812
12812
  deleteDialogJsx = "",
12813
+ createDialogJsx = "",
12813
12814
  commandBarBlock = "",
12814
12815
  selectionModeAttr = "",
12815
12816
  onSelectionChangedAttr = ""
@@ -12836,7 +12837,7 @@ const ${componentName}: React.FC<{ items: Record<string, unknown>[] }> = ({ item
12836
12837
  editable
12837
12838
  editTrigger="click"
12838
12839
  getKey={(it) => String((it as { __rowIndex?: number }).__rowIndex ?? '')}${selectionModeAttr}${onSelectionChangedAttr}${onValueChangeAttr}${rowCommandsAttr}
12839
- />${editableAggregate}${editablePagination}${saveStatusJsx}${deleteDialogJsx}
12840
+ />${editableAggregate}${editablePagination}${saveStatusJsx}${deleteDialogJsx}${createDialogJsx}
12840
12841
  </div>
12841
12842
  );
12842
12843
  };`;
@@ -12889,6 +12890,7 @@ function buildLiveReadOnlyV8Body(args) {
12889
12890
  handlerBlock = "",
12890
12891
  rowCommandsLiteral = "",
12891
12892
  deleteDialogJsx = "",
12893
+ createDialogJsx = "",
12892
12894
  commandBarBlock = ""
12893
12895
  } = args;
12894
12896
  const rowCommandsAttr = rowCommandsLiteral ? `
@@ -12917,7 +12919,7 @@ const ${helperName}: React.FC = () => {
12917
12919
  ] as ColumnDef[]}
12918
12920
  registry={registry}
12919
12921
  getKey={(it) => String((it as { __rowIndex?: number }).__rowIndex ?? '')}${rowCommandsAttr}
12920
- />${flatAggregateInner}${flatPaginationInner}${deleteDialogJsx}
12922
+ />${flatAggregateInner}${flatPaginationInner}${deleteDialogJsx}${createDialogJsx}
12921
12923
  </div>
12922
12924
  );
12923
12925
  };`;
@@ -12963,6 +12965,7 @@ function buildCardV8LiveBody(args) {
12963
12965
  handlerBlock = "",
12964
12966
  rowCommandsLiteral = "",
12965
12967
  deleteDialogJsx = "",
12968
+ createDialogJsx = "",
12966
12969
  commandBarBlock = "",
12967
12970
  selectionModeAttr = "",
12968
12971
  onSelectionChangedAttr = ""
@@ -12994,7 +12997,7 @@ const ${helperName}: React.FC = () => {
12994
12997
  registry={registry}
12995
12998
  getKey={(it) => String((it as { __rowIndex?: number }).__rowIndex ?? '')}${selectionModeAttr}${onSelectionChangedAttr}
12996
12999
  card={{ ${cardConfigLiteral} }}${rowCommandsAttr}
12997
- />${flatAggregateInner}${flatPaginationInner}${deleteDialogJsx}
13000
+ />${flatAggregateInner}${flatPaginationInner}${deleteDialogJsx}${createDialogJsx}
12998
13001
  </div>
12999
13002
  );
13000
13003
  };`;
@@ -13320,6 +13323,7 @@ function buildNestedSubgridBody(args) {
13320
13323
  commandBarBlock,
13321
13324
  handlerBlock,
13322
13325
  deleteDialogJsx,
13326
+ createDialogJsx,
13323
13327
  hasSelection,
13324
13328
  hasHandler,
13325
13329
  dataverseHooks,
@@ -13375,7 +13379,7 @@ const ${componentName}: React.FC<{ items: Record<string, unknown>[] }> = ({ item
13375
13379
  calloutMaxRows: ${calloutMaxRows},
13376
13380
  hoverDelay: ${hoverDelay},${childEditableLiteral}
13377
13381
  }}
13378
- />${deleteDialogJsx}${childSaveStatusJsx}
13382
+ />${deleteDialogJsx}${createDialogJsx}${childSaveStatusJsx}
13379
13383
  </div>
13380
13384
  );
13381
13385
  };`;
@@ -13418,6 +13422,7 @@ function buildFocusedViewSubgridBody(args) {
13418
13422
  commandBarBlock,
13419
13423
  handlerBlock,
13420
13424
  deleteDialogJsx,
13425
+ createDialogJsx,
13421
13426
  hasSelection,
13422
13427
  hasHandler,
13423
13428
  dataverseHooks,
@@ -13471,7 +13476,7 @@ const ${componentName}: React.FC<{ items: Record<string, unknown>[] }> = ({ item
13471
13476
  childSelectionMode: ${JSON.stringify(childSelectionMode)},
13472
13477
  childSelectionGating: ${JSON.stringify(childSelectionGating)},${childEditableLiteral}
13473
13478
  }}
13474
- />${deleteDialogJsx}${childSaveStatusJsx}
13479
+ />${deleteDialogJsx}${createDialogJsx}${childSaveStatusJsx}
13475
13480
  </div>
13476
13481
  );
13477
13482
  };`;
@@ -14250,14 +14255,182 @@ function effectiveMinSelection(item) {
14250
14255
  if (typeof item.minSelectionCount === "number") return item.minSelectionCount;
14251
14256
  return DEFAULT_MIN_SEL_BY_ACTION[item.actionType ?? "custom"] ?? 0;
14252
14257
  }
14258
+ function buildExportColumnsLiteral(cols) {
14259
+ return cols.map(
14260
+ (c) => `{ key: ${JSON.stringify(c.fieldName)}, name: ${JSON.stringify(c.displayName ?? c.fieldName)} }`
14261
+ ).join(", ");
14262
+ }
14263
+ var CREATE_FIELD_DENYLIST = /* @__PURE__ */ new Set([
14264
+ "createdon",
14265
+ "createdby",
14266
+ "createdonbehalfby",
14267
+ "modifiedon",
14268
+ "modifiedby",
14269
+ "modifiedonbehalfby",
14270
+ "owningbusinessunit",
14271
+ "owningteam",
14272
+ "owninguser",
14273
+ "ownerid",
14274
+ "versionnumber",
14275
+ "overriddencreatedon",
14276
+ "importsequencenumber",
14277
+ "timezoneruleversionnumber",
14278
+ "utcconversiontimezonecode",
14279
+ "statecode",
14280
+ "statuscode"
14281
+ ]);
14282
+ function buildCreateFields(cols, primaryIdAttribute) {
14283
+ const primaryLower = (primaryIdAttribute ?? "").toLowerCase();
14284
+ const entries = [];
14285
+ for (const c of cols) {
14286
+ if (!c.fieldName) continue;
14287
+ const logical = (c.attributeLogicalName ?? c.fieldName).toLowerCase();
14288
+ if (logical === primaryLower) continue;
14289
+ if (c.isLocked) continue;
14290
+ if (c.dataType === "lookup" || c.dataType === "image") continue;
14291
+ if (CREATE_FIELD_DENYLIST.has(logical)) continue;
14292
+ const label = c.displayName ?? c.fieldName;
14293
+ let kind = "text";
14294
+ let inputType;
14295
+ let optionsLit = "";
14296
+ switch (c.dataType) {
14297
+ case "numeric":
14298
+ case "currency":
14299
+ kind = "number";
14300
+ inputType = "number";
14301
+ break;
14302
+ case "boolean":
14303
+ kind = "boolean";
14304
+ break;
14305
+ case "date":
14306
+ kind = "date";
14307
+ inputType = "date";
14308
+ break;
14309
+ case "datetime":
14310
+ kind = "date";
14311
+ inputType = "datetime-local";
14312
+ break;
14313
+ case "optionset": {
14314
+ const opts = c.rendererConfig?.options ?? [];
14315
+ if (opts.length === 0) {
14316
+ kind = "number";
14317
+ inputType = "number";
14318
+ } else {
14319
+ kind = "optionset";
14320
+ optionsLit = opts.map(
14321
+ (o) => `{ key: ${JSON.stringify(o.value)}, text: ${JSON.stringify(o.label)} }`
14322
+ ).join(", ");
14323
+ }
14324
+ break;
14325
+ }
14326
+ case "email":
14327
+ kind = "text";
14328
+ inputType = "email";
14329
+ break;
14330
+ case "phone":
14331
+ kind = "text";
14332
+ inputType = "tel";
14333
+ break;
14334
+ case "url":
14335
+ kind = "text";
14336
+ inputType = "url";
14337
+ break;
14338
+ default:
14339
+ kind = "text";
14340
+ break;
14341
+ }
14342
+ const payloadKey = c.attributeLogicalName ?? c.fieldName;
14343
+ const parts = [
14344
+ `key: ${JSON.stringify(payloadKey)}`,
14345
+ `label: ${JSON.stringify(label)}`,
14346
+ `kind: ${JSON.stringify(kind)}`
14347
+ ];
14348
+ if (inputType) parts.push(`inputType: ${JSON.stringify(inputType)}`);
14349
+ if (kind === "optionset") parts.push(`options: [${optionsLit}]`);
14350
+ entries.push(`{ ${parts.join(", ")} }`);
14351
+ }
14352
+ return entries.join(", ");
14353
+ }
14253
14354
  function buildGridCommandHandlerBlock(args) {
14254
14355
  const {
14255
14356
  entityName,
14256
14357
  entitySetName,
14257
14358
  primaryIdAttribute,
14258
14359
  itemsExpr,
14259
- selectionExpr
14360
+ selectionExpr,
14361
+ exportColumnsLiteral,
14362
+ createColumnsLiteral
14260
14363
  } = args;
14364
+ const exportCase = exportColumnsLiteral ? `{
14365
+ const exportColumns = [${exportColumnsLiteral}];
14366
+ const rowsToExport = (indices.length ? indices.map((i) => items[i]) : items.slice())
14367
+ .filter((r): r is Record<string, unknown> => Boolean(r))
14368
+ .map((r) => {
14369
+ const formattedRow: Record<string, unknown> = {};
14370
+ for (const col of exportColumns) {
14371
+ formattedRow[col.key] = r[col.key + '@OData.Community.Display.V1.FormattedValue'] ?? r[col.key];
14372
+ }
14373
+ return formattedRow;
14374
+ });
14375
+ exportToFile(rowsToExport, exportColumns, 'csv', generateDefaultFilename(${JSON.stringify(entityName + "-export")}));
14376
+ return;
14377
+ }` : `{
14378
+ console.warn('[grid] Export to Excel is not yet wired in generated forms.');
14379
+ return;
14380
+ }`;
14381
+ const createStateBlock = createColumnsLiteral ? `
14382
+ const gridCreateMutation = useCreateRecord<Record<string, unknown>>('${entitySetName}');
14383
+ const [pendingCreate, setPendingCreate] = React.useState(false);
14384
+ const [createValues, setCreateValues] = React.useState<Record<string, unknown>>({});
14385
+ const [createError, setCreateError] = React.useState<string | null>(null);
14386
+ // Derived from the grid's columns; lookups/images/system fields are excluded by
14387
+ // the emitter. The payload is best-effort and validated server-side (errors show
14388
+ // in \`createError\`). NOTE: against a mock/standalone host (no Dataverse token),
14389
+ // MockApiService.createRecord no-ops and resolves \u2014 the dialog closes as if it
14390
+ // succeeded but nothing is created. Xrm is the primary path in a model-driven host.
14391
+ const createFields = React.useMemo<Array<{ key: string; label: string; kind: 'text' | 'number' | 'boolean' | 'optionset' | 'date'; inputType?: string; options?: Array<{ key: number; text: string }> }>>(
14392
+ () => [${createColumnsLiteral}],
14393
+ [],
14394
+ );
14395
+ const submitCreate = React.useCallback(async () => {
14396
+ setCreateError(null);
14397
+ const payload: Record<string, unknown> = {};
14398
+ for (const f of createFields) {
14399
+ const raw = createValues[f.key];
14400
+ if (raw === undefined || raw === null || raw === '') continue;
14401
+ payload[f.key] = (f.kind === 'number' || f.kind === 'optionset') ? Number(raw) : raw;
14402
+ }
14403
+ if (Object.keys(payload).length === 0) {
14404
+ setCreateError('Enter at least one value before creating.');
14405
+ return;
14406
+ }
14407
+ try {
14408
+ await gridCreateMutation.mutateAsync(payload);
14409
+ setPendingCreate(false);
14410
+ setCreateValues({});
14411
+ } catch (err) {
14412
+ setCreateError((err as Error)?.message ?? 'Create failed.');
14413
+ }
14414
+ }, [createValues, gridCreateMutation, createFields]);` : "";
14415
+ const newCase = createColumnsLiteral ? `{
14416
+ if (xrm?.Navigation?.openForm) {
14417
+ await xrm.Navigation.openForm({ entityName: '${entityName}', useQuickCreateForm: false });
14418
+ await refreshGrid();
14419
+ } else {
14420
+ setCreateError(null);
14421
+ setCreateValues({});
14422
+ setPendingCreate(true);
14423
+ }
14424
+ return;
14425
+ }` : `{
14426
+ if (xrm?.Navigation?.openForm) {
14427
+ await xrm.Navigation.openForm({ entityName: '${entityName}', useQuickCreateForm: false });
14428
+ await refreshGrid();
14429
+ } else {
14430
+ console.warn('[grid] New action requires Xrm.Navigation.openForm; not available in this host.');
14431
+ }
14432
+ return;
14433
+ }`;
14261
14434
  return `
14262
14435
  const queryClient = useQueryClient();
14263
14436
  const gridUpdateMutation = useUpdateRecord<Record<string, unknown>>('${entitySetName}');
@@ -14281,7 +14454,7 @@ function buildGridCommandHandlerBlock(args) {
14281
14454
  } catch (err) {
14282
14455
  setDeleteError((err as Error)?.message ?? 'Delete failed.');
14283
14456
  }
14284
- }, [pendingDelete, gridDeleteMutation]);
14457
+ }, [pendingDelete, gridDeleteMutation]);${createStateBlock}
14285
14458
  const handleGridCommand = React.useCallback(async (actionType: string, overrideRowIndex?: number) => {
14286
14459
  const xrm = (typeof window !== 'undefined' ? (window as unknown as { Xrm?: any }).Xrm : undefined);
14287
14460
  const items = ${itemsExpr} as ReadonlyArray<Record<string, unknown>>;
@@ -14306,15 +14479,7 @@ function buildGridCommandHandlerBlock(args) {
14306
14479
  return true;
14307
14480
  };
14308
14481
  switch (actionType) {
14309
- case 'new': {
14310
- if (xrm?.Navigation?.openForm) {
14311
- await xrm.Navigation.openForm({ entityName: '${entityName}', useQuickCreateForm: false });
14312
- await refreshGrid();
14313
- } else {
14314
- console.warn('[grid] New action requires Xrm.Navigation.openForm; not available in this host.');
14315
- }
14316
- return;
14317
- }
14482
+ case 'new': ${newCase}
14318
14483
  case 'addExisting': {
14319
14484
  if (xrm?.Navigation?.openForm) {
14320
14485
  await xrm.Navigation.openForm({ entityName: '${entityName}' });
@@ -14359,10 +14524,7 @@ function buildGridCommandHandlerBlock(args) {
14359
14524
  await refreshGrid();
14360
14525
  return;
14361
14526
  }
14362
- case 'export': {
14363
- console.warn('[grid] Export to Excel is not yet wired in generated forms.');
14364
- return;
14365
- }
14527
+ case 'export': ${exportCase}
14366
14528
  case 'bulkEdit': {
14367
14529
  if (!requireSel('bulk edit')) return;
14368
14530
  if (xrm?.Navigation?.openBulkEditForm) {
@@ -14379,7 +14541,7 @@ function buildGridCommandHandlerBlock(args) {
14379
14541
  }, [${itemsExpr}, ${selectionExpr}, gridUpdateMutation, refreshGrid]);`;
14380
14542
  }
14381
14543
  function buildRowCommandsLiteral(contextMenuItems) {
14382
- return contextMenuItems.filter((ci) => (ci.actionType ?? "custom") !== "custom").map(
14544
+ return contextMenuItems.filter((ci) => (ci.actionType ?? "custom") !== "custom").filter((ci) => ci.actionType !== "new").map(
14383
14545
  (ci) => `{ key: ${JSON.stringify(ci.id)}, text: ${JSON.stringify(ci.text)}` + (ci.iconName ? `, iconName: ${JSON.stringify(ci.iconName)}` : "") + `, onClick: (item: Record<string, unknown>) => { void handleGridCommand(${JSON.stringify(ci.actionType)}, (item as { __rowIndex?: number }).__rowIndex); } }`
14384
14546
  ).join(",\n ");
14385
14547
  }
@@ -14415,6 +14577,68 @@ function buildGridDeleteDialogJsx(entityName) {
14415
14577
  </DialogFooter>
14416
14578
  </Dialog>`;
14417
14579
  }
14580
+ function buildGridCreateDialogJsx(entityName) {
14581
+ return `
14582
+ <Dialog
14583
+ hidden={!pendingCreate}
14584
+ onDismiss={() => { if (!gridCreateMutation.isPending) setPendingCreate(false); }}
14585
+ dialogContentProps={{
14586
+ type: DialogType.normal,
14587
+ title: ${JSON.stringify("Create " + entityName)},
14588
+ }}
14589
+ modalProps={{ isBlocking: true }}
14590
+ >
14591
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
14592
+ {createFields.map((f) => {
14593
+ if (f.kind === 'boolean') {
14594
+ return (
14595
+ <Checkbox
14596
+ key={f.key}
14597
+ label={f.label}
14598
+ checked={createValues[f.key] === true}
14599
+ onChange={(_ev, checked) => setCreateValues((prev) => ({ ...prev, [f.key]: !!checked }))}
14600
+ />
14601
+ );
14602
+ }
14603
+ if (f.kind === 'optionset') {
14604
+ return (
14605
+ <Dropdown
14606
+ key={f.key}
14607
+ label={f.label}
14608
+ options={f.options ?? []}
14609
+ selectedKey={(createValues[f.key] as number | undefined) ?? null}
14610
+ onChange={(_ev, opt) => setCreateValues((prev) => ({ ...prev, [f.key]: opt?.key }))}
14611
+ />
14612
+ );
14613
+ }
14614
+ return (
14615
+ <TextField
14616
+ key={f.key}
14617
+ label={f.label}
14618
+ type={f.inputType ?? 'text'}
14619
+ value={createValues[f.key] == null ? '' : String(createValues[f.key])}
14620
+ onChange={(_ev, val) => setCreateValues((prev) => ({ ...prev, [f.key]: val }))}
14621
+ />
14622
+ );
14623
+ })}
14624
+ </div>
14625
+ {createError && (
14626
+ <div style={{ color: '#a4262c', fontSize: 12, marginTop: 8 }}>{createError}</div>
14627
+ )}
14628
+ <DialogFooter>
14629
+ <PrimaryButton
14630
+ onClick={submitCreate}
14631
+ text={gridCreateMutation.isPending ? 'Creating\u2026' : 'Create'}
14632
+ disabled={gridCreateMutation.isPending}
14633
+ />
14634
+ <DefaultButton
14635
+ onClick={() => setPendingCreate(false)}
14636
+ text="Cancel"
14637
+ disabled={gridCreateMutation.isPending}
14638
+ />
14639
+ </DialogFooter>
14640
+ </Dialog>`;
14641
+ }
14418
14642
  function buildV9RenderCell(col) {
14419
14643
  const safeFieldName = JSON.stringify(col.fieldName);
14420
14644
  switch (col.rendererType) {
@@ -14792,6 +15016,8 @@ function generateLinkedSubgrid(gridDef, entityName, imports, library = "fluent-v
14792
15016
  // need the dispatcher in scope even when no wired commandBarItems exist.
14793
15017
  !!gridDef.toolbar?.showRefresh)
14794
15018
  );
15019
+ const enableExport = _handlerAvailable && (showExport || barItems.some((ci) => ci.actionType === "export") || contextMenuItems.some((ci) => ci.actionType === "export"));
15020
+ const enableCreate = _handlerAvailable && barItems.some((ci) => ci.actionType === "new");
14795
15021
  if (gridDef.showCommandBar && (barItems.length > 0 || showSearch || hasToolbarIcons)) {
14796
15022
  if (showSearch) imports.add("SearchBox");
14797
15023
  imports.add("DefaultButton");
@@ -14843,10 +15069,12 @@ function generateLinkedSubgrid(gridDef, entityName, imports, library = "fluent-v
14843
15069
  toolbarIcons.push(
14844
15070
  `<IconButton iconProps={{ iconName: 'ColumnOptions' }} title="Column chooser" ariaLabel="Column chooser" />`
14845
15071
  );
14846
- if (showExport)
15072
+ if (showExport) {
15073
+ const exportOnClick = _handlerAvailable ? ` onClick={() => { void handleGridCommand('export'); }}` : "";
14847
15074
  toolbarIcons.push(
14848
- `<IconButton iconProps={{ iconName: 'Download' }} title="Export" ariaLabel="Export" />`
15075
+ `<IconButton iconProps={{ iconName: 'Download' }} title="Export" ariaLabel="Export"${exportOnClick} />`
14849
15076
  );
15077
+ }
14850
15078
  if (showRefresh) {
14851
15079
  const refreshOnClick = _handlerAvailable ? ` onClick={() => { void handleGridCommand('refresh'); }}` : "";
14852
15080
  toolbarIcons.push(
@@ -14870,6 +15098,9 @@ function generateLinkedSubgrid(gridDef, entityName, imports, library = "fluent-v
14870
15098
  const childGridDef = gridDef.nestedGridId ? _currentGridCustomizers.find((g) => g.id === gridDef.nestedGridId) : void 0;
14871
15099
  const isGridKitNested = !!childGridDef;
14872
15100
  const visibleCols = [...gridDef.columns].filter((c) => c.isVisible).sort((a, b) => a.order - b.order);
15101
+ const exportColumnsLiteral = enableExport ? buildExportColumnsLiteral(visibleCols) : "";
15102
+ const primaryIdAttr = resolvePrimaryIdAttribute(gridDef);
15103
+ const createColumnsLiteral = enableCreate ? buildCreateFields(visibleCols, primaryIdAttr) : "";
14873
15104
  visibleCols.filter((c) => c.rendererType !== "text");
14874
15105
  const colEntries = isGridKitNested ? "" : generateColumnEntries(visibleCols, library);
14875
15106
  const selectionMode = gridDef.selectionMode === "multiple" ? "SelectionMode.multiple" : gridDef.selectionMode === "single" ? "SelectionMode.single" : "SelectionMode.none";
@@ -14935,19 +15166,27 @@ ${childEntries.join(",\n")},
14935
15166
  entitySetName: gridDef.dataSource.entitySetName,
14936
15167
  primaryIdAttribute: resolvePrimaryIdAttribute(gridDef),
14937
15168
  itemsExpr: "keyedItems",
14938
- selectionExpr: "selectedIndices"
15169
+ selectionExpr: "selectedIndices",
15170
+ exportColumnsLiteral,
15171
+ createColumnsLiteral
14939
15172
  }) : "";
14940
15173
  const ngHasDelete = (gridDef.commandBarItems ?? []).some(
14941
15174
  (ci) => ci.actionType === "delete"
14942
15175
  );
14943
15176
  const ngDeleteDialogJsx = ngHasDelete && ngHandlerBlock !== "" ? buildGridDeleteDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
14944
- if (ngDeleteDialogJsx) {
15177
+ const ngCreateDialogJsx = ngHandlerBlock !== "" && createColumnsLiteral ? buildGridCreateDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15178
+ if (ngDeleteDialogJsx || ngCreateDialogJsx) {
14945
15179
  imports.add("Dialog");
14946
15180
  imports.add("DialogType");
14947
15181
  imports.add("DialogFooter");
14948
15182
  imports.add("PrimaryButton");
14949
15183
  imports.add("DefaultButton");
14950
15184
  }
15185
+ if (ngCreateDialogJsx) {
15186
+ imports.add("TextField");
15187
+ imports.add("Dropdown");
15188
+ imports.add("Checkbox");
15189
+ }
14951
15190
  const ngRowCommandsLiteral = _handlerAvailable && (ngHasCommandBar || ngHasContextMenu && useLiveNested) ? buildRowCommandsLiteral(contextMenuItems) : "";
14952
15191
  const ngToolbarWired = (gridDef.commandBarItems ?? []).some(
14953
15192
  (ci) => (ci.actionType ?? "custom") !== "custom"
@@ -14961,9 +15200,18 @@ ${childEntries.join(",\n")},
14961
15200
  const ngDataverseHooks = [
14962
15201
  ...useLiveNested ? ["useDataverseQuery"] : [],
14963
15202
  ...useLiveNested && ngNeedsUpdate || ngHasHandler ? ["useUpdateRecord"] : [],
14964
- ...useLiveNested && ngNeedsDelete || ngHasHandler ? ["useDeleteRecord"] : []
15203
+ ...useLiveNested && ngNeedsDelete || ngHasHandler ? ["useDeleteRecord"] : [],
15204
+ // Create mutation only when the create dialog is wired (the `new` case's
15205
+ // non-Xrm fallback) — gated like the export util import to stay byte-stable
15206
+ // for non-create handler grids.
15207
+ ...ngHasHandler && createColumnsLiteral ? ["useCreateRecord"] : []
15208
+ ];
15209
+ const ngCommandBarImports = [
15210
+ ...useLiveNested && ngNeedsDelete || ngHasHandler ? [`import { useQueryClient } from '@tanstack/react-query';`] : [],
15211
+ // Export case (shared dispatcher → both nested + focused-view) calls
15212
+ // exportToFile/generateDefaultFilename when export is wired.
15213
+ ...ngHasHandler && enableExport ? [`import { exportToFile, generateDefaultFilename } from '../lib/grid-kit/utils';`] : []
14965
15214
  ];
14966
- const ngCommandBarImports = useLiveNested && ngNeedsDelete || ngHasHandler ? [`import { useQueryClient } from '@tanstack/react-query';`] : [];
14967
15215
  const ngParentSelectionMode = ngHasCommandBar ? gridDef.selectionMode === "single" ? "single" : "multiple" : gridDef.selectionMode ?? "none";
14968
15216
  const ngChildSaveBack = Boolean(
14969
15217
  useLiveNested && live && (childGridDef.isEditable ?? false)
@@ -15012,6 +15260,7 @@ ${childEntries.join(",\n")},
15012
15260
  commandBarBlock: gridCommandBarBlock,
15013
15261
  handlerBlock: ngHandlerBlock,
15014
15262
  deleteDialogJsx: ngDeleteDialogJsx,
15263
+ createDialogJsx: ngCreateDialogJsx,
15015
15264
  hasSelection: ngHasCommandBar,
15016
15265
  hasHandler: ngHandlerBlock !== "",
15017
15266
  dataverseHooks: ngDataverseHooks,
@@ -15067,6 +15316,7 @@ ${childEntries.join(",\n")},
15067
15316
  commandBarBlock: gridCommandBarBlock,
15068
15317
  handlerBlock: ngHandlerBlock,
15069
15318
  deleteDialogJsx: ngDeleteDialogJsx,
15319
+ createDialogJsx: ngCreateDialogJsx,
15070
15320
  hasSelection: ngHasCommandBar,
15071
15321
  dataverseHooks: ngDataverseHooks,
15072
15322
  commandBarImports: ngCommandBarImports,
@@ -15147,11 +15397,14 @@ ${childEntries.join(",\n")},
15147
15397
  entitySetName: gridDef.dataSource.entitySetName,
15148
15398
  primaryIdAttribute: resolvePrimaryIdAttribute(gridDef),
15149
15399
  itemsExpr: "rows",
15150
- selectionExpr: "selectedIndices"
15400
+ selectionExpr: "selectedIndices",
15401
+ exportColumnsLiteral,
15402
+ createColumnsLiteral
15151
15403
  }) : "";
15152
15404
  const cardSelectedIndicesState = cardEmitHandler ? "\n const [selectedIndices, setSelectedIndices] = React.useState<Set<number>>(new Set());" : "";
15153
15405
  const cardRowCommandsLiteral = cardEmitRowCommands ? buildRowCommandsLiteral(contextMenuItems) : "";
15154
15406
  const cardDeleteDialogJsx = cardEmitRowCommands && flatHasDelete || cardEmitToolbar && flatBarHasDelete ? buildGridDeleteDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15407
+ const cardCreateDialogJsx = cardEmitHandler && createColumnsLiteral ? buildGridCreateDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15155
15408
  const cardCommandBarBlock = cardEmitToolbar ? gridCommandBarBlock : "";
15156
15409
  const cardSelectionModeAttr = cardEmitToolbar ? flatSelectionModeAttr : "";
15157
15410
  const cardOnSelectionChangedAttr = cardEmitToolbar ? flatOnSelectionChangedAttr : "";
@@ -15170,20 +15423,26 @@ ${childEntries.join(",\n")},
15170
15423
  handlerBlock: cardHandlerBlock,
15171
15424
  rowCommandsLiteral: cardRowCommandsLiteral,
15172
15425
  deleteDialogJsx: cardDeleteDialogJsx,
15426
+ createDialogJsx: cardCreateDialogJsx,
15173
15427
  commandBarBlock: cardCommandBarBlock,
15174
15428
  selectionModeAttr: cardSelectionModeAttr,
15175
15429
  onSelectionChangedAttr: cardOnSelectionChangedAttr
15176
15430
  })
15177
15431
  ];
15178
15432
  _usesGridKit = true;
15179
- const cardDataverseImport = cardEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord } from '../lib/dataverse';` : `import { useDataverseQuery } from '../lib/dataverse';`;
15180
- if (cardDeleteDialogJsx) {
15433
+ const cardDataverseImport = cardEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord${createColumnsLiteral ? ", useCreateRecord" : ""} } from '../lib/dataverse';` : `import { useDataverseQuery } from '../lib/dataverse';`;
15434
+ if (cardDeleteDialogJsx || cardCreateDialogJsx) {
15181
15435
  imports.add("Dialog");
15182
15436
  imports.add("DialogType");
15183
15437
  imports.add("DialogFooter");
15184
15438
  imports.add("PrimaryButton");
15185
15439
  imports.add("DefaultButton");
15186
15440
  }
15441
+ if (cardCreateDialogJsx) {
15442
+ imports.add("TextField");
15443
+ imports.add("Dropdown");
15444
+ imports.add("Checkbox");
15445
+ }
15187
15446
  return {
15188
15447
  imports,
15189
15448
  v9Imports,
@@ -15191,7 +15450,10 @@ ${childEntries.join(",\n")},
15191
15450
  extraImports: cardIsLive ? cardEmitHandler ? [
15192
15451
  cardDataverseImport,
15193
15452
  `import { useQueryClient } from '@tanstack/react-query';`,
15194
- `import { CardGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
15453
+ `import { CardGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`,
15454
+ // Export case calls exportToFile/generateDefaultFilename (cardEmitHandler
15455
+ // here; the export case is only real when enableExport).
15456
+ ...enableExport ? [`import { exportToFile, generateDefaultFilename } from '../lib/grid-kit/utils';`] : []
15195
15457
  ] : [
15196
15458
  `import { useDataverseQuery } from '../lib/dataverse';`,
15197
15459
  `import { CardGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
@@ -15229,11 +15491,14 @@ ${childEntries.join(",\n")},
15229
15491
  entitySetName: gridDef.dataSource.entitySetName,
15230
15492
  primaryIdAttribute: resolvePrimaryIdAttribute(gridDef),
15231
15493
  itemsExpr: "rows",
15232
- selectionExpr: "selectedIndices"
15494
+ selectionExpr: "selectedIndices",
15495
+ exportColumnsLiteral,
15496
+ createColumnsLiteral
15233
15497
  }) : "";
15234
15498
  const roSelectedIndicesState = roEmitHandler ? "\n const [selectedIndices, setSelectedIndices] = React.useState<Set<number>>(new Set());" : "";
15235
15499
  const roRowCommandsLiteral = roEmitRowCommands ? buildRowCommandsLiteral(contextMenuItems) : "";
15236
15500
  const roDeleteDialogJsx = roEmitRowCommands && flatHasDelete ? buildGridDeleteDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15501
+ const roCreateDialogJsx = roEmitHandler && createColumnsLiteral ? buildGridCreateDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15237
15502
  const roCommandBarBlock = roEmitToolbar ? gridCommandBarBlock : "";
15238
15503
  const helperComponents = [
15239
15504
  buildLiveReadOnlySubgridBody({
@@ -15252,18 +15517,24 @@ ${childEntries.join(",\n")},
15252
15517
  handlerBlock: roHandlerBlock,
15253
15518
  rowCommandsLiteral: roRowCommandsLiteral,
15254
15519
  deleteDialogJsx: roDeleteDialogJsx,
15520
+ createDialogJsx: roCreateDialogJsx,
15255
15521
  commandBarBlock: roCommandBarBlock
15256
15522
  })
15257
15523
  ];
15258
15524
  if (!isV9) _usesGridKit = true;
15259
- const roDataverseImport = roEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord } from '../lib/dataverse';` : `import { useDataverseQuery } from '../lib/dataverse';`;
15260
- if (roDeleteDialogJsx) {
15525
+ const roDataverseImport = roEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord${createColumnsLiteral ? ", useCreateRecord" : ""} } from '../lib/dataverse';` : `import { useDataverseQuery } from '../lib/dataverse';`;
15526
+ if (roDeleteDialogJsx || roCreateDialogJsx) {
15261
15527
  imports.add("Dialog");
15262
15528
  imports.add("DialogType");
15263
15529
  imports.add("DialogFooter");
15264
15530
  imports.add("PrimaryButton");
15265
15531
  imports.add("DefaultButton");
15266
15532
  }
15533
+ if (roCreateDialogJsx) {
15534
+ imports.add("TextField");
15535
+ imports.add("Dropdown");
15536
+ imports.add("Checkbox");
15537
+ }
15267
15538
  return {
15268
15539
  imports,
15269
15540
  v9Imports,
@@ -15271,7 +15542,8 @@ ${childEntries.join(",\n")},
15271
15542
  extraImports: isV9 ? [`import { useDataverseQuery } from '../lib/dataverse';`] : roEmitHandler ? [
15272
15543
  roDataverseImport,
15273
15544
  `import { useQueryClient } from '@tanstack/react-query';`,
15274
- `import { ReadOnlyGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
15545
+ `import { ReadOnlyGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`,
15546
+ ...enableExport ? [`import { exportToFile, generateDefaultFilename } from '../lib/grid-kit/utils';`] : []
15275
15547
  ] : [
15276
15548
  `import { useDataverseQuery } from '../lib/dataverse';`,
15277
15549
  `import { ReadOnlyGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
@@ -15331,11 +15603,14 @@ const ${liveWrapperName}: React.FC = () => {
15331
15603
  entitySetName: gridDef.dataSource.entitySetName,
15332
15604
  primaryIdAttribute: resolvePrimaryIdAttribute(gridDef),
15333
15605
  itemsExpr: "keyedItems",
15334
- selectionExpr: "selectedIndices"
15606
+ selectionExpr: "selectedIndices",
15607
+ exportColumnsLiteral,
15608
+ createColumnsLiteral
15335
15609
  }) : "";
15336
15610
  const edSelectedIndicesState = edEmitHandler ? "\n const [selectedIndices, setSelectedIndices] = React.useState<Set<number>>(new Set());" : "";
15337
15611
  const edRowCommandsLiteral = edEmitRowCommands ? buildRowCommandsLiteral(contextMenuItems) : "";
15338
15612
  const edDeleteDialogJsx = edEmitRowCommands && flatHasDelete || edEmitToolbar && flatBarHasDelete ? buildGridDeleteDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15613
+ const edCreateDialogJsx = edEmitHandler && createColumnsLiteral ? buildGridCreateDialogJsx(gridDef.dataSource?.entityName ?? entityName) : "";
15339
15614
  const edCommandBarBlock = edEmitToolbar ? gridCommandBarBlock : "";
15340
15615
  const edSelectionModeAttr = edEmitToolbar ? flatSelectionModeAttr : "";
15341
15616
  const edOnSelectionChangedAttr = edEmitToolbar ? flatOnSelectionChangedAttr : "";
@@ -15352,6 +15627,7 @@ const ${liveWrapperName}: React.FC = () => {
15352
15627
  handlerBlock: edHandlerBlock,
15353
15628
  rowCommandsLiteral: edRowCommandsLiteral,
15354
15629
  deleteDialogJsx: edDeleteDialogJsx,
15630
+ createDialogJsx: edCreateDialogJsx,
15355
15631
  commandBarBlock: edCommandBarBlock,
15356
15632
  selectionModeAttr: edSelectionModeAttr,
15357
15633
  onSelectionChangedAttr: edOnSelectionChangedAttr
@@ -15363,18 +15639,24 @@ const ${liveWrapperName}: React.FC = () => {
15363
15639
  const jsx3 = editableUsesLiveData && liveWrapperName ? `{/* Subgrid: ${safeEntityName} \u2014 ${safeGridName} (editable, live) */}${todoComment}
15364
15640
  <${liveWrapperName} />` : `{/* Subgrid: ${safeEntityName} \u2014 ${safeGridName} (editable) */}${todoComment}
15365
15641
  <${componentName} items={${itemsLiteral}} />`;
15366
- const edDataverseImport = edEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord } from '../lib/dataverse';` : `import { useDataverseQuery, useUpdateRecord } from '../lib/dataverse';`;
15367
- if (edDeleteDialogJsx) {
15642
+ const edDataverseImport = edEmitHandler ? `import { useDataverseQuery, useUpdateRecord, useDeleteRecord${createColumnsLiteral ? ", useCreateRecord" : ""} } from '../lib/dataverse';` : `import { useDataverseQuery, useUpdateRecord } from '../lib/dataverse';`;
15643
+ if (edDeleteDialogJsx || edCreateDialogJsx) {
15368
15644
  imports.add("Dialog");
15369
15645
  imports.add("DialogType");
15370
15646
  imports.add("DialogFooter");
15371
15647
  imports.add("PrimaryButton");
15372
15648
  imports.add("DefaultButton");
15373
15649
  }
15650
+ if (edCreateDialogJsx) {
15651
+ imports.add("TextField");
15652
+ imports.add("Dropdown");
15653
+ imports.add("Checkbox");
15654
+ }
15374
15655
  const extraImports2 = editableUsesLiveData ? edEmitHandler ? [
15375
15656
  edDataverseImport,
15376
15657
  `import { useQueryClient } from '@tanstack/react-query';`,
15377
- `import { DataGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
15658
+ `import { DataGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`,
15659
+ ...enableExport ? [`import { exportToFile, generateDefaultFilename } from '../lib/grid-kit/utils';`] : []
15378
15660
  ] : [
15379
15661
  `import { useDataverseQuery, useUpdateRecord } from '../lib/dataverse';`,
15380
15662
  `import { DataGrid, createCellRegistry, type ColumnDef } from '../lib/grid-kit';`
@@ -20278,7 +20560,7 @@ function walkForm(form, entities, gridById) {
20278
20560
  for (const section of sections) {
20279
20561
  for (const row of section.rows ?? []) {
20280
20562
  for (const cell of row.cells ?? []) {
20281
- for (const control of cell.controls ?? []) {
20563
+ for (const control of cellControls(cell)) {
20282
20564
  absorbControl(control, primary, entities, gridById);
20283
20565
  }
20284
20566
  }
@@ -20286,11 +20568,17 @@ function walkForm(form, entities, gridById) {
20286
20568
  }
20287
20569
  const headerCells = form.header?.cells ?? [];
20288
20570
  for (const cell of headerCells) {
20289
- for (const control of cell.controls ?? []) {
20571
+ for (const control of cellControls(cell)) {
20290
20572
  absorbControl(control, primary, entities, gridById);
20291
20573
  }
20292
20574
  }
20293
20575
  }
20576
+ function cellControls(cell) {
20577
+ return [
20578
+ ...cell.control ? [cell.control] : [],
20579
+ ...cell.controls ?? []
20580
+ ];
20581
+ }
20294
20582
  function absorbControl(control, primary, entities, gridById) {
20295
20583
  if (control.dataBinding && primary) {
20296
20584
  absorbBinding(control.dataBinding, primary);
@@ -20816,7 +21104,11 @@ function anyFormHasBindings(forms) {
20816
21104
  for (const section of sections) {
20817
21105
  for (const row of section.rows ?? []) {
20818
21106
  for (const cell of row.cells ?? []) {
20819
- for (const control of cell.controls ?? []) {
21107
+ const controls = [
21108
+ ...cell.control ? [cell.control] : [],
21109
+ ...cell.controls ?? []
21110
+ ];
21111
+ for (const control of controls) {
20820
21112
  if (control.dataBinding) return true;
20821
21113
  if (control.type === "subgrid" && typeof control.properties?.entityName === "string" && control.properties.entityName) {
20822
21114
  return true;