@memberjunction/ng-base-forms 6.2.0-edge.2 → 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 (188) 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 +132 -1
  30. package/dist/lib/base-form-component.d.ts.map +1 -1
  31. package/dist/lib/base-form-component.js +228 -19
  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 +240 -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 +976 -249
  52. package/dist/lib/container/record-form-container.component.js.map +1 -1
  53. package/dist/lib/field/form-field.component.d.ts +17 -0
  54. package/dist/lib/field/form-field.component.d.ts.map +1 -1
  55. package/dist/lib/field/form-field.component.js +41 -5
  56. package/dist/lib/field/form-field.component.js.map +1 -1
  57. package/dist/lib/form-state.service.d.ts +5 -0
  58. package/dist/lib/form-state.service.d.ts.map +1 -1
  59. package/dist/lib/form-state.service.js +6 -1
  60. package/dist/lib/form-state.service.js.map +1 -1
  61. package/dist/lib/host/entity-form-host.component.d.ts +16 -1
  62. package/dist/lib/host/entity-form-host.component.d.ts.map +1 -1
  63. package/dist/lib/host/entity-form-host.component.js +27 -6
  64. package/dist/lib/host/entity-form-host.component.js.map +1 -1
  65. package/dist/lib/interactive-form/form-panel-host-props.builder.d.ts +24 -0
  66. package/dist/lib/interactive-form/form-panel-host-props.builder.d.ts.map +1 -0
  67. package/dist/lib/interactive-form/form-panel-host-props.builder.js +99 -0
  68. package/dist/lib/interactive-form/form-panel-host-props.builder.js.map +1 -0
  69. package/dist/lib/interactive-form/interactive-form-panel.component.d.ts +109 -0
  70. package/dist/lib/interactive-form/interactive-form-panel.component.d.ts.map +1 -0
  71. package/dist/lib/interactive-form/interactive-form-panel.component.js +424 -0
  72. package/dist/lib/interactive-form/interactive-form-panel.component.js.map +1 -0
  73. package/dist/lib/interactive-form/interactive-form.component.d.ts +2 -0
  74. package/dist/lib/interactive-form/interactive-form.component.d.ts.map +1 -1
  75. package/dist/lib/interactive-form/interactive-form.component.js +4 -5
  76. package/dist/lib/interactive-form/interactive-form.component.js.map +1 -1
  77. package/dist/lib/panel/collapsible-panel.component.d.ts +69 -1
  78. package/dist/lib/panel/collapsible-panel.component.d.ts.map +1 -1
  79. package/dist/lib/panel/collapsible-panel.component.js +148 -12
  80. package/dist/lib/panel/collapsible-panel.component.js.map +1 -1
  81. package/dist/lib/panel-manager/form-audience.d.ts +46 -0
  82. package/dist/lib/panel-manager/form-audience.d.ts.map +1 -0
  83. package/dist/lib/panel-manager/form-audience.js +34 -0
  84. package/dist/lib/panel-manager/form-audience.js.map +1 -0
  85. package/dist/lib/panel-manager/form-panel-admin.service.d.ts +150 -0
  86. package/dist/lib/panel-manager/form-panel-admin.service.d.ts.map +1 -0
  87. package/dist/lib/panel-manager/form-panel-admin.service.js +433 -0
  88. package/dist/lib/panel-manager/form-panel-admin.service.js.map +1 -0
  89. package/dist/lib/panel-manager/form-panel-inventory.d.ts +255 -0
  90. package/dist/lib/panel-manager/form-panel-inventory.d.ts.map +1 -0
  91. package/dist/lib/panel-manager/form-panel-inventory.js +293 -0
  92. package/dist/lib/panel-manager/form-panel-inventory.js.map +1 -0
  93. package/dist/lib/panel-manager/panel-manager.component.d.ts +232 -0
  94. package/dist/lib/panel-manager/panel-manager.component.d.ts.map +1 -0
  95. package/dist/lib/panel-manager/panel-manager.component.js +1112 -0
  96. package/dist/lib/panel-manager/panel-manager.component.js.map +1 -0
  97. package/dist/lib/panel-slot/base-contribution-panel.d.ts +40 -0
  98. package/dist/lib/panel-slot/base-contribution-panel.d.ts.map +1 -0
  99. package/dist/lib/panel-slot/base-contribution-panel.js +55 -0
  100. package/dist/lib/panel-slot/base-contribution-panel.js.map +1 -0
  101. package/dist/lib/panel-slot/base-form-panel.d.ts +116 -8
  102. package/dist/lib/panel-slot/base-form-panel.d.ts.map +1 -1
  103. package/dist/lib/panel-slot/base-form-panel.js +76 -5
  104. package/dist/lib/panel-slot/base-form-panel.js.map +1 -1
  105. package/dist/lib/panel-slot/collect-form-contribution-registrations.d.ts +29 -0
  106. package/dist/lib/panel-slot/collect-form-contribution-registrations.d.ts.map +1 -0
  107. package/dist/lib/panel-slot/collect-form-contribution-registrations.js +214 -0
  108. package/dist/lib/panel-slot/collect-form-contribution-registrations.js.map +1 -0
  109. package/dist/lib/panel-slot/collect-form-panel-registrations.d.ts +6 -3
  110. package/dist/lib/panel-slot/collect-form-panel-registrations.d.ts.map +1 -1
  111. package/dist/lib/panel-slot/collect-form-panel-registrations.js +8 -14
  112. package/dist/lib/panel-slot/collect-form-panel-registrations.js.map +1 -1
  113. package/dist/lib/panel-slot/form-contribution.d.ts +170 -7
  114. package/dist/lib/panel-slot/form-contribution.d.ts.map +1 -1
  115. package/dist/lib/panel-slot/form-contribution.js +242 -64
  116. package/dist/lib/panel-slot/form-contribution.js.map +1 -1
  117. package/dist/lib/panel-slot/form-contributions.component.d.ts +16 -5
  118. package/dist/lib/panel-slot/form-contributions.component.d.ts.map +1 -1
  119. package/dist/lib/panel-slot/form-contributions.component.js +43 -7
  120. package/dist/lib/panel-slot/form-contributions.component.js.map +1 -1
  121. package/dist/lib/panel-slot/form-field-panel-slot.component.d.ts +66 -0
  122. package/dist/lib/panel-slot/form-field-panel-slot.component.d.ts.map +1 -0
  123. package/dist/lib/panel-slot/form-field-panel-slot.component.js +190 -0
  124. package/dist/lib/panel-slot/form-field-panel-slot.component.js.map +1 -0
  125. package/dist/lib/panel-slot/form-panel-slot.component.d.ts +52 -16
  126. package/dist/lib/panel-slot/form-panel-slot.component.d.ts.map +1 -1
  127. package/dist/lib/panel-slot/form-panel-slot.component.js +190 -66
  128. package/dist/lib/panel-slot/form-panel-slot.component.js.map +1 -1
  129. package/dist/lib/panel-slot/form-slot-coordinator.service.d.ts +11 -0
  130. package/dist/lib/panel-slot/form-slot-coordinator.service.d.ts.map +1 -1
  131. package/dist/lib/panel-slot/form-slot-coordinator.service.js +17 -0
  132. package/dist/lib/panel-slot/form-slot-coordinator.service.js.map +1 -1
  133. package/dist/lib/panel-slot/merge-panel-validation.d.ts +7 -0
  134. package/dist/lib/panel-slot/merge-panel-validation.d.ts.map +1 -0
  135. package/dist/lib/panel-slot/merge-panel-validation.js +16 -0
  136. package/dist/lib/panel-slot/merge-panel-validation.js.map +1 -0
  137. package/dist/lib/panel-slot/mount-form-contribution.d.ts +15 -0
  138. package/dist/lib/panel-slot/mount-form-contribution.d.ts.map +1 -0
  139. package/dist/lib/panel-slot/mount-form-contribution.js +37 -0
  140. package/dist/lib/panel-slot/mount-form-contribution.js.map +1 -0
  141. package/dist/lib/panel-slot/panel-hides.d.ts +35 -0
  142. package/dist/lib/panel-slot/panel-hides.d.ts.map +1 -0
  143. package/dist/lib/panel-slot/panel-hides.js +111 -0
  144. package/dist/lib/panel-slot/panel-hides.js.map +1 -0
  145. package/dist/lib/panel-slot/placement-preview-panel.component.d.ts +16 -0
  146. package/dist/lib/panel-slot/placement-preview-panel.component.d.ts.map +1 -0
  147. package/dist/lib/panel-slot/placement-preview-panel.component.js +112 -0
  148. package/dist/lib/panel-slot/placement-preview-panel.component.js.map +1 -0
  149. package/dist/lib/panel-slot/placement-preview.d.ts +57 -0
  150. package/dist/lib/panel-slot/placement-preview.d.ts.map +1 -0
  151. package/dist/lib/panel-slot/placement-preview.js +86 -0
  152. package/dist/lib/panel-slot/placement-preview.js.map +1 -0
  153. package/dist/lib/panel-slot/related-entity-grid-panel.component.d.ts +2 -0
  154. package/dist/lib/panel-slot/related-entity-grid-panel.component.d.ts.map +1 -1
  155. package/dist/lib/panel-slot/related-entity-grid-panel.component.js +10 -3
  156. package/dist/lib/panel-slot/related-entity-grid-panel.component.js.map +1 -1
  157. package/dist/lib/panel-slot/slot-order.d.ts +19 -0
  158. package/dist/lib/panel-slot/slot-order.d.ts.map +1 -0
  159. package/dist/lib/panel-slot/slot-order.js +53 -0
  160. package/dist/lib/panel-slot/slot-order.js.map +1 -0
  161. package/dist/lib/resolver/form-resolver.service.d.ts +4 -2
  162. package/dist/lib/resolver/form-resolver.service.d.ts.map +1 -1
  163. package/dist/lib/resolver/form-resolver.service.js +18 -8
  164. package/dist/lib/resolver/form-resolver.service.js.map +1 -1
  165. package/dist/lib/resolver/form-variants.d.ts +28 -0
  166. package/dist/lib/resolver/form-variants.d.ts.map +1 -0
  167. package/dist/lib/resolver/form-variants.js +40 -0
  168. package/dist/lib/resolver/form-variants.js.map +1 -0
  169. package/dist/lib/section-counts/form-section-counts.d.ts +99 -0
  170. package/dist/lib/section-counts/form-section-counts.d.ts.map +1 -0
  171. package/dist/lib/section-counts/form-section-counts.js +223 -0
  172. package/dist/lib/section-counts/form-section-counts.js.map +1 -0
  173. package/dist/lib/toolbar/form-toolbar.component.d.ts +7 -0
  174. package/dist/lib/toolbar/form-toolbar.component.d.ts.map +1 -1
  175. package/dist/lib/toolbar/form-toolbar.component.js +194 -128
  176. package/dist/lib/toolbar/form-toolbar.component.js.map +1 -1
  177. package/dist/lib/types/form-types.d.ts +8 -0
  178. package/dist/lib/types/form-types.d.ts.map +1 -1
  179. package/dist/lib/types/form-types.js.map +1 -1
  180. package/dist/module.d.ts +29 -23
  181. package/dist/module.d.ts.map +1 -1
  182. package/dist/module.js +43 -5
  183. package/dist/module.js.map +1 -1
  184. package/dist/public-api.d.ts +20 -0
  185. package/dist/public-api.d.ts.map +1 -1
  186. package/dist/public-api.js +21 -0
  187. package/dist/public-api.js.map +1 -1
  188. package/package.json +20 -20
@@ -0,0 +1,86 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { Subject } from 'rxjs';
3
+ import { UUIDsEqual } from '@memberjunction/global';
4
+ import { ContributionSpecToRegistration, ResolveContributionKey } from './form-contribution';
5
+ /**
6
+ * A panel the placement dialog shows on a real form before anything is saved.
7
+ *
8
+ * The dialog provides one of these to the form it renders as its preview. Every place that
9
+ * collects a form's contributions adds this registration, so the form itself decides where the
10
+ * panel draws, what it hides and what rail item it gets. A form outside the preview has no
11
+ * provider, so nothing else ever sees it.
12
+ */
13
+ export class FormPlacementPreview {
14
+ changed = new Subject();
15
+ registration = null;
16
+ replacesRowID = null;
17
+ /** Emits after the previewed panel changes, so mounted slots can redraw. */
18
+ get Changed$() {
19
+ return this.changed.asObservable();
20
+ }
21
+ /** The previewed panel, or null when there is none. */
22
+ get Registration() {
23
+ return this.registration;
24
+ }
25
+ /** The saved row this panel is an edit of. That row is left off the preview form. */
26
+ get ReplacesRowID() {
27
+ return this.replacesRowID;
28
+ }
29
+ /**
30
+ * Shows `spec` on the preview form, or nothing when it is null. With a `component` the
31
+ * panel draws that component; without one it draws a placeholder.
32
+ */
33
+ Show(entityName, spec, replacesRowID = null, component = null) {
34
+ this.registration = spec ? PlacementPreviewRegistration(entityName, spec, component) : null;
35
+ this.replacesRowID = replacesRowID;
36
+ this.changed.next();
37
+ }
38
+ }
39
+ /** Provided by the placement dialog's preview. Absent everywhere else. */
40
+ export const FORM_PLACEMENT_PREVIEW = new InjectionToken('FormPlacementPreview');
41
+ /** The key a preview uses when the spec names none, so its panel still has a stable identity. */
42
+ export const PLACEMENT_PREVIEW_KEY = 'placement-preview';
43
+ /**
44
+ * The previewed spec as a registration.
45
+ *
46
+ * Ranked 0, like a new row: {@link WithPlacementPreview} already drops whatever it replaces, so
47
+ * it competes with nothing, and on a `SortKey` tie it draws after the panels already there, as
48
+ * the saved row will. A spec with no key of its own takes the derived one, or
49
+ * {@link PLACEMENT_PREVIEW_KEY}.
50
+ */
51
+ export function PlacementPreviewRegistration(entityName, spec, component = null) {
52
+ const registration = ContributionSpecToRegistration(entityName, spec, component?.ComponentID ?? undefined);
53
+ registration.Metadata.contributionKey = ResolveContributionKey(registration.Metadata) || PLACEMENT_PREVIEW_KEY;
54
+ registration.IsPreview = true;
55
+ if (component?.Spec)
56
+ registration.ComponentSpec = component.Spec;
57
+ return registration;
58
+ }
59
+ const merged = new WeakMap();
60
+ /**
61
+ * `base` with the previewed panel added.
62
+ *
63
+ * A registration under the same key is dropped, as is the row being edited, so the preview
64
+ * shows the panel that would be saved and not the one it replaces. The result is memoized per
65
+ * (registration, base list), because the form reads this on every change-detection pass and
66
+ * compares lists by identity.
67
+ */
68
+ export function WithPlacementPreview(base, preview) {
69
+ const reg = preview?.Registration;
70
+ if (!reg)
71
+ return base;
72
+ const replacesRowID = preview.ReplacesRowID;
73
+ const hit = merged.get(reg);
74
+ if (hit && hit.Base === base && hit.ReplacesRowID === replacesRowID)
75
+ return hit.List;
76
+ const key = ResolveContributionKey(reg.Metadata);
77
+ const kept = base.filter((other) => {
78
+ if (replacesRowID && other.RowID && UUIDsEqual(other.RowID, replacesRowID))
79
+ return false;
80
+ return ResolveContributionKey(other.Metadata) !== key;
81
+ });
82
+ const list = [...kept, reg];
83
+ merged.set(reg, { Base: base, ReplacesRowID: replacesRowID, List: list });
84
+ return list;
85
+ }
86
+ //# sourceMappingURL=placement-preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placement-preview.js","sourceRoot":"","sources":["../../../src/lib/panel-slot/placement-preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAm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IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { Subject, type Observable } from 'rxjs';\nimport type { FormContributionSpec } from '@memberjunction/interactive-component-types/forms';\nimport type { ComponentSpec } from '@memberjunction/interactive-component-types';\nimport { UUIDsEqual } from '@memberjunction/global';\nimport { ContributionSpecToRegistration, ResolveContributionKey, type FormContributionRegistration } from './form-contribution';\n\n/**\n * A panel the placement dialog shows on a real form before anything is saved.\n *\n * The dialog provides one of these to the form it renders as its preview. Every place that\n * collects a form's contributions adds this registration, so the form itself decides where the\n * panel draws, what it hides and what rail item it gets. A form outside the preview has no\n * provider, so nothing else ever sees it.\n */\nexport class FormPlacementPreview {\n private readonly changed = new Subject<void>();\n private registration: FormContributionRegistration | null = null;\n private replacesRowID: string | null = null;\n\n /** Emits after the previewed panel changes, so mounted slots can redraw. */\n public get Changed$(): Observable<void> {\n return this.changed.asObservable();\n }\n\n /** The previewed panel, or null when there is none. */\n public get Registration(): FormContributionRegistration | null {\n return this.registration;\n }\n\n /** The saved row this panel is an edit of. That row is left off the preview form. */\n public get ReplacesRowID(): string | null {\n return this.replacesRowID;\n }\n\n /**\n * Shows `spec` on the preview form, or nothing when it is null. With a `component` the\n * panel draws that component; without one it draws a placeholder.\n */\n public Show(\n entityName: string,\n spec: FormContributionSpec | null,\n replacesRowID: string | null = null,\n component: PlacementPreviewComponent | null = null,\n ): void {\n this.registration = spec ? PlacementPreviewRegistration(entityName, spec, component) : null;\n this.replacesRowID = replacesRowID;\n this.changed.next();\n }\n}\n\n/** The component the previewed panel draws: a spec not saved yet, or a saved component's ID. */\nexport interface PlacementPreviewComponent {\n Spec?: ComponentSpec | null;\n ComponentID?: string | null;\n}\n\n/** Provided by the placement dialog's preview. Absent everywhere else. */\nexport const FORM_PLACEMENT_PREVIEW = new InjectionToken<FormPlacementPreview>('FormPlacementPreview');\n\n/** The key a preview uses when the spec names none, so its panel still has a stable identity. */\nexport const PLACEMENT_PREVIEW_KEY = 'placement-preview';\n\n/**\n * The previewed spec as a registration.\n *\n * Ranked 0, like a new row: {@link WithPlacementPreview} already drops whatever it replaces, so\n * it competes with nothing, and on a `SortKey` tie it draws after the panels already there, as\n * the saved row will. A spec with no key of its own takes the derived one, or\n * {@link PLACEMENT_PREVIEW_KEY}.\n */\nexport function PlacementPreviewRegistration(\n entityName: string,\n spec: FormContributionSpec,\n component: PlacementPreviewComponent | null = null,\n): FormContributionRegistration {\n const registration = ContributionSpecToRegistration(entityName, spec, component?.ComponentID ?? undefined);\n registration.Metadata.contributionKey = ResolveContributionKey(registration.Metadata) || PLACEMENT_PREVIEW_KEY;\n registration.IsPreview = true;\n if (component?.Spec) registration.ComponentSpec = component.Spec;\n return registration;\n}\n\nconst merged = new WeakMap<FormContributionRegistration, { Base: readonly FormContributionRegistration[]; ReplacesRowID: string | null; List: FormContributionRegistration[] }>();\n\n/**\n * `base` with the previewed panel added.\n *\n * A registration under the same key is dropped, as is the row being edited, so the preview\n * shows the panel that would be saved and not the one it replaces. The result is memoized per\n * (registration, base list), because the form reads this on every change-detection pass and\n * compares lists by identity.\n */\nexport function WithPlacementPreview(\n base: FormContributionRegistration[],\n preview: FormPlacementPreview | null | undefined,\n): FormContributionRegistration[] {\n const reg = preview?.Registration;\n if (!reg) return base;\n const replacesRowID = preview!.ReplacesRowID;\n const hit = merged.get(reg);\n if (hit && hit.Base === base && hit.ReplacesRowID === replacesRowID) return hit.List;\n\n const key = ResolveContributionKey(reg.Metadata);\n const kept = base.filter((other) => {\n if (replacesRowID && other.RowID && UUIDsEqual(other.RowID, replacesRowID)) return false;\n return ResolveContributionKey(other.Metadata) !== key;\n });\n const list = [...kept, reg];\n merged.set(reg, { Base: base, ReplacesRowID: replacesRowID, List: list });\n return list;\n}\n"]}
@@ -10,6 +10,8 @@ import * as i0 from "@angular/core";
10
10
  * registered panel. Mirrors the CodeGen EntityDataGrid template.
11
11
  */
12
12
  export declare class RelatedEntityGridPanelComponent {
13
+ /** Sits with the related grids rather than after the field sections. */
14
+ get DisplayOrder(): number;
13
15
  Contribution: FormContributionWinner;
14
16
  Record: BaseEntity;
15
17
  FormComponent: BaseFormComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"related-entity-grid-panel.component.d.ts","sourceRoot":"","sources":["../../../src/lib/panel-slot/related-entity-grid-panel.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;;AAElE;;;;GAIG;AACH,qBA0Ba,+BAA+B;IAC/B,YAAY,EAAG,sBAAsB,CAAC;IACtC,MAAM,EAAG,UAAU,CAAC;IACpB,aAAa,EAAG,iBAAiB,CAAC;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;IAE5B,UAAU,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAItD,0CAA0C;IACnC,UAAU,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAItD,IAAW,QAAQ,IAAI,MAAM,CAK5B;yCApBQ,+BAA+B;2CAA/B,+BAA+B;CAqB3C"}
1
+ {"version":3,"file":"related-entity-grid-panel.component.d.ts","sourceRoot":"","sources":["../../../src/lib/panel-slot/related-entity-grid-panel.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;;AAGlE;;;;GAIG;AACH,qBA4Ba,+BAA+B;IACxC,wEAAwE;IACxE,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEQ,YAAY,EAAG,sBAAsB,CAAC;IACtC,MAAM,EAAG,UAAU,CAAC;IACpB,aAAa,EAAG,iBAAiB,CAAC;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;IAE5B,UAAU,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAItD,0CAA0C;IACnC,UAAU,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAItD,IAAW,QAAQ,IAAI,MAAM,CAK5B;yCAzBQ,+BAA+B;2CAA/B,+BAA+B;CA0B3C"}
@@ -1,4 +1,5 @@
1
1
  import { Component, Input } from '@angular/core';
2
+ import { SlotDisplayOrder } from './slot-order';
2
3
  import * as i0 from "@angular/core";
3
4
  import * as i1 from "../panel/collapsible-panel.component";
4
5
  import * as i2 from "../explorer-entity-data-grid.component";
@@ -17,6 +18,10 @@ function RelatedEntityGridPanelComponent_Conditional_1_Template(rf, ctx) { if (r
17
18
  * registered panel. Mirrors the CodeGen EntityDataGrid template.
18
19
  */
19
20
  export class RelatedEntityGridPanelComponent {
21
+ /** Sits with the related grids rather than after the field sections. */
22
+ get DisplayOrder() {
23
+ return SlotDisplayOrder('after-related', this.Contribution.SortKey ?? 0);
24
+ }
20
25
  Contribution;
21
26
  Record;
22
27
  FormComponent;
@@ -36,12 +41,12 @@ export class RelatedEntityGridPanelComponent {
36
41
  return icon || 'fa fa-table';
37
42
  }
38
43
  static ɵfac = function RelatedEntityGridPanelComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || RelatedEntityGridPanelComponent)(); };
39
- static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: RelatedEntityGridPanelComponent, selectors: [["mj-related-entity-grid-panel"]], inputs: { Contribution: "Contribution", Record: "Record", FormComponent: "FormComponent", FormContext: "FormContext" }, standalone: false, decls: 2, vars: 7, consts: [["Variant", "related-entity", 3, "SectionKey", "SectionName", "Icon", "Form", "FormContext", "DefaultExpanded"], [3, "Params", "NewRecordValues", "AllowLoad", "ShowToolbar"], [3, "Navigate", "AfterDataLoad", "Params", "NewRecordValues", "AllowLoad", "ShowToolbar"]], template: function RelatedEntityGridPanelComponent_Template(rf, ctx) { if (rf & 1) {
44
+ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: RelatedEntityGridPanelComponent, selectors: [["mj-related-entity-grid-panel"]], inputs: { Contribution: "Contribution", Record: "Record", FormComponent: "FormComponent", FormContext: "FormContext" }, standalone: false, decls: 2, vars: 9, consts: [["Variant", "related-entity", 3, "SectionKey", "Order", "SectionName", "Icon", "Form", "FormContext", "BadgeCount", "DefaultExpanded"], [3, "Params", "NewRecordValues", "AllowLoad", "ShowToolbar"], [3, "Navigate", "AfterDataLoad", "Params", "NewRecordValues", "AllowLoad", "ShowToolbar"]], template: function RelatedEntityGridPanelComponent_Template(rf, ctx) { if (rf & 1) {
40
45
  i0.ɵɵelementStart(0, "mj-collapsible-panel", 0);
41
46
  i0.ɵɵconditionalCreate(1, RelatedEntityGridPanelComponent_Conditional_1_Template, 1, 4, "mj-explorer-entity-data-grid", 1);
42
47
  i0.ɵɵelementEnd();
43
48
  } if (rf & 2) {
44
- i0.ɵɵproperty("SectionKey", ctx.Contribution.BakedSectionKey)("SectionName", ctx.Contribution.DisplayName)("Icon", ctx.GridIcon)("Form", ctx.FormComponent)("FormContext", ctx.FormContext)("DefaultExpanded", false);
49
+ i0.ɵɵproperty("SectionKey", ctx.Contribution.BakedSectionKey)("Order", ctx.DisplayOrder)("SectionName", ctx.Contribution.DisplayName)("Icon", ctx.GridIcon)("Form", ctx.FormComponent)("FormContext", ctx.FormContext)("BadgeCount", ctx.FormComponent.GetSectionRowCount(ctx.Contribution.BakedSectionKey))("DefaultExpanded", false);
45
50
  i0.ɵɵadvance();
46
51
  i0.ɵɵconditional(ctx.Record.IsSaved ? 1 : -1);
47
52
  } }, dependencies: [i1.MjCollapsiblePanelComponent, i2.ExplorerEntityDataGridComponent], styles: ["[_nghost-%COMP%] { display: contents; }"] });
@@ -51,11 +56,13 @@ export class RelatedEntityGridPanelComponent {
51
56
  args: [{ standalone: false, selector: 'mj-related-entity-grid-panel', template: `
52
57
  <mj-collapsible-panel
53
58
  [SectionKey]="Contribution.BakedSectionKey"
59
+ [Order]="DisplayOrder"
54
60
  [SectionName]="Contribution.DisplayName"
55
61
  [Icon]="GridIcon"
56
62
  Variant="related-entity"
57
63
  [Form]="FormComponent"
58
64
  [FormContext]="FormContext"
65
+ [BadgeCount]="FormComponent.GetSectionRowCount(Contribution.BakedSectionKey)"
59
66
  [DefaultExpanded]="false">
60
67
  @if (Record.IsSaved) {
61
68
  <mj-explorer-entity-data-grid
@@ -78,5 +85,5 @@ export class RelatedEntityGridPanelComponent {
78
85
  }], FormContext: [{
79
86
  type: Input
80
87
  }] }); })();
81
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(RelatedEntityGridPanelComponent, { className: "RelatedEntityGridPanelComponent", filePath: "src/lib/panel-slot/related-entity-grid-panel.component.ts", lineNumber: 39 }); })();
88
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(RelatedEntityGridPanelComponent, { className: "RelatedEntityGridPanelComponent", filePath: "src/lib/panel-slot/related-entity-grid-panel.component.ts", lineNumber: 42 }); })();
82
89
  //# sourceMappingURL=related-entity-grid-panel.component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"related-entity-grid-panel.component.js","sourceRoot":"","sources":["../../../src/lib/panel-slot/related-entity-grid-panel.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;;;;;;IAyBjC,uDAMyC;IAArC,AADA,qOAAY,2CAAoC,KAAC,kOAChC,yBAAkB,KAAC;IACxC,iBAA+B;;;IAH3B,AADA,AADA,AADA,8JAA4H,kIACf,0FAClC,qBACvD;;AAtBxC;;;;GAIG;AA2BH,MAAM,OAAO,+BAA+B;IAC/B,YAAY,CAA0B;IACtC,MAAM,CAAc;IACpB,aAAa,CAAqB;IAClC,WAAW,CAAe;IAE5B,UAAU,CAAC,KAA6B;QAC3C,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAClG,CAAC;IAED,0CAA0C;IACnC,UAAU,CAAC,KAA6B;QAC3C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAW,QAAQ;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;QAC7C,IAAI,CAAC,IAAI;YAAE,OAAO,aAAa,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/E,OAAO,IAAI,IAAI,aAAa,CAAC;IACjC,CAAC;yHApBQ,+BAA+B;6DAA/B,+BAA+B;YAtBpC,+CAO8B;YAC1B,0HAAsB;YAU1B,iBAAuB;;YAXnB,AADA,AADA,AAFA,AADA,AADA,6DAA2C,6CACH,sBACvB,2BAEK,gCACK,0BACF;YACzB,cASC;YATD,6CASC;;;iFAKA,+BAA+B;cA1B3C,SAAS;6BACM,KAAK,YACP,8BAA8B,YAC9B;;;;;;;;;;;;;;;;;;;;KAoBT;;kBAIA,KAAK;;kBACL,KAAK;;kBACL,KAAK;;kBACL,KAAK;;kFAJG,+BAA+B","sourcesContent":["import { Component, Input } from '@angular/core';\nimport { BaseEntity } from '@memberjunction/core';\nimport type { AfterDataLoadEventArgs } from '@memberjunction/ng-entity-viewer';\nimport { BaseFormComponent } from '../base-form-component';\nimport { FormContext } from '../types/form-types';\nimport type { FormContributionWinner } from './form-contribution';\n\n/**\n * Stock related-entity grid the composer mounts when a DisplayInForm\n * relationship is neither baked into the form template nor claimed by a\n * registered panel. Mirrors the CodeGen EntityDataGrid template.\n */\n@Component({\n standalone: false,\n selector: 'mj-related-entity-grid-panel',\n template: `\n <mj-collapsible-panel\n [SectionKey]=\"Contribution.BakedSectionKey\"\n [SectionName]=\"Contribution.DisplayName\"\n [Icon]=\"GridIcon\"\n Variant=\"related-entity\"\n [Form]=\"FormComponent\"\n [FormContext]=\"FormContext\"\n [DefaultExpanded]=\"false\">\n @if (Record.IsSaved) {\n <mj-explorer-entity-data-grid\n [Params]=\"FormComponent.BuildRelationshipViewParamsByEntityName(Contribution.RelatedEntity!, Contribution.RelatedJoinField)\"\n [NewRecordValues]=\"FormComponent.NewRecordValues(Contribution.RelatedEntity!, Contribution.RelatedJoinField)\"\n [AllowLoad]=\"FormComponent.IsSectionExpanded(Contribution.BakedSectionKey)\"\n [ShowToolbar]=\"true\"\n (Navigate)=\"FormComponent.OnFormNavigate($event)\"\n (AfterDataLoad)=\"onDataLoad($event)\">\n </mj-explorer-entity-data-grid>\n }\n </mj-collapsible-panel>\n `,\n styles: [`:host { display: contents; }`],\n})\nexport class RelatedEntityGridPanelComponent {\n @Input() Contribution!: FormContributionWinner;\n @Input() Record!: BaseEntity;\n @Input() FormComponent!: BaseFormComponent;\n @Input() FormContext?: FormContext;\n\n public OnDataLoad(event: AfterDataLoadEventArgs): void {\n this.FormComponent.SetSectionRowCount(this.Contribution.BakedSectionKey, event.totalRowCount);\n }\n\n /** @deprecated Use {@link OnDataLoad}. */\n public onDataLoad(event: AfterDataLoadEventArgs): void {\n return this.OnDataLoad(event);\n }\n\n public get GridIcon(): string {\n const name = this.Contribution.RelatedEntity;\n if (!name) return 'fa fa-table';\n const icon = this.FormComponent.ProviderToUse.EntityByName(name)?.Icon?.trim();\n return icon || 'fa fa-table';\n }\n}\n"]}
1
+ {"version":3,"file":"related-entity-grid-panel.component.js","sourceRoot":"","sources":["../../../src/lib/panel-slot/related-entity-grid-panel.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAMjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;;;;;;IAsBhC,uDAMyC;IAArC,AADA,qOAAY,2CAAoC,KAAC,kOAChC,yBAAkB,KAAC;IACxC,iBAA+B;;;IAH3B,AADA,AADA,AADA,8JAA4H,kIACf,0FAClC,qBACvD;;AAxBxC;;;;GAIG;AA6BH,MAAM,OAAO,+BAA+B;IACxC,wEAAwE;IACxE,IAAW,YAAY;QACnB,OAAO,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;IAC7E,CAAC;IAEQ,YAAY,CAA0B;IACtC,MAAM,CAAc;IACpB,aAAa,CAAqB;IAClC,WAAW,CAAe;IAE5B,UAAU,CAAC,KAA6B;QAC3C,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAClG,CAAC;IAED,0CAA0C;IACnC,UAAU,CAAC,KAA6B;QAC3C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAW,QAAQ;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;QAC7C,IAAI,CAAC,IAAI;YAAE,OAAO,aAAa,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/E,OAAO,IAAI,IAAI,aAAa,CAAC;IACjC,CAAC;yHAzBQ,+BAA+B;6DAA/B,+BAA+B;YAxBpC,+CAS8B;YAC1B,0HAAsB;YAU1B,iBAAuB;;YAXnB,AADA,AADA,AADA,AAFA,AADA,AADA,AADA,6DAA2C,2BACrB,6CACkB,sBACvB,2BAEK,gCACK,sFACkD,0BACpD;YACzB,cASC;YATD,6CASC;;;iFAKA,+BAA+B;cA5B3C,SAAS;6BACM,KAAK,YACP,8BAA8B,YAC9B;;;;;;;;;;;;;;;;;;;;;;KAsBT;;kBASA,KAAK;;kBACL,KAAK;;kBACL,KAAK;;kBACL,KAAK;;kFATG,+BAA+B","sourcesContent":["import { Component, Input } from '@angular/core';\nimport { BaseEntity } from '@memberjunction/core';\nimport type { AfterDataLoadEventArgs } from '@memberjunction/ng-entity-viewer';\nimport { BaseFormComponent } from '../base-form-component';\nimport { FormContext } from '../types/form-types';\nimport type { FormContributionWinner } from './form-contribution';\nimport { SlotDisplayOrder } from './slot-order';\n\n/**\n * Stock related-entity grid the composer mounts when a DisplayInForm\n * relationship is neither baked into the form template nor claimed by a\n * registered panel. Mirrors the CodeGen EntityDataGrid template.\n */\n@Component({\n standalone: false,\n selector: 'mj-related-entity-grid-panel',\n template: `\n <mj-collapsible-panel\n [SectionKey]=\"Contribution.BakedSectionKey\"\n [Order]=\"DisplayOrder\"\n [SectionName]=\"Contribution.DisplayName\"\n [Icon]=\"GridIcon\"\n Variant=\"related-entity\"\n [Form]=\"FormComponent\"\n [FormContext]=\"FormContext\"\n [BadgeCount]=\"FormComponent.GetSectionRowCount(Contribution.BakedSectionKey)\"\n [DefaultExpanded]=\"false\">\n @if (Record.IsSaved) {\n <mj-explorer-entity-data-grid\n [Params]=\"FormComponent.BuildRelationshipViewParamsByEntityName(Contribution.RelatedEntity!, Contribution.RelatedJoinField)\"\n [NewRecordValues]=\"FormComponent.NewRecordValues(Contribution.RelatedEntity!, Contribution.RelatedJoinField)\"\n [AllowLoad]=\"FormComponent.IsSectionExpanded(Contribution.BakedSectionKey)\"\n [ShowToolbar]=\"true\"\n (Navigate)=\"FormComponent.OnFormNavigate($event)\"\n (AfterDataLoad)=\"onDataLoad($event)\">\n </mj-explorer-entity-data-grid>\n }\n </mj-collapsible-panel>\n `,\n styles: [`:host { display: contents; }`],\n})\nexport class RelatedEntityGridPanelComponent {\n /** Sits with the related grids rather than after the field sections. */\n public get DisplayOrder(): number {\n return SlotDisplayOrder('after-related', this.Contribution.SortKey ?? 0);\n }\n\n @Input() Contribution!: FormContributionWinner;\n @Input() Record!: BaseEntity;\n @Input() FormComponent!: BaseFormComponent;\n @Input() FormContext?: FormContext;\n\n public OnDataLoad(event: AfterDataLoadEventArgs): void {\n this.FormComponent.SetSectionRowCount(this.Contribution.BakedSectionKey, event.totalRowCount);\n }\n\n /** @deprecated Use {@link OnDataLoad}. */\n public onDataLoad(event: AfterDataLoadEventArgs): void {\n return this.OnDataLoad(event);\n }\n\n public get GridIcon(): string {\n const name = this.Contribution.RelatedEntity;\n if (!name) return 'fa fa-table';\n const icon = this.FormComponent.ProviderToUse.EntityByName(name)?.Icon?.trim();\n return icon || 'fa fa-table';\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { FormPanelSlot } from './base-form-panel';
2
+ /** The band for `slot`, offset within it by `sortKey` so higher sort keys render earlier. */
3
+ export declare function SlotDisplayOrder(slot: FormPanelSlot, sortKey?: number): number;
4
+ /** Slots that sit between the form's own blocks, so their place is read off the page. */
5
+ export declare const ANCHORED_SLOTS: ReadonlySet<FormPanelSlot>;
6
+ /**
7
+ * The section a slot sits next to on the page: the first section after it, else the last
8
+ * section before it. Null when the slot's column holds no section.
9
+ *
10
+ * Related grids take places in the form's section order just as field sections do, so no fixed
11
+ * band lands between the last field and the first grid on every form. Taking the order of the
12
+ * neighbouring section does: equal orders keep page order, so a panel anchored `before` a
13
+ * section draws just above it, and one anchored `after` draws just below.
14
+ */
15
+ export declare function SlotAnchorSectionKey(slotElement: Element): {
16
+ Key: string;
17
+ Side: 'before' | 'after';
18
+ } | null;
19
+ //# sourceMappingURL=slot-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot-order.d.ts","sourceRoot":"","sources":["../../../src/lib/panel-slot/slot-order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAuBvD,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,SAAI,GAAG,MAAM,CAEzE;AAED,yFAAyF;AACzF,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,aAAa,CAA8E,CAAC;AAErI;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,OAAO,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,GAAG,IAAI,CAK3G"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Flex order for a panel mounted in a slot.
3
+ *
4
+ * A form lays its panels out in one flex column and sequences them with CSS `order`, taken
5
+ * from the form's section order. A contribution's key is not in that list, so
6
+ * `getSectionDisplayOrder` falls back to the section count — the highest order on the form —
7
+ * and the panel renders last however early its slot sits in the document.
8
+ *
9
+ * These bands restore the document meaning of a slot. Field sections occupy 0..n, so the
10
+ * slots above them are negative and the slots below start far past any realistic section
11
+ * count. `sortKey` orders panels sharing one slot, higher first, matching how the slot host
12
+ * sorts them.
13
+ */
14
+ const SLOT_BANDS = {
15
+ 'top-area': -2_000_000,
16
+ 'before-fields': -1_000_000,
17
+ 'after-fields': 1_000_000,
18
+ 'after-related': 2_000_000,
19
+ 'after-everything': 3_000_000,
20
+ };
21
+ /** The band for `slot`, offset within it by `sortKey` so higher sort keys render earlier. */
22
+ export function SlotDisplayOrder(slot, sortKey = 0) {
23
+ return (SLOT_BANDS[slot] ?? SLOT_BANDS['after-everything']) - sortKey;
24
+ }
25
+ /** Slots that sit between the form's own blocks, so their place is read off the page. */
26
+ export const ANCHORED_SLOTS = new Set(['before-fields', 'after-fields', 'after-related']);
27
+ /**
28
+ * The section a slot sits next to on the page: the first section after it, else the last
29
+ * section before it. Null when the slot's column holds no section.
30
+ *
31
+ * Related grids take places in the form's section order just as field sections do, so no fixed
32
+ * band lands between the last field and the first grid on every form. Taking the order of the
33
+ * neighbouring section does: equal orders keep page order, so a panel anchored `before` a
34
+ * section draws just above it, and one anchored `after` draws just below.
35
+ */
36
+ export function SlotAnchorSectionKey(slotElement) {
37
+ const after = neighbourSection(slotElement, 'next');
38
+ if (after)
39
+ return { Key: after, Side: 'before' };
40
+ const before = neighbourSection(slotElement, 'previous');
41
+ return before ? { Key: before, Side: 'after' } : null;
42
+ }
43
+ function neighbourSection(from, direction) {
44
+ let node = direction === 'next' ? from.nextElementSibling : from.previousElementSibling;
45
+ while (node) {
46
+ const key = node.matches('mj-collapsible-panel') ? node.getAttribute('data-section-key')?.trim() : '';
47
+ if (key)
48
+ return key;
49
+ node = direction === 'next' ? node.nextElementSibling : node.previousElementSibling;
50
+ }
51
+ return null;
52
+ }
53
+ //# sourceMappingURL=slot-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot-order.js","sourceRoot":"","sources":["../../../src/lib/panel-slot/slot-order.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,GAAkC;IAC9C,UAAU,EAAE,CAAC,SAAS;IACtB,eAAe,EAAE,CAAC,SAAS;IAC3B,cAAc,EAAE,SAAS;IACzB,eAAe,EAAE,SAAS;IAC1B,kBAAkB,EAAE,SAAS;CAChC,CAAC;AAEF,6FAA6F;AAC7F,MAAM,UAAU,gBAAgB,CAAC,IAAmB,EAAE,OAAO,GAAG,CAAC;IAC7D,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAAC,GAAG,OAAO,CAAC;AAC1E,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAA+B,IAAI,GAAG,CAAgB,CAAC,eAAe,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;AAErI;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAoB;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACpD,IAAI,KAAK;QAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAa,EAAE,SAA8B;IACnE,IAAI,IAAI,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC;IACxF,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtG,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;QACpB,IAAI,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC;IACxF,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import type { FormPanelSlot } from './base-form-panel';\n\n/**\n * Flex order for a panel mounted in a slot.\n *\n * A form lays its panels out in one flex column and sequences them with CSS `order`, taken\n * from the form's section order. A contribution's key is not in that list, so\n * `getSectionDisplayOrder` falls back to the section count — the highest order on the form —\n * and the panel renders last however early its slot sits in the document.\n *\n * These bands restore the document meaning of a slot. Field sections occupy 0..n, so the\n * slots above them are negative and the slots below start far past any realistic section\n * count. `sortKey` orders panels sharing one slot, higher first, matching how the slot host\n * sorts them.\n */\nconst SLOT_BANDS: Record<FormPanelSlot, number> = {\n 'top-area': -2_000_000,\n 'before-fields': -1_000_000,\n 'after-fields': 1_000_000,\n 'after-related': 2_000_000,\n 'after-everything': 3_000_000,\n};\n\n/** The band for `slot`, offset within it by `sortKey` so higher sort keys render earlier. */\nexport function SlotDisplayOrder(slot: FormPanelSlot, sortKey = 0): number {\n return (SLOT_BANDS[slot] ?? SLOT_BANDS['after-everything']) - sortKey;\n}\n\n/** Slots that sit between the form's own blocks, so their place is read off the page. */\nexport const ANCHORED_SLOTS: ReadonlySet<FormPanelSlot> = new Set<FormPanelSlot>(['before-fields', 'after-fields', 'after-related']);\n\n/**\n * The section a slot sits next to on the page: the first section after it, else the last\n * section before it. Null when the slot's column holds no section.\n *\n * Related grids take places in the form's section order just as field sections do, so no fixed\n * band lands between the last field and the first grid on every form. Taking the order of the\n * neighbouring section does: equal orders keep page order, so a panel anchored `before` a\n * section draws just above it, and one anchored `after` draws just below.\n */\nexport function SlotAnchorSectionKey(slotElement: Element): { Key: string; Side: 'before' | 'after' } | null {\n const after = neighbourSection(slotElement, 'next');\n if (after) return { Key: after, Side: 'before' };\n const before = neighbourSection(slotElement, 'previous');\n return before ? { Key: before, Side: 'after' } : null;\n}\n\nfunction neighbourSection(from: Element, direction: 'next' | 'previous'): string | null {\n let node = direction === 'next' ? from.nextElementSibling : from.previousElementSibling;\n while (node) {\n const key = node.matches('mj-collapsible-panel') ? node.getAttribute('data-section-key')?.trim() : '';\n if (key) return key;\n node = direction === 'next' ? node.nextElementSibling : node.previousElementSibling;\n }\n return null;\n}\n"]}
@@ -128,8 +128,10 @@ export declare class FormResolverService {
128
128
  * form-loading path falls back to CodeGen's `@RegisterClass` lookup.
129
129
  * This is what makes the Angular fallback reachable from the UI.
130
130
  * - Else if the user has a saved variant ID AND that variant is in
131
- * the applicable list AND it's Active → use it.
132
- * - Else → first Active row in tier+priority order (auto-pick).
131
+ * the applicable list AND it is selectable (`IsSelectableFormOverride`:
132
+ * Active, or the user's own form set aside by a later apply) → use it.
133
+ * - Else → the stored choice is dropped, and the first Active row in
134
+ * tier+priority order is used (auto-pick).
133
135
  * - Else → null (fall back to CodeGen/@RegisterClass path).
134
136
  */
135
137
  private pickActive;
@@ -1 +1 @@
1
- {"version":3,"file":"form-resolver.service.d.ts","sourceRoot":"","sources":["../../../src/lib/resolver/form-resolver.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAY,MAAM,sBAAsB,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;;AAG3D;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,kEAAkE;AAClE,MAAM,MAAM,cAAc,GACpB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,qBAAqB,CAAC;IAAC,QAAQ,EAAE,qBAAqB,EAAE,CAAA;CAAE,GAC3F;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAAC,QAAQ,EAAE,qBAAqB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AO,CAAC,UAAU;IAIlB;;;;;;OAMG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAIhE;;;;;OAKG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAO5C;;;;;OAKG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAK9C;;;;;OAKG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;YAMvC,sBAAsB;IAgFpC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,UAAU;yCAvMT,mBAAmB;6CAAnB,mBAAmB;CA2N/B"}
@@ -1,9 +1,10 @@
1
1
  import { Injectable } from '@angular/core';
2
2
  import { LogError } from '@memberjunction/core';
3
- import { InteractiveFormsEngine } from '@memberjunction/core-entities';
3
+ import { FormScopeAllowedOnEntity, InteractiveFormsEngine, IsSelectableFormOverride } from '@memberjunction/core-entities';
4
4
  import { MJGlobal, UUIDsEqual } from '@memberjunction/global';
5
5
  import { BaseFormComponent } from '../base-form-component';
6
6
  import { UserInfoEngine } from '@memberjunction/core-entities';
7
+ import { FORM_VARIANT_EXPLICIT_DEFAULT, FORM_VARIANT_SETTING_PREFIX, } from '@memberjunction/interactive-component-types/forms';
7
8
  import * as i0 from "@angular/core";
8
9
  /**
9
10
  * UserInfoEngine setting-key prefix for per-user, per-entity form-variant
@@ -18,7 +19,7 @@ import * as i0 from "@angular/core";
18
19
  * the CodeGen Angular fallback explicitly; resolver skips all overrides
19
20
  * - (key absent) → no preference, apply auto-pick rules
20
21
  */
21
- const VARIANT_SETTING_PREFIX = 'mj.formVariant.';
22
+ const VARIANT_SETTING_PREFIX = FORM_VARIANT_SETTING_PREFIX;
22
23
  /**
23
24
  * Picks the form to render for an entity record and exposes the full list of
24
25
  * applicable variants so the toolbar's variant switcher can offer alternates.
@@ -79,7 +80,7 @@ export class FormResolverService {
79
80
  * Format: a leading `__` makes it visually distinct from a UUID and
80
81
  * impossible to collide with one (UUIDs don't contain underscores).
81
82
  */
82
- static EXPLICIT_DEFAULT_SENTINEL = '__codegen-default__';
83
+ static EXPLICIT_DEFAULT_SENTINEL = FORM_VARIANT_EXPLICIT_DEFAULT;
83
84
  /**
84
85
  * Build the per-entity setting key. Lowercased so case variants of
85
86
  * the entity name collapse onto a single record in `MJ: User Settings`.
@@ -147,12 +148,15 @@ export class FormResolverService {
147
148
  }
148
149
  const userRoleIds = new Set((user.UserRoles ?? []).map(r => r.RoleID).filter((id) => !!id));
149
150
  // Filter cached overrides for this (entity, user, roles) tuple.
150
- // Includes Active + Pending + Inactive (the variant picker shows
151
- // all three; pickActive() filters to Active separately). Replaces
151
+ // Includes Active + Pending + Inactive; the variant picker and
152
+ // pickActive() keep the ones IsSelectableFormOverride allows. Replaces
152
153
  // a per-LoadForm RunView with an in-memory predicate — sub-ms.
154
+ // An identity or permission entity takes only the user's own forms.
153
155
  const applicable = InteractiveFormsEngine.Instance.Overrides.filter(o => {
154
156
  if (!o.EntityID || !UUIDsEqual(o.EntityID, entity.ID))
155
157
  return false;
158
+ if (!FormScopeAllowedOnEntity(entity.Name, o.Scope))
159
+ return false;
156
160
  if (o.Scope === 'User')
157
161
  return !!o.UserID && o.UserID.toLowerCase() === user.ID.toLowerCase();
158
162
  if (o.Scope === 'Role')
@@ -212,8 +216,10 @@ export class FormResolverService {
212
216
  * form-loading path falls back to CodeGen's `@RegisterClass` lookup.
213
217
  * This is what makes the Angular fallback reachable from the UI.
214
218
  * - Else if the user has a saved variant ID AND that variant is in
215
- * the applicable list AND it's Active → use it.
216
- * - Else → first Active row in tier+priority order (auto-pick).
219
+ * the applicable list AND it is selectable (`IsSelectableFormOverride`:
220
+ * Active, or the user's own form set aside by a later apply) → use it.
221
+ * - Else → the stored choice is dropped, and the first Active row in
222
+ * tier+priority order is used (auto-pick).
217
223
  * - Else → null (fall back to CodeGen/@RegisterClass path).
218
224
  */
219
225
  pickActive(entity, variants) {
@@ -222,7 +228,11 @@ export class FormResolverService {
222
228
  return null;
223
229
  }
224
230
  if (selectedID) {
225
- const sel = variants.find(v => v.Status === 'Active' && UUIDsEqual(v.ID, selectedID));
231
+ // The user's own set-aside form is a legitimate choice, not history: applying a
232
+ // second form sets the first one aside rather than merging into it, so the picker
233
+ // offers both and the user's pick outranks which row happens to hold Active. A
234
+ // shared form set aside was retracted, and a Pending row is a draft; neither renders.
235
+ const sel = variants.find(v => IsSelectableFormOverride(v) && UUIDsEqual(v.ID, selectedID));
226
236
  if (sel)
227
237
  return sel;
228
238
  // Selection no longer valid — wipe it so future loads auto-pick.
@@ -1 +1 @@
1
- {"version":3,"file":"form-resolver.service.js","sourceRoot":"","sources":["../../../src/lib/resolver/form-resolver.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,eAAe,CAAC;AACjD,OAAO,EAA2C,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;;AA4B/D;;;;;;;;;;;;GAYG;AACH,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,OAAO,mBAAmB;IAE5B,KAAK,CAAC,oBAAoB,CACtB,MAAkB,EAClB,IAAc,EACd,QAA2B;QAE3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEjD,IAAI,MAAM,EAAE,C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,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,UAAU,KAAK,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;YACtF,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC;YACpB,iEAAiE;YACjE,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,IAAI,IAAI,CAAC;IAC7D,CAAC;6GAlNQ,mBAAmB;gEAAnB,mBAAmB,WAAnB,mBAAmB,mBADN,MAAM;;iFACnB,mBAAmB;cAD/B,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable, Type } from '@angular/core';\nimport { IMetadataProvider, UserInfo, EntityInfo, LogError } from '@memberjunction/core';\nimport { InteractiveFormsEngine } from '@memberjunction/core-entities';\nimport { MJGlobal, UUIDsEqual } from '@memberjunction/global';\nimport { BaseFormComponent } from '../base-form-component';\nimport { UserInfoEngine } from '@memberjunction/core-entities';\n\n/**\n * Slim row shape for an `EntityFormOverride` lookup. Resolution doesn't need\n * the full BaseEntity object — `simple` ResultType is faster and avoids a\n * compile-time dependency on the generated entity class. The row is only ever\n * read by the resolver; mutation goes through the generated entity in other\n * code paths (Studio, AI authoring).\n */\nexport interface EntityFormOverrideRow {\n ID: string;\n EntityID: string;\n ComponentID: string;\n Scope: 'User' | 'Role' | 'Global';\n UserID: string | null;\n RoleID: string | null;\n Priority: number;\n Status: 'Active' | 'Inactive' | 'Pending';\n Name?: string;\n Description?: string | null;\n}\n\n/** Resolved form kind for a given (entity, user, roles) tuple. */\nexport type FormResolution =\n | { kind: 'interactive'; override: EntityFormOverrideRow; variants: EntityFormOverrideRow[] }\n | { kind: 'class'; subClass: Type<BaseFormComponent>; variants: EntityFormOverrideRow[] }\n | { kind: 'none'; variants: EntityFormOverrideRow[] };\n\n/**\n * UserInfoEngine setting-key prefix for per-user, per-entity form-variant\n * preferences. Persisted to `MJ: User Settings` so the choice follows the\n * user across browsers and devices — localStorage is intentionally NOT used.\n *\n * Key format: `mj.formVariant.<entityname-lowercased>`.\n *\n * Value is one of:\n * - an `EntityFormOverride.ID` (UUID) → use that specific override\n * - {@link FormResolverService.EXPLICIT_DEFAULT_SENTINEL} → user picked\n * the CodeGen Angular fallback explicitly; resolver skips all overrides\n * - (key absent) → no preference, apply auto-pick rules\n */\nconst VARIANT_SETTING_PREFIX = 'mj.formVariant.';\n\n/**\n * Picks the form to render for an entity record and exposes the full list of\n * applicable variants so the toolbar's variant switcher can offer alternates.\n *\n * Tier order for the **default** pick:\n * 1. `EntityFormOverride` row matching the caller's User/Role/Global scope,\n * Status='Active', ordered by scope tier (User > Role > Global), then\n * Priority DESC, then `__mj_CreatedAt DESC`. First row wins.\n * 2. Existing `ClassFactory.GetRegistration(BaseFormComponent, entityName)` —\n * the @RegisterClass + CodeGen-generated path used today.\n * 3. None — caller surfaces the \"no form registered\" error.\n *\n * **Session selection.** If the user previously chose a non-default variant\n * via the variant switcher and that choice is still applicable + Active, that\n * choice wins over the default. Choice is keyed by entity name in\n * `localStorage`. Honoring this is part of the variant-switcher contract;\n * without it, switching variants would only last for the lifetime of the\n * record-form view.\n *\n * **Performance.** Backed by `InteractiveFormsEngine` (in MJCoreEntities)\n * — overrides are cached in memory with BaseEntity event-driven\n * invalidation, so resolution is an O(N) JS filter against a small\n * set instead of a per-LoadForm RunView round-trip. Cold latency\n * dropped from ~50ms to <1ms after the first load. The engine is\n * lazy-Config'd here on first resolution; users who never open a\n * record pay nothing.\n */\n@Injectable({ providedIn: 'root' })\nexport class FormResolverService {\n\n async ResolveFormForEntity(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<FormResolution> {\n const variants = await this.listApplicableVariants(entity, user, provider);\n const active = this.pickActive(entity, variants);\n\n if (active) {\n return { kind: 'interactive', override: active, variants };\n }\n\n const reg = MJGlobal.Instance.ClassFactory.GetRegistration(BaseFormComponent, entity.Name);\n return reg\n ? { kind: 'class', subClass: reg.SubClass as Type<BaseFormComponent>, variants }\n : { kind: 'none', variants };\n }\n\n /**\n * Public list-API for the variant switcher UI. Returns all variants\n * applicable to (entity, user). Includes Active, Pending, and Inactive\n * rows so the picker can offer \"switch back to v1.0.0\" alongside the\n * current active variant.\n */\n async ListVariantsForEntity(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<EntityFormOverrideRow[]> {\n return this.listApplicableVariants(entity, user, provider);\n }\n\n /**\n * Sentinel stored in localStorage when the user **explicitly picks the\n * \"Default form\"** option from the variant picker. Distinct from a\n * missing localStorage key (= \"no preference, use auto-pick rules\")\n * and from an override UUID. Without this sentinel, picking \"Default\"\n * cleared the preference and `pickActive` re-applied the auto-pick —\n * which always selects the first Active override, making the\n * CodeGen/Angular fallback unreachable from the UI.\n *\n * Format: a leading `__` makes it visually distinct from a UUID and\n * impossible to collide with one (UUIDs don't contain underscores).\n */\n public static readonly EXPLICIT_DEFAULT_SENTINEL = '__codegen-default__';\n\n /**\n * Build the per-entity setting key. Lowercased so case variants of\n * the entity name collapse onto a single record in `MJ: User Settings`.\n */\n private settingKey(entityName: string): string {\n return VARIANT_SETTING_PREFIX + entityName.toLowerCase();\n }\n\n /**\n * Persist a specific override choice. Pass the override UUID. Writes\n * via `UserInfoEngine.SetSettingDebounced` so rapid successive picks\n * don't hammer the DB. Use {@link SetExplicitDefault} to record \"user\n * wants the CodeGen Angular fallback\" and {@link ClearSelectedVariant}\n * to wipe the preference entirely (revert to auto-pick).\n */\n SetSelectedVariant(entityName: string, overrideID: string): void {\n UserInfoEngine.Instance.SetSettingDebounced(this.settingKey(entityName), overrideID);\n }\n\n /**\n * Record that the user explicitly picked the \"Default form\" row in\n * the picker. `pickActive` reads this sentinel and returns null even\n * when Active overrides exist for the entity, so the form-loading\n * path falls back to CodeGen's `@RegisterClass` lookup.\n */\n SetExplicitDefault(entityName: string): void {\n UserInfoEngine.Instance.SetSettingDebounced(\n this.settingKey(entityName),\n FormResolverService.EXPLICIT_DEFAULT_SENTINEL,\n );\n }\n\n /**\n * Wipe the user's stored preference for this entity. Next load\n * applies the auto-pick rules (first Active override in tier order).\n * Called internally when a saved override ID is no longer valid.\n * Fire-and-forget — the resolver doesn't need to await the delete.\n */\n ClearSelectedVariant(entityName: string): void {\n void UserInfoEngine.Instance.DeleteSetting(this.settingKey(entityName))\n .catch(err => LogError(`FormResolverService.ClearSelectedVariant: ${err instanceof Error ? err.message : String(err)}`));\n }\n\n /**\n * Read the user's previously-saved variant choice for the entity.\n * Synchronous because `UserInfoEngine` keeps the user-settings table\n * in memory after bootstrap. Returns the stored UUID, the explicit-\n * default sentinel, or null when no preference exists.\n */\n GetSelectedVariant(entityName: string): string | null {\n return UserInfoEngine.Instance.GetSetting(this.settingKey(entityName)) ?? null;\n }\n\n // ── internals ────────────────────────────────────────────────────────\n\n private async listApplicableVariants(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<EntityFormOverrideRow[]> {\n // Lazy-load the form-metadata engine on first call. No-op when\n // already loaded. BaseEngine's event subscription keeps the\n // cache fresh through save / delete / remote-invalidate — we\n // don't need `BypassCache: true` (the previous RunView path's\n // escape hatch) because the engine's invalidation IS that\n // freshness guarantee. See `InteractiveFormsEngine` doc-block.\n try {\n await InteractiveFormsEngine.Instance.Config(false, user, provider);\n } catch (err) {\n LogError(`FormResolverService: InteractiveFormsEngine.Config failed: ${err instanceof Error ? err.message : String(err)}`);\n return [];\n }\n\n // If the engine couldn't load due to permission denial, fall back to\n // the generated form — no overrides available.\n if (InteractiveFormsEngine.Instance.IsPermissionConstrained) {\n return [];\n }\n\n const userRoleIds = new Set(\n (user.UserRoles ?? []).map(r => r.RoleID).filter((id): id is string => !!id),\n );\n\n // Filter cached overrides for this (entity, user, roles) tuple.\n // Includes Active + Pending + Inactive (the variant picker shows\n // all three; pickActive() filters to Active separately). Replaces\n // a per-LoadForm RunView with an in-memory predicate — sub-ms.\n const applicable = InteractiveFormsEngine.Instance.Overrides.filter(o => {\n if (!o.EntityID || !UUIDsEqual(o.EntityID, entity.ID)) return false;\n if (o.Scope === 'User') return !!o.UserID && o.UserID.toLowerCase() === user.ID.toLowerCase();\n if (o.Scope === 'Role') return !!o.RoleID && userRoleIds.has(o.RoleID);\n if (o.Scope === 'Global') return true;\n return false;\n });\n\n // Sort: User > Role > Global, then Priority DESC (higher beats),\n // then newest first. Matches the prior SQL ORDER BY semantics so\n // pickActive() / the variant switcher see the same order.\n const scopeRank = (s: string | null | undefined): number => {\n if (s === 'User') return 1;\n if (s === 'Role') return 2;\n if (s === 'Global') return 3;\n return 4;\n };\n applicable.sort((a, b) => {\n const sa = scopeRank(a.Scope);\n const sb = scopeRank(b.Scope);\n if (sa !== sb) return sa - sb;\n const pa = a.Priority ?? 0;\n const pb = b.Priority ?? 0;\n if (pa !== pb) return pb - pa; // Priority DESC\n const ca = a.__mj_CreatedAt instanceof Date ? a.__mj_CreatedAt.getTime() : 0;\n const cb = b.__mj_CreatedAt instanceof Date ? b.__mj_CreatedAt.getTime() : 0;\n return cb - ca; // newest first\n });\n\n // Project to the slim row shape the resolver returns. Keeps the\n // contract identical to the old RunView return so callers don't\n // change shape.\n return applicable.map(o => ({\n ID: o.ID,\n EntityID: o.EntityID,\n ComponentID: o.ComponentID,\n Scope: o.Scope as 'User' | 'Role' | 'Global',\n UserID: o.UserID,\n RoleID: o.RoleID,\n Priority: o.Priority,\n Status: o.Status as 'Active' | 'Inactive' | 'Pending',\n Name: o.Name,\n Description: o.Description,\n }));\n }\n\n /**\n * Pick the override that should actually render given the variant list\n * and the user's stored selection (if any).\n *\n * Selection rules:\n * - If the user explicitly picked the \"Default form\" row in the\n * variant picker (sentinel in localStorage) → return null so the\n * form-loading path falls back to CodeGen's `@RegisterClass` lookup.\n * This is what makes the Angular fallback reachable from the UI.\n * - Else if the user has a saved variant ID AND that variant is in\n * the applicable list AND it's Active → use it.\n * - Else → first Active row in tier+priority order (auto-pick).\n * - Else → null (fall back to CodeGen/@RegisterClass path).\n */\n private pickActive(\n entity: EntityInfo,\n variants: EntityFormOverrideRow[],\n ): EntityFormOverrideRow | null {\n const selectedID = this.GetSelectedVariant(entity.Name);\n if (selectedID === FormResolverService.EXPLICIT_DEFAULT_SENTINEL) {\n return null;\n }\n if (selectedID) {\n const sel = variants.find(v => v.Status === 'Active' && UUIDsEqual(v.ID, selectedID));\n if (sel) return sel;\n // Selection no longer valid — wipe it so future loads auto-pick.\n this.ClearSelectedVariant(entity.Name);\n }\n return variants.find(v => v.Status === 'Active') ?? null;\n }\n}\n"]}
1
+ {"version":3,"file":"form-resolver.service.js","sourceRoot":"","sources":["../../../src/lib/resolver/form-resolver.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,eAAe,CAAC;AACjD,OAAO,EAA2C,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC3H,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EACH,6BAA6B,EAC7B,2BAA2B,GAC9B,MAAM,mDAAmD,CAAC;;AA4B3D;;;;;;;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AAmB,WAAnB,mBAAmB,mBADN,MAAM;;iFACnB,mBAAmB;cAD/B,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable, Type } from '@angular/core';\nimport { IMetadataProvider, UserInfo, EntityInfo, LogError } from '@memberjunction/core';\nimport { FormScopeAllowedOnEntity, InteractiveFormsEngine, IsSelectableFormOverride } from '@memberjunction/core-entities';\nimport { MJGlobal, UUIDsEqual } from '@memberjunction/global';\nimport { BaseFormComponent } from '../base-form-component';\nimport { UserInfoEngine } from '@memberjunction/core-entities';\nimport {\n FORM_VARIANT_EXPLICIT_DEFAULT,\n FORM_VARIANT_SETTING_PREFIX,\n} from '@memberjunction/interactive-component-types/forms';\n\n/**\n * Slim row shape for an `EntityFormOverride` lookup. Resolution doesn't need\n * the full BaseEntity object — `simple` ResultType is faster and avoids a\n * compile-time dependency on the generated entity class. The row is only ever\n * read by the resolver; mutation goes through the generated entity in other\n * code paths (Studio, AI authoring).\n */\nexport interface EntityFormOverrideRow {\n ID: string;\n EntityID: string;\n ComponentID: string;\n Scope: 'User' | 'Role' | 'Global';\n UserID: string | null;\n RoleID: string | null;\n Priority: number;\n Status: 'Active' | 'Inactive' | 'Pending';\n Name?: string;\n Description?: string | null;\n}\n\n/** Resolved form kind for a given (entity, user, roles) tuple. */\nexport type FormResolution =\n | { kind: 'interactive'; override: EntityFormOverrideRow; variants: EntityFormOverrideRow[] }\n | { kind: 'class'; subClass: Type<BaseFormComponent>; variants: EntityFormOverrideRow[] }\n | { kind: 'none'; variants: EntityFormOverrideRow[] };\n\n/**\n * UserInfoEngine setting-key prefix for per-user, per-entity form-variant\n * preferences. Persisted to `MJ: User Settings` so the choice follows the\n * user across browsers and devices — localStorage is intentionally NOT used.\n *\n * Key format: `mj.formVariant.<entityname-lowercased>`.\n *\n * Value is one of:\n * - an `EntityFormOverride.ID` (UUID) → use that specific override\n * - {@link FormResolverService.EXPLICIT_DEFAULT_SENTINEL} → user picked\n * the CodeGen Angular fallback explicitly; resolver skips all overrides\n * - (key absent) → no preference, apply auto-pick rules\n */\nconst VARIANT_SETTING_PREFIX = FORM_VARIANT_SETTING_PREFIX;\n\n/**\n * Picks the form to render for an entity record and exposes the full list of\n * applicable variants so the toolbar's variant switcher can offer alternates.\n *\n * Tier order for the **default** pick:\n * 1. `EntityFormOverride` row matching the caller's User/Role/Global scope,\n * Status='Active', ordered by scope tier (User > Role > Global), then\n * Priority DESC, then `__mj_CreatedAt DESC`. First row wins.\n * 2. Existing `ClassFactory.GetRegistration(BaseFormComponent, entityName)` —\n * the @RegisterClass + CodeGen-generated path used today.\n * 3. None — caller surfaces the \"no form registered\" error.\n *\n * **Session selection.** If the user previously chose a non-default variant\n * via the variant switcher and that choice is still applicable + Active, that\n * choice wins over the default. Choice is keyed by entity name in\n * `localStorage`. Honoring this is part of the variant-switcher contract;\n * without it, switching variants would only last for the lifetime of the\n * record-form view.\n *\n * **Performance.** Backed by `InteractiveFormsEngine` (in MJCoreEntities)\n * — overrides are cached in memory with BaseEntity event-driven\n * invalidation, so resolution is an O(N) JS filter against a small\n * set instead of a per-LoadForm RunView round-trip. Cold latency\n * dropped from ~50ms to <1ms after the first load. The engine is\n * lazy-Config'd here on first resolution; users who never open a\n * record pay nothing.\n */\n@Injectable({ providedIn: 'root' })\nexport class FormResolverService {\n\n async ResolveFormForEntity(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<FormResolution> {\n const variants = await this.listApplicableVariants(entity, user, provider);\n const active = this.pickActive(entity, variants);\n\n if (active) {\n return { kind: 'interactive', override: active, variants };\n }\n\n const reg = MJGlobal.Instance.ClassFactory.GetRegistration(BaseFormComponent, entity.Name);\n return reg\n ? { kind: 'class', subClass: reg.SubClass as Type<BaseFormComponent>, variants }\n : { kind: 'none', variants };\n }\n\n /**\n * Public list-API for the variant switcher UI. Returns all variants\n * applicable to (entity, user). Includes Active, Pending, and Inactive\n * rows so the picker can offer \"switch back to v1.0.0\" alongside the\n * current active variant.\n */\n async ListVariantsForEntity(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<EntityFormOverrideRow[]> {\n return this.listApplicableVariants(entity, user, provider);\n }\n\n /**\n * Sentinel stored in localStorage when the user **explicitly picks the\n * \"Default form\"** option from the variant picker. Distinct from a\n * missing localStorage key (= \"no preference, use auto-pick rules\")\n * and from an override UUID. Without this sentinel, picking \"Default\"\n * cleared the preference and `pickActive` re-applied the auto-pick —\n * which always selects the first Active override, making the\n * CodeGen/Angular fallback unreachable from the UI.\n *\n * Format: a leading `__` makes it visually distinct from a UUID and\n * impossible to collide with one (UUIDs don't contain underscores).\n */\n public static readonly EXPLICIT_DEFAULT_SENTINEL = FORM_VARIANT_EXPLICIT_DEFAULT;\n\n /**\n * Build the per-entity setting key. Lowercased so case variants of\n * the entity name collapse onto a single record in `MJ: User Settings`.\n */\n private settingKey(entityName: string): string {\n return VARIANT_SETTING_PREFIX + entityName.toLowerCase();\n }\n\n /**\n * Persist a specific override choice. Pass the override UUID. Writes\n * via `UserInfoEngine.SetSettingDebounced` so rapid successive picks\n * don't hammer the DB. Use {@link SetExplicitDefault} to record \"user\n * wants the CodeGen Angular fallback\" and {@link ClearSelectedVariant}\n * to wipe the preference entirely (revert to auto-pick).\n */\n SetSelectedVariant(entityName: string, overrideID: string): void {\n UserInfoEngine.Instance.SetSettingDebounced(this.settingKey(entityName), overrideID);\n }\n\n /**\n * Record that the user explicitly picked the \"Default form\" row in\n * the picker. `pickActive` reads this sentinel and returns null even\n * when Active overrides exist for the entity, so the form-loading\n * path falls back to CodeGen's `@RegisterClass` lookup.\n */\n SetExplicitDefault(entityName: string): void {\n UserInfoEngine.Instance.SetSettingDebounced(\n this.settingKey(entityName),\n FormResolverService.EXPLICIT_DEFAULT_SENTINEL,\n );\n }\n\n /**\n * Wipe the user's stored preference for this entity. Next load\n * applies the auto-pick rules (first Active override in tier order).\n * Called internally when a saved override ID is no longer valid.\n * Fire-and-forget — the resolver doesn't need to await the delete.\n */\n ClearSelectedVariant(entityName: string): void {\n void UserInfoEngine.Instance.DeleteSetting(this.settingKey(entityName))\n .catch(err => LogError(`FormResolverService.ClearSelectedVariant: ${err instanceof Error ? err.message : String(err)}`));\n }\n\n /**\n * Read the user's previously-saved variant choice for the entity.\n * Synchronous because `UserInfoEngine` keeps the user-settings table\n * in memory after bootstrap. Returns the stored UUID, the explicit-\n * default sentinel, or null when no preference exists.\n */\n GetSelectedVariant(entityName: string): string | null {\n return UserInfoEngine.Instance.GetSetting(this.settingKey(entityName)) ?? null;\n }\n\n // ── internals ────────────────────────────────────────────────────────\n\n private async listApplicableVariants(\n entity: EntityInfo,\n user: UserInfo,\n provider: IMetadataProvider,\n ): Promise<EntityFormOverrideRow[]> {\n // Lazy-load the form-metadata engine on first call. No-op when\n // already loaded. BaseEngine's event subscription keeps the\n // cache fresh through save / delete / remote-invalidate — we\n // don't need `BypassCache: true` (the previous RunView path's\n // escape hatch) because the engine's invalidation IS that\n // freshness guarantee. See `InteractiveFormsEngine` doc-block.\n try {\n await InteractiveFormsEngine.Instance.Config(false, user, provider);\n } catch (err) {\n LogError(`FormResolverService: InteractiveFormsEngine.Config failed: ${err instanceof Error ? err.message : String(err)}`);\n return [];\n }\n\n // If the engine couldn't load due to permission denial, fall back to\n // the generated form — no overrides available.\n if (InteractiveFormsEngine.Instance.IsPermissionConstrained) {\n return [];\n }\n\n const userRoleIds = new Set(\n (user.UserRoles ?? []).map(r => r.RoleID).filter((id): id is string => !!id),\n );\n\n // Filter cached overrides for this (entity, user, roles) tuple.\n // Includes Active + Pending + Inactive; the variant picker and\n // pickActive() keep the ones IsSelectableFormOverride allows. Replaces\n // a per-LoadForm RunView with an in-memory predicate — sub-ms.\n // An identity or permission entity takes only the user's own forms.\n const applicable = InteractiveFormsEngine.Instance.Overrides.filter(o => {\n if (!o.EntityID || !UUIDsEqual(o.EntityID, entity.ID)) return false;\n if (!FormScopeAllowedOnEntity(entity.Name, o.Scope)) return false;\n if (o.Scope === 'User') return !!o.UserID && o.UserID.toLowerCase() === user.ID.toLowerCase();\n if (o.Scope === 'Role') return !!o.RoleID && userRoleIds.has(o.RoleID);\n if (o.Scope === 'Global') return true;\n return false;\n });\n\n // Sort: User > Role > Global, then Priority DESC (higher beats),\n // then newest first. Matches the prior SQL ORDER BY semantics so\n // pickActive() / the variant switcher see the same order.\n const scopeRank = (s: string | null | undefined): number => {\n if (s === 'User') return 1;\n if (s === 'Role') return 2;\n if (s === 'Global') return 3;\n return 4;\n };\n applicable.sort((a, b) => {\n const sa = scopeRank(a.Scope);\n const sb = scopeRank(b.Scope);\n if (sa !== sb) return sa - sb;\n const pa = a.Priority ?? 0;\n const pb = b.Priority ?? 0;\n if (pa !== pb) return pb - pa; // Priority DESC\n const ca = a.__mj_CreatedAt instanceof Date ? a.__mj_CreatedAt.getTime() : 0;\n const cb = b.__mj_CreatedAt instanceof Date ? b.__mj_CreatedAt.getTime() : 0;\n return cb - ca; // newest first\n });\n\n // Project to the slim row shape the resolver returns. Keeps the\n // contract identical to the old RunView return so callers don't\n // change shape.\n return applicable.map(o => ({\n ID: o.ID,\n EntityID: o.EntityID,\n ComponentID: o.ComponentID,\n Scope: o.Scope as 'User' | 'Role' | 'Global',\n UserID: o.UserID,\n RoleID: o.RoleID,\n Priority: o.Priority,\n Status: o.Status as 'Active' | 'Inactive' | 'Pending',\n Name: o.Name,\n Description: o.Description,\n }));\n }\n\n /**\n * Pick the override that should actually render given the variant list\n * and the user's stored selection (if any).\n *\n * Selection rules:\n * - If the user explicitly picked the \"Default form\" row in the\n * variant picker (sentinel in localStorage) → return null so the\n * form-loading path falls back to CodeGen's `@RegisterClass` lookup.\n * This is what makes the Angular fallback reachable from the UI.\n * - Else if the user has a saved variant ID AND that variant is in\n * the applicable list AND it is selectable (`IsSelectableFormOverride`:\n * Active, or the user's own form set aside by a later apply) → use it.\n * - Else → the stored choice is dropped, and the first Active row in\n * tier+priority order is used (auto-pick).\n * - Else → null (fall back to CodeGen/@RegisterClass path).\n */\n private pickActive(\n entity: EntityInfo,\n variants: EntityFormOverrideRow[],\n ): EntityFormOverrideRow | null {\n const selectedID = this.GetSelectedVariant(entity.Name);\n if (selectedID === FormResolverService.EXPLICIT_DEFAULT_SENTINEL) {\n return null;\n }\n if (selectedID) {\n // The user's own set-aside form is a legitimate choice, not history: applying a\n // second form sets the first one aside rather than merging into it, so the picker\n // offers both and the user's pick outranks which row happens to hold Active. A\n // shared form set aside was retracted, and a Pending row is a draft; neither renders.\n const sel = variants.find(v => IsSelectableFormOverride(v) && UUIDsEqual(v.ID, selectedID));\n if (sel) return sel;\n // Selection no longer valid — wipe it so future loads auto-pick.\n this.ClearSelectedVariant(entity.Name);\n }\n return variants.find(v => v.Status === 'Active') ?? null;\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import type { EntityFormOverrideRow } from './form-resolver.service';
2
+ /** One entry in the toolbar's form picker. */
3
+ export interface FormVariantChoice {
4
+ ID: string;
5
+ Label: string;
6
+ Scope: 'User' | 'Role' | 'Global';
7
+ Status: 'Active' | 'Pending' | 'Inactive';
8
+ }
9
+ /**
10
+ * The forms the picker offers, out of every override that applies to this user.
11
+ *
12
+ * Applying a custom form does not merge it into whatever was there before: the new form
13
+ * becomes live and the previous one is set aside, both rows intact. So the user's own set
14
+ * aside ones belong in the picker — without them a user who applies a second form can never
15
+ * get back to the first, and "swap" would mean "discard".
16
+ *
17
+ * Three kinds of row are left out. A `Pending` row is an unfinished draft an agent is still
18
+ * iterating on, not a form anyone chose. A shared row set aside was retracted
19
+ * ({@link IsSelectableFormOverride}; the resolver's list holds only the current user's own
20
+ * `User` rows, so a `User` row here is always the caller's). And a set-aside row that shares
21
+ * its name with a newer one is a superseded VERSION of the same form rather than a different
22
+ * form, so only the newest of each name is offered; the older versions stay reachable through
23
+ * the form's own version history.
24
+ *
25
+ * `rows` must arrive newest-first within each name, which is the order the resolver returns.
26
+ */
27
+ export declare function FormVariantChoices(rows: readonly EntityFormOverrideRow[]): FormVariantChoice[];
28
+ //# sourceMappingURL=form-variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-variants.d.ts","sourceRoot":"","sources":["../../../src/lib/resolver/form-variants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,qBAAqB,EAAE,GAAG,iBAAiB,EAAE,CAgB9F"}
@@ -0,0 +1,40 @@
1
+ import { IsSelectableFormOverride } from '@memberjunction/core-entities';
2
+ /**
3
+ * The forms the picker offers, out of every override that applies to this user.
4
+ *
5
+ * Applying a custom form does not merge it into whatever was there before: the new form
6
+ * becomes live and the previous one is set aside, both rows intact. So the user's own set
7
+ * aside ones belong in the picker — without them a user who applies a second form can never
8
+ * get back to the first, and "swap" would mean "discard".
9
+ *
10
+ * Three kinds of row are left out. A `Pending` row is an unfinished draft an agent is still
11
+ * iterating on, not a form anyone chose. A shared row set aside was retracted
12
+ * ({@link IsSelectableFormOverride}; the resolver's list holds only the current user's own
13
+ * `User` rows, so a `User` row here is always the caller's). And a set-aside row that shares
14
+ * its name with a newer one is a superseded VERSION of the same form rather than a different
15
+ * form, so only the newest of each name is offered; the older versions stay reachable through
16
+ * the form's own version history.
17
+ *
18
+ * `rows` must arrive newest-first within each name, which is the order the resolver returns.
19
+ */
20
+ export function FormVariantChoices(rows) {
21
+ const seenNames = new Set();
22
+ const choices = [];
23
+ for (const row of rows) {
24
+ if (!IsSelectableFormOverride(row))
25
+ continue;
26
+ const label = row.Name?.trim() || `Override ${row.ID.substring(0, 8)}`;
27
+ if (row.Status === 'Inactive') {
28
+ const lineage = label.toLowerCase();
29
+ if (seenNames.has(lineage))
30
+ continue;
31
+ seenNames.add(lineage);
32
+ }
33
+ else {
34
+ seenNames.add(label.toLowerCase());
35
+ }
36
+ choices.push({ ID: row.ID, Label: label, Scope: row.Scope, Status: row.Status });
37
+ }
38
+ return choices;
39
+ }
40
+ //# sourceMappingURL=form-variants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-variants.js","sourceRoot":"","sources":["../../../src/lib/resolver/form-variants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAWzE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAsC;IACrE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,MAAM,OAAO,GAAwB,EAAE,CAAC;IACxC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC;YAAE,SAAS;QAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACvE,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;gBAAE,SAAS;YACrC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACJ,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import { IsSelectableFormOverride } from '@memberjunction/core-entities';\nimport type { EntityFormOverrideRow } from './form-resolver.service';\n\n/** One entry in the toolbar's form picker. */\nexport interface FormVariantChoice {\n ID: string;\n Label: string;\n Scope: 'User' | 'Role' | 'Global';\n Status: 'Active' | 'Pending' | 'Inactive';\n}\n\n/**\n * The forms the picker offers, out of every override that applies to this user.\n *\n * Applying a custom form does not merge it into whatever was there before: the new form\n * becomes live and the previous one is set aside, both rows intact. So the user's own set\n * aside ones belong in the picker — without them a user who applies a second form can never\n * get back to the first, and \"swap\" would mean \"discard\".\n *\n * Three kinds of row are left out. A `Pending` row is an unfinished draft an agent is still\n * iterating on, not a form anyone chose. A shared row set aside was retracted\n * ({@link IsSelectableFormOverride}; the resolver's list holds only the current user's own\n * `User` rows, so a `User` row here is always the caller's). And a set-aside row that shares\n * its name with a newer one is a superseded VERSION of the same form rather than a different\n * form, so only the newest of each name is offered; the older versions stay reachable through\n * the form's own version history.\n *\n * `rows` must arrive newest-first within each name, which is the order the resolver returns.\n */\nexport function FormVariantChoices(rows: readonly EntityFormOverrideRow[]): FormVariantChoice[] {\n const seenNames = new Set<string>();\n const choices: FormVariantChoice[] = [];\n for (const row of rows) {\n if (!IsSelectableFormOverride(row)) continue;\n const label = row.Name?.trim() || `Override ${row.ID.substring(0, 8)}`;\n if (row.Status === 'Inactive') {\n const lineage = label.toLowerCase();\n if (seenNames.has(lineage)) continue;\n seenNames.add(lineage);\n } else {\n seenNames.add(label.toLowerCase());\n }\n choices.push({ ID: row.ID, Label: label, Scope: row.Scope, Status: row.Status });\n }\n return choices;\n}\n"]}