@floless/app 0.154.0 → 0.155.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.
- package/dist/floless-server.cjs +49492 -37984
- package/dist/schemas/steel.model.v2.schema.json +19 -5
- package/dist/skills/floless-app-onboarding/SKILL.md +22 -13
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +12 -8
- package/dist/skills/floless-app-steel-model/SKILL.md +23 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +158 -65
- package/dist/skills/floless-app-workflows/SKILL.md +23 -5
- package/dist/skills/floless-app-workflows/references/blender-exec.md +183 -0
- package/dist/skills/floless-app-workflows/references/dev-server-and-run-trace.md +27 -12
- package/dist/templates/blender-construction-sequence.flo +96 -0
- package/dist/web/agents.js +33 -13
- package/dist/web/app.css +275 -33
- package/dist/web/aware.js +745 -82
- package/dist/web/chat-question-card.js +477 -0
- package/dist/web/chat.css +177 -12
- package/dist/web/chat.js +1537 -717
- package/dist/web/commands-shell.js +424 -7
- package/dist/web/commands-steel.js +105 -4
- package/dist/web/guide.js +4 -3
- package/dist/web/index.html +96 -7
- package/dist/web/instructor.js +10 -9
- package/dist/web/left-pane.js +40 -3
- package/dist/web/media-player.js +234 -0
- package/dist/web/model-editor-contract.js +2 -0
- package/dist/web/model-editor-revit-adapter.js +1 -0
- package/dist/web/model-editor-steel-adapter.js +89 -1
- package/dist/web/model-panel-bridge.js +16 -2
- package/dist/web/model-view-query.js +590 -0
- package/dist/web/model-viewport-revit-adapter.js +15 -1
- package/dist/web/model-viewport-toolbar.js +5 -2
- package/dist/web/pages.js +592 -0
- package/dist/web/panels.js +2 -1
- package/dist/web/revit-editor.js +181 -16
- package/dist/web/run-progress.js +193 -0
- package/dist/web/run-strip.js +173 -0
- package/dist/web/steel-3d-core.js +70 -0
- package/dist/web/steel-editor.html +2751 -219
- package/dist/web/steel-frames-core.js +958 -0
- package/dist/web/steel-last-seen.js +315 -0
- package/dist/web/steel-marks-core.js +530 -0
- package/dist/web/steel-model-slim.js +95 -0
- package/dist/web/steel-model-v2-client-validation.js +14 -2
- package/dist/web/steel-model-v2-commands.js +258 -27
- package/dist/web/steel-model-v2-projection.js +78 -18
- package/dist/web/steel-read-confidence.js +11 -2
- package/dist/web/workspaces.js +416 -26
- package/package.json +3 -2
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The marks a drawing view carries — callouts, details, top-of-steel callouts and detail-bubble anchors —
|
|
3
|
+
* and the ONE rule for letting a revision read ADD them (#2211).
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS MODULE EXISTS. A drawing set's callouts (detail, section and elevation marks and the sheet each
|
|
6
|
+
* points to) are what make the drawings followable from sheet to sheet. The editor already draws and
|
|
7
|
+
* follows them, but nothing ever recorded them on a v2 model, and the revision registry refused every
|
|
8
|
+
* attempt to add them to a view that was already in the model. The owner ruled that a read must be able to
|
|
9
|
+
* record them. That widens what an AI-authored document may write, so this module is built around ONE
|
|
10
|
+
* property: **an incoming collection can only ADD entries.** Existing entries are kept verbatim and in
|
|
11
|
+
* order; omission is a no-op; a differing entry is reported, never applied. A read can therefore never
|
|
12
|
+
* delete or overwrite a callout a person drew or corrected by hand.
|
|
13
|
+
*
|
|
14
|
+
* PURE and framework-free (no DOM, no node: imports) so the server and the browser share one answer —
|
|
15
|
+
* same shape as steel-detail-refs.js / steel-plan-view-id.js. Everything that needs a hash or the clock
|
|
16
|
+
* (deterministic ids) takes it as an argument.
|
|
17
|
+
*
|
|
18
|
+
* STRICTNESS IS IN CODE, NOT IN THE SCHEMA. The five schema nodes stay permissive on purpose: legacy models
|
|
19
|
+
* carry callouts with a numeric-string `disp`, no `kind`, no `target`, and a stored model that stopped
|
|
20
|
+
* validating would fail every autosave. These validators are applied ONLY to entries that are NEW to a
|
|
21
|
+
* document (a read adding one, a hand-add). Stored entries are never re-validated, and an incoming entry
|
|
22
|
+
* that matches a stored one is exempt, so a read that copies legacy entries forward cannot trip them.
|
|
23
|
+
*
|
|
24
|
+
* Three shapes, all kept (see steel-detail-refs.js, which reads both of the first two):
|
|
25
|
+
* callouts[] {id?, kind, text, disp:[x,y], target:{sheet, number?, outsideSet?}, elementId?, origin?, readKey?}
|
|
26
|
+
* details[] {id?, text, disp:[x,y], elementId?, origin?, readKey?} (legacy shape)
|
|
27
|
+
* tos_callouts[] {id?, elevationMm, type:'TOS'|'TOD'|'TOC', disp:[x,y], text?, origin?, readKey?}
|
|
28
|
+
* detail_bubbles { sheet: { number: [fx, fy] } }, both in [0,1]
|
|
29
|
+
*
|
|
30
|
+
* `origin` ('read' | 'manual') is stamped by whoever admits the entry, never trusted from the document, and
|
|
31
|
+
* `source` is never touched. `readKey` remembers the entry AS READ so a later re-read of the original still
|
|
32
|
+
* matches a mark a person has since corrected (it is reported as a difference, not appended again).
|
|
33
|
+
*/
|
|
34
|
+
import { sheetOf, numOf, calloutRefText } from './steel-detail-refs.js';
|
|
35
|
+
import { IN_TO_MM } from './steel-units.js';
|
|
36
|
+
|
|
37
|
+
/** What a callout can point at. */
|
|
38
|
+
export const CALLOUT_KINDS = Object.freeze(['detail', 'section', 'elevation']);
|
|
39
|
+
/** NEEDS OWNER: two marks of the same kind and text this close (display px) are one mark on a re-read. About the 11 px bubble radius. */
|
|
40
|
+
export const CALLOUT_SAME_SPOT_PX = 12;
|
|
41
|
+
/** NEEDS OWNER: most marks a read may ADD to one view and field (also: sheets, and numbers per sheet, in detail_bubbles). Existing collections over this are kept untouched. */
|
|
42
|
+
export const MARKS_MAX_PER_VIEW = 500;
|
|
43
|
+
export const MARK_TEXT_MAX = 64;
|
|
44
|
+
export const MARK_SHEET_MAX = 64;
|
|
45
|
+
export const MARK_NUMBER_MAX = 16;
|
|
46
|
+
const MARK_ID_MAX = 96;
|
|
47
|
+
const MARK_ELEMENT_ID_MAX = 128;
|
|
48
|
+
/** Two top-of-steel elevations this close (mm) are the same level. */
|
|
49
|
+
const TOS_SAME_LEVEL_MM = 1;
|
|
50
|
+
const TOS_TYPES = Object.freeze(['TOS', 'TOD', 'TOC']);
|
|
51
|
+
|
|
52
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
53
|
+
const ID_PATTERN = /^[A-Za-z0-9._:\-/ ]{1,96}$/;
|
|
54
|
+
const BUBBLE_KEY_PATTERN = /^[A-Za-z0-9._\- ]{1,64}$/;
|
|
55
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
56
|
+
|
|
57
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
58
|
+
/**
|
|
59
|
+
* Set `obj[key]` as an OWN data property, whatever the key is called. A plain `obj[key] = value` with
|
|
60
|
+
* `key === '__proto__'` runs the legacy setter instead: it re-points the object's prototype (or does nothing
|
|
61
|
+
* for a value that is not an object), so the key never becomes a member and the next serialisation silently
|
|
62
|
+
* drops it. `JSON.parse` DOES produce an own `"__proto__"` key, so a stored sheet map can carry one; copying
|
|
63
|
+
* it must keep it. Every write into a map keyed by something a document supplied goes through here.
|
|
64
|
+
*/
|
|
65
|
+
function own(obj, key, value) {
|
|
66
|
+
Object.defineProperty(obj, key, { value, enumerable: true, writable: true, configurable: true });
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
/** JSON with object keys sorted, so two spellings of one value compare equal. Arrays keep their order. */
|
|
70
|
+
function stableJson(v) {
|
|
71
|
+
if (v === undefined) return 'null';
|
|
72
|
+
return JSON.stringify(v, (_key, val) => (isObject(val)
|
|
73
|
+
? Object.fromEntries(Object.keys(val).sort().map((k) => [k, val[k]]))
|
|
74
|
+
: val));
|
|
75
|
+
}
|
|
76
|
+
const finiteNumber = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
77
|
+
const str = (v) => (v == null ? '' : String(v)).trim();
|
|
78
|
+
|
|
79
|
+
/** A drawable position of two finite NUMBERS (new entries; legacy numeric strings are tolerated on read, never written). */
|
|
80
|
+
const isPoint = (d) => Array.isArray(d) && d.length === 2 && finiteNumber(d[0]) && finiteNumber(d[1]);
|
|
81
|
+
/** The same, tolerant of numeric strings — for reading what is already stored. */
|
|
82
|
+
const looseNumber = (v) => (typeof v === 'number' || (typeof v === 'string' && v.trim() !== '')) && Number.isFinite(Number(v));
|
|
83
|
+
const isLoosePoint = (d) => Array.isArray(d) && d.length >= 2 && looseNumber(d[0]) && looseNumber(d[1]);
|
|
84
|
+
const pointOf = (d) => [Number(d[0]), Number(d[1])];
|
|
85
|
+
const distance = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1]);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A MATCHING AID, never an identity: uppercase, trim, collapse whitespace, and treat `-` and `/` as one
|
|
89
|
+
* separator, so `5-S504` ≡ `5/S504` ≡ `5 / S504`. The same rule as `normalizeDetailKey`
|
|
90
|
+
* (server/detail-recipes.ts), mirrored here because that module is server-only.
|
|
91
|
+
*/
|
|
92
|
+
export function normMarkText(text) {
|
|
93
|
+
return str(text).toUpperCase().replace(/\s+/g, ' ').replace(/\s*[-/]\s*/g, '/');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A sheet name as the editor compares it: case- and whitespace-insensitive. */
|
|
97
|
+
export const normSheet = (sheet) => str(sheet).replace(/\s+/g, '').toUpperCase();
|
|
98
|
+
|
|
99
|
+
/** A stored kind, read leniently: a missing kind is a detail; `detailref` (the old pipeline's word) is a detail. */
|
|
100
|
+
export function normKind(kind) {
|
|
101
|
+
const k = str(kind).toLowerCase();
|
|
102
|
+
if (!k) return 'detail';
|
|
103
|
+
if (k.startsWith('elev')) return 'elevation';
|
|
104
|
+
if (k.startsWith('section')) return 'section';
|
|
105
|
+
if (k.startsWith('detail')) return 'detail';
|
|
106
|
+
return k;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What a stored callout names as its target: the structured target if it has one, else the one its text spells. */
|
|
110
|
+
export function calloutTargetOf(entry) {
|
|
111
|
+
if (!isObject(entry)) return { sheet: '', number: '', outsideSet: false };
|
|
112
|
+
const t = isObject(entry.target) ? entry.target : null;
|
|
113
|
+
if (t && str(t.sheet)) {
|
|
114
|
+
return { sheet: str(t.sheet), number: str(t.number), outsideSet: t.outsideSet === true };
|
|
115
|
+
}
|
|
116
|
+
const printed = str(entry.text);
|
|
117
|
+
return { sheet: sheetOf(printed) || '', number: numOf(printed) || '', outsideSet: false };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Plain-English "problem" objects: `code` is stable and what tests assert, `reason` completes "Left out one callout on S-202: …". */
|
|
121
|
+
const problem = (code, reason) => ({ code, reason });
|
|
122
|
+
|
|
123
|
+
// ── per-field specs ────────────────────────────────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Each field declares: how to validate and clean a NEW entry, how to compare two entries (`signature` +
|
|
127
|
+
* `sameSignature`), and what "the same content" means once two entries are matched.
|
|
128
|
+
*/
|
|
129
|
+
const CALLOUT_SPEC = {
|
|
130
|
+
field: 'callouts',
|
|
131
|
+
noun: 'callout',
|
|
132
|
+
signature(e) {
|
|
133
|
+
const text = str(e.text) || (calloutRefText(e) || '');
|
|
134
|
+
return { kind: normKind(e.kind), text, disp: isLoosePoint(e.disp) ? pointOf(e.disp) : null };
|
|
135
|
+
},
|
|
136
|
+
sameSignature(a, b) {
|
|
137
|
+
return a.kind === b.kind && normMarkText(a.text) === normMarkText(b.text) && near(a.disp, b.disp);
|
|
138
|
+
},
|
|
139
|
+
contentEqual(a, b) {
|
|
140
|
+
const sa = CALLOUT_SPEC.signature(a), sb = CALLOUT_SPEC.signature(b);
|
|
141
|
+
if (!CALLOUT_SPEC.sameSignature(sa, sb)) return false;
|
|
142
|
+
const ta = calloutTargetOf(a), tb = calloutTargetOf(b);
|
|
143
|
+
return normSheet(ta.sheet) === normSheet(tb.sheet) && normMarkText(ta.number) === normMarkText(tb.number);
|
|
144
|
+
},
|
|
145
|
+
hashParts(clean) {
|
|
146
|
+
return [normKind(clean.kind), normMarkText(clean.text), Math.round(clean.disp[0]), Math.round(clean.disp[1])];
|
|
147
|
+
},
|
|
148
|
+
clean(raw) {
|
|
149
|
+
const problems = [];
|
|
150
|
+
const kind = str(raw.kind).toLowerCase();
|
|
151
|
+
if (!CALLOUT_KINDS.includes(kind)) problems.push(problem('kind', "it isn't marked as a detail, section or elevation"));
|
|
152
|
+
const text = typeof raw.text === 'string' ? raw.text.trim() : '';
|
|
153
|
+
if (!text) problems.push(problem('text', "it doesn't say what the mark reads"));
|
|
154
|
+
else if (text.length > MARK_TEXT_MAX) problems.push(problem('text', `its mark is longer than ${MARK_TEXT_MAX} characters`));
|
|
155
|
+
else if (CONTROL.test(text)) problems.push(problem('text', 'its mark has characters that cannot be printed'));
|
|
156
|
+
if (!isPoint(raw.disp)) problems.push(problem('disp', "it doesn't say where on the sheet it is drawn"));
|
|
157
|
+
const t = raw.target;
|
|
158
|
+
const sheet = isObject(t) && typeof t.sheet === 'string' ? t.sheet.trim() : '';
|
|
159
|
+
if (!sheet) problems.push(problem('target-sheet', "it doesn't say which sheet it points to"));
|
|
160
|
+
else if (sheet.length > MARK_SHEET_MAX || CONTROL.test(sheet)) problems.push(problem('target-sheet', `the sheet it points to is longer than ${MARK_SHEET_MAX} characters or has characters that cannot be printed`));
|
|
161
|
+
let number = '';
|
|
162
|
+
if (isObject(t) && t.number != null) {
|
|
163
|
+
number = typeof t.number === 'number' && Number.isFinite(t.number) ? String(t.number) : (typeof t.number === 'string' ? t.number.trim() : null);
|
|
164
|
+
if (number === null || number.length > MARK_NUMBER_MAX || CONTROL.test(number)) {
|
|
165
|
+
problems.push(problem('target-number', `its detail number is longer than ${MARK_NUMBER_MAX} characters or has characters that cannot be printed`));
|
|
166
|
+
number = '';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (problems.length) return { ok: false, problems };
|
|
170
|
+
const out = {
|
|
171
|
+
kind, text, disp: [raw.disp[0], raw.disp[1]],
|
|
172
|
+
target: { sheet, ...(number ? { number } : {}), ...(t.outsideSet === true ? { outsideSet: true } : {}) },
|
|
173
|
+
};
|
|
174
|
+
if (typeof raw.elementId === 'string' && raw.elementId.trim() && raw.elementId.length <= MARK_ELEMENT_ID_MAX && !CONTROL.test(raw.elementId)) out.elementId = raw.elementId.trim();
|
|
175
|
+
return { ok: true, entry: out };
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const DETAIL_SPEC = {
|
|
180
|
+
field: 'details',
|
|
181
|
+
noun: 'detail',
|
|
182
|
+
signature(e) {
|
|
183
|
+
return { text: str(e.text) || (calloutRefText(e) || ''), disp: isLoosePoint(e.disp) ? pointOf(e.disp) : null };
|
|
184
|
+
},
|
|
185
|
+
sameSignature(a, b) {
|
|
186
|
+
return normMarkText(a.text) === normMarkText(b.text) && near(a.disp, b.disp);
|
|
187
|
+
},
|
|
188
|
+
contentEqual(a, b) {
|
|
189
|
+
return DETAIL_SPEC.sameSignature(DETAIL_SPEC.signature(a), DETAIL_SPEC.signature(b));
|
|
190
|
+
},
|
|
191
|
+
hashParts(clean) {
|
|
192
|
+
return [normMarkText(clean.text), Math.round(clean.disp[0]), Math.round(clean.disp[1])];
|
|
193
|
+
},
|
|
194
|
+
clean(raw) {
|
|
195
|
+
const problems = [];
|
|
196
|
+
const text = typeof raw.text === 'string' ? raw.text.trim() : '';
|
|
197
|
+
if (!text) problems.push(problem('text', "it doesn't say what the detail reads"));
|
|
198
|
+
else if (text.length > MARK_TEXT_MAX) problems.push(problem('text', `its text is longer than ${MARK_TEXT_MAX} characters`));
|
|
199
|
+
else if (CONTROL.test(text)) problems.push(problem('text', 'its text has characters that cannot be printed'));
|
|
200
|
+
if (!isPoint(raw.disp)) problems.push(problem('disp', "it doesn't say where on the sheet it is drawn"));
|
|
201
|
+
if (problems.length) return { ok: false, problems };
|
|
202
|
+
const out = { text, disp: [raw.disp[0], raw.disp[1]] };
|
|
203
|
+
if (typeof raw.elementId === 'string' && raw.elementId.trim() && raw.elementId.length <= MARK_ELEMENT_ID_MAX && !CONTROL.test(raw.elementId)) out.elementId = raw.elementId.trim();
|
|
204
|
+
return { ok: true, entry: out };
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const tosMm = (e) => (finiteNumber(e.elevationMm) ? e.elevationMm : (looseNumber(e.elev_in) ? Number(e.elev_in) * IN_TO_MM : null));
|
|
209
|
+
const TOS_SPEC = {
|
|
210
|
+
field: 'tos_callouts',
|
|
211
|
+
noun: 'top-of-steel callout',
|
|
212
|
+
signature(e) {
|
|
213
|
+
return { type: str(e.type).toUpperCase(), elevationMm: tosMm(e), disp: isLoosePoint(e.disp) ? pointOf(e.disp) : null };
|
|
214
|
+
},
|
|
215
|
+
sameSignature(a, b) {
|
|
216
|
+
return a.type === b.type
|
|
217
|
+
&& a.elevationMm !== null && b.elevationMm !== null && Math.abs(a.elevationMm - b.elevationMm) <= TOS_SAME_LEVEL_MM
|
|
218
|
+
&& near(a.disp, b.disp);
|
|
219
|
+
},
|
|
220
|
+
contentEqual(a, b) {
|
|
221
|
+
return TOS_SPEC.sameSignature(TOS_SPEC.signature(a), TOS_SPEC.signature(b));
|
|
222
|
+
},
|
|
223
|
+
hashParts(clean) {
|
|
224
|
+
return [clean.type, Math.round(clean.elevationMm), Math.round(clean.disp[0]), Math.round(clean.disp[1])];
|
|
225
|
+
},
|
|
226
|
+
clean(raw) {
|
|
227
|
+
const problems = [];
|
|
228
|
+
const type = str(raw.type).toUpperCase();
|
|
229
|
+
if (!TOS_TYPES.includes(type)) problems.push(problem('type', "it isn't marked as top of steel, deck or concrete"));
|
|
230
|
+
if (!finiteNumber(raw.elevationMm) || Math.abs(raw.elevationMm) > 1e7) problems.push(problem('elevation', "it doesn't give an elevation"));
|
|
231
|
+
if (!isPoint(raw.disp)) problems.push(problem('disp', "it doesn't say where on the sheet it is drawn"));
|
|
232
|
+
const text = raw.text == null ? '' : (typeof raw.text === 'string' ? raw.text.trim() : null);
|
|
233
|
+
if (text === null || text.length > MARK_TEXT_MAX || (text && CONTROL.test(text))) problems.push(problem('text', `its text is longer than ${MARK_TEXT_MAX} characters or has characters that cannot be printed`));
|
|
234
|
+
if (problems.length) return { ok: false, problems };
|
|
235
|
+
return { ok: true, entry: { elevationMm: raw.elevationMm, type, disp: [raw.disp[0], raw.disp[1]], ...(text ? { text } : {}) } };
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/** Both positions known and within a few pixels (jitter), or both unknown is NOT near: no position, no geometric identity. */
|
|
240
|
+
function near(a, b) {
|
|
241
|
+
return !!a && !!b && distance(a, b) <= CALLOUT_SAME_SPOT_PX;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** field name -> spec. Own-property lookups only (`MARK_SPECS.constructor` must be undefined). */
|
|
245
|
+
export const MARK_SPECS = Object.freeze({ callouts: CALLOUT_SPEC, details: DETAIL_SPEC, tos_callouts: TOS_SPEC });
|
|
246
|
+
export const markSpecFor = (field) => (typeof field === 'string' && Object.hasOwn(MARK_SPECS, field) ? MARK_SPECS[field] : null);
|
|
247
|
+
|
|
248
|
+
// ── public validators (one entry, no document) ─────────────────────────────────────────────────────────
|
|
249
|
+
|
|
250
|
+
const validatorFor = (spec) => (entry) => {
|
|
251
|
+
if (!isObject(entry)) return { ok: false, problems: [problem('shape', "it isn't a callout record")] };
|
|
252
|
+
const r = spec.clean(entry);
|
|
253
|
+
return r.ok ? { ok: true, problems: [] } : { ok: false, problems: r.problems };
|
|
254
|
+
};
|
|
255
|
+
/** @returns {{ok: boolean, problems: {code: string, reason: string}[]}} */
|
|
256
|
+
export const validateCallout = validatorFor(CALLOUT_SPEC);
|
|
257
|
+
export const validateDetailEntry = validatorFor(DETAIL_SPEC);
|
|
258
|
+
export const validateTosCallout = validatorFor(TOS_SPEC);
|
|
259
|
+
|
|
260
|
+
/** A hand-add's own cleaned record (kind lower-cased, text trimmed, only the known keys), or the problems. */
|
|
261
|
+
export function cleanCallout(raw) {
|
|
262
|
+
if (!isObject(raw)) return { ok: false, problems: [problem('shape', "it isn't a callout record")] };
|
|
263
|
+
return CALLOUT_SPEC.clean(raw);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── matching ───────────────────────────────────────────────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
/** Did the read attach anything to this mark that FloLess does not store? (`id` is the one extra it may keep.) */
|
|
269
|
+
function carriesExtras(raw, cleaned) {
|
|
270
|
+
const kept = new Set(['id', ...Object.keys(cleaned)]);
|
|
271
|
+
if (Object.keys(raw).some((k) => !kept.has(k))) return true;
|
|
272
|
+
if (isObject(raw.target)) return Object.keys(raw.target).some((k) => k !== 'sheet' && k !== 'number' && k !== 'outsideSet');
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Is `incoming` the same mark as `existing`? Field-specific and PAIRWISE (a distance cannot be a key):
|
|
278
|
+
* 1. the same `id`;
|
|
279
|
+
* 2. the same `elementId` (the saved Filter text element it was read from);
|
|
280
|
+
* 3. the same `readKey` — the entry AS READ, which a hand edit never changes, so the original still
|
|
281
|
+
* matches a mark that has since been corrected;
|
|
282
|
+
* 4. the same signature (kind and text, normalised, and a real Euclidean distance within
|
|
283
|
+
* CALLOUT_SAME_SPOT_PX — no rounding buckets, so 5.9 and 6.1 are the same spot).
|
|
284
|
+
*/
|
|
285
|
+
export function marksMatch(spec, existing, incoming) {
|
|
286
|
+
if (!isObject(existing) || !isObject(incoming)) return false;
|
|
287
|
+
if (typeof existing.id === 'string' && existing.id && existing.id === incoming.id) return true;
|
|
288
|
+
if (typeof existing.elementId === 'string' && existing.elementId && existing.elementId === incoming.elementId) return true;
|
|
289
|
+
const incomingSig = spec.signature(incoming);
|
|
290
|
+
if (isObject(existing.readKey) && spec.sameSignature(spec.signature(existing.readKey), incomingSig)) return true;
|
|
291
|
+
return spec.sameSignature(spec.signature(existing), incomingSig);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ── differential admission ─────────────────────────────────────────────────────────────────────────────
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Admit the NEW entries of `after` into `before`, and nothing else.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} field 'callouts' | 'details' | 'tos_callouts'
|
|
300
|
+
* @param {unknown} before the stored list (undefined is []; a non-list is treated as [])
|
|
301
|
+
* @param {unknown} after the incoming list (undefined / a non-list adds nothing)
|
|
302
|
+
* @param {{origin: 'read'|'manual', viewId: string, hash10: (s: string) => string, cap?: number}} ctx
|
|
303
|
+
* @returns {{merged: unknown[], added: object[], differs: {index: number, existing: object, incoming: object, fromStored: boolean}[],
|
|
304
|
+
* malformed: {index: number, entry: unknown, problems: {code: string, reason: string}[]}[],
|
|
305
|
+
* overCap: number, notAList: boolean, storedBlocked: boolean, trimmed: number}}
|
|
306
|
+
*
|
|
307
|
+
* `merged` = the stored entries verbatim and in order (legacy and malformed ones are never touched), then
|
|
308
|
+
* the newly admitted ones in incoming order. DETERMINISTIC: nothing here reads a clock or a random source,
|
|
309
|
+
* which the revision envelope hash depends on (a confirm re-stages the same candidate and must get the
|
|
310
|
+
* same hash). Ids are minted from content only, AFTER matching, with `-2`, `-3`… on a collision.
|
|
311
|
+
*
|
|
312
|
+
* Only entries NOT already present are validated, so unchanged legacy entries are exempt.
|
|
313
|
+
*/
|
|
314
|
+
export function admitMarks(field, before, after, ctx) {
|
|
315
|
+
const spec = markSpecFor(field);
|
|
316
|
+
if (!spec) throw new Error(`admitMarks: "${field}" is not a mark field`);
|
|
317
|
+
const result = { merged: [], added: [], differs: [], malformed: [], overCap: 0, notAList: false, storedBlocked: false, trimmed: 0 };
|
|
318
|
+
// WHAT IS STORED IS NOT OURS TO REPLACE. A stored value that is neither absent nor a list (a legacy oddity) is kept
|
|
319
|
+
// exactly as it is and nothing is added to it: the read is told, plainly, instead of the stored value being
|
|
320
|
+
// quietly overwritten by an empty list. Only reported when the read actually had something to add.
|
|
321
|
+
if (before !== undefined && before !== null && !Array.isArray(before)) {
|
|
322
|
+
result.merged = /** @type {any} */ (before); // kept untouched, whatever it is (the caller adds nothing)
|
|
323
|
+
result.storedBlocked = after !== undefined && after !== null && !(Array.isArray(after) && after.length === 0);
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
const stored = Array.isArray(before) ? before : [];
|
|
327
|
+
result.merged = stored.slice();
|
|
328
|
+
if (after === undefined || after === null) return result;
|
|
329
|
+
if (!Array.isArray(after)) {
|
|
330
|
+
result.notAList = true;
|
|
331
|
+
result.malformed.push({ index: -1, entry: after, problems: [problem('shape', `${spec.field} isn't a list`)] });
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
const cap = Number.isInteger(ctx.cap) && ctx.cap >= 0 ? ctx.cap : MARKS_MAX_PER_VIEW;
|
|
335
|
+
const usedIds = new Set();
|
|
336
|
+
for (const e of stored) if (isObject(e) && typeof e.id === 'string') usedIds.add(e.id);
|
|
337
|
+
// An incoming value that is byte-for-byte (canonically) a STORED one is simply present: a read that copies
|
|
338
|
+
// the model forward must not be told off for a legacy row it did not author, however odd that row is.
|
|
339
|
+
const storedForms = new Set(stored.map(stableJson));
|
|
340
|
+
|
|
341
|
+
for (let index = 0; index < after.length; index += 1) {
|
|
342
|
+
const raw = after[index];
|
|
343
|
+
if (storedForms.has(stableJson(raw))) continue;
|
|
344
|
+
if (!isObject(raw)) {
|
|
345
|
+
result.malformed.push({ index, entry: raw, problems: [problem('shape', "it isn't a callout record")] });
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const hit = result.merged.find((e) => marksMatch(spec, e, raw));
|
|
349
|
+
if (hit) {
|
|
350
|
+
// `fromStored`: the mark it collides with is one the model already holds (a person's, or an earlier read's), as
|
|
351
|
+
// opposed to one admitted a moment ago from this same read, which nobody has seen yet.
|
|
352
|
+
if (!spec.contentEqual(hit, raw)) result.differs.push({ index, existing: hit, incoming: raw, fromStored: stored.includes(hit) });
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const cleaned = spec.clean(raw);
|
|
356
|
+
if (!cleaned.ok) {
|
|
357
|
+
result.malformed.push({ index, entry: raw, problems: cleaned.problems });
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (stored.length + result.added.length >= cap) {
|
|
361
|
+
result.overCap += 1;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const entry = cleaned.entry;
|
|
365
|
+
// Only what FloLess stores for a mark is kept: anything else the read attached (a confidence, a box, a note) is
|
|
366
|
+
// dropped, and the read is told that it was, once per sheet and field rather than per entry.
|
|
367
|
+
if (carriesExtras(raw, entry)) result.trimmed += 1;
|
|
368
|
+
// The entry AS READ, remembered so a person's later correction does not make the original look new.
|
|
369
|
+
const readKey = JSON.parse(JSON.stringify(spec.signature(entry)));
|
|
370
|
+
let id = typeof raw.id === 'string' && ID_PATTERN.test(raw.id.trim()) && raw.id.trim().length <= MARK_ID_MAX ? raw.id.trim() : '';
|
|
371
|
+
if (id && usedIds.has(id)) id = '';
|
|
372
|
+
if (!id) {
|
|
373
|
+
const base = `mk-${ctx.viewId}-${ctx.hash10([spec.field, ...spec.hashParts(entry)].join('|'))}`;
|
|
374
|
+
id = base;
|
|
375
|
+
for (let n = 2; usedIds.has(id); n += 1) id = `${base}-${n}`;
|
|
376
|
+
}
|
|
377
|
+
usedIds.add(id);
|
|
378
|
+
const stamped = { id, ...entry, origin: ctx.origin, readKey: ctx.origin === 'read' ? readKey : undefined };
|
|
379
|
+
if (stamped.readKey === undefined) delete stamped.readKey;
|
|
380
|
+
result.added.push(stamped);
|
|
381
|
+
result.merged.push(stamped);
|
|
382
|
+
}
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The same rule for `detail_bubbles` — `{sheet: {number: [fx, fy]}}`. Identity is sheet + number; a value
|
|
388
|
+
* is two finite numbers in [0,1]. Keys are checked against a pattern and `__proto__`/`constructor`/
|
|
389
|
+
* `prototype` are refused outright, and every lookup is `Object.hasOwn`, so an AI-authored key can never
|
|
390
|
+
* reach `Object.prototype`.
|
|
391
|
+
*
|
|
392
|
+
* @returns {{merged: object, added: {sheet: string, number: string}[], differs: {sheet: string, number: string}[],
|
|
393
|
+
* malformed: {sheet: string, number: string|null, reason: string}[], overCap: number, overCapSheets: number,
|
|
394
|
+
* overCapNumbers: string[], notAMap: boolean, storedBlocked: boolean, blockedSheets: string[]}}
|
|
395
|
+
*/
|
|
396
|
+
export function admitBubbleMap(before, after, ctx = {}) {
|
|
397
|
+
const cap = Number.isInteger(ctx.cap) && ctx.cap >= 0 ? ctx.cap : MARKS_MAX_PER_VIEW;
|
|
398
|
+
const result = { merged: {}, added: [], differs: [], malformed: [], overCap: 0, overCapSheets: 0, overCapNumbers: [], notAMap: false, storedBlocked: false, blockedSheets: [] };
|
|
399
|
+
// What is stored is not ours to replace: a value that is neither absent nor a map is kept exactly as it is, and the
|
|
400
|
+
// read is told (only when it had something to add).
|
|
401
|
+
if (before !== undefined && before !== null && !isObject(before)) {
|
|
402
|
+
result.merged = before;
|
|
403
|
+
result.storedBlocked = after !== undefined && after !== null && !(isObject(after) && Object.keys(after).length === 0);
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
const base = isObject(before) ? before : {};
|
|
407
|
+
const merged = result.merged;
|
|
408
|
+
for (const sheet of Object.keys(base)) own(merged, sheet, isObject(base[sheet]) ? { ...base[sheet] } : base[sheet]); // `own`: a stored sheet may be called "__proto__"
|
|
409
|
+
if (after === undefined || after === null) return result;
|
|
410
|
+
if (!isObject(after)) {
|
|
411
|
+
result.notAMap = true;
|
|
412
|
+
result.malformed.push({ sheet: '', number: null, reason: "the detail anchors aren't a list of sheets" });
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
const sheetKeys = (map) => Object.keys(map);
|
|
416
|
+
const same = (a, b) => Array.isArray(a) && Array.isArray(b) && a.length === 2 && b.length === 2
|
|
417
|
+
&& Number(a[0]) === Number(b[0]) && Number(a[1]) === Number(b[1]);
|
|
418
|
+
for (const sheetIn of Object.keys(after)) {
|
|
419
|
+
const numbersIn = after[sheetIn];
|
|
420
|
+
// `__proto__` and friends are refused whatever is stored: no lookup below may ever reach Object.prototype.
|
|
421
|
+
if (FORBIDDEN_KEYS.has(sheetIn)) {
|
|
422
|
+
result.malformed.push({ sheet: sheetIn.slice(0, MARK_SHEET_MAX), number: null, reason: "the sheet name isn't one FloLess can store" });
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
// Case- and space-insensitive sheet identity, writing into the existing key when there is one.
|
|
426
|
+
const existingKey = sheetKeys(merged).find((k) => normSheet(k) === normSheet(sheetIn));
|
|
427
|
+
// A sheet the model ALREADY holds is exempt from the naming rules (a stored legacy key such as "S-501/502" or
|
|
428
|
+
// "S-501 (REV 2)" is not malformed just because it is stored), exactly as a stored callout is. Only a NEW sheet is checked.
|
|
429
|
+
if (existingKey === undefined && (!BUBBLE_KEY_PATTERN.test(sheetIn) || sheetIn.length > MARK_SHEET_MAX)) {
|
|
430
|
+
result.malformed.push({ sheet: sheetIn.slice(0, MARK_SHEET_MAX), number: null, reason: "the sheet name isn't one FloLess can store" });
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const sheet = existingKey ?? sheetIn;
|
|
434
|
+
if (!isObject(numbersIn)) {
|
|
435
|
+
// A non-object that equals what is stored is simply present; anything else cannot be anchors.
|
|
436
|
+
if (existingKey !== undefined && !isObject(merged[sheet]) && stableJson(merged[sheet]) === stableJson(numbersIn)) continue;
|
|
437
|
+
result.malformed.push({ sheet, number: null, reason: "its anchors aren't a list of detail numbers" });
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
// The model holds something for this sheet that is not a set of detail numbers: kept, nothing added to it.
|
|
441
|
+
if (existingKey !== undefined && !isObject(merged[sheet])) {
|
|
442
|
+
result.blockedSheets.push(sheet);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
for (const numberIn of Object.keys(numbersIn)) {
|
|
446
|
+
const anchor = numbersIn[numberIn];
|
|
447
|
+
if (FORBIDDEN_KEYS.has(numberIn)) {
|
|
448
|
+
result.malformed.push({ sheet, number: numberIn.slice(0, MARK_NUMBER_MAX), reason: "the detail number isn't one FloLess can store" });
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const slot = isObject(merged[sheet]) ? merged[sheet] : null;
|
|
452
|
+
// Same-or-differs FIRST, so an anchor the model already holds (under whatever legacy key) is never "malformed".
|
|
453
|
+
if (slot && Object.hasOwn(slot, numberIn)) {
|
|
454
|
+
if (!same(slot[numberIn], anchor)) result.differs.push({ sheet, number: numberIn });
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (!BUBBLE_KEY_PATTERN.test(numberIn) || numberIn.length > MARK_NUMBER_MAX) {
|
|
458
|
+
result.malformed.push({ sheet, number: numberIn.slice(0, MARK_NUMBER_MAX), reason: "the detail number isn't one FloLess can store" });
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (!(Array.isArray(anchor) && anchor.length === 2 && anchor.every((v) => finiteNumber(v) && v >= 0 && v <= 1))) {
|
|
462
|
+
result.malformed.push({ sheet, number: numberIn, reason: "its anchor isn't a pair of positions between 0 and 1" });
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const sheetCount = sheetKeys(merged).length;
|
|
466
|
+
const numberCount = slot ? Object.keys(slot).length : 0;
|
|
467
|
+
if (!slot && sheetCount >= cap) {
|
|
468
|
+
result.overCap += 1;
|
|
469
|
+
result.overCapSheets += 1;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
if (slot && numberCount >= cap) {
|
|
473
|
+
result.overCap += 1;
|
|
474
|
+
result.overCapNumbers.push(sheet);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (!slot) own(merged, sheet, {});
|
|
478
|
+
own(merged[sheet], numberIn, [anchor[0], anchor[1]]);
|
|
479
|
+
result.added.push({ sheet, number: numberIn });
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// ── plain-English issue wording (shared by staging and the editor) ─────────────────────────────────────
|
|
486
|
+
|
|
487
|
+
/** "Left out one callout on S-202: it doesn't say which sheet it points to." */
|
|
488
|
+
export function malformedMessage(spec, viewLabel, entry, problems) {
|
|
489
|
+
const text = isObject(entry) && typeof entry.text === 'string' ? entry.text.trim() : '';
|
|
490
|
+
const named = text && text.length <= MARK_TEXT_MAX && !CONTROL.test(text) ? `${spec.noun} "${text}"` : `one ${spec.noun}`;
|
|
491
|
+
return `Left out ${named} on ${viewLabel}: ${problems.map((p) => p.reason).join(', and ')}.`;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ── target resolution (shared by the click, the tooltip and the tests) ─────────────────────────────────
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Where does a callout lead? Never guesses.
|
|
498
|
+
*
|
|
499
|
+
* no-target the callout does not say which sheet it points to
|
|
500
|
+
* view exactly one view on that sheet (after preferring views of the callout's own kind)
|
|
501
|
+
* choose several views on that sheet: a person picks (`views` lists them, kind-matching first)
|
|
502
|
+
* missing no view in the model has that sheet. `outsideSet` is only what the READ claimed.
|
|
503
|
+
*
|
|
504
|
+
* A section or elevation callout prefers views of that kind, so it never silently lands on an unrelated
|
|
505
|
+
* framing plan that happens to share the page. A detail callout has no kind preference.
|
|
506
|
+
*/
|
|
507
|
+
export function resolveCalloutTarget(model, callout) {
|
|
508
|
+
const target = calloutTargetOf(callout);
|
|
509
|
+
const kind = isObject(callout) ? normKind(callout.kind) : 'detail';
|
|
510
|
+
if (!target.sheet) return { state: 'no-target', sheet: '', number: target.number, kind, views: [] };
|
|
511
|
+
const wanted = normSheet(target.sheet);
|
|
512
|
+
const plans = Array.isArray(model?.plans) ? model.plans : [];
|
|
513
|
+
let views = plans
|
|
514
|
+
.filter((p) => p && typeof p.sheet === 'string' && normSheet(p.sheet) === wanted)
|
|
515
|
+
.map((p) => ({ viewId: typeof p.id === 'string' && p.id.trim() ? p.id : p.sheet, sheet: p.sheet, viewKind: p.viewKind || 'unknown', title: typeof p.title === 'string' ? p.title : '' }));
|
|
516
|
+
if (!views.length) return { state: 'missing', sheet: target.sheet, number: target.number, kind, outsideSet: target.outsideSet, views: [] };
|
|
517
|
+
// A section or elevation callout prefers views of its own kind, so it never silently lands on an
|
|
518
|
+
// unrelated framing plan that shares the page. Kind-matching views are listed first either way.
|
|
519
|
+
const matching = kind === 'section' || kind === 'elevation' ? views.filter((v) => v.viewKind === kind) : [];
|
|
520
|
+
views = [...matching, ...views.filter((v) => !matching.includes(v))];
|
|
521
|
+
const only = views.length === 1 ? views[0] : (matching.length === 1 ? matching[0] : null);
|
|
522
|
+
if (only) return { state: 'view', sheet: target.sheet, number: target.number, kind, viewId: only.viewId, viewKind: only.viewKind, views };
|
|
523
|
+
return { state: 'choose', sheet: target.sheet, number: target.number, kind, views };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** How many marks a view carries, for the honest empty states. */
|
|
527
|
+
export function markCounts(plan) {
|
|
528
|
+
const n = (v) => (Array.isArray(v) ? v.length : 0);
|
|
529
|
+
return { callouts: n(plan?.callouts), details: n(plan?.details), tosCallouts: n(plan?.tos_callouts) };
|
|
530
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* steel-model-slim.js - the slim copy of a steel model that "See what changed" keeps and compares.
|
|
3
|
+
*
|
|
4
|
+
* WHY A SLIM COPY AT ALL. The model-changed bar (#2209) must be able to say what changed since the model
|
|
5
|
+
* this tab last had. The server keeps no history of working-model writes, so the tab keeps a copy of the
|
|
6
|
+
* model as it last saw it. A real model is mostly the saved Drawing Filter (93% of a measured 8 MB model,
|
|
7
|
+
* and 99.99% of the largest known one), which no comparison reads. The copy therefore drops what the
|
|
8
|
+
* comparison cannot see, and the server applies this SAME function to the current model before it
|
|
9
|
+
* compares, so both sides lack the same fields and the comparison cannot report a difference in a field it
|
|
10
|
+
* never looked at.
|
|
11
|
+
*
|
|
12
|
+
* WHY THIS IS SAFE TO DO ON THE CLIENT (the History comment in server/version-diff.ts records two failed
|
|
13
|
+
* repairs). Values are DELETED or BLANKED TO "" - never replaced by objects, so the schema's string types
|
|
14
|
+
* keep holding. KEYS are kept wherever a reference can point at them (`custom_details` names are what
|
|
15
|
+
* `detail_placements[].detailName` resolves against), so nothing the reference check reads goes missing.
|
|
16
|
+
* Only fields that are optional in the schema AND never read by `checkModelReferences` or `diffContracts`
|
|
17
|
+
* are touched.
|
|
18
|
+
*
|
|
19
|
+
* SLIMMING NEVER LAUNDERS A BAD DOCUMENT. A carrier is removed only when it has the type the schema says
|
|
20
|
+
* it has (a string `raster_b64`, string preview and custom-detail values, a string `connections[].image`,
|
|
21
|
+
* an object `filter`). A malformed carrier is left exactly as it is, so the slim fails validation whenever
|
|
22
|
+
* the original did and for the same reasons.
|
|
23
|
+
*
|
|
24
|
+
* PURE. No DOM, no storage, no I/O, never mutates its input (callers may pass a frozen document). The
|
|
25
|
+
* result shares unchanged sub-objects with the input, so it is meant to be serialised immediately; the
|
|
26
|
+
* editor does that in the same tick as the request body (JSON.stringify(slimForChangeList(C))).
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** Version of the slimming rules. Stored beside each copy so a future rule change can discard old copies. */
|
|
30
|
+
export const LAST_SEEN_SLIM_VERSION = 1;
|
|
31
|
+
|
|
32
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The object with every string-valued entry removed (`mode: 'delete'`) or blanked to "" (`mode: 'blank'`),
|
|
36
|
+
* or the SAME object when nothing in it is a string. Non-string entries are kept untouched.
|
|
37
|
+
*/
|
|
38
|
+
function withoutStringValues(map, mode) {
|
|
39
|
+
let out = null;
|
|
40
|
+
for (const key of Object.keys(map)) {
|
|
41
|
+
if (typeof map[key] !== 'string') continue;
|
|
42
|
+
if (!out) out = { ...map };
|
|
43
|
+
if (mode === 'blank') out[key] = '';
|
|
44
|
+
else delete out[key];
|
|
45
|
+
}
|
|
46
|
+
return out || map;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The slim copy of a steel.model/v2 document, or null when the input is not a v2 document at all.
|
|
51
|
+
* Idempotent: slim(slim(x)) deep-equals slim(x).
|
|
52
|
+
*/
|
|
53
|
+
export function slimForChangeList(doc) {
|
|
54
|
+
if (!isObj(doc) || doc.type !== 'steel.model/v2') return null;
|
|
55
|
+
const out = { ...doc };
|
|
56
|
+
|
|
57
|
+
// The saved Drawing Filter: an object with no constraint on its insides, never read by the comparison.
|
|
58
|
+
if (isObj(out.filter)) delete out.filter;
|
|
59
|
+
|
|
60
|
+
// sheet -> base64 preview. Only string entries are carriers; anything else is left for validation to refuse.
|
|
61
|
+
if (isObj(out.sheet_previews)) {
|
|
62
|
+
const kept = withoutStringValues(out.sheet_previews, 'delete');
|
|
63
|
+
if (Object.keys(kept).length === 0) delete out.sheet_previews;
|
|
64
|
+
else out.sheet_previews = kept;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Custom detail images: blank the bytes, KEEP the names (detail_placements reference them).
|
|
68
|
+
if (isObj(out.custom_details)) out.custom_details = withoutStringValues(out.custom_details, 'blank');
|
|
69
|
+
|
|
70
|
+
if (Array.isArray(out.plans)) {
|
|
71
|
+
let plans = null;
|
|
72
|
+
out.plans.forEach((plan, i) => {
|
|
73
|
+
if (!isObj(plan) || typeof plan.raster_b64 !== 'string') return;
|
|
74
|
+
if (!plans) plans = out.plans.slice();
|
|
75
|
+
const next = { ...plan };
|
|
76
|
+
delete next.raster_b64;
|
|
77
|
+
plans[i] = next;
|
|
78
|
+
});
|
|
79
|
+
if (plans) out.plans = plans;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(out.connections)) {
|
|
83
|
+
let rows = null;
|
|
84
|
+
out.connections.forEach((row, i) => {
|
|
85
|
+
if (!isObj(row) || typeof row.image !== 'string') return;
|
|
86
|
+
if (!rows) rows = out.connections.slice();
|
|
87
|
+
const next = { ...row };
|
|
88
|
+
delete next.image;
|
|
89
|
+
rows[i] = next;
|
|
90
|
+
});
|
|
91
|
+
if (rows) out.connections = rows;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
@@ -129,10 +129,22 @@ export function validateClientSteelModelV2(doc, schema) {
|
|
|
129
129
|
}
|
|
130
130
|
for (const obs of rows(plan.memberObservations)) {
|
|
131
131
|
const bound = rows(obs?.binding?.memberIds);
|
|
132
|
+
// EVERY bound member must resolve, whatever the binding's status (the server's `observation-member-unresolved`): a superseded
|
|
133
|
+
// binding naming a member that is not there would pass here and be refused on save, an edit that could never be saved.
|
|
134
|
+
// Only the presentation bookkeeping is active-only: a superseded or archived trace presents nothing.
|
|
135
|
+
for (const id of bound) entityRef(id, `$.plans[${pi}].memberObservations`);
|
|
132
136
|
if (obs?.binding?.status === 'active') {
|
|
133
137
|
if (!bound.length) issues.push(`observation-cardinality at $.plans[${pi}].memberObservations`);
|
|
134
|
-
for (const id of bound)
|
|
135
|
-
} else if (bound.length)
|
|
138
|
+
for (const id of bound) presented.add(id);
|
|
139
|
+
} else if (obs?.binding?.status === 'archived' && bound.length) {
|
|
140
|
+
// The server's rule, word for word: an ARCHIVED binding binds nothing, a SUPERSEDED one is free (it may still carry
|
|
141
|
+
// its members until they are explicitly rebound). This check used to refuse every non-active binding that had members.
|
|
142
|
+
issues.push(`observation-cardinality at $.plans[${pi}].memberObservations`);
|
|
143
|
+
}
|
|
144
|
+
// A release records that a person dropped the link to a member that is GONE: never beside a binding that still names it.
|
|
145
|
+
const released = rows(obs?.binding?.released).map((row) => row?.memberId);
|
|
146
|
+
if (released.some((id) => bound.includes(id))) issues.push(`observation-released-still-bound at $.plans[${pi}].memberObservations`);
|
|
147
|
+
if (new Set(released).size !== released.length) issues.push(`observation-released-repeated at $.plans[${pi}].memberObservations`);
|
|
136
148
|
}
|
|
137
149
|
for (const dim of rows(plan.dims)) {
|
|
138
150
|
for (const key of ['aRef', 'bRef']) {
|