@genesislcap/ai-assistant 15.37.0 → 15.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/custom-elements.json +638 -0
  2. package/dist/dts/genesis/calendar.d.ts +25 -0
  3. package/dist/dts/genesis/calendar.d.ts.map +1 -0
  4. package/dist/dts/genesis/config.d.ts +16 -0
  5. package/dist/dts/genesis/config.d.ts.map +1 -1
  6. package/dist/dts/genesis/criteria.d.ts +24 -2
  7. package/dist/dts/genesis/criteria.d.ts.map +1 -1
  8. package/dist/dts/genesis/event-fields.d.ts +84 -0
  9. package/dist/dts/genesis/event-fields.d.ts.map +1 -0
  10. package/dist/dts/genesis/filter-fields.d.ts +69 -5
  11. package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
  12. package/dist/dts/genesis/index.d.ts +3 -0
  13. package/dist/dts/genesis/index.d.ts.map +1 -1
  14. package/dist/dts/genesis/register-genesis-assistant.d.ts +13 -0
  15. package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
  16. package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
  17. package/dist/dts/genesis/review-model.d.ts +202 -0
  18. package/dist/dts/genesis/review-model.d.ts.map +1 -0
  19. package/dist/dts/genesis/row-source.d.ts +102 -0
  20. package/dist/dts/genesis/row-source.d.ts.map +1 -0
  21. package/dist/dts/genesis/serialisable.d.ts +25 -0
  22. package/dist/dts/genesis/serialisable.d.ts.map +1 -0
  23. package/dist/dts/genesis/server-text.d.ts +63 -0
  24. package/dist/dts/genesis/server-text.d.ts.map +1 -0
  25. package/dist/dts/genesis/type-name.d.ts +18 -0
  26. package/dist/dts/genesis/type-name.d.ts.map +1 -0
  27. package/dist/dts/genesis/types.d.ts +7 -0
  28. package/dist/dts/genesis/types.d.ts.map +1 -1
  29. package/dist/dts/genesis/value-compare.d.ts +19 -0
  30. package/dist/dts/genesis/value-compare.d.ts.map +1 -0
  31. package/dist/dts/genesis/write-commit.d.ts +53 -0
  32. package/dist/dts/genesis/write-commit.d.ts.map +1 -0
  33. package/dist/dts/genesis/write-outcome.d.ts +133 -0
  34. package/dist/dts/genesis/write-outcome.d.ts.map +1 -0
  35. package/dist/dts/genesis/write-payload.d.ts +129 -0
  36. package/dist/dts/genesis/write-payload.d.ts.map +1 -0
  37. package/dist/dts/genesis/write-plan.d.ts +109 -0
  38. package/dist/dts/genesis/write-plan.d.ts.map +1 -0
  39. package/dist/dts/genesis/write-review/write-review.d.ts +127 -0
  40. package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -0
  41. package/dist/dts/genesis/write-review/write-review.styles.d.ts +2 -0
  42. package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -0
  43. package/dist/dts/genesis/write-review/write-review.template.d.ts +4 -0
  44. package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -0
  45. package/dist/dts/genesis/write-tools.d.ts +99 -0
  46. package/dist/dts/genesis/write-tools.d.ts.map +1 -0
  47. package/dist/dts/react.d.ts +10 -0
  48. package/dist/esm/genesis/calendar.js +38 -0
  49. package/dist/esm/genesis/config.js +36 -1
  50. package/dist/esm/genesis/criteria.js +59 -55
  51. package/dist/esm/genesis/event-fields.js +158 -0
  52. package/dist/esm/genesis/filter-fields.js +111 -20
  53. package/dist/esm/genesis/index.js +2 -0
  54. package/dist/esm/genesis/register-genesis-assistant.js +76 -4
  55. package/dist/esm/genesis/resource-tools.js +21 -103
  56. package/dist/esm/genesis/review-model.js +248 -0
  57. package/dist/esm/genesis/row-source.js +127 -0
  58. package/dist/esm/genesis/serialisable.js +38 -0
  59. package/dist/esm/genesis/server-text.js +186 -0
  60. package/dist/esm/genesis/type-name.js +20 -0
  61. package/dist/esm/genesis/value-compare.js +87 -0
  62. package/dist/esm/genesis/write-commit.js +78 -0
  63. package/dist/esm/genesis/write-outcome.js +299 -0
  64. package/dist/esm/genesis/write-payload.js +632 -0
  65. package/dist/esm/genesis/write-plan.js +275 -0
  66. package/dist/esm/genesis/write-review/write-review.js +252 -0
  67. package/dist/esm/genesis/write-review/write-review.styles.js +214 -0
  68. package/dist/esm/genesis/write-review/write-review.template.js +182 -0
  69. package/dist/esm/genesis/write-tools.js +660 -0
  70. package/dist/react.cjs +7 -0
  71. package/dist/react.mjs +6 -0
  72. package/docs/genesis.md +152 -10
  73. package/package.json +18 -18
@@ -0,0 +1,275 @@
1
+ import { __awaiter } from "tslib";
2
+ import { sameValue } from './value-compare';
3
+ import { buildEventPayload, isBlankEntry, PLATFORM_MAINTAINED, sendableFields, } from './write-payload';
4
+ /**
5
+ * A batch a person can actually read before approving it.
6
+ *
7
+ * @remarks
8
+ * A cap rather than a truncation: writing the first 25 of 400 rows and reporting it as done is
9
+ * the kind of partial success nobody asked for. The model is told to send fewer, and each batch
10
+ * gets its own approval.
11
+ */
12
+ export const MAX_WRITE_ROWS = 25;
13
+ const asRecord = (value) => value && typeof value === 'object' && !Array.isArray(value)
14
+ ? value
15
+ : undefined;
16
+ /** The key a modify or delete entry names its row by; `changes` carries what it wants set. */
17
+ const keyOf = (entry) => asRecord(entry.key);
18
+ /**
19
+ * Builds what the review will show, reading the current row for every modify and delete.
20
+ *
21
+ * @remarks
22
+ * Reads run together — they are reads, and a batch of 25 sequential round trips is a visibly
23
+ * slow assistant — while the writes that follow are strictly sequential (see `commitRows`).
24
+ *
25
+ * @internal
26
+ */
27
+ export function planWrite(rows_1, _a) {
28
+ return __awaiter(this, arguments, void 0, function* (rows, { op, fields, source }) {
29
+ if (!Array.isArray(rows) || !rows.length) {
30
+ return { status: 'rejected', reason: 'rows must be a non-empty list of rows to write.' };
31
+ }
32
+ if (rows.length > MAX_WRITE_ROWS) {
33
+ return {
34
+ status: 'rejected',
35
+ reason: `${rows.length} rows is more than one review can sensibly be read: send at most ` +
36
+ `${MAX_WRITE_ROWS} at a time.`,
37
+ };
38
+ }
39
+ const needsRow = op === 'modify' || op === 'delete';
40
+ // Shape first, so a bad entry costs no round trip and the reads that follow all have a key.
41
+ const prepared = rows.map((entry, index) => {
42
+ const given = asRecord(entry);
43
+ if (!given) {
44
+ return { index, problems: ['each row must be an object of field names to values'] };
45
+ }
46
+ if (!needsRow)
47
+ return { index, given };
48
+ const key = keyOf(given);
49
+ if (!key) {
50
+ return {
51
+ index,
52
+ problems: [`a ${op} names its row with key, e.g. {"key": {"TRADE_ID": "..."}}`],
53
+ };
54
+ }
55
+ // A modify has to SAY what changes, and is refused by name when it does not — the same way a
56
+ // missing key is, one line up. `changes` used to fall back to `{}`, so a modify with none
57
+ // (absent, not an object, or empty) merged nothing over the row, wrote it back UNCHANGED, and
58
+ // was reported to the model as written: a confident success for a request that did nothing.
59
+ // A delete sends no changes and is not asked for any.
60
+ const changes = asRecord(given.changes);
61
+ if (op === 'modify' && (!changes || !Object.keys(changes).length)) {
62
+ return {
63
+ index,
64
+ key,
65
+ problems: [
66
+ 'a modify says what changes, e.g. {"key": {...}, "changes": {"QUANTITY": 900}}, and ' +
67
+ 'this one names no field to change',
68
+ ],
69
+ };
70
+ }
71
+ if (!source) {
72
+ return { index, key, problems: [`a ${op} needs a row to read, and none is configured`] };
73
+ }
74
+ return { index, given, key };
75
+ });
76
+ // Reads run together — they are reads, and twenty-five sequential round trips before a review
77
+ // even appears is a visibly slow assistant. The writes that follow are strictly sequential.
78
+ const reads = yield Promise.all(prepared.map((entry) => entry.key && !entry.problems ? source.read(entry.key) : Promise.resolve(undefined)));
79
+ // Walked in POSITION order, not in the order the reads came back, so which of two entries for
80
+ // one row is refused does not depend on the network.
81
+ const seen = new Map();
82
+ return {
83
+ status: 'ok',
84
+ rows: prepared.map((entry, at) => {
85
+ var _a;
86
+ if (entry.problems)
87
+ return { index: entry.index, key: entry.key, problems: entry.problems };
88
+ if (!needsRow) {
89
+ const built = buildEventPayload(fields, entry.given, { op });
90
+ return built.status === 'ok'
91
+ ? { index: entry.index, details: built.details }
92
+ : { index: entry.index, problems: built.problems };
93
+ }
94
+ const read = reads[at];
95
+ const refuse = (problem) => ({
96
+ index: entry.index,
97
+ key: entry.key,
98
+ problems: [problem],
99
+ });
100
+ if (read.status === 'missing')
101
+ return refuse(`no row in ${source.resource} matches that key`);
102
+ if (read.status === 'ambiguous') {
103
+ return refuse(`that key matches more than one row in ${source.resource}, so it does not identify ` +
104
+ 'one row. Narrow it.');
105
+ }
106
+ if (read.status === 'failed')
107
+ return refuse(`the row could not be read: ${read.reason}`);
108
+ // Deduped for a modify and a delete ONLY, which is deliberate and not the branch being
109
+ // in the wrong place.
110
+ //
111
+ // Two modifies of one row are destructive: the second carries a pre-image taken before
112
+ // the first landed, so the user saw two changes and got one. Two identical INSERTS are
113
+ // two records, which is what the instruction means — two identical trades are an ordinary
114
+ // thing — and nothing is silent, since both rows render, both must be ticked and both
115
+ // outcomes report.
116
+ //
117
+ // The deciding reason is that a pre-check here is not implementable rather than merely
118
+ // unevidenced: a Create-generated reqrep publishes `INDICES: []` and no reliable key list
119
+ // (NEW-22), which is why this path has no key-detection heuristic anywhere and why a
120
+ // delete takes its key from the resolved ROW. The bridge cannot know at proposal time
121
+ // whether two inserts would collide, so refusing the second would be guessing at a
122
+ // constraint it cannot read. Where the key IS caller-supplied and does collide, the
123
+ // second write comes back DUPLICATE_KEY and is reported against its own row.
124
+ //
125
+ // Deduped on the ROW the key resolved to, never on the key itself. The key is whatever
126
+ // shape the model chose — any field of the event may appear in it — so two entries for
127
+ // one row need not look alike, and a fingerprint of the key shape does not notice them.
128
+ // Both would then pass their staleness check (taken before either commit) and commit in
129
+ // order under replace semantics, so the second would silently undo the first while the
130
+ // review showed the user two changes.
131
+ const identity = rowIdentity(read.row);
132
+ const first = seen.get(identity);
133
+ if (first !== undefined) {
134
+ return {
135
+ index: entry.index,
136
+ key: entry.key,
137
+ preImage: read.row,
138
+ problems: [
139
+ `this is the same row as the one at position ${first + 1}. Change a row once per ` +
140
+ 'write: two changes to one row would be committed in order and only the last ' +
141
+ 'would survive.',
142
+ ],
143
+ };
144
+ }
145
+ seen.set(identity, entry.index);
146
+ // `changes` on a delete is meaningless: the row is the row. Ignored rather than refused,
147
+ // so a model that sends one does not lose the whole batch over it. On a modify it has
148
+ // already been checked above to be a non-empty object, so no default is needed here —
149
+ // and a default here is exactly what hid a modify that changed nothing.
150
+ const changes = op === 'modify' ? asRecord(entry.given.changes) : {};
151
+ // The key wins over changes, so a change cannot rename the row it selected. A modify that
152
+ // moved its own key would be a write against a record the user never saw — and on a
153
+ // generated handler it either creates a second record or fails, neither of which is what
154
+ // a review of "change TR1's quantity" asked for. Said out loud rather than done quietly.
155
+ const overridden = Object.keys(changes).filter((name) => name in entry.key && !sameValue(changes[name], entry.key[name]));
156
+ const built = buildEventPayload(fields, Object.assign(Object.assign({}, changes), entry.key), {
157
+ op,
158
+ preImage: read.row,
159
+ });
160
+ // A modify has to CHANGE something, and saying what is not the same as changing it. A
161
+ // non-empty `changes` can still leave every value as it is — `{NOTE: ''}` (an empty string
162
+ // keeps the row's value), or one that only restates the key — and the row went back
163
+ // unchanged and was reported `written`: the end state the refusal of an empty `changes`
164
+ // exists to stop, reached with a non-empty object.
165
+ //
166
+ // Compared over every SENDABLE field, not over the payload's own keys: under replace
167
+ // semantics a field the row holds and the payload lacks IS a change (it is written empty),
168
+ // and comparing only what the payload carries could not see one. Each with its declared
169
+ // type, the same way the staleness check and the changed-mark compare.
170
+ const changesNothing = op === 'modify' &&
171
+ built.status === 'ok' &&
172
+ sendableFields(fields, op)
173
+ .filter((field) => !PLATFORM_MAINTAINED.has(field.name))
174
+ .every((field) => sameValue(built.details[field.name], read.row[field.name], field.type));
175
+ // The fields the model tried to BLANK. `''` and `null` leave a field as it is, so a modify
176
+ // whose only "change" is a blank on a field that holds a value changes nothing — but
177
+ // "the row already has that value" is not the reason, and a model told so may report to
178
+ // the user that it cleared the column. Said as it is instead.
179
+ const blanked = op === 'modify'
180
+ ? Object.entries((_a = asRecord(entry.given.changes)) !== null && _a !== void 0 ? _a : {})
181
+ .filter(([name, value]) => isBlankEntry(value) && read.row[name] != null)
182
+ .map(([name]) => name)
183
+ : [];
184
+ const problems = [
185
+ ...(overridden.length
186
+ ? [
187
+ `${overridden.join(', ')} names the row and cannot be changed by the same write. ` +
188
+ 'Its key value is the one being used.',
189
+ ]
190
+ : []),
191
+ ...(built.status === 'rejected' ? built.problems : []),
192
+ ...(changesNothing
193
+ ? [
194
+ blanked.length
195
+ ? `this modify changes nothing: '' and null leave a field as it is, and this tool ` +
196
+ `cannot clear a column (${blanked.join(', ')}). If the user wants it cleared, ` +
197
+ 'ask them — it cannot be done here.'
198
+ : 'this modify changes nothing: every value it sets is the value the row already ' +
199
+ 'has. Say what should be different.',
200
+ ]
201
+ : []),
202
+ ];
203
+ return problems.length
204
+ ? { index: entry.index, key: entry.key, preImage: read.row, problems }
205
+ : Object.assign({ index: entry.index, key: entry.key, details: built.status === 'ok' ? built.details : undefined, preImage: read.row }, (blanked.length
206
+ ? {
207
+ notes: [
208
+ `${blanked.join(', ')} ${blanked.length > 1 ? 'were' : 'was'} left as it is: ` +
209
+ "'' and null do not clear a column, and this tool cannot.",
210
+ ],
211
+ }
212
+ : {}));
213
+ }),
214
+ };
215
+ });
216
+ }
217
+ /**
218
+ * What makes two reads the same row.
219
+ *
220
+ * @remarks
221
+ * `RECORD_ID` when the resource returns it, because that is the platform's own answer.
222
+ * Otherwise every value the row carries: two rows a resource cannot tell apart are two rows
223
+ * this bridge cannot tell apart either, and refusing the second is the safe way to be wrong.
224
+ */
225
+ function rowIdentity(row) {
226
+ const recordId = row.RECORD_ID;
227
+ if (recordId !== undefined && recordId !== null && String(recordId).length) {
228
+ return `RECORD_ID:${String(recordId)}`;
229
+ }
230
+ return JSON.stringify(Object.entries(row)
231
+ .map(([name, value]) => [name, String(value)])
232
+ .sort());
233
+ }
234
+ /**
235
+ * Re-reads one row and compares it with what the review showed.
236
+ *
237
+ * @remarks
238
+ * A review is open for as long as it takes a person to read it, and the same row can be changed
239
+ * by somebody else in that time. Committing the payload built from the row as it WAS would write
240
+ * the reviewed values straight over their change, and the ACK would say it worked.
241
+ *
242
+ * Compared over the event's own fields, because those are exactly the ones the write can affect.
243
+ * That deliberately includes a field that was empty and now is not: a generated modify replaces
244
+ * the record, so a field the pre-image had no value for is written as null, and "someone filled
245
+ * it in while you were reading" is precisely the change that would be undone.
246
+ *
247
+ * Both sides go through {@link sameValue}, which normalises each with the field's declared type
248
+ * — never one raw against one normalised. A read stamps a big integer as text where the payload
249
+ * holds a number, so a raw comparison would call every row changed and drop the whole batch.
250
+ *
251
+ * @internal
252
+ */
253
+ export function stillCurrent(row_1, _a) {
254
+ return __awaiter(this, arguments, void 0, function* (row, { source, fields }) {
255
+ if (!row.key || !row.preImage) {
256
+ return { status: 'unreadable', reason: 'it was never read in the first place' };
257
+ }
258
+ const read = yield source.read(row.key);
259
+ if (read.status === 'missing')
260
+ return { status: 'gone' };
261
+ if (read.status === 'ambiguous') {
262
+ return {
263
+ status: 'unreadable',
264
+ reason: 'its key now matches more than one row',
265
+ };
266
+ }
267
+ if (read.status === 'failed')
268
+ return { status: 'unreadable', reason: read.reason };
269
+ const changed = fields
270
+ .filter((field) => !PLATFORM_MAINTAINED.has(field.name))
271
+ .filter((field) => !sameValue(row.preImage[field.name], read.row[field.name], field.type))
272
+ .map((field) => field.name);
273
+ return changed.length ? { status: 'changed', fields: changed } : { status: 'current' };
274
+ });
275
+ }
@@ -0,0 +1,252 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement, GenesisElement, observable } from '@genesislcap/web-core';
3
+ import { canWrite, initialSelection, restoredSelection } from '../review-model';
4
+ import { WriteReviewStyles as styles } from './write-review.styles';
5
+ import { WriteReviewTemplate as template } from './write-review.template';
6
+ /**
7
+ * The tag the bridge asks for by name when it requests the review interaction.
8
+ *
9
+ * @beta
10
+ */
11
+ export const GENESIS_WRITE_REVIEW = 'genesis-write-review';
12
+ /** Where a still-open review parks what the user has done, on its interaction context's state. */
13
+ const PARKED = {
14
+ selected: 'selected',
15
+ denying: 'denying',
16
+ denyReason: 'denyReason',
17
+ };
18
+ /**
19
+ * The review a user reads before anything is written.
20
+ *
21
+ * @remarks
22
+ * Deliberately thin: it renders {@link ReviewModel} and reports which rows were selected. Every
23
+ * rule it obeys — nothing selected at first, no Write on an empty selection, a refused row that
24
+ * cannot be chosen, which fields are marked as changed — lives in the model, where it is tested
25
+ * without a DOM and cannot be undone by a change to the markup.
26
+ *
27
+ * **It resolves with row INDEXES, never rows.** The payloads stay with the tool that built
28
+ * them, so what gets committed is the object the user saw by construction rather than by
29
+ * discipline: nothing this component returns could be a rebuilt or cloned row, because it
30
+ * returns no rows at all.
31
+ *
32
+ * @beta
33
+ */
34
+ let GenesisWriteReview = class GenesisWriteReview extends GenesisElement {
35
+ constructor() {
36
+ super(...arguments);
37
+ /** Set by the interaction wrapper on every (re)mount. */
38
+ this.interactionId = '';
39
+ /** Chosen rows, by index. Starts empty — see {@link canWrite} and the model's own reasoning. */
40
+ this.selected = initialSelection();
41
+ /** True while the user is writing a reason for denying. */
42
+ this.denying = false;
43
+ this.denyReason = '';
44
+ }
45
+ /**
46
+ * The rows, whether the review is still open or already resolved: a user who has approved a
47
+ * write should still be able to see what they approved. Acting on it is what `resolved`
48
+ * stops, not reading it.
49
+ */
50
+ get model() {
51
+ var _a;
52
+ return (_a = this.interaction) === null || _a === void 0 ? void 0 : _a.data;
53
+ }
54
+ get resolved() {
55
+ var _a;
56
+ return ((_a = this.interaction) === null || _a === void 0 ? void 0 : _a.status) === 'resolved';
57
+ }
58
+ /**
59
+ * The rows the user approved, once the review has resolved — empty for a rejection or a
60
+ * timeout, and while it is still open.
61
+ */
62
+ get approved() {
63
+ var _a, _b, _c;
64
+ const interaction = this.interaction;
65
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'resolved' || ((_a = interaction.result) === null || _a === void 0 ? void 0 : _a.status) !== 'approved')
66
+ return [];
67
+ const payload = interaction.result.payload;
68
+ // Only rows that COULD be approved: a refused row's index in a payload is not an approval of
69
+ // it, and counting it would tell the user a row was approved that the review never offered.
70
+ const selectable = (_c = (_b = this.model) === null || _b === void 0 ? void 0 : _b.selectable) !== null && _c !== void 0 ? _c : [];
71
+ return Array.isArray(payload)
72
+ ? payload.filter((index) => typeof index === 'number' && selectable.includes(index))
73
+ : [];
74
+ }
75
+ /**
76
+ * What a CLOSED review can truthfully say about its outcome.
77
+ *
78
+ * @remarks
79
+ * A review knows what was approved; only the tool's reply knows what was WRITTEN. A delete the
80
+ * user approved can still be refused at commit — the row changed while the review was open — and
81
+ * a review that went on showing its removal tint read as though it happened, on every re-mount.
82
+ * So it says what it knows and where the rest is, in words a screen reader and a greyscale
83
+ * screen carry as well as the tints do.
84
+ */
85
+ get closedSummary() {
86
+ var _a, _b;
87
+ const interaction = this.interaction;
88
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'resolved')
89
+ return '';
90
+ if (((_a = interaction.result) === null || _a === void 0 ? void 0 : _a.status) === 'approved') {
91
+ return `Approved ${this.approved.length} row(s). The reply says which were written.`;
92
+ }
93
+ if (((_b = interaction.result) === null || _b === void 0 ? void 0 : _b.status) === 'timeout') {
94
+ return 'Closed without a decision. Nothing was written.';
95
+ }
96
+ return 'Denied. Nothing was written.';
97
+ }
98
+ /**
99
+ * Every mount is a fresh element whose selection starts empty, so each state says where its
100
+ * selection comes from.
101
+ *
102
+ * @remarks
103
+ * A RESOLVED review shows what was approved, whether it resolved just now or is re-mounted from
104
+ * history — its boxes used to show unticked under the tints of rows that WERE approved. Seeded
105
+ * from the result, the one thing both paths have, and never from the context: the host disposes
106
+ * that on resolve, and a disposed context's state still holds whatever was last parked there.
107
+ *
108
+ * A PENDING review resumes from its interaction context what the user had ticked, and a deny
109
+ * they had started: a reparent, a dock or a transcript re-render rebuilds the element while
110
+ * the review is open, and everything it held was dropped. Assigned once, not replayed through
111
+ * the setters, and never written back from here — only a user's action parks (see `park`).
112
+ * Each restored box goes from unticked to ticked once when it binds and echoes once, into a
113
+ * setter that already agrees.
114
+ */
115
+ interactionChanged() {
116
+ const interaction = this.interaction;
117
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) === 'resolved') {
118
+ this.selected = this.approved;
119
+ return;
120
+ }
121
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'pending')
122
+ return;
123
+ const { state } = interaction.interactionContext;
124
+ this.selected = restoredSelection(interaction.data, state[PARKED.selected]);
125
+ this.denying = state[PARKED.denying] === true;
126
+ const reason = state[PARKED.denyReason];
127
+ this.denyReason = typeof reason === 'string' ? reason : '';
128
+ }
129
+ /**
130
+ * Keeps what the user has done so far on the interaction's context, where the next mount of a
131
+ * still-open review finds it.
132
+ *
133
+ * @remarks
134
+ * Called from the user-driven mutators only. Writing from `selectedChanged` or
135
+ * `interactionChanged` would let the field initializer's empty selection, or a resolved
136
+ * re-seed, overwrite what was parked. The context is read from `interaction` every time and
137
+ * never cached: once the review resolves there is none, and a kept reference to a disposed one
138
+ * would go on accepting writes nobody reads.
139
+ */
140
+ park() {
141
+ const interaction = this.interaction;
142
+ if ((interaction === null || interaction === void 0 ? void 0 : interaction.status) !== 'pending')
143
+ return;
144
+ const { state } = interaction.interactionContext;
145
+ state[PARKED.selected] = [...this.selected];
146
+ state[PARKED.denying] = this.denying;
147
+ state[PARKED.denyReason] = this.denyReason;
148
+ }
149
+ get rowsSelected() {
150
+ return this.selected.length;
151
+ }
152
+ /** Whether Write may fire: never on an empty selection. */
153
+ get writable() {
154
+ return !this.resolved && canWrite(this.selected);
155
+ }
156
+ get allSelected() {
157
+ var _a, _b;
158
+ const selectable = (_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable) !== null && _b !== void 0 ? _b : [];
159
+ return selectable.length > 0 && selectable.every((index) => this.selected.includes(index));
160
+ }
161
+ isSelected(index) {
162
+ return this.selected.includes(index);
163
+ }
164
+ /**
165
+ * Makes one row agree with what its checkbox now says. A row the bridge refused cannot be
166
+ * chosen, whatever the markup does.
167
+ *
168
+ * @remarks
169
+ * SET from the checkbox, never toggled, and a no-op when the row already agrees. The checkbox
170
+ * emits `change` for a PROGRAMMATIC update too (FAST's `checkedChanged`), so every time the
171
+ * selection moves a box through its `:checked` binding, that box echoes. A handler that
172
+ * toggled turned each echo into another change of selection, which moved another box, which
173
+ * echoed — and FAST drains updates queued during a flush in the same flush, so the loop never
174
+ * yielded the main thread and the whole application froze. An echo now finds the row already
175
+ * agreeing and does nothing, so the first echo is the last.
176
+ */
177
+ setSelected(index, checked) {
178
+ var _a;
179
+ if (this.resolved || !((_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable.includes(index)))
180
+ return;
181
+ if (checked === this.isSelected(index))
182
+ return;
183
+ this.selected = checked
184
+ ? [...this.selected, index]
185
+ : this.selected.filter((chosen) => chosen !== index);
186
+ this.park();
187
+ }
188
+ /**
189
+ * One click for a good batch — a deliberate one, which is the point of starting empty.
190
+ *
191
+ * @remarks
192
+ * Compared with {@link allSelected}, the value the select-all box DISPLAYS, and not with the
193
+ * selection. The difference is the case that matters: unticking one row of a full selection
194
+ * makes `allSelected` false, the select-all box follows it, and it echoes `change` with
195
+ * `false`. Measured against the selection, that echo reads as "clear everything" and takes
196
+ * every other row with it. Measured against what the box displays, it agrees and does nothing.
197
+ */
198
+ setAll(checked) {
199
+ var _a, _b;
200
+ if (this.resolved || checked === this.allSelected)
201
+ return;
202
+ this.selected = checked ? [...((_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.selectable) !== null && _b !== void 0 ? _b : [])] : [];
203
+ this.park();
204
+ }
205
+ write() {
206
+ var _a, _b;
207
+ if (!this.writable)
208
+ return;
209
+ // Indexes, in the order the table shows them. The rows never leave the tool.
210
+ const ordered = ((_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.rows) !== null && _b !== void 0 ? _b : [])
211
+ .map((row) => row.index)
212
+ .filter((index) => this.selected.includes(index));
213
+ this.resolve({ status: 'approved', payload: ordered });
214
+ }
215
+ /** The one way this widget talks back: `interaction-completed`, exactly once. */
216
+ resolve(result) {
217
+ this.$emit('interaction-completed', result);
218
+ }
219
+ startDeny() {
220
+ this.denying = true;
221
+ this.park();
222
+ }
223
+ /** The deny reason as the user types it. */
224
+ setDenyReason(reason) {
225
+ this.denyReason = reason;
226
+ this.park();
227
+ }
228
+ confirmDeny() {
229
+ if (this.resolved)
230
+ return;
231
+ this.resolve({
232
+ status: 'rejected',
233
+ message: this.denyReason.trim() || 'The user did not approve the write',
234
+ });
235
+ }
236
+ };
237
+ __decorate([
238
+ observable
239
+ ], GenesisWriteReview.prototype, "interaction", void 0);
240
+ __decorate([
241
+ observable
242
+ ], GenesisWriteReview.prototype, "selected", void 0);
243
+ __decorate([
244
+ observable
245
+ ], GenesisWriteReview.prototype, "denying", void 0);
246
+ __decorate([
247
+ observable
248
+ ], GenesisWriteReview.prototype, "denyReason", void 0);
249
+ GenesisWriteReview = __decorate([
250
+ customElement({ name: GENESIS_WRITE_REVIEW, template, styles })
251
+ ], GenesisWriteReview);
252
+ export { GenesisWriteReview };