@memberjunction/ng-base-forms 6.2.0-edge.1 → 6.2.0-edge.3

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 (207) hide show
  1. package/dist/lib/apply/form-placement-dialog.component.d.ts +266 -0
  2. package/dist/lib/apply/form-placement-dialog.component.d.ts.map +1 -0
  3. package/dist/lib/apply/form-placement-dialog.component.js +1522 -0
  4. package/dist/lib/apply/form-placement-dialog.component.js.map +1 -0
  5. package/dist/lib/apply/form-placement-order.d.ts +37 -0
  6. package/dist/lib/apply/form-placement-order.d.ts.map +1 -0
  7. package/dist/lib/apply/form-placement-order.js +111 -0
  8. package/dist/lib/apply/form-placement-order.js.map +1 -0
  9. package/dist/lib/apply/form-placement-preview.component.d.ts +112 -0
  10. package/dist/lib/apply/form-placement-preview.component.d.ts.map +1 -0
  11. package/dist/lib/apply/form-placement-preview.component.js +346 -0
  12. package/dist/lib/apply/form-placement-preview.component.js.map +1 -0
  13. package/dist/lib/apply/form-placement-text.d.ts +61 -0
  14. package/dist/lib/apply/form-placement-text.d.ts.map +1 -0
  15. package/dist/lib/apply/form-placement-text.js +279 -0
  16. package/dist/lib/apply/form-placement-text.js.map +1 -0
  17. package/dist/lib/apply/form-placement.d.ts +320 -0
  18. package/dist/lib/apply/form-placement.d.ts.map +1 -0
  19. package/dist/lib/apply/form-placement.js +432 -0
  20. package/dist/lib/apply/form-placement.js.map +1 -0
  21. package/dist/lib/apply/form-slot-probe.service.d.ts +121 -0
  22. package/dist/lib/apply/form-slot-probe.service.d.ts.map +1 -0
  23. package/dist/lib/apply/form-slot-probe.service.js +264 -0
  24. package/dist/lib/apply/form-slot-probe.service.js.map +1 -0
  25. package/dist/lib/base-form-component-internals.d.ts +11 -0
  26. package/dist/lib/base-form-component-internals.d.ts.map +1 -0
  27. package/dist/lib/base-form-component-internals.js +33 -0
  28. package/dist/lib/base-form-component-internals.js.map +1 -0
  29. package/dist/lib/base-form-component.d.ts +166 -1
  30. package/dist/lib/base-form-component.d.ts.map +1 -1
  31. package/dist/lib/base-form-component.js +296 -20
  32. package/dist/lib/base-form-component.js.map +1 -1
  33. package/dist/lib/chrome/form-chrome.d.ts +78 -0
  34. package/dist/lib/chrome/form-chrome.d.ts.map +1 -1
  35. package/dist/lib/chrome/form-chrome.js +128 -2
  36. package/dist/lib/chrome/form-chrome.js.map +1 -1
  37. package/dist/lib/chrome/form-composition-registry.d.ts +34 -0
  38. package/dist/lib/chrome/form-composition-registry.d.ts.map +1 -0
  39. package/dist/lib/chrome/form-composition-registry.js +56 -0
  40. package/dist/lib/chrome/form-composition-registry.js.map +1 -0
  41. package/dist/lib/chrome/form-composition-snapshot.d.ts +151 -0
  42. package/dist/lib/chrome/form-composition-snapshot.d.ts.map +1 -0
  43. package/dist/lib/chrome/form-composition-snapshot.js +137 -0
  44. package/dist/lib/chrome/form-composition-snapshot.js.map +1 -0
  45. package/dist/lib/chrome/resolve-form-chrome.d.ts +15 -0
  46. package/dist/lib/chrome/resolve-form-chrome.d.ts.map +1 -1
  47. package/dist/lib/chrome/resolve-form-chrome.js +31 -2
  48. package/dist/lib/chrome/resolve-form-chrome.js.map +1 -1
  49. package/dist/lib/container/record-form-container.component.d.ts +261 -5
  50. package/dist/lib/container/record-form-container.component.d.ts.map +1 -1
  51. package/dist/lib/container/record-form-container.component.js +1180 -371
  52. package/dist/lib/container/record-form-container.component.js.map +1 -1
  53. package/dist/lib/duplicate-entry-check/duplicate-entry-check.d.ts +150 -0
  54. package/dist/lib/duplicate-entry-check/duplicate-entry-check.d.ts.map +1 -0
  55. package/dist/lib/duplicate-entry-check/duplicate-entry-check.js +263 -0
  56. package/dist/lib/duplicate-entry-check/duplicate-entry-check.js.map +1 -0
  57. package/dist/lib/field/form-field.component.d.ts +22 -0
  58. package/dist/lib/field/form-field.component.d.ts.map +1 -1
  59. package/dist/lib/field/form-field.component.js +51 -6
  60. package/dist/lib/field/form-field.component.js.map +1 -1
  61. package/dist/lib/form-field-edit.coordinator.d.ts +25 -0
  62. package/dist/lib/form-field-edit.coordinator.d.ts.map +1 -0
  63. package/dist/lib/form-field-edit.coordinator.js +27 -0
  64. package/dist/lib/form-field-edit.coordinator.js.map +1 -0
  65. package/dist/lib/form-state.service.d.ts +5 -0
  66. package/dist/lib/form-state.service.d.ts.map +1 -1
  67. package/dist/lib/form-state.service.js +6 -1
  68. package/dist/lib/form-state.service.js.map +1 -1
  69. package/dist/lib/host/entity-form-host.component.d.ts +16 -1
  70. package/dist/lib/host/entity-form-host.component.d.ts.map +1 -1
  71. package/dist/lib/host/entity-form-host.component.js +27 -6
  72. package/dist/lib/host/entity-form-host.component.js.map +1 -1
  73. package/dist/lib/interactive-form/form-panel-host-props.builder.d.ts +24 -0
  74. package/dist/lib/interactive-form/form-panel-host-props.builder.d.ts.map +1 -0
  75. package/dist/lib/interactive-form/form-panel-host-props.builder.js +99 -0
  76. package/dist/lib/interactive-form/form-panel-host-props.builder.js.map +1 -0
  77. package/dist/lib/interactive-form/interactive-form-panel.component.d.ts +109 -0
  78. package/dist/lib/interactive-form/interactive-form-panel.component.d.ts.map +1 -0
  79. package/dist/lib/interactive-form/interactive-form-panel.component.js +424 -0
  80. package/dist/lib/interactive-form/interactive-form-panel.component.js.map +1 -0
  81. package/dist/lib/interactive-form/interactive-form.component.d.ts +2 -0
  82. package/dist/lib/interactive-form/interactive-form.component.d.ts.map +1 -1
  83. package/dist/lib/interactive-form/interactive-form.component.js +4 -5
  84. package/dist/lib/interactive-form/interactive-form.component.js.map +1 -1
  85. package/dist/lib/panel/collapsible-panel.component.d.ts +69 -1
  86. package/dist/lib/panel/collapsible-panel.component.d.ts.map +1 -1
  87. package/dist/lib/panel/collapsible-panel.component.js +148 -12
  88. package/dist/lib/panel/collapsible-panel.component.js.map +1 -1
  89. package/dist/lib/panel-manager/form-audience.d.ts +46 -0
  90. package/dist/lib/panel-manager/form-audience.d.ts.map +1 -0
  91. package/dist/lib/panel-manager/form-audience.js +34 -0
  92. package/dist/lib/panel-manager/form-audience.js.map +1 -0
  93. package/dist/lib/panel-manager/form-panel-admin.service.d.ts +150 -0
  94. package/dist/lib/panel-manager/form-panel-admin.service.d.ts.map +1 -0
  95. package/dist/lib/panel-manager/form-panel-admin.service.js +433 -0
  96. package/dist/lib/panel-manager/form-panel-admin.service.js.map +1 -0
  97. package/dist/lib/panel-manager/form-panel-inventory.d.ts +255 -0
  98. package/dist/lib/panel-manager/form-panel-inventory.d.ts.map +1 -0
  99. package/dist/lib/panel-manager/form-panel-inventory.js +293 -0
  100. package/dist/lib/panel-manager/form-panel-inventory.js.map +1 -0
  101. package/dist/lib/panel-manager/panel-manager.component.d.ts +232 -0
  102. package/dist/lib/panel-manager/panel-manager.component.d.ts.map +1 -0
  103. package/dist/lib/panel-manager/panel-manager.component.js +1112 -0
  104. package/dist/lib/panel-manager/panel-manager.component.js.map +1 -0
  105. package/dist/lib/panel-slot/base-contribution-panel.d.ts +40 -0
  106. package/dist/lib/panel-slot/base-contribution-panel.d.ts.map +1 -0
  107. package/dist/lib/panel-slot/base-contribution-panel.js +55 -0
  108. package/dist/lib/panel-slot/base-contribution-panel.js.map +1 -0
  109. package/dist/lib/panel-slot/base-form-panel.d.ts +116 -8
  110. package/dist/lib/panel-slot/base-form-panel.d.ts.map +1 -1
  111. package/dist/lib/panel-slot/base-form-panel.js +76 -5
  112. package/dist/lib/panel-slot/base-form-panel.js.map +1 -1
  113. package/dist/lib/panel-slot/collect-form-contribution-registrations.d.ts +29 -0
  114. package/dist/lib/panel-slot/collect-form-contribution-registrations.d.ts.map +1 -0
  115. package/dist/lib/panel-slot/collect-form-contribution-registrations.js +214 -0
  116. package/dist/lib/panel-slot/collect-form-contribution-registrations.js.map +1 -0
  117. package/dist/lib/panel-slot/collect-form-panel-registrations.d.ts +6 -3
  118. package/dist/lib/panel-slot/collect-form-panel-registrations.d.ts.map +1 -1
  119. package/dist/lib/panel-slot/collect-form-panel-registrations.js +8 -14
  120. package/dist/lib/panel-slot/collect-form-panel-registrations.js.map +1 -1
  121. package/dist/lib/panel-slot/form-contribution.d.ts +170 -7
  122. package/dist/lib/panel-slot/form-contribution.d.ts.map +1 -1
  123. package/dist/lib/panel-slot/form-contribution.js +242 -64
  124. package/dist/lib/panel-slot/form-contribution.js.map +1 -1
  125. package/dist/lib/panel-slot/form-contributions.component.d.ts +16 -5
  126. package/dist/lib/panel-slot/form-contributions.component.d.ts.map +1 -1
  127. package/dist/lib/panel-slot/form-contributions.component.js +43 -7
  128. package/dist/lib/panel-slot/form-contributions.component.js.map +1 -1
  129. package/dist/lib/panel-slot/form-field-panel-slot.component.d.ts +66 -0
  130. package/dist/lib/panel-slot/form-field-panel-slot.component.d.ts.map +1 -0
  131. package/dist/lib/panel-slot/form-field-panel-slot.component.js +190 -0
  132. package/dist/lib/panel-slot/form-field-panel-slot.component.js.map +1 -0
  133. package/dist/lib/panel-slot/form-panel-slot.component.d.ts +52 -16
  134. package/dist/lib/panel-slot/form-panel-slot.component.d.ts.map +1 -1
  135. package/dist/lib/panel-slot/form-panel-slot.component.js +190 -66
  136. package/dist/lib/panel-slot/form-panel-slot.component.js.map +1 -1
  137. package/dist/lib/panel-slot/form-slot-coordinator.service.d.ts +11 -0
  138. package/dist/lib/panel-slot/form-slot-coordinator.service.d.ts.map +1 -1
  139. package/dist/lib/panel-slot/form-slot-coordinator.service.js +17 -0
  140. package/dist/lib/panel-slot/form-slot-coordinator.service.js.map +1 -1
  141. package/dist/lib/panel-slot/merge-panel-validation.d.ts +7 -0
  142. package/dist/lib/panel-slot/merge-panel-validation.d.ts.map +1 -0
  143. package/dist/lib/panel-slot/merge-panel-validation.js +16 -0
  144. package/dist/lib/panel-slot/merge-panel-validation.js.map +1 -0
  145. package/dist/lib/panel-slot/mount-form-contribution.d.ts +15 -0
  146. package/dist/lib/panel-slot/mount-form-contribution.d.ts.map +1 -0
  147. package/dist/lib/panel-slot/mount-form-contribution.js +37 -0
  148. package/dist/lib/panel-slot/mount-form-contribution.js.map +1 -0
  149. package/dist/lib/panel-slot/panel-hides.d.ts +35 -0
  150. package/dist/lib/panel-slot/panel-hides.d.ts.map +1 -0
  151. package/dist/lib/panel-slot/panel-hides.js +111 -0
  152. package/dist/lib/panel-slot/panel-hides.js.map +1 -0
  153. package/dist/lib/panel-slot/placement-preview-panel.component.d.ts +16 -0
  154. package/dist/lib/panel-slot/placement-preview-panel.component.d.ts.map +1 -0
  155. package/dist/lib/panel-slot/placement-preview-panel.component.js +112 -0
  156. package/dist/lib/panel-slot/placement-preview-panel.component.js.map +1 -0
  157. package/dist/lib/panel-slot/placement-preview.d.ts +57 -0
  158. package/dist/lib/panel-slot/placement-preview.d.ts.map +1 -0
  159. package/dist/lib/panel-slot/placement-preview.js +86 -0
  160. package/dist/lib/panel-slot/placement-preview.js.map +1 -0
  161. package/dist/lib/panel-slot/related-entity-grid-panel.component.d.ts +2 -0
  162. package/dist/lib/panel-slot/related-entity-grid-panel.component.d.ts.map +1 -1
  163. package/dist/lib/panel-slot/related-entity-grid-panel.component.js +10 -3
  164. package/dist/lib/panel-slot/related-entity-grid-panel.component.js.map +1 -1
  165. package/dist/lib/panel-slot/slot-order.d.ts +19 -0
  166. package/dist/lib/panel-slot/slot-order.d.ts.map +1 -0
  167. package/dist/lib/panel-slot/slot-order.js +53 -0
  168. package/dist/lib/panel-slot/slot-order.js.map +1 -0
  169. package/dist/lib/resolver/form-resolver.service.d.ts +4 -2
  170. package/dist/lib/resolver/form-resolver.service.d.ts.map +1 -1
  171. package/dist/lib/resolver/form-resolver.service.js +18 -8
  172. package/dist/lib/resolver/form-resolver.service.js.map +1 -1
  173. package/dist/lib/resolver/form-variants.d.ts +28 -0
  174. package/dist/lib/resolver/form-variants.d.ts.map +1 -0
  175. package/dist/lib/resolver/form-variants.js +40 -0
  176. package/dist/lib/resolver/form-variants.js.map +1 -0
  177. package/dist/lib/section-counts/form-section-counts.d.ts +99 -0
  178. package/dist/lib/section-counts/form-section-counts.d.ts.map +1 -0
  179. package/dist/lib/section-counts/form-section-counts.js +223 -0
  180. package/dist/lib/section-counts/form-section-counts.js.map +1 -0
  181. package/dist/lib/toolbar/form-toolbar.component.d.ts +129 -2
  182. package/dist/lib/toolbar/form-toolbar.component.d.ts.map +1 -1
  183. package/dist/lib/toolbar/form-toolbar.component.js +974 -307
  184. package/dist/lib/toolbar/form-toolbar.component.js.map +1 -1
  185. package/dist/lib/types/form-events.d.ts +6 -0
  186. package/dist/lib/types/form-events.d.ts.map +1 -1
  187. package/dist/lib/types/form-events.js +6 -0
  188. package/dist/lib/types/form-events.js.map +1 -1
  189. package/dist/lib/types/form-toolbar-item.d.ts +20 -1
  190. package/dist/lib/types/form-toolbar-item.d.ts.map +1 -1
  191. package/dist/lib/types/form-toolbar-item.js.map +1 -1
  192. package/dist/lib/types/form-types.d.ts +13 -0
  193. package/dist/lib/types/form-types.d.ts.map +1 -1
  194. package/dist/lib/types/form-types.js.map +1 -1
  195. package/dist/lib/types/toolbar-config.d.ts +16 -0
  196. package/dist/lib/types/toolbar-config.d.ts.map +1 -1
  197. package/dist/lib/types/toolbar-config.js +3 -0
  198. package/dist/lib/types/toolbar-config.js.map +1 -1
  199. package/dist/module.d.ts +29 -22
  200. package/dist/module.d.ts.map +1 -1
  201. package/dist/module.js +50 -8
  202. package/dist/module.js.map +1 -1
  203. package/dist/public-api.d.ts +22 -0
  204. package/dist/public-api.d.ts.map +1 -1
  205. package/dist/public-api.js +24 -0
  206. package/dist/public-api.js.map +1 -1
  207. package/package.json +20 -18
@@ -1,14 +1,19 @@
1
1
  import { Directive, ViewChildren, ElementRef, ChangeDetectorRef, Output, EventEmitter, inject } from '@angular/core';
2
2
  import { Subject, debounceTime } from 'rxjs';
3
- import { EntityInfo, EntityPermissionType, LogError, RunView } from '@memberjunction/core';
3
+ import { EntityInfo, EntityPermissionType, LogError, CompositeKey, RunView } from '@memberjunction/core';
4
4
  import { DeserializeValidationErrors, MJEventType, MJGlobal } from '@memberjunction/global';
5
5
  import { FormEditingCompleteEvent, BaseFormComponentEventCodes } from '@memberjunction/ng-base-types';
6
+ import { GraphQLAIClient, GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';
6
7
  import { BaseRecordComponent } from './base-record-component';
8
+ import { MergePanelValidation } from './panel-slot/merge-panel-validation';
7
9
  import { BaseFormSectionInfo } from './base-form-section-info';
8
10
  import { MjCollapsiblePanelComponent } from './panel/collapsible-panel.component';
9
11
  import { FormStateService } from './form-state.service';
10
- import { CollectFormPanelRegistrations } from './panel-slot/collect-form-panel-registrations';
11
- import { ContributionHiddenSectionKeys } from './panel-slot/form-contribution';
12
+ import { CollectFormContributionRegistrations } from './panel-slot/collect-form-contribution-registrations';
13
+ import { FORM_PLACEMENT_PREVIEW } from './panel-slot/placement-preview';
14
+ import { FormContextsEqual } from './base-form-component-internals';
15
+ import { ContributionClaimedFieldNames, ContributionHiddenSectionKeys } from './panel-slot/form-contribution';
16
+ import { DuplicateEntryCheckController } from './duplicate-entry-check/duplicate-entry-check';
12
17
  import * as i0 from "@angular/core";
13
18
  /**
14
19
  * Abstract base class for all entity record forms in MemberJunction.
@@ -174,6 +179,8 @@ export class BaseFormComponent extends BaseRecordComponent {
174
179
  elementRef = inject(ElementRef);
175
180
  cdr = inject(ChangeDetectorRef);
176
181
  formStateService = inject(FormStateService);
182
+ /** The placement dialog's unsaved panel, when this form is the dialog's preview. */
183
+ placementPreview = inject(FORM_PLACEMENT_PREVIEW, { optional: true });
177
184
  // #endregion
178
185
  // #region @Output Events
179
186
  /** Emitted when navigation is requested (record link, external link, email, new record, etc.) */
@@ -198,6 +205,54 @@ export class BaseFormComponent extends BaseRecordComponent {
198
205
  * the container to start loading badge counts and other record-dependent data.
199
206
  */
200
207
  RecordReady = new EventEmitter();
208
+ /**
209
+ * Emitted whenever edit mode starts (`true`) or ends (`false`). The Explorer
210
+ * shell uses the `true` edge to PROMOTE a records preview tab — pin it — the
211
+ * moment the user starts editing (VS Code's promote-on-modify), so a record
212
+ * being edited is neither replaceable by the next plain open nor italic.
213
+ * Fires on every call, not only on transitions: a new record's ngOnInit
214
+ * re-asserts edit mode and the shell's pin is idempotent.
215
+ */
216
+ EditModeChanged = new EventEmitter();
217
+ /** Layout the container resolved for this form. Set by `<mj-record-form-container>`; read by panel hosts. */
218
+ ChromeLayout = 'accordion';
219
+ /**
220
+ * Whether this form renders its own body in full.
221
+ *
222
+ * A form that returns true accepts nothing the container would otherwise compose into
223
+ * it: no `BaseFormPanel` mounts, no contribution claims a section, and no stock grid is
224
+ * filled in for a `DisplayInForm` relationship. The composition snapshot reports none of
225
+ * them either. Container chrome that belongs to the *record* rather than to the body —
226
+ * the toolbar, Save/Delete, History, Record Changes — is unaffected.
227
+ *
228
+ * The fill-in reads an unbaked relationship as stale CodeGen and supplies the missing
229
+ * grid. A form that replaced the body bakes nothing by design, so without this flag
230
+ * every relationship reads as missing and the container composes a form the author
231
+ * never asked for.
232
+ */
233
+ get OwnsEntireFormBody() { return false; }
234
+ /**
235
+ * Last composition snapshot the container published — what is actually on this form:
236
+ * sections, related grids, contributions and slots. Consumers: agent context (so Skip
237
+ * can target a real slot and section key) and Form Studio.
238
+ */
239
+ CompositionSnapshot = null;
240
+ CompositionChanged = new EventEmitter();
241
+ _formPanels = new Set();
242
+ /** Slot hosts register every mounted panel so validation can include panel-owned checks. */
243
+ RegisterFormPanel(panel) {
244
+ this._formPanels.add(panel);
245
+ }
246
+ UnregisterFormPanel(panel) {
247
+ this._formPanels.delete(panel);
248
+ }
249
+ /**
250
+ * Fires when a section's known row count changes — from the container's batched
251
+ * count prefetch, a related grid load (including a manual grid refresh), or a
252
+ * contribution reporting its own count. The container re-resolves empty-section
253
+ * chrome (`whenEmpty`) when a count crosses zero.
254
+ */
255
+ SectionRowCountChanged = new EventEmitter();
201
256
  // #endregion
202
257
  /** Subscription to form state changes */
203
258
  formStateSubscription;
@@ -248,6 +303,7 @@ export class BaseFormComponent extends BaseRecordComponent {
248
303
  if (this.formStateSubscription) {
249
304
  this.formStateSubscription.unsubscribe();
250
305
  }
306
+ this._duplicateEntryCheck?.Dispose();
251
307
  }
252
308
  // #region Pending Records
253
309
  get PendingRecords() {
@@ -305,6 +361,7 @@ export class BaseFormComponent extends BaseRecordComponent {
305
361
  if (entityName) {
306
362
  this.formStateService.setEditMode(entityName, true);
307
363
  }
364
+ this.EditModeChanged.emit(true);
308
365
  }
309
366
  EndEditMode() {
310
367
  this.EditMode = false;
@@ -313,6 +370,7 @@ export class BaseFormComponent extends BaseRecordComponent {
313
370
  if (entityName) {
314
371
  this.formStateService.setEditMode(entityName, false);
315
372
  }
373
+ this.EditModeChanged.emit(false);
316
374
  }
317
375
  handleHistoryDialog() {
318
376
  this.isHistoryDialogOpen = !this.isHistoryDialogOpen;
@@ -322,7 +380,48 @@ export class BaseFormComponent extends BaseRecordComponent {
322
380
  }
323
381
  // #endregion
324
382
  // #region Core Form Operations
383
+ /**
384
+ * Record + pending-record validation, merged with whatever panel validity is
385
+ * already known.
386
+ *
387
+ * Synchronous, and therefore blind to a panel validator that has not reported yet —
388
+ * any path that gates a save must use {@link ValidateAsync}. The signature stays
389
+ * synchronous because this is published API with external callers.
390
+ */
325
391
  Validate() {
392
+ const valResults = this.validateRecordAndPending();
393
+ if (this._omitLastKnownPanelValidation) {
394
+ return valResults;
395
+ }
396
+ return MergePanelValidation(valResults, [...this._formPanels].map((panel) => panel.LastKnownValidation()));
397
+ }
398
+ /** True only while {@link ValidateAsync} calls {@link Validate}: the awaited panel results take the place of the last-known ones. */
399
+ _omitLastKnownPanelValidation = false;
400
+ /**
401
+ * {@link Validate}, merged with every mounted panel's validator, awaited. This is what
402
+ * `SaveRecord()` calls.
403
+ *
404
+ * It starts from `Validate()`, so a subclass that overrides `Validate()` still gates the
405
+ * save; the panels' last-known state is left out of that call, because their awaited
406
+ * results replace it.
407
+ *
408
+ * A panel's `Validate()` may be async — anything checking server state will be — and
409
+ * reading such a result synchronously yields a Promise, which tests as "no opinion"
410
+ * and lets an invalid record save with no error and no log.
411
+ */
412
+ async ValidateAsync() {
413
+ let base;
414
+ this._omitLastKnownPanelValidation = true;
415
+ try {
416
+ base = this.Validate();
417
+ }
418
+ finally {
419
+ this._omitLastKnownPanelValidation = false;
420
+ }
421
+ const panelResults = await Promise.all([...this._formPanels].map((panel) => panel.Validate()));
422
+ return MergePanelValidation(base, panelResults);
423
+ }
424
+ validateRecordAndPending() {
326
425
  const valResults = this.record.Validate();
327
426
  const pendingValResults = this.ValidatePendingRecords();
328
427
  for (let i = 0; i < pendingValResults.length; i++) {
@@ -365,7 +464,7 @@ export class BaseFormComponent extends BaseRecordComponent {
365
464
  return false;
366
465
  }
367
466
  this.PopulatePendingRecords();
368
- const valResults = this.Validate();
467
+ const valResults = await this.ValidateAsync();
369
468
  if (!valResults.Success) {
370
469
  this.publishValidationFailure(valResults.Errors);
371
470
  return false;
@@ -374,6 +473,7 @@ export class BaseFormComponent extends BaseRecordComponent {
374
473
  if (result) {
375
474
  this._pendingRecords = [];
376
475
  this.clearValidationState();
476
+ this._duplicateEntryCheck?.RecordSaved();
377
477
  if (StopEditModeAfterSave)
378
478
  this.EndEditMode();
379
479
  this.Notification.emit({ Message: 'Record saved successfully', Type: 'success', Duration: 2500 });
@@ -541,6 +641,69 @@ export class BaseFormComponent extends BaseRecordComponent {
541
641
  return new Promise(resolve => setTimeout(resolve, duration));
542
642
  }
543
643
  // #endregion
644
+ // #region Duplicate Entry Check
645
+ _duplicateEntryCheck = null;
646
+ /**
647
+ * The entry-time duplicate check. While a person enters a new record it asks the server, after
648
+ * each pause in editing, whether the values duplicate existing records, and holds the ones to
649
+ * flag. It only flags: saving is never blocked and nothing is merged. `mj-record-form-container`
650
+ * shows the notice.
651
+ */
652
+ get DuplicateEntryCheck() {
653
+ if (!this._duplicateEntryCheck) {
654
+ this._duplicateEntryCheck = new DuplicateEntryCheckController((entityName, values) => this.CheckDuplicateEntry(entityName, values));
655
+ }
656
+ return this._duplicateEntryCheck;
657
+ }
658
+ /** Whether the possible-duplicate notice shows: a new record with flagged candidates not dismissed. */
659
+ get ShowDuplicateEntryNotice() {
660
+ return !!this.record && !this.record.IsSaved && (this._duplicateEntryCheck?.IsNoticeVisible ?? false);
661
+ }
662
+ /**
663
+ * A person edited a field on this form. For a new record this restarts the entry-time duplicate
664
+ * check. `mj-record-form-container` calls it for every `mj-form-field` edit; a custom editor that
665
+ * changes the record some other way can call it too.
666
+ *
667
+ * A user who cannot read the entity (one who may only create its records) never starts a check:
668
+ * the server would refuse it, and a flagged record is one they could not open anyway.
669
+ */
670
+ OnFieldEdited() {
671
+ if (this.record && !this.record.IsSaved && this.UserCanRead) {
672
+ this.DuplicateEntryCheck.RecordEdited(this.record);
673
+ }
674
+ }
675
+ /**
676
+ * Opens a flagged candidate the way the form opens any record: a `Navigate` event the host
677
+ * handles, never a router call. It asks for a new tab, so the record being entered is kept.
678
+ */
679
+ OpenDuplicateCandidate(candidate) {
680
+ const entityInfo = this.record?.EntityInfo;
681
+ if (!entityInfo)
682
+ return;
683
+ this.Navigate.emit({
684
+ Kind: 'record',
685
+ EntityName: entityInfo.Name,
686
+ PrimaryKey: CompositeKey.FromURLSegment(entityInfo, candidate.RecordID),
687
+ OpenInNewTab: true
688
+ });
689
+ }
690
+ /** The person dismissed the possible-duplicate notice. */
691
+ DismissDuplicateNotice() {
692
+ this._duplicateEntryCheck?.Dismiss();
693
+ }
694
+ /**
695
+ * Asks the server whether the values being entered duplicate existing records. A form on a
696
+ * provider that is not a `GraphQLDataProvider` has no server to ask, so the check reports
697
+ * `NotConfigured` and stops for the entity. Override to send the check elsewhere.
698
+ */
699
+ async CheckDuplicateEntry(entityName, values) {
700
+ const provider = this.ProviderToUse;
701
+ if (!(provider instanceof GraphQLDataProvider)) {
702
+ return { Status: 'NotConfigured', Candidates: [] };
703
+ }
704
+ return new GraphQLAIClient(provider).CheckDuplicateEntry({ EntityName: entityName, Values: values });
705
+ }
706
+ // #endregion
544
707
  // #region Permissions
545
708
  _userPermissions = [];
546
709
  CheckUserPermission(type) {
@@ -801,8 +964,24 @@ export class BaseFormComponent extends BaseRecordComponent {
801
964
  _showValidation = false;
802
965
  /** Validation errors from the most recent failed save attempt */
803
966
  _validationErrors = [];
967
+ _formContextMemo = null;
968
+ /**
969
+ * Context handed to every field, panel and slot in the form.
970
+ *
971
+ * Returns the SAME object while nothing in it has changed. Templates bind this getter in
972
+ * dozens of places per form, and Angular evaluates each binding on every change-detection
973
+ * pass — so allocating a fresh object per access handed every child a new reference each
974
+ * pass, defeating input-identity checks and cascading re-renders through the whole form.
975
+ * Building the candidate is cheap (the expensive part, hidden section keys, is memoized);
976
+ * the identity comparison below is what stops the cascade.
977
+ */
804
978
  get formContext() {
805
- return {
979
+ // One collector read per access; both contribution-derived values come from it.
980
+ const entity = this.record?.EntityInfo;
981
+ const regs = entity
982
+ ? CollectFormContributionRegistrations(entity, this.ProviderToUse, { Preview: this.placementPreview })
983
+ : null;
984
+ const next = {
806
985
  sectionFilter: this.searchFilter,
807
986
  showEmptyFields: this.showEmptyFields,
808
987
  showValidation: this._showValidation,
@@ -811,27 +990,79 @@ export class BaseFormComponent extends BaseRecordComponent {
811
990
  collapsibleSections: this.Config?.CollapsibleSections,
812
991
  enableRecordLinks: this.Config?.EnableRecordLinks,
813
992
  showRelatedEntities: this.Config?.ShowRelatedEntities,
814
- hiddenSectionKeys: this.resolveHiddenSectionKeys(),
993
+ hiddenSectionKeys: this.resolveHiddenSectionKeys(entity, regs),
994
+ claimedFieldNames: this.contributionClaimedFieldNames(entity, regs),
815
995
  visibleSectionKeys: this.Config?.VisibleSectionKeys,
816
996
  allowSectionReorder: this.resolveAllowSectionReorder()
817
997
  };
818
- }
998
+ const prev = this._formContextMemo;
999
+ if (prev && FormContextsEqual(prev, next))
1000
+ return prev;
1001
+ this._formContextMemo = next;
1002
+ return next;
1003
+ }
1004
+ /** Memo for {@link resolveHiddenSectionKeys}. */
1005
+ _resolvedHiddenKeysMemo = null;
819
1006
  /**
820
1007
  * Config HiddenSectionKeys plus section keys winning contributions asked
821
1008
  * to hide (related-entity claims and `replacesSectionKey` field panels).
822
1009
  */
823
- resolveHiddenSectionKeys() {
824
- const claimed = this.contributionHiddenSectionKeys();
1010
+ resolveHiddenSectionKeys(entity, regs) {
1011
+ const claimed = this.contributionHiddenSectionKeys(entity, regs);
825
1012
  const configured = this.Config?.HiddenSectionKeys;
826
1013
  if (claimed.length === 0)
827
1014
  return configured;
828
- return [...(configured ?? []), ...claimed];
1015
+ // Memoized on the identity of both inputs: without it this concatenation returns a new
1016
+ // array per access, which alone would make every formContext look changed.
1017
+ const memo = this._resolvedHiddenKeysMemo;
1018
+ if (memo && memo.claimed === claimed && memo.configured === configured)
1019
+ return memo.merged;
1020
+ const merged = [...(configured ?? []), ...claimed];
1021
+ this._resolvedHiddenKeysMemo = { claimed, configured, merged };
1022
+ return merged;
1023
+ }
1024
+ /** Memo for {@link contributionClaimedFieldNames} — same reasoning as the hidden-keys memo. */
1025
+ _claimedFieldsMemo = null;
1026
+ /**
1027
+ * Field names a winning contribution stands in for, so no section draws them.
1028
+ *
1029
+ * Empty stays `undefined` rather than `[]`: `formContext` is compared by value on every
1030
+ * change-detection pass, and a fresh empty array per pass would make every context look
1031
+ * different from the last one.
1032
+ */
1033
+ contributionClaimedFieldNames(entity, regs) {
1034
+ if (!entity || !regs)
1035
+ return undefined;
1036
+ const memo = this._claimedFieldsMemo;
1037
+ if (!(memo && memo.entity === entity && memo.regs === regs)) {
1038
+ const names = ContributionClaimedFieldNames(entity.Name, entity.RelatedEntities, entity.ChildEntities.map((child) => child.ID), regs);
1039
+ this._claimedFieldsMemo = { entity, regs, names };
1040
+ }
1041
+ const names = this._claimedFieldsMemo.names;
1042
+ return names.length > 0 ? names : undefined;
829
1043
  }
830
- contributionHiddenSectionKeys() {
831
- const entity = this.record?.EntityInfo;
832
- if (!entity)
1044
+ /** Memo for {@link contributionHiddenSectionKeys} — see the comment there. */
1045
+ _hiddenKeysMemo = null;
1046
+ /**
1047
+ * Section keys hidden because a contribution claimed them.
1048
+ *
1049
+ * Memoized on the identity of the merged registration list, which the collector returns as
1050
+ * a stable reference until something actually changes. That matters because this sits under
1051
+ * the `formContext` getter, which is bound in dozens of places per form and re-evaluated on
1052
+ * every change-detection pass — and `ContributionHiddenSectionKeys` runs the WHOLE composer
1053
+ * (collapse, relationship walk, section-key construction) on each call. Running that per
1054
+ * binding per pass is what made forms lag.
1055
+ */
1056
+ contributionHiddenSectionKeys(entity, regs) {
1057
+ // `regs` is merged: compiled registrations plus the rows that apply to this user.
1058
+ if (!entity || !regs)
833
1059
  return [];
834
- return ContributionHiddenSectionKeys(entity.Name, entity.RelatedEntities, entity.ChildEntities.map((child) => child.ID), CollectFormPanelRegistrations());
1060
+ const memo = this._hiddenKeysMemo;
1061
+ if (memo && memo.entity === entity && memo.regs === regs)
1062
+ return memo.keys;
1063
+ const keys = ContributionHiddenSectionKeys(entity.Name, entity.RelatedEntities, entity.ChildEntities.map((child) => child.ID), regs);
1064
+ this._hiddenKeysMemo = { entity, regs, keys };
1065
+ return keys;
835
1066
  }
836
1067
  /**
837
1068
  * Resolves whether section drag-reorder is allowed for the current Config.
@@ -937,18 +1168,45 @@ export class BaseFormComponent extends BaseRecordComponent {
937
1168
  section.isExpanded = isExpanded;
938
1169
  }
939
1170
  }
1171
+ /**
1172
+ * The row count shown as a section's badge. `undefined` until known, and always
1173
+ * `undefined` for a section whose badge is turned off (`showCount: false`) — use
1174
+ * {@link PeekSectionRowCount} for the underlying number.
1175
+ */
940
1176
  GetSectionRowCount(sectionKey) {
941
- const section = this.sectionMap.get(sectionKey);
942
- return section?.rowCount;
1177
+ if (this.suppressedBadgeSectionKeys.has(sectionKey))
1178
+ return undefined;
1179
+ return this.PeekSectionRowCount(sectionKey);
1180
+ }
1181
+ /** The last known row count for a section, regardless of whether its badge shows. */
1182
+ PeekSectionRowCount(sectionKey) {
1183
+ return this.sectionMap.get(sectionKey)?.rowCount;
1184
+ }
1185
+ suppressedBadgeSectionKeys = new Set();
1186
+ /** Show or hide a section's row-count badge (metadata `showCount`). The count itself is still tracked. */
1187
+ SetSectionBadgeVisible(sectionKey, visible) {
1188
+ const changed = visible ? this.suppressedBadgeSectionKeys.delete(sectionKey) : !this.suppressedBadgeSectionKeys.has(sectionKey);
1189
+ if (!visible)
1190
+ this.suppressedBadgeSectionKeys.add(sectionKey);
1191
+ if (changed)
1192
+ this.cdr.markForCheck();
943
1193
  }
944
1194
  SetSectionRowCount(sectionKey, rowCount) {
1195
+ const previous = this.PeekSectionRowCount(sectionKey);
1196
+ this.applySectionRowCount(sectionKey, rowCount);
1197
+ if (previous !== rowCount) {
1198
+ this.SectionRowCountChanged.emit({ SectionKey: sectionKey, RowCount: rowCount, Previous: previous });
1199
+ }
1200
+ }
1201
+ applySectionRowCount(sectionKey, rowCount) {
945
1202
  let section = this.sectionMap.get(sectionKey);
946
1203
  if (!section) {
947
1204
  // Contribution panels use their own SectionKey (e.g. 'orders') which
948
- // is never seeded by generated initSections(). Upsert so the left-nav
949
- // rail badge can read the count the same way baked grids do.
1205
+ // is never seeded by generated initSections(). Kept in the map only, so the
1206
+ // left-nav rail badge reads the count the same way baked grids do. It stays out
1207
+ // of `sections`: that list is the form's declared order, and a key in it is drawn
1208
+ // at its index instead of at the slot the panel was placed in.
950
1209
  section = new BaseFormSectionInfo(sectionKey, sectionKey, false, rowCount);
951
- this.sections.push(section);
952
1210
  this.sectionMap.set(sectionKey, section);
953
1211
  }
954
1212
  else {
@@ -1122,6 +1380,18 @@ export class BaseFormComponent extends BaseRecordComponent {
1122
1380
  const index = order.indexOf(sectionKey);
1123
1381
  return index >= 0 ? index : this.sections.length;
1124
1382
  }
1383
+ /**
1384
+ * Where this key sits in the section order, or null when it is not in it at all.
1385
+ *
1386
+ * {@link getSectionDisplayOrder} cannot answer that: it returns the section count for
1387
+ * an unknown key, which is indistinguishable from a real last position. A contribution
1388
+ * panel is not in the form's declared sections, so a caller has to be able to tell
1389
+ * "the user placed this here" from "nobody has said where this goes".
1390
+ */
1391
+ getSectionOrderIndex(sectionKey) {
1392
+ const index = this.getSectionOrder().indexOf(sectionKey);
1393
+ return index >= 0 ? index : null;
1394
+ }
1125
1395
  // #endregion
1126
1396
  // #region Form Container Event Handlers
1127
1397
  /**
@@ -1189,7 +1459,7 @@ export class BaseFormComponent extends BaseRecordComponent {
1189
1459
  } if (rf & 2) {
1190
1460
  let _t;
1191
1461
  i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.collapsiblePanels = _t);
1192
- } }, outputs: { Navigate: "Navigate", Notification: "Notification", RecordSaved: "RecordSaved", RecordRefreshed: "RecordRefreshed", RecordDeleted: "RecordDeleted", RecordSaveFailed: "RecordSaveFailed", RecordDeleteFailed: "RecordDeleteFailed", ValidationFailed: "ValidationFailed", RecordReady: "RecordReady" }, features: [i0.ɵɵInheritDefinitionFeature] });
1462
+ } }, outputs: { Navigate: "Navigate", Notification: "Notification", RecordSaved: "RecordSaved", RecordRefreshed: "RecordRefreshed", RecordDeleted: "RecordDeleted", RecordSaveFailed: "RecordSaveFailed", RecordDeleteFailed: "RecordDeleteFailed", ValidationFailed: "ValidationFailed", RecordReady: "RecordReady", EditModeChanged: "EditModeChanged", CompositionChanged: "CompositionChanged", SectionRowCountChanged: "SectionRowCountChanged" }, features: [i0.ɵɵInheritDefinitionFeature] });
1193
1463
  }
1194
1464
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BaseFormComponent, [{
1195
1465
  type: Directive
@@ -1211,6 +1481,12 @@ export class BaseFormComponent extends BaseRecordComponent {
1211
1481
  type: Output
1212
1482
  }], RecordReady: [{
1213
1483
  type: Output
1484
+ }], EditModeChanged: [{
1485
+ type: Output
1486
+ }], CompositionChanged: [{
1487
+ type: Output
1488
+ }], SectionRowCountChanged: [{
1489
+ type: Output
1214
1490
  }], collapsiblePanels: [{
1215
1491
  type: ViewChildren,
1216
1492
  args: [MjCollapsiblePanelComponent]