@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,433 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { LogError, Metadata, } from '@memberjunction/core';
3
+ import { UUIDsEqual } from '@memberjunction/global';
4
+ import { ActiveContributionSiblings, ApplyContributionSpecToRow, FormLifecycleComponentStatus, InteractiveFormsEngine, ParseClaimedFieldNames, UserCanManageFormDefaults, } from '@memberjunction/core-entities';
5
+ import { CollectFormContributionRegistrations, InvalidateFormContributionRegistrationCache, } from '../panel-slot/collect-form-contribution-registrations';
6
+ import { ResolveFormContributionWinners } from '../panel-slot/form-contribution';
7
+ import { ParseContributionConfiguration } from './form-panel-inventory';
8
+ import { PanelHideKey, SetPanelHidden } from '../panel-slot/panel-hides';
9
+ import { AudienceColumns, LiveContributionAt, LiveOverrideAt, } from './form-audience';
10
+ import * as i0 from "@angular/core";
11
+ /**
12
+ * The row's stored configuration with the decision's keys over it, so a key the placement
13
+ * dialog does not write survives an edit. Undefined when both are empty.
14
+ */
15
+ function mergeConfiguration(stored, decided) {
16
+ const merged = { ...(ParseContributionConfiguration(stored) ?? {}), ...(decided ?? {}) };
17
+ return Object.keys(merged).length > 0 ? merged : undefined;
18
+ }
19
+ /**
20
+ * Loads and changes the contribution rows behind one entity's form.
21
+ *
22
+ * Reads come from {@link InteractiveFormsEngine}, which already caches every row for
23
+ * every scope and status and emits when one changes — the same cache the form runtime
24
+ * reads, so the manager cannot disagree with the form it is managing.
25
+ *
26
+ * Writes go through `BaseEntity.Save()` and `.Delete()`. Direct SQL against an entity
27
+ * skips the Record Changes audit row, the server cache invalidation, entity actions and
28
+ * validation, all of which fail silently and leave a database that looks right.
29
+ *
30
+ * Turning a form or panel on follows the rule the Activate actions follow: the one live under the
31
+ * same key for the same audience is retired first, in the same transaction, and each component's
32
+ * status mirrors its row's.
33
+ */
34
+ export class FormPanelAdminService {
35
+ /**
36
+ * Every contribution registered on this entity, whatever its scope or status.
37
+ *
38
+ * Not `GetApplicableContributions`: that answers what should render right now, which
39
+ * excludes the drafts and switched-off rows this surface exists to bring back.
40
+ */
41
+ RowsForEntity(entity) {
42
+ if (!entity?.ID)
43
+ return [];
44
+ try {
45
+ return InteractiveFormsEngine.Instance.Contributions
46
+ .filter((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID))
47
+ .map((row) => this.project(row));
48
+ }
49
+ catch (err) {
50
+ LogError(`FormPanelAdminService: could not read contributions: ${this.message(err)}`);
51
+ return [];
52
+ }
53
+ }
54
+ /**
55
+ * Whether the entity carries any contribution row at all, whatever its status.
56
+ *
57
+ * Separate from {@link RowsForEntity} because the container asks this on every
58
+ * change-detection pass to decide whether to offer the manager, and projecting every
59
+ * row to answer a yes-or-no question allocates on the hottest path in the form runtime.
60
+ */
61
+ HasRowsForEntity(entity) {
62
+ if (!entity?.ID)
63
+ return false;
64
+ try {
65
+ return InteractiveFormsEngine.Instance.Contributions
66
+ .some((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID));
67
+ }
68
+ catch {
69
+ // No engine in this context — nothing to manage.
70
+ return false;
71
+ }
72
+ }
73
+ /**
74
+ * Switches a row on or off. Off leaves the row in place, rendering for nobody. On retires the
75
+ * panel live under the same key for the same audience first, in the same transaction.
76
+ */
77
+ async SetActive(rowID, active, provider) {
78
+ return this.write(rowID, provider, (row, md) => this.saveAs(md, row, active ? 'Active' : 'Inactive'));
79
+ }
80
+ /**
81
+ * Which panels on this form draw for the current user: the winner of each key, with the
82
+ * user's hidden panels left out — the same resolution the form makes. Undefined when that
83
+ * cannot be resolved, so the list falls back to each item's own status.
84
+ */
85
+ RenderingFor(entity, provider) {
86
+ const md = provider ?? Metadata.Provider;
87
+ if (!entity || !md)
88
+ return undefined;
89
+ try {
90
+ const rowIDs = new Set();
91
+ const compiledKeys = new Set();
92
+ const registrations = CollectFormContributionRegistrations(entity, md);
93
+ for (const winner of ResolveFormContributionWinners(entity.Name, registrations).Winners) {
94
+ if (winner.Source === 'metadata') {
95
+ if (winner.RowID)
96
+ rowIDs.add(winner.RowID.toLowerCase());
97
+ continue;
98
+ }
99
+ const key = PanelHideKey(winner);
100
+ if (key)
101
+ compiledKeys.add(key);
102
+ }
103
+ return { RowIDs: rowIDs, CompiledKeys: compiledKeys };
104
+ }
105
+ catch (err) {
106
+ LogError(`FormPanelAdminService: could not resolve what the form draws: ${this.message(err)}`);
107
+ return undefined;
108
+ }
109
+ }
110
+ /**
111
+ * Writes a new placement onto an existing row, through the same row mapper the Create and
112
+ * Modify actions use.
113
+ *
114
+ * Every claim column is rewritten, including the ones the decision leaves out, so a claim the
115
+ * user has just dropped is actually cleared. The key is the one the decision names, or the
116
+ * one the write path derives from its grid claim or the row's component. The order,
117
+ * rail inclusion and configuration, which the placement dialog does not edit, are kept.
118
+ *
119
+ * @param status What the row is saved as: on, a draft, or off. On retires the panel live under
120
+ * the row's new key for its audience, in the same transaction.
121
+ */
122
+ async SetPlacement(rowID, contribution, status, provider) {
123
+ return this.write(rowID, provider, async (row, md) => {
124
+ const relatedName = contribution.relatedEntity?.trim();
125
+ const related = relatedName ? (provider ?? Metadata.Provider)?.EntityByName(relatedName) : null;
126
+ if (relatedName && !related) {
127
+ return { Success: false, Message: `The related entity "${relatedName}" is not registered.` };
128
+ }
129
+ ApplyContributionSpecToRow(row, this.keepUneditedColumns(contribution, row), {
130
+ relatedEntityID: related?.ID ?? null,
131
+ relatedEntityName: related?.Name ?? null,
132
+ componentName: row.Component || null,
133
+ });
134
+ return this.saveAs(md, row, status);
135
+ });
136
+ }
137
+ /** Deletes a row outright. The Component it points at is left alone. */
138
+ async Remove(rowID, provider) {
139
+ return this.write(rowID, provider, async (row) => {
140
+ const deleted = await row.Delete();
141
+ return deleted
142
+ ? { Success: true }
143
+ : { Success: false, Message: row.LatestResult?.CompleteMessage ?? 'The panel could not be removed.' };
144
+ });
145
+ }
146
+ /**
147
+ * Whether the current user may publish to a role or to everyone.
148
+ *
149
+ * Only decides what the drawer draws. The server-side entity subclasses enforce the same rule
150
+ * on every save, so a client that draws itself a Publish button still has the write refused.
151
+ */
152
+ CanPublish(provider) {
153
+ const md = provider ?? Metadata.Provider;
154
+ return UserCanManageFormDefaults(md?.CurrentUser, md);
155
+ }
156
+ /**
157
+ * The full custom forms the engine holds for this entity, in every status: every shared form
158
+ * and the signed-in user's own.
159
+ */
160
+ OverridesForEntity(entity) {
161
+ if (!entity?.ID)
162
+ return [];
163
+ try {
164
+ return InteractiveFormsEngine.Instance.Overrides
165
+ .filter((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID))
166
+ .map((row) => ({
167
+ ID: row.ID, Name: row.Name, Status: row.Status, Scope: row.Scope,
168
+ UserID: row.UserID, RoleID: row.RoleID, Role: row.Role,
169
+ }));
170
+ }
171
+ catch (err) {
172
+ LogError(`FormPanelAdminService: could not read forms: ${this.message(err)}`);
173
+ return [];
174
+ }
175
+ }
176
+ /**
177
+ * Changes who a panel is for, and turns it on.
178
+ *
179
+ * The panel live for that audience under the same key is retired first, in the same
180
+ * transaction, so the audience never sees two and the unique index on active contributions
181
+ * never sees two either. A draft or a panel that is off goes live in the same transaction —
182
+ * publishing one never leaves the audience with neither.
183
+ */
184
+ async PublishContribution(rowID, audience, provider) {
185
+ const rows = this.contributionRows();
186
+ const target = rows.find((row) => UUIDsEqual(row.ID, rowID));
187
+ if (!target)
188
+ return { Success: false, Message: 'That panel is no longer registered.' };
189
+ const callerID = (provider ?? Metadata.Provider)?.CurrentUser?.ID ?? '';
190
+ const retiring = LiveContributionAt(rows, target, audience, callerID);
191
+ return this.publish('MJ: Entity Form Contributions', target.ID, retiring?.ID ?? null, audience, provider);
192
+ }
193
+ /**
194
+ * Changes who a full custom form is for, and makes it live. Whichever form was live for that
195
+ * audience is set aside in the same transaction. A personal form set aside stays in its
196
+ * owner's picker, so the two can be swapped back; a role or everyone form set aside is
197
+ * retracted and no longer offered to anyone.
198
+ */
199
+ async PublishOverride(overrideID, audience, provider) {
200
+ const rows = this.overrideRows();
201
+ const target = rows.find((row) => UUIDsEqual(row.ID, overrideID));
202
+ if (!target)
203
+ return { Success: false, Message: 'That form is no longer registered.' };
204
+ const callerID = (provider ?? Metadata.Provider)?.CurrentUser?.ID ?? '';
205
+ const retiring = LiveOverrideAt(rows, target, audience, callerID);
206
+ return this.publish('MJ: Entity Form Overrides', target.ID, retiring?.ID ?? null, audience, provider);
207
+ }
208
+ /** Hides a panel from this user's form. Stored per user; nobody else is affected. */
209
+ Hide(entityName, key) {
210
+ SetPanelHidden(entityName, key, true);
211
+ InvalidateFormContributionRegistrationCache();
212
+ }
213
+ /** Brings a hidden panel back. */
214
+ Show(entityName, key) {
215
+ SetPanelHidden(entityName, key, false);
216
+ InvalidateFormContributionRegistrationCache();
217
+ }
218
+ /**
219
+ * Retire the live item for the audience, then re-aim the target and turn it on, in one
220
+ * transaction.
221
+ *
222
+ * The retirement is enqueued first because the transaction applies writes in order, and the
223
+ * unique index on active contributions would otherwise see two live rows mid-statement.
224
+ */
225
+ async publish(entityName, targetID, retiringID, audience, provider) {
226
+ try {
227
+ const md = provider ?? Metadata.Provider;
228
+ if (!md?.CurrentUser)
229
+ return { Success: false, Message: 'No signed-in user.' };
230
+ const write = await this.begin(md, retiringID ? [targetID, retiringID] : [targetID]);
231
+ if (retiringID) {
232
+ const retired = await this.retire(write, entityName, retiringID);
233
+ if (retired)
234
+ return retired;
235
+ }
236
+ const target = await this.loadScoped(md, entityName, targetID);
237
+ if (!target)
238
+ return { Success: false, Message: 'That item is no longer registered.' };
239
+ const columns = AudienceColumns(audience, md.CurrentUser.ID);
240
+ target.Scope = columns.Scope;
241
+ target.RoleID = columns.RoleID;
242
+ target.UserID = columns.UserID;
243
+ const failed = await this.enqueue(write, target, 'Active', 'The change could not be saved.');
244
+ if (failed)
245
+ return failed;
246
+ const result = await this.submit(write);
247
+ if (result.Success)
248
+ InvalidateFormContributionRegistrationCache();
249
+ return result;
250
+ }
251
+ catch (err) {
252
+ const message = this.message(err);
253
+ LogError(`FormPanelAdminService: publish of ${targetID} failed: ${message}`);
254
+ return { Success: false, Message: message };
255
+ }
256
+ }
257
+ /**
258
+ * Saves a panel row in `status`, in one transaction with what that carries: turning it on
259
+ * retires the panel live under its key for its audience first, and each component's status
260
+ * follows its row's.
261
+ */
262
+ async saveAs(md, row, status) {
263
+ const retiring = status === 'Active' ? ActiveContributionSiblings(this.contributionRows(), row) : [];
264
+ const write = await this.begin(md, [row.ID, ...retiring.map((sibling) => sibling.ID)]);
265
+ for (const sibling of retiring) {
266
+ const retired = await this.retire(write, 'MJ: Entity Form Contributions', sibling.ID);
267
+ if (retired)
268
+ return retired;
269
+ }
270
+ const failed = await this.enqueue(write, row, status, 'The change could not be saved.');
271
+ return failed ?? this.submit(write);
272
+ }
273
+ async begin(md, changing) {
274
+ return { Provider: md, Group: await md.CreateTransactionGroup(), Changing: new Set(changing), Queued: [] };
275
+ }
276
+ /** Submits the transaction. When it fails, the reason the first refused write recorded. */
277
+ async submit(write) {
278
+ if (await write.Group.Submit())
279
+ return { Success: true };
280
+ const refused = write.Queued.find((entity) => entity.LatestResult?.Success === false);
281
+ return { Success: false, Message: refused?.LatestResult?.CompleteMessage || 'The change could not be saved.' };
282
+ }
283
+ /** Enqueues turning off a live form or panel and its component. Null when that is enqueued. */
284
+ async retire(write, entityName, id) {
285
+ const row = await this.loadScoped(write.Provider, entityName, id);
286
+ if (!row)
287
+ return { Success: false, Message: 'The item it replaces could not be loaded.' };
288
+ return this.enqueue(write, row, 'Inactive', 'The item it replaces could not be retired.');
289
+ }
290
+ /** Enqueues a row's save in `status`, then its component's. Null when both are enqueued. */
291
+ async enqueue(write, row, status, fallback) {
292
+ row.Status = status;
293
+ row.TransactionGroup = write.Group;
294
+ write.Queued.push(row);
295
+ if (!(await row.Save()))
296
+ return this.failure(row, fallback);
297
+ return this.mirrorOnComponent(write, row.ComponentID, status);
298
+ }
299
+ /**
300
+ * Enqueues the component status that mirrors `status`. A component another live row still
301
+ * renders keeps its status, and one that already has it is not written. Null unless the write
302
+ * is refused.
303
+ */
304
+ async mirrorOnComponent(write, componentID, status) {
305
+ if (!componentID)
306
+ return null;
307
+ if (status !== 'Active' && this.componentLiveElsewhere(componentID, write.Changing))
308
+ return null;
309
+ const component = await write.Provider.GetEntityObject('MJ: Components');
310
+ if (!(await component.Load(componentID))) {
311
+ console.warn(`FormPanelAdminService: component ${componentID} could not be loaded, so its status was left as it is.`);
312
+ return null;
313
+ }
314
+ const next = FormLifecycleComponentStatus(status);
315
+ if (component.Status === next)
316
+ return null;
317
+ component.Status = next;
318
+ component.TransactionGroup = write.Group;
319
+ write.Queued.push(component);
320
+ return (await component.Save()) ? null : this.failure(component, 'Its component could not be updated.');
321
+ }
322
+ /** Whether a live form or panel outside this write still renders the component. */
323
+ componentLiveElsewhere(componentID, changing) {
324
+ const ids = [...changing];
325
+ const renders = (row) => row.Status === 'Active'
326
+ && UUIDsEqual(row.ComponentID, componentID)
327
+ && !ids.some((id) => UUIDsEqual(id, row.ID));
328
+ try {
329
+ const engine = InteractiveFormsEngine.Instance;
330
+ return engine.Contributions.some(renders) || engine.Overrides.some(renders);
331
+ }
332
+ catch {
333
+ return false;
334
+ }
335
+ }
336
+ /** A fresh copy of a form or panel row, never the engine's own cached instance. */
337
+ async loadScoped(md, entityName, id) {
338
+ const row = entityName === 'MJ: Entity Form Contributions'
339
+ ? await md.GetEntityObject(entityName)
340
+ : await md.GetEntityObject(entityName);
341
+ return (await row.Load(id)) ? row : null;
342
+ }
343
+ failure(row, fallback) {
344
+ return { Success: false, Message: row.LatestResult?.CompleteMessage || fallback };
345
+ }
346
+ contributionRows() {
347
+ return InteractiveFormsEngine.Instance.Contributions.map((row) => ({
348
+ ID: row.ID, EntityID: row.EntityID, Status: row.Status, Scope: row.Scope,
349
+ RoleID: row.RoleID, UserID: row.UserID, ContributionKey: row.ContributionKey,
350
+ }));
351
+ }
352
+ overrideRows() {
353
+ return InteractiveFormsEngine.Instance.Overrides.map((row) => ({
354
+ ID: row.ID, EntityID: row.EntityID, Status: row.Status, Scope: row.Scope,
355
+ RoleID: row.RoleID, UserID: row.UserID,
356
+ }));
357
+ }
358
+ /**
359
+ * Load the row, hand it to the caller, then drop the memo the form runtime reads.
360
+ *
361
+ * The engine emits on its own and that clears the registration cache, but the emission
362
+ * is not guaranteed to land before the next change-detection pass, and a form still
363
+ * drawing a panel the user just removed reads as the removal having failed.
364
+ */
365
+ async write(rowID, provider, act) {
366
+ if (!rowID)
367
+ return { Success: false, Message: 'No panel was named.' };
368
+ try {
369
+ const md = provider ?? Metadata.Provider;
370
+ if (!md)
371
+ return { Success: false, Message: 'No metadata provider is available.' };
372
+ const row = await md.GetEntityObject('MJ: Entity Form Contributions');
373
+ if (!(await row.Load(rowID))) {
374
+ return { Success: false, Message: 'That panel is no longer registered.' };
375
+ }
376
+ const result = await act(row, md);
377
+ if (result.Success)
378
+ InvalidateFormContributionRegistrationCache();
379
+ return result;
380
+ }
381
+ catch (err) {
382
+ const message = this.message(err);
383
+ LogError(`FormPanelAdminService: write on ${rowID} failed: ${message}`);
384
+ return { Success: false, Message: message };
385
+ }
386
+ }
387
+ /** The decision, with the columns the placement dialog does not edit filled in from the row. */
388
+ keepUneditedColumns(contribution, row) {
389
+ return {
390
+ ...contribution,
391
+ sortKey: contribution.sortKey ?? row.SortKey,
392
+ inclusion: contribution.inclusion ?? row.Inclusion ?? undefined,
393
+ configuration: mergeConfiguration(row.Configuration, contribution.configuration),
394
+ };
395
+ }
396
+ project(row) {
397
+ return {
398
+ ID: row.ID,
399
+ Name: row.Name,
400
+ Title: row.Title,
401
+ Icon: row.Icon,
402
+ Slot: row.Slot,
403
+ Presentation: row.Presentation,
404
+ Status: row.Status,
405
+ Scope: row.Scope,
406
+ UserID: row.UserID,
407
+ RoleID: row.RoleID,
408
+ Role: row.Role,
409
+ ReplacesSectionKey: row.ReplacesSectionKey,
410
+ ReplacesFieldNames: ParseClaimedFieldNames(row.ReplacesFieldNames),
411
+ ReplacesSectionKeys: ParseClaimedFieldNames(row.ReplacesSectionKeys),
412
+ InSectionKey: row.InSectionKey,
413
+ SectionPosition: row.SectionPosition,
414
+ RelatedEntity: row.RelatedEntity,
415
+ RelatedJoinField: row.RelatedJoinField,
416
+ ChromeGroup: row.ChromeGroup,
417
+ ContributionKey: row.ContributionKey,
418
+ ComponentID: row.ComponentID,
419
+ SortKey: row.SortKey ?? 0,
420
+ Configuration: row.Configuration,
421
+ };
422
+ }
423
+ message(err) {
424
+ return err instanceof Error ? err.message : String(err);
425
+ }
426
+ static ɵfac = function FormPanelAdminService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || FormPanelAdminService)(); };
427
+ static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: FormPanelAdminService, factory: FormPanelAdminService.ɵfac, providedIn: 'root' });
428
+ }
429
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FormPanelAdminService, [{
430
+ type: Injectable,
431
+ args: [{ providedIn: 'root' }]
432
+ }], null, null); })();
433
+ //# sourceMappingURL=form-panel-admin.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-panel-admin.service.js","sourceRoot":"","sources":["../../../src/lib/panel-manager/form-panel-admin.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACH,QAAQ,EAAE,QAAQ,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACH,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAK5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,oCAAoC,EACpC,2CAA2C,GAC9C,MAA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AAG,CAAC,kBAAkB,CAAC;YAClE,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,CAAC,mBAAmB,CAAC;YACpE,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,eAAe,EAAE,GAAG,CAAC,eAAe;YACpC,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;YACtC,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,eAAe,EAAE,GAAG,CAAC,eAAe;YACpC,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,CAAC;YACzB,aAAa,EAAE,GAAG,CAAC,aAAa;SACnC,CAAC;IACN,CAAC;IAEO,OAAO,CAAC,GAAY;QACxB,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;+GArbQ,qBAAqB;gEAArB,qBAAqB,WAArB,qBAAqB,mBADR,MAAM;;iFACnB,qBAAqB;cADjC,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport {\n LogError, Metadata, type BaseEntity, type EntityInfo, type IMetadataProvider, type TransactionGroupBase,\n} from '@memberjunction/core';\nimport { UUIDsEqual } from '@memberjunction/global';\nimport {\n ActiveContributionSiblings,\n ApplyContributionSpecToRow,\n FormLifecycleComponentStatus,\n InteractiveFormsEngine,\n ParseClaimedFieldNames,\n UserCanManageFormDefaults,\n type FormLifecycleStatus,\n type MJComponentEntity,\n type MJEntityFormContributionEntity,\n type MJEntityFormOverrideEntity,\n} from '@memberjunction/core-entities';\nimport {\n CollectFormContributionRegistrations,\n InvalidateFormContributionRegistrationCache,\n} from '../panel-slot/collect-form-contribution-registrations';\nimport { ResolveFormContributionWinners } from '../panel-slot/form-contribution';\nimport type { FormContributionSpec } from '@memberjunction/interactive-component-types/forms';\nimport { ParseContributionConfiguration, type FormOverrideRow, type FormPanelContributionRow, type FormPanelRendering } from './form-panel-inventory';\nimport { PanelHideKey, SetPanelHidden } from '../panel-slot/panel-hides';\nimport {\n AudienceColumns,\n LiveContributionAt,\n LiveOverrideAt,\n type FormAudience,\n type ScopedRow,\n} from './form-audience';\n\n/** What a write attempt did, in terms the drawer can show. */\nexport interface FormPanelAdminResult {\n Success: boolean;\n Message?: string;\n}\n\n/** The two entities the drawer writes. */\ntype ScopedEntityName = 'MJ: Entity Form Contributions' | 'MJ: Entity Form Overrides';\n\n/** A form or panel row loaded for a write. */\ntype ScopedEntity = MJEntityFormContributionEntity | MJEntityFormOverrideEntity;\n\n/** One transaction being built: the rows whose status it changes, and every entity enqueued in it. */\ninterface PendingWrite {\n Provider: IMetadataProvider;\n Group: TransactionGroupBase;\n Changing: ReadonlySet<string>;\n Queued: BaseEntity[];\n}\n\n/**\n * The row's stored configuration with the decision's keys over it, so a key the placement\n * dialog does not write survives an edit. Undefined when both are empty.\n */\nfunction mergeConfiguration(stored: string | null, decided: Record<string, unknown> | undefined): Record<string, unknown> | undefined {\n const merged = { ...(ParseContributionConfiguration(stored) ?? {}), ...(decided ?? {}) };\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\n/**\n * Loads and changes the contribution rows behind one entity's form.\n *\n * Reads come from {@link InteractiveFormsEngine}, which already caches every row for\n * every scope and status and emits when one changes — the same cache the form runtime\n * reads, so the manager cannot disagree with the form it is managing.\n *\n * Writes go through `BaseEntity.Save()` and `.Delete()`. Direct SQL against an entity\n * skips the Record Changes audit row, the server cache invalidation, entity actions and\n * validation, all of which fail silently and leave a database that looks right.\n *\n * Turning a form or panel on follows the rule the Activate actions follow: the one live under the\n * same key for the same audience is retired first, in the same transaction, and each component's\n * status mirrors its row's.\n */\n@Injectable({ providedIn: 'root' })\nexport class FormPanelAdminService {\n\n /**\n * Every contribution registered on this entity, whatever its scope or status.\n *\n * Not `GetApplicableContributions`: that answers what should render right now, which\n * excludes the drafts and switched-off rows this surface exists to bring back.\n */\n public RowsForEntity(entity: EntityInfo | null | undefined): FormPanelContributionRow[] {\n if (!entity?.ID) return [];\n try {\n return InteractiveFormsEngine.Instance.Contributions\n .filter((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID))\n .map((row) => this.project(row));\n } catch (err: unknown) {\n LogError(`FormPanelAdminService: could not read contributions: ${this.message(err)}`);\n return [];\n }\n }\n\n /**\n * Whether the entity carries any contribution row at all, whatever its status.\n *\n * Separate from {@link RowsForEntity} because the container asks this on every\n * change-detection pass to decide whether to offer the manager, and projecting every\n * row to answer a yes-or-no question allocates on the hottest path in the form runtime.\n */\n public HasRowsForEntity(entity: EntityInfo | null | undefined): boolean {\n if (!entity?.ID) return false;\n try {\n return InteractiveFormsEngine.Instance.Contributions\n .some((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID));\n } catch {\n // No engine in this context — nothing to manage.\n return false;\n }\n }\n\n /**\n * Switches a row on or off. Off leaves the row in place, rendering for nobody. On retires the\n * panel live under the same key for the same audience first, in the same transaction.\n */\n public async SetActive(\n rowID: string,\n active: boolean,\n provider?: IMetadataProvider | null,\n ): Promise<FormPanelAdminResult> {\n return this.write(rowID, provider, (row, md) => this.saveAs(md, row, active ? 'Active' : 'Inactive'));\n }\n\n /**\n * Which panels on this form draw for the current user: the winner of each key, with the\n * user's hidden panels left out — the same resolution the form makes. Undefined when that\n * cannot be resolved, so the list falls back to each item's own status.\n */\n public RenderingFor(\n entity: EntityInfo | null | undefined,\n provider?: IMetadataProvider | null,\n ): FormPanelRendering | undefined {\n const md = provider ?? Metadata.Provider;\n if (!entity || !md) return undefined;\n try {\n const rowIDs = new Set<string>();\n const compiledKeys = new Set<string>();\n const registrations = CollectFormContributionRegistrations(entity, md);\n for (const winner of ResolveFormContributionWinners(entity.Name, registrations).Winners) {\n if (winner.Source === 'metadata') {\n if (winner.RowID) rowIDs.add(winner.RowID.toLowerCase());\n continue;\n }\n const key = PanelHideKey(winner);\n if (key) compiledKeys.add(key);\n }\n return { RowIDs: rowIDs, CompiledKeys: compiledKeys };\n } catch (err: unknown) {\n LogError(`FormPanelAdminService: could not resolve what the form draws: ${this.message(err)}`);\n return undefined;\n }\n }\n\n /**\n * Writes a new placement onto an existing row, through the same row mapper the Create and\n * Modify actions use.\n *\n * Every claim column is rewritten, including the ones the decision leaves out, so a claim the\n * user has just dropped is actually cleared. The key is the one the decision names, or the\n * one the write path derives from its grid claim or the row's component. The order,\n * rail inclusion and configuration, which the placement dialog does not edit, are kept.\n *\n * @param status What the row is saved as: on, a draft, or off. On retires the panel live under\n * the row's new key for its audience, in the same transaction.\n */\n public async SetPlacement(\n rowID: string,\n contribution: FormContributionSpec,\n status: FormLifecycleStatus,\n provider?: IMetadataProvider | null,\n ): Promise<FormPanelAdminResult> {\n return this.write(rowID, provider, async (row, md) => {\n const relatedName = contribution.relatedEntity?.trim();\n const related = relatedName ? (provider ?? Metadata.Provider)?.EntityByName(relatedName) : null;\n if (relatedName && !related) {\n return { Success: false, Message: `The related entity \"${relatedName}\" is not registered.` };\n }\n ApplyContributionSpecToRow(row, this.keepUneditedColumns(contribution, row), {\n relatedEntityID: related?.ID ?? null,\n relatedEntityName: related?.Name ?? null,\n componentName: row.Component || null,\n });\n return this.saveAs(md, row, status);\n });\n }\n\n /** Deletes a row outright. The Component it points at is left alone. */\n public async Remove(rowID: string, provider?: IMetadataProvider | null): Promise<FormPanelAdminResult> {\n return this.write(rowID, provider, async (row) => {\n const deleted = await row.Delete();\n return deleted\n ? { Success: true }\n : { Success: false, Message: row.LatestResult?.CompleteMessage ?? 'The panel could not be removed.' };\n });\n }\n\n /**\n * Whether the current user may publish to a role or to everyone.\n *\n * Only decides what the drawer draws. The server-side entity subclasses enforce the same rule\n * on every save, so a client that draws itself a Publish button still has the write refused.\n */\n public CanPublish(provider?: IMetadataProvider | null): boolean {\n const md = provider ?? Metadata.Provider;\n return UserCanManageFormDefaults(md?.CurrentUser, md);\n }\n\n /**\n * The full custom forms the engine holds for this entity, in every status: every shared form\n * and the signed-in user's own.\n */\n public OverridesForEntity(entity: EntityInfo | null | undefined): FormOverrideRow[] {\n if (!entity?.ID) return [];\n try {\n return InteractiveFormsEngine.Instance.Overrides\n .filter((row) => row.EntityID && UUIDsEqual(row.EntityID, entity.ID))\n .map((row) => ({\n ID: row.ID, Name: row.Name, Status: row.Status, Scope: row.Scope,\n UserID: row.UserID, RoleID: row.RoleID, Role: row.Role,\n }));\n } catch (err: unknown) {\n LogError(`FormPanelAdminService: could not read forms: ${this.message(err)}`);\n return [];\n }\n }\n\n /**\n * Changes who a panel is for, and turns it on.\n *\n * The panel live for that audience under the same key is retired first, in the same\n * transaction, so the audience never sees two and the unique index on active contributions\n * never sees two either. A draft or a panel that is off goes live in the same transaction —\n * publishing one never leaves the audience with neither.\n */\n public async PublishContribution(\n rowID: string,\n audience: FormAudience,\n provider?: IMetadataProvider | null,\n ): Promise<FormPanelAdminResult> {\n const rows = this.contributionRows();\n const target = rows.find((row) => UUIDsEqual(row.ID, rowID));\n if (!target) return { Success: false, Message: 'That panel is no longer registered.' };\n const callerID = (provider ?? Metadata.Provider)?.CurrentUser?.ID ?? '';\n const retiring = LiveContributionAt(rows, target, audience, callerID);\n return this.publish('MJ: Entity Form Contributions', target.ID, retiring?.ID ?? null, audience, provider);\n }\n\n /**\n * Changes who a full custom form is for, and makes it live. Whichever form was live for that\n * audience is set aside in the same transaction. A personal form set aside stays in its\n * owner's picker, so the two can be swapped back; a role or everyone form set aside is\n * retracted and no longer offered to anyone.\n */\n public async PublishOverride(\n overrideID: string,\n audience: FormAudience,\n provider?: IMetadataProvider | null,\n ): Promise<FormPanelAdminResult> {\n const rows = this.overrideRows();\n const target = rows.find((row) => UUIDsEqual(row.ID, overrideID));\n if (!target) return { Success: false, Message: 'That form is no longer registered.' };\n const callerID = (provider ?? Metadata.Provider)?.CurrentUser?.ID ?? '';\n const retiring = LiveOverrideAt(rows, target, audience, callerID);\n return this.publish('MJ: Entity Form Overrides', target.ID, retiring?.ID ?? null, audience, provider);\n }\n\n /** Hides a panel from this user's form. Stored per user; nobody else is affected. */\n public Hide(entityName: string, key: string): void {\n SetPanelHidden(entityName, key, true);\n InvalidateFormContributionRegistrationCache();\n }\n\n /** Brings a hidden panel back. */\n public Show(entityName: string, key: string): void {\n SetPanelHidden(entityName, key, false);\n InvalidateFormContributionRegistrationCache();\n }\n\n /**\n * Retire the live item for the audience, then re-aim the target and turn it on, in one\n * transaction.\n *\n * The retirement is enqueued first because the transaction applies writes in order, and the\n * unique index on active contributions would otherwise see two live rows mid-statement.\n */\n private async publish(\n entityName: ScopedEntityName,\n targetID: string,\n retiringID: string | null,\n audience: FormAudience,\n provider?: IMetadataProvider | null,\n ): Promise<FormPanelAdminResult> {\n try {\n const md = provider ?? Metadata.Provider;\n if (!md?.CurrentUser) return { Success: false, Message: 'No signed-in user.' };\n const write = await this.begin(md, retiringID ? [targetID, retiringID] : [targetID]);\n if (retiringID) {\n const retired = await this.retire(write, entityName, retiringID);\n if (retired) return retired;\n }\n const target = await this.loadScoped(md, entityName, targetID);\n if (!target) return { Success: false, Message: 'That item is no longer registered.' };\n const columns = AudienceColumns(audience, md.CurrentUser.ID);\n target.Scope = columns.Scope;\n target.RoleID = columns.RoleID;\n target.UserID = columns.UserID;\n const failed = await this.enqueue(write, target, 'Active', 'The change could not be saved.');\n if (failed) return failed;\n const result = await this.submit(write);\n if (result.Success) InvalidateFormContributionRegistrationCache();\n return result;\n } catch (err: unknown) {\n const message = this.message(err);\n LogError(`FormPanelAdminService: publish of ${targetID} failed: ${message}`);\n return { Success: false, Message: message };\n }\n }\n\n /**\n * Saves a panel row in `status`, in one transaction with what that carries: turning it on\n * retires the panel live under its key for its audience first, and each component's status\n * follows its row's.\n */\n private async saveAs(\n md: IMetadataProvider,\n row: MJEntityFormContributionEntity,\n status: FormLifecycleStatus,\n ): Promise<FormPanelAdminResult> {\n const retiring = status === 'Active' ? ActiveContributionSiblings(this.contributionRows(), row) : [];\n const write = await this.begin(md, [row.ID, ...retiring.map((sibling) => sibling.ID)]);\n for (const sibling of retiring) {\n const retired = await this.retire(write, 'MJ: Entity Form Contributions', sibling.ID);\n if (retired) return retired;\n }\n const failed = await this.enqueue(write, row, status, 'The change could not be saved.');\n return failed ?? this.submit(write);\n }\n\n private async begin(md: IMetadataProvider, changing: readonly string[]): Promise<PendingWrite> {\n return { Provider: md, Group: await md.CreateTransactionGroup(), Changing: new Set(changing), Queued: [] };\n }\n\n /** Submits the transaction. When it fails, the reason the first refused write recorded. */\n private async submit(write: PendingWrite): Promise<FormPanelAdminResult> {\n if (await write.Group.Submit()) return { Success: true };\n const refused = write.Queued.find((entity) => entity.LatestResult?.Success === false);\n return { Success: false, Message: refused?.LatestResult?.CompleteMessage || 'The change could not be saved.' };\n }\n\n /** Enqueues turning off a live form or panel and its component. Null when that is enqueued. */\n private async retire(write: PendingWrite, entityName: ScopedEntityName, id: string): Promise<FormPanelAdminResult | null> {\n const row = await this.loadScoped(write.Provider, entityName, id);\n if (!row) return { Success: false, Message: 'The item it replaces could not be loaded.' };\n return this.enqueue(write, row, 'Inactive', 'The item it replaces could not be retired.');\n }\n\n /** Enqueues a row's save in `status`, then its component's. Null when both are enqueued. */\n private async enqueue(\n write: PendingWrite,\n row: ScopedEntity,\n status: FormLifecycleStatus,\n fallback: string,\n ): Promise<FormPanelAdminResult | null> {\n row.Status = status;\n row.TransactionGroup = write.Group;\n write.Queued.push(row);\n if (!(await row.Save())) return this.failure(row, fallback);\n return this.mirrorOnComponent(write, row.ComponentID, status);\n }\n\n /**\n * Enqueues the component status that mirrors `status`. A component another live row still\n * renders keeps its status, and one that already has it is not written. Null unless the write\n * is refused.\n */\n private async mirrorOnComponent(\n write: PendingWrite,\n componentID: string | null | undefined,\n status: FormLifecycleStatus,\n ): Promise<FormPanelAdminResult | null> {\n if (!componentID) return null;\n if (status !== 'Active' && this.componentLiveElsewhere(componentID, write.Changing)) return null;\n const component = await write.Provider.GetEntityObject<MJComponentEntity>('MJ: Components');\n if (!(await component.Load(componentID))) {\n console.warn(`FormPanelAdminService: component ${componentID} could not be loaded, so its status was left as it is.`);\n return null;\n }\n const next = FormLifecycleComponentStatus(status);\n if (component.Status === next) return null;\n component.Status = next;\n component.TransactionGroup = write.Group;\n write.Queued.push(component);\n return (await component.Save()) ? null : this.failure(component, 'Its component could not be updated.');\n }\n\n /** Whether a live form or panel outside this write still renders the component. */\n private componentLiveElsewhere(componentID: string, changing: ReadonlySet<string>): boolean {\n const ids = [...changing];\n const renders = (row: { ID: string; ComponentID: string; Status: string }): boolean =>\n row.Status === 'Active'\n && UUIDsEqual(row.ComponentID, componentID)\n && !ids.some((id) => UUIDsEqual(id, row.ID));\n try {\n const engine = InteractiveFormsEngine.Instance;\n return engine.Contributions.some(renders) || engine.Overrides.some(renders);\n } catch {\n return false;\n }\n }\n\n /** A fresh copy of a form or panel row, never the engine's own cached instance. */\n private async loadScoped(\n md: IMetadataProvider,\n entityName: ScopedEntityName,\n id: string,\n ): Promise<ScopedEntity | null> {\n const row = entityName === 'MJ: Entity Form Contributions'\n ? await md.GetEntityObject<MJEntityFormContributionEntity>(entityName)\n : await md.GetEntityObject<MJEntityFormOverrideEntity>(entityName);\n return (await row.Load(id)) ? row : null;\n }\n\n private failure(row: { LatestResult?: { CompleteMessage?: string } | null }, fallback: string): FormPanelAdminResult {\n return { Success: false, Message: row.LatestResult?.CompleteMessage || fallback };\n }\n\n private contributionRows(): ScopedRow[] {\n return InteractiveFormsEngine.Instance.Contributions.map((row) => ({\n ID: row.ID, EntityID: row.EntityID, Status: row.Status, Scope: row.Scope,\n RoleID: row.RoleID, UserID: row.UserID, ContributionKey: row.ContributionKey,\n }));\n }\n\n private overrideRows(): ScopedRow[] {\n return InteractiveFormsEngine.Instance.Overrides.map((row) => ({\n ID: row.ID, EntityID: row.EntityID, Status: row.Status, Scope: row.Scope,\n RoleID: row.RoleID, UserID: row.UserID,\n }));\n }\n\n /**\n * Load the row, hand it to the caller, then drop the memo the form runtime reads.\n *\n * The engine emits on its own and that clears the registration cache, but the emission\n * is not guaranteed to land before the next change-detection pass, and a form still\n * drawing a panel the user just removed reads as the removal having failed.\n */\n private async write(\n rowID: string,\n provider: IMetadataProvider | null | undefined,\n act: (row: MJEntityFormContributionEntity, md: IMetadataProvider) => Promise<FormPanelAdminResult>,\n ): Promise<FormPanelAdminResult> {\n if (!rowID) return { Success: false, Message: 'No panel was named.' };\n try {\n const md = provider ?? Metadata.Provider;\n if (!md) return { Success: false, Message: 'No metadata provider is available.' };\n const row = await md.GetEntityObject<MJEntityFormContributionEntity>('MJ: Entity Form Contributions');\n if (!(await row.Load(rowID))) {\n return { Success: false, Message: 'That panel is no longer registered.' };\n }\n const result = await act(row, md);\n if (result.Success) InvalidateFormContributionRegistrationCache();\n return result;\n } catch (err: unknown) {\n const message = this.message(err);\n LogError(`FormPanelAdminService: write on ${rowID} failed: ${message}`);\n return { Success: false, Message: message };\n }\n }\n\n /** The decision, with the columns the placement dialog does not edit filled in from the row. */\n private keepUneditedColumns(contribution: FormContributionSpec, row: MJEntityFormContributionEntity): FormContributionSpec {\n return {\n ...contribution,\n sortKey: contribution.sortKey ?? row.SortKey,\n inclusion: contribution.inclusion ?? row.Inclusion ?? undefined,\n configuration: mergeConfiguration(row.Configuration, contribution.configuration),\n };\n }\n\n private project(row: MJEntityFormContributionEntity): FormPanelContributionRow {\n return {\n ID: row.ID,\n Name: row.Name,\n Title: row.Title,\n Icon: row.Icon,\n Slot: row.Slot,\n Presentation: row.Presentation,\n Status: row.Status,\n Scope: row.Scope,\n UserID: row.UserID,\n RoleID: row.RoleID,\n Role: row.Role,\n ReplacesSectionKey: row.ReplacesSectionKey,\n ReplacesFieldNames: ParseClaimedFieldNames(row.ReplacesFieldNames),\n ReplacesSectionKeys: ParseClaimedFieldNames(row.ReplacesSectionKeys),\n InSectionKey: row.InSectionKey,\n SectionPosition: row.SectionPosition,\n RelatedEntity: row.RelatedEntity,\n RelatedJoinField: row.RelatedJoinField,\n ChromeGroup: row.ChromeGroup,\n ContributionKey: row.ContributionKey,\n ComponentID: row.ComponentID,\n SortKey: row.SortKey ?? 0,\n Configuration: row.Configuration,\n };\n }\n\n private message(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n }\n}\n"]}