@floless/app 0.136.0 → 0.137.1

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.
@@ -14,6 +14,7 @@ import { validateSchemaSubset } from './json-schema-subset.js';
14
14
  export { validateSchemaSubset };
15
15
  import { parseSpacings } from './grid-core.js';
16
16
  import { positionBasisIssue,POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
17
+ import { rawPlanViewId } from './steel-plan-view-id.js';
17
18
  export const POSITION_BASIS_CLIENT_VALIDATION_VERSION=POSITION_BASIS_CAPABILITY_VERSION;
18
19
 
19
20
  const rows = (v) => Array.isArray(v) ? v : [];
@@ -33,7 +34,13 @@ export function validateClientSteelModelV2(doc, schema) {
33
34
  for (const [id, count] of memberCounts) if (!id || count !== 1) issues.push(`member-id-${id ? 'duplicate' : 'empty'} at $.members`);
34
35
 
35
36
  const plans = rows(doc.plans);
36
- const sheets = new Set();
37
+ const viewIds = new Map();
38
+ // Counted up front so EVERY colliding row is named, not just the ones after the first — a report that
39
+ // says "$.plans[3]" and nothing else leaves the author guessing which other row it collides with.
40
+ for (const plan of plans) {
41
+ const id = rawPlanViewId(plan);
42
+ if (id !== null) viewIds.set(id, (viewIds.get(id) || 0) + 1);
43
+ }
37
44
  const presented = new Set();
38
45
  const axes = rows(doc.grid?.axes);
39
46
  const axisIds = new Set();
@@ -88,8 +95,14 @@ export function validateClientSteelModelV2(doc, schema) {
88
95
  };
89
96
  for (let pi = 0; pi < plans.length; pi += 1) {
90
97
  const plan = plans[pi];
91
- if (sheets.has(plan.sheet)) issues.push(`plan-sheet-duplicate at $.plans[${pi}].sheet`);
92
- sheets.add(plan.sheet);
98
+ /*
99
+ * A row is one drawing VIEW, identified by its resolved view id (#938). Two views may share a
100
+ * physical page — five elevations on one sheet — but never an id. Server parity:
101
+ * `plan-view-id-duplicate` in `steel-model-v2.ts`, which replaced `plan-sheet-duplicate` because
102
+ * two unnamed rows on one page collide on IDENTITY, not on the page.
103
+ */
104
+ const viewId = rawPlanViewId(plan);
105
+ if (viewId !== null && (viewIds.get(viewId) ?? 0) > 1) issues.push(`plan-view-id-duplicate at $.plans[${pi}]`);
93
106
  controlRef(plan.datum_ref, `$.plans[${pi}].datum_ref`);
94
107
  controlRef(plan.control2_ref, `$.plans[${pi}].control2_ref`);
95
108
  for (const id of rows(plan.memberRefs)) {
@@ -10,6 +10,7 @@
10
10
  * This module is inert until steel-editor.html creates a session and hands it tagged projection objects.
11
11
  */
12
12
 
13
+ import { planViewId } from './steel-plan-view-id.js';
13
14
  import { sheetPxToWorld, worldToSheetPx } from './steel-plan-transform.js';
14
15
  import { memberPresence, projectionLink } from './steel-model-v2-projection.js';
15
16
  import { axisLabelsFor, gridLabelPatch, parseSpacings } from './grid-core.js';
@@ -73,9 +74,15 @@ export class V2CommandError extends Error {
73
74
  }
74
75
  }
75
76
 
76
- function planBySheet(doc, sheet) {
77
- const plan = (doc.plans || []).find((p) => p?.sheet === sheet);
78
- if (!plan) throw new V2CommandError('sheet-unresolved', `sheet "${sheet}" does not exist`);
77
+ /**
78
+ * The row this command acts on, resolved by VIEW ID (#938).
79
+ *
80
+ * Was `p.sheet === sheet`, which returned the first row on a page. Five elevations on one page would
81
+ * therefore all have been edited through whichever came first, at that row's registration and scale.
82
+ */
83
+ function planByViewId(doc, viewId) {
84
+ const plan = (doc.plans || []).find((p) => planViewId(p) === viewId);
85
+ if (!plan) throw new V2CommandError('view-unresolved', `drawing view "${viewId}" does not exist`);
79
86
  return plan;
80
87
  }
81
88
 
@@ -432,9 +439,11 @@ export function createV2CommandSession(model, options = {}) {
432
439
  return session.transact('restore undo snapshot', (draft) => {
433
440
  draft.members = Array.isArray(saved.members) ? clone(saved.members) : [];
434
441
  draft.grid = Object.hasOwn(saved, 'grid') ? clone(saved.grid) : null;
435
- const bySheet = new Map((saved.plans || []).map((plan) => [plan.sheet, plan]));
442
+ // Keyed by VIEW ID, not page (#938): with two views on one sheet a page-keyed map holds one of
443
+ // them, and every sibling would be restored from its neighbour's dims, refs and observations.
444
+ const byView = new Map((saved.plans || []).map((plan) => [planViewId(plan), plan]));
436
445
  for (const plan of draft.plans || []) {
437
- const row = bySheet.get(plan.sheet);
446
+ const row = byView.get(planViewId(plan));
438
447
  if (!row) continue;
439
448
  plan.dims = clone(row.dims || []);
440
449
  plan.memberRefs = clone(row.memberRefs || []);
@@ -504,12 +513,12 @@ export function createV2CommandSession(model, options = {}) {
504
513
  });
505
514
  },
506
515
 
507
- setEndpointPx(sheet, memberId, index, point) {
516
+ setEndpointPx(viewId, memberId, index, point) {
508
517
  return session.transact('set endpoint', (doc) => {
509
518
  const member = memberById(doc, memberId);
510
519
  const old = endpoint(member, index);
511
520
  setEndpoint(member, index, sheetPxToWorld(point, {
512
- ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid,
521
+ ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid,
513
522
  }, clone(old.z)));
514
523
  return { changedIds: [memberId] };
515
524
  });
@@ -605,11 +614,11 @@ export function createV2CommandSession(model, options = {}) {
605
614
  });
606
615
  },
607
616
 
608
- addMemberPx(sheet, projected) {
617
+ addMemberPx(viewId, projected) {
609
618
  return session.transact('add member', (doc) => {
610
619
  const id = projected.id && !(doc.members || []).some((m) => m.id === projected.id)
611
620
  ? projected.id : mintId();
612
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
621
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
613
622
  const fromZ = projected.role === 'column' ? projected.col?.bos : projected.ends?.[0]?.tos;
614
623
  const toZ = projected.role === 'column' ? projected.col?.tos : projected.ends?.[1]?.tos;
615
624
  const from = sheetPxToWorld(projected.wp[0], plan,
@@ -631,25 +640,25 @@ export function createV2CommandSession(model, options = {}) {
631
640
  });
632
641
  }
633
642
  doc.members.push(member);
634
- const canonicalPlan = planBySheet(doc, sheet);
643
+ const canonicalPlan = planByViewId(doc, viewId);
635
644
  canonicalPlan.memberRefs = [...new Set([...(canonicalPlan.memberRefs || []), id])];
636
645
  return { changedIds: [id], structural: true, value: id };
637
646
  });
638
647
  },
639
648
 
640
- setEndpointsPx(sheet, memberId, a, b) {
649
+ setEndpointsPx(viewId, memberId, a, b) {
641
650
  return session.transact('set endpoints', (doc) => {
642
651
  const member = memberById(doc, memberId);
643
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
652
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
644
653
  member.from = sheetPxToWorld(a, plan, clone(member.from.z));
645
654
  member.to = sheetPxToWorld(b, plan, clone(member.to.z));
646
655
  return { changedIds: [memberId] };
647
656
  });
648
657
  },
649
658
 
650
- translatePx(sheet, ids, offset) {
659
+ translatePx(viewId, ids, offset) {
651
660
  return session.transact('translate members', (doc) => {
652
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
661
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
653
662
  for (const id of ids) {
654
663
  const member = memberById(doc, id);
655
664
  const a = sheetPxToWorld(worldPoint(member.from, plan, offset), plan, clone(member.from.z));
@@ -713,9 +722,9 @@ export function createV2CommandSession(model, options = {}) {
713
722
  });
714
723
  },
715
724
 
716
- patchPlan(sheet, patch) {
725
+ patchPlan(viewId, patch) {
717
726
  return session.transact('patch plan', (doc) => {
718
- const plan = planBySheet(doc, sheet);
727
+ const plan = planByViewId(doc, viewId);
719
728
  for (const [key, value] of Object.entries(patch)) {
720
729
  if (value === undefined) delete plan[key];
721
730
  else plan[key] = key === 'dims' ? canonicalizeDimensionRefs(doc, value) : clone(value);
@@ -724,18 +733,18 @@ export function createV2CommandSession(model, options = {}) {
724
733
  });
725
734
  },
726
735
 
727
- addPlanDims(sheet, dims) {
736
+ addPlanDims(viewId, dims) {
728
737
  return session.transact('add plan dimensions', (doc) => {
729
- const plan = planBySheet(doc, sheet);
738
+ const plan = planByViewId(doc, viewId);
730
739
  plan.dims = [...(plan.dims || []), ...canonicalizeDimensionRefs(doc, dims)];
731
740
  return { structural: true };
732
741
  });
733
742
  },
734
743
 
735
- detachDimRefs(sheet, ids) {
744
+ detachDimRefs(viewId, ids) {
736
745
  return session.transact('detach dimension references', (doc) => {
737
746
  const selected = new Set(ids);
738
- for (const dim of planBySheet(doc, sheet).dims || []) {
747
+ for (const dim of planByViewId(doc, viewId).dims || []) {
739
748
  for (const key of ['aRef', 'bRef']) if (selected.has(dim[key]?.m)) delete dim[key];
740
749
  }
741
750
  return { structural: true };
@@ -810,10 +819,10 @@ export function createV2CommandSession(model, options = {}) {
810
819
  return session.offsetElevation(memberId, Number(targetDefaultIn) - Number(sourceDefaultIn));
811
820
  },
812
821
 
813
- patchGrid(sheet, patch) {
822
+ patchGrid(viewId, patch) {
814
823
  return session.transact('patch grid', (doc) => {
815
824
  if (!doc.grid) throw new V2CommandError('grid-unavailable', 'the model has no grid');
816
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
825
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
817
826
  for (const [key, value] of Object.entries(patch)) {
818
827
  if (value === undefined) delete doc.grid[key];
819
828
  else if (key === 'origin') {
@@ -849,11 +858,11 @@ export function createV2CommandSession(model, options = {}) {
849
858
  });
850
859
  },
851
860
 
852
- setPlanGrid(sheet, grid) {
861
+ setPlanGrid(viewId, grid) {
853
862
  return session.transact('set model grid', (doc) => {
854
863
  if (grid == null) doc.grid = null;
855
864
  else {
856
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid || grid, grid: doc.grid || grid };
865
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid || grid, grid: doc.grid || grid };
857
866
  const next = clone(grid);
858
867
  if (Array.isArray(next.origin)) {
859
868
  const p = sheetPxToWorld(next.origin, plan, { unknown: true });
@@ -887,10 +896,10 @@ export function createV2CommandSession(model, options = {}) {
887
896
  });
888
897
  },
889
898
 
890
- addGridLine(sheet, line) {
899
+ addGridLine(viewId, line) {
891
900
  return session.transact('add grid line', (doc) => {
892
901
  if (!doc.grid) throw new V2CommandError('grid-unavailable', 'the model has no grid');
893
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
902
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
894
903
  const next = clone(line);
895
904
  for (const key of ['a', 'b']) {
896
905
  const p = sheetPxToWorld(next[key], plan, { unknown: true });
@@ -901,11 +910,11 @@ export function createV2CommandSession(model, options = {}) {
901
910
  });
902
911
  },
903
912
 
904
- setGridLineEnds(sheet, id, a, b) {
913
+ setGridLineEnds(viewId, id, a, b) {
905
914
  return session.transact('move grid line', (doc) => {
906
915
  const line = (doc.grid?.lines || []).find((row) => String(row.id) === String(id));
907
916
  if (!line) throw new V2CommandError('grid-line-unresolved', `grid line "${id}" does not exist`);
908
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
917
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
909
918
  const aw = sheetPxToWorld(a, plan, { unknown: true });
910
919
  const bw = sheetPxToWorld(b, plan, { unknown: true });
911
920
  line.a = [aw.x, aw.y]; line.b = [bw.x, bw.y];
@@ -913,9 +922,9 @@ export function createV2CommandSession(model, options = {}) {
913
922
  });
914
923
  },
915
924
 
916
- presentOnSheet(sheet, ids, on) {
917
- return session.transact(on ? 'show members on sheet' : 'hide members on sheet', (doc) => {
918
- const plan = planBySheet(doc, sheet);
925
+ presentOnSheet(viewId, ids, on) {
926
+ return session.transact(on ? 'show members on view' : 'hide members on view', (doc) => {
927
+ const plan = planByViewId(doc, viewId);
919
928
  const selected = new Set(ids);
920
929
  if (on) plan.memberRefs = [...new Set([...(plan.memberRefs || []), ...selected])];
921
930
  else {
@@ -927,9 +936,9 @@ export function createV2CommandSession(model, options = {}) {
927
936
  });
928
937
  },
929
938
 
930
- copyMembers(sheet, ids, offsetPx = [0, 0, 0]) {
939
+ copyMembers(viewId, ids, offsetPx = [0, 0, 0]) {
931
940
  return session.transact('copy members', (doc) => {
932
- const plan = { ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid };
941
+ const plan = { ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid };
933
942
  const made = [];
934
943
  for (const id of ids) {
935
944
  const source = memberById(doc, id);
@@ -945,24 +954,26 @@ export function createV2CommandSession(model, options = {}) {
945
954
  copy.to.z = { known: known(copy.to.z, `${source.id}.to`) + dz };
946
955
  }
947
956
  doc.members.push(copy);
948
- planBySheet(doc, sheet).memberRefs = [...new Set([...(planBySheet(doc, sheet).memberRefs || []), copy.id])];
957
+ planByViewId(doc, viewId).memberRefs = [...new Set([...(planByViewId(doc, viewId).memberRefs || []), copy.id])];
949
958
  made.push(copy.id);
950
959
  }
951
960
  return { changedIds: made, structural: true, value: made };
952
961
  });
953
962
  },
954
963
 
955
- moveOrCopyToSheet(targetSheet, entries, copy = false) {
956
- return session.transact(copy ? 'copy members to sheet' : 'move members to sheet', (doc) => {
957
- const target = planBySheet(doc, targetSheet);
964
+ // Both ends are VIEW ids (#938) — `entries[].sourceViewId` names the row the member is being taken
965
+ // from, which on a page with several views is not answerable from the page name.
966
+ moveOrCopyToView(targetViewId, entries, copy = false) {
967
+ return session.transact(copy ? 'copy members to view' : 'move members to view', (doc) => {
968
+ const target = planByViewId(doc, targetViewId);
958
969
  if (!Number.isFinite(target.elevation_in)) {
959
- throw new V2CommandError('target-elevation-unknown', `sheet "${targetSheet}" has no known plan elevation`);
970
+ throw new V2CommandError('target-elevation-unknown', `drawing view "${targetViewId}" has no known plan elevation`);
960
971
  }
961
972
  const made = [];
962
973
  for (const entry of entries || []) {
963
- const sourcePlan = planBySheet(doc, entry.sourceSheet);
974
+ const sourcePlan = planByViewId(doc, entry.sourceViewId);
964
975
  if (!Number.isFinite(sourcePlan.elevation_in)) {
965
- throw new V2CommandError('source-elevation-unknown', `sheet "${entry.sourceSheet}" has no known plan elevation`);
976
+ throw new V2CommandError('source-elevation-unknown', `drawing view "${entry.sourceViewId}" has no known plan elevation`);
966
977
  }
967
978
  const source = memberById(doc, entry.id);
968
979
  const member = copy ? detachCopiedEngineeringReferences(clone(source)) : source;
@@ -984,12 +995,12 @@ export function createV2CommandSession(model, options = {}) {
984
995
  });
985
996
  },
986
997
 
987
- splitMember(sheet, memberId, splitPx) {
998
+ splitMember(viewId, memberId, splitPx) {
988
999
  return session.transact('split member', (doc) => {
989
1000
  const original = memberById(doc, memberId);
990
1001
  assertNoWholeMemberRefs(doc, new Set([memberId]));
991
1002
  const split = sheetPxToWorld(splitPx, {
992
- ...planBySheet(doc, sheet), modelGrid: doc.grid, grid: doc.grid,
1003
+ ...planByViewId(doc, viewId), modelGrid: doc.grid, grid: doc.grid,
993
1004
  }, clone(original.from.z));
994
1005
  if (!pointOnSegment(split, original.from, original.to)
995
1006
  || Math.hypot(split.x - original.from.x, split.y - original.from.y) <= 1e-6
@@ -1011,16 +1022,16 @@ export function createV2CommandSession(model, options = {}) {
1011
1022
  });
1012
1023
  },
1013
1024
 
1014
- mergeMembers(sheet, memberIds, mergedPx) {
1025
+ mergeMembers(viewId, memberIds, mergedPx) {
1015
1026
  return session.transact('merge members', (doc) => {
1016
- const id = mergeMemberGroup(doc, sheet, memberIds, mergedPx, mintId, resolveSection);
1027
+ const id = mergeMemberGroup(doc, viewId, memberIds, mergedPx, mintId, resolveSection);
1017
1028
  return { changedIds: [id], structural: true, value: id };
1018
1029
  });
1019
1030
  },
1020
1031
 
1021
- mergeMemberGroups(sheet, groups) {
1032
+ mergeMemberGroups(viewId, groups) {
1022
1033
  return session.transact('merge member groups', (doc) => {
1023
- const made = groups.map((group) => mergeMemberGroup(doc, sheet, group.memberIds, group.wp, mintId, resolveSection));
1034
+ const made = groups.map((group) => mergeMemberGroup(doc, viewId, group.memberIds, group.wp, mintId, resolveSection));
1024
1035
  return { changedIds: made, structural: true, value: made };
1025
1036
  });
1026
1037
  },
@@ -1033,12 +1044,12 @@ export function createV2CommandSession(model, options = {}) {
1033
1044
  },
1034
1045
 
1035
1046
  /**
1036
- * @param {string} sheet
1047
+ * @param {string} viewId
1037
1048
  * @param {{memberIds?: string[], dimIds?: string[], jointIds?: string[], gridLineIds?: string[]}} selection
1038
1049
  */
1039
- deleteSelection(sheet, { memberIds = [], dimIds = [], jointIds = [], gridLineIds = [] } = {}) {
1050
+ deleteSelection(viewId, { memberIds = [], dimIds = [], jointIds = [], gridLineIds = [] } = {}) {
1040
1051
  return session.transact('delete selection', (doc) => {
1041
- const plan = planBySheet(doc, sheet);
1052
+ const plan = planByViewId(doc, viewId);
1042
1053
  const dims = new Set(dimIds), joints = new Set(jointIds), lines = new Set(gridLineIds);
1043
1054
  if (dims.size) plan.dims = (plan.dims || []).filter((dim) => !dims.has(dim.id));
1044
1055
  if (joints.size) doc.joints = (doc.joints || []).filter((joint) => !joints.has(joint.id));
@@ -1083,25 +1094,25 @@ export function dispatchV2ProjectionCommand(target, operation, args = []) {
1083
1094
  case 'reverseEnds': s.reverseEndMetadata(link.memberId); return true;
1084
1095
  case 'elevateBy': s.offsetElevation(link.memberId, args[0]); return true;
1085
1096
  case 'retargetTos': s.retargetElevation(link.memberId, args[0], args[1]); return true;
1086
- case 'setEndpoint': s.setEndpointPx(link.sheet, link.memberId, args[0], args[1]); return true;
1087
- case 'setEndpointsInPlace': s.setEndpointsPx(link.sheet, link.memberId, args[0], args[1]); return true;
1088
- case 'replaceEndpoints': s.setEndpointsPx(link.sheet, link.memberId, args[0][0], args[0][1]); return true;
1097
+ case 'setEndpoint': s.setEndpointPx(link.viewId, link.memberId, args[0], args[1]); return true;
1098
+ case 'setEndpointsInPlace': s.setEndpointsPx(link.viewId, link.memberId, args[0], args[1]); return true;
1099
+ case 'replaceEndpoints': s.setEndpointsPx(link.viewId, link.memberId, args[0][0], args[0][1]); return true;
1089
1100
  case 'moveWorkPoints': s.moveWorkPoints(link.memberId, args[0]); return true; // world mm, no sheet — the 3D gizmo's reference-line handles (slice 3b.1)
1090
1101
  case 'translate':
1091
- s.translatePx(link.sheet, args[0].map((m) => projectionLink(m)?.memberId).filter(Boolean), args[1]);
1102
+ s.translatePx(link.viewId, args[0].map((m) => projectionLink(m)?.memberId).filter(Boolean), args[1]);
1092
1103
  return true;
1093
- case 'addMember': s.addMemberPx(link.sheet, args[0]); return true;
1104
+ case 'addMember': s.addMemberPx(link.viewId, args[0]); return true;
1094
1105
  case 'removeMembers': s.deleteMembers(args[0]); return true;
1095
1106
  case 'setMemberType': s.patchMember(link.memberId, { memberType: args[0] }); return true;
1096
1107
  case 'patchMember': s.patchMember(link.memberId, args[0]); return true;
1097
1108
  case 'patchEnd': s.patchEnd(link.memberId, link.kind === 'column' ? 1 : link.end, args[0]); return true;
1098
1109
  case 'setMemberBrace': s.patchMember(link.memberId, { brace: args[0] == null ? undefined : args[0] }); return true;
1099
1110
  case 'patchMemberBrace': s.patchMember(link.memberId, { brace: { ...(target || {}), ...(args[0] || {}) } }); return true;
1100
- case 'patchGrid': s.patchGrid(link.sheet, args[0]); return true;
1111
+ case 'patchGrid': s.patchGrid(link.viewId, args[0]); return true;
1101
1112
  case 'setGridLabels': s.setGridLabels(args[0], args[1]); return true;
1102
- case 'setPlanGrid': s.setPlanGrid(link.sheet, args[0]); return true;
1113
+ case 'setPlanGrid': s.setPlanGrid(link.viewId, args[0]); return true;
1103
1114
  case 'ensurePlanGrid':
1104
- if (!target.grid) s.setPlanGrid(link.sheet, args[0]());
1115
+ if (!target.grid) s.setPlanGrid(link.viewId, args[0]());
1105
1116
  return true;
1106
1117
  case 'removeGridLines': s.removeGridLines(args[0]); return true;
1107
1118
  case 'clearGridLines': s.removeGridLines(new Set((target.lines || []).map((line) => String(line.id)))); return true;
@@ -1110,16 +1121,16 @@ export function dispatchV2ProjectionCommand(target, operation, args = []) {
1110
1121
  if (!line) return true;
1111
1122
  s.setGridLineLabel(String(line.id), args[1]); return true;
1112
1123
  }
1113
- case 'setGridLineEnds': s.setGridLineEnds(link.sheet, link.gridLineId, args[0], args[1]); return true;
1114
- case 'addGridLine': s.addGridLine(link.sheet, args[0]); return true;
1124
+ case 'setGridLineEnds': s.setGridLineEnds(link.viewId, link.gridLineId, args[0], args[1]); return true;
1125
+ case 'addGridLine': s.addGridLine(link.viewId, args[0]); return true;
1115
1126
  case 'setPlanDefaultTos':
1116
1127
  throw new V2CommandError('default-tos-retired', 'steel.model/v2 stores explicit endpoint elevations and has no sheet default T.O.S link');
1117
1128
  case 'setPlanMembers':
1118
1129
  throw new V2CommandError('structural-operation-explicit', 'v2 merge/split/delete commands must declare identity and reference reconciliation');
1119
- case 'setPlanDims': s.patchPlan(link.sheet, { dims: args[0] }); return true;
1120
- case 'addPlanDims': s.addPlanDims(link.sheet, args[0]); return true;
1121
- case 'setPlanFrame': s.patchPlan(link.sheet, { frame: args[0] }); return true;
1122
- case 'detachDimRefs': s.detachDimRefs(link.sheet, args[0]); return true;
1130
+ case 'setPlanDims': s.patchPlan(link.viewId, { dims: args[0] }); return true;
1131
+ case 'addPlanDims': s.addPlanDims(link.viewId, args[0]); return true;
1132
+ case 'setPlanFrame': s.patchPlan(link.viewId, { frame: args[0] }); return true;
1133
+ case 'detachDimRefs': s.detachDimRefs(link.viewId, args[0]); return true;
1123
1134
  default:
1124
1135
  throw new V2CommandError('projection-command-unimplemented', `no v2 projection arm exists for ${operation}`);
1125
1136
  }
@@ -6,6 +6,10 @@
6
6
  * It never mutates the model; importing this module is therefore inert.
7
7
  */
8
8
 
9
+ import { planViewId, planViewLabels } from './steel-plan-view-id.js';
10
+ /* Re-exported so the editor, which loads this module dynamically as `V2Projection`, has ONE place to
11
+ * ask what a row's identity and display name are — rather than reading `.sheet` and hoping (#938). */
12
+ export { planViewId, planViewLabels };
9
13
  import { sheetIncludesElevation,POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
10
14
  export const POSITION_BASIS_PROJECTION_VERSION=POSITION_BASIS_CAPABILITY_VERSION;
11
15
  import { worldToSheetPx, planTransform, PlanTransformError } from './steel-plan-transform.js';
@@ -44,10 +48,34 @@ export function memberPresence(model, plan, member) {
44
48
  return { observed, explicit, crossing, visible: observed || explicit || crossing };
45
49
  }
46
50
 
47
- export function memberSheets(model, memberId) {
51
+ /**
52
+ * The drawing VIEWS that display this member (#938), in document order.
53
+ *
54
+ * It used to return `p.sheet`, which was the same list only while a page could carry one view. With
55
+ * five elevations on S5.1 that answer collapses five different registrations into one repeated string,
56
+ * and every caller that then looked a plan up by it got whichever row came first. The two questions are
57
+ * now separate functions, because the callers genuinely want different things: identity here, and a
58
+ * human-facing page list from `memberPhysicalSheets`.
59
+ */
60
+ export function memberViewIds(model, memberId) {
48
61
  const member = (model.members || []).find((m) => m?.id === memberId);
49
62
  if (!member) return [];
50
- return (model.plans || []).filter((p) => memberPresence(model, p, member).visible).map((p) => p.sheet);
63
+ return (model.plans || []).filter((p) => memberPresence(model, p, member).visible).map(planViewId);
64
+ }
65
+
66
+ /**
67
+ * The PAGES this member appears on — deduplicated, for display only.
68
+ *
69
+ * Never an identity: two views on one page yield one page name, which is exactly right for "also shown
70
+ * on S5.1" and exactly wrong for looking a row up.
71
+ */
72
+ export function memberPhysicalSheets(model, memberId) {
73
+ const member = (model.members || []).find((m) => m?.id === memberId);
74
+ if (!member) return [];
75
+ return [...new Set((model.plans || [])
76
+ .filter((p) => memberPresence(model, p, member).visible)
77
+ .map((p) => (p && typeof p.sheet === 'string' ? p.sheet : ''))
78
+ .filter(Boolean))];
51
79
  }
52
80
 
53
81
  /**
@@ -60,10 +88,15 @@ export function memberSheets(model, memberId) {
60
88
  * sheet that states a registration which does not hold is a fault someone has to correct. Both leave
61
89
  * the projection empty; only the second is a warning.
62
90
  *
63
- * @param {any} plan @returns {{code: string, message: string, registered: boolean} | null}
91
+ * @param {any} plan
92
+ * @param {string} [subject] How to NAME this view in the refusal message. Without it the message
93
+ says the physical page, so two views on one page produce identical text and the banner that
94
+ renders it cannot say which one is at fault (#938). The caller supplies it because the rule is a
95
+ sibling count and this function is handed one row.
96
+ * @returns {{code: string, message: string, registered: boolean} | null}
64
97
  */
65
- export function registrationRefusal(plan) {
66
- try { planTransform(plan); return null; } catch (err) {
98
+ export function registrationRefusal(plan, subject) {
99
+ try { planTransform(plan, subject); return null; } catch (err) {
67
100
  /*
68
101
  * ONLY a real refusal degrades. `planTransform` is ordinary code and can fail for ordinary reasons —
69
102
  * a TypeError, a future regression — and catching those into `registration-invalid` would blame the
@@ -123,10 +156,23 @@ function projectGrid(modelGrid, plan) {
123
156
  return out;
124
157
  }
125
158
 
126
- /** One canonical member mapped into the display-space vocabulary the 2D canvas consumes. */
127
- export function projectMember(member, plan, session = null) {
128
- const a = worldToSheetPx(member.from, plan);
129
- const b = worldToSheetPx(member.to, plan);
159
+ /**
160
+ * The registration-INDEPENDENT half of a projected member row — everything a consumer can know about a
161
+ * member WITHOUT a sheet to draw it on: its mark, profile, material, member type, placement, elevations,
162
+ * end notes/details and connection references.
163
+ *
164
+ * THE CANONICAL READ PATH (#942). A refused sheet projects empty, because every projected COORDINATE
165
+ * derives from a registration that does not hold. But the properties above derive from the canonical
166
+ * member alone — `from.z`/`to.z` in world mm, and plain metadata — so a model-wide consumer that needs a
167
+ * member's properties and not its plan pixels has no reason to be blocked by a refusal. Such a consumer
168
+ * reads THIS, and never gets a `wp` it could accidentally do coordinate maths with: the key is absent, not
169
+ * null, so a consumer that reaches for one fails loudly instead of quietly computing NaN.
170
+ *
171
+ * `projectMember` composes it with the two mapped points, which is what keeps the two from ever drifting:
172
+ * there is one definition of what a member's properties are, and the projected row is that definition plus
173
+ * a position.
174
+ */
175
+ export function memberProperties(member) {
130
176
  const meta = {
131
177
  id: member.id,
132
178
  profile: member.profile,
@@ -142,9 +188,8 @@ export function projectMember(member, plan, session = null) {
142
188
  tos: knownIn(i === 0 ? member.from.z : member.to.z),
143
189
  tosDef: false,
144
190
  }));
145
- const projected = {
191
+ return {
146
192
  ...meta,
147
- wp: [a, b],
148
193
  ends,
149
194
  col: {
150
195
  bos: knownIn(member.from.z),
@@ -156,7 +201,20 @@ export function projectMember(member, plan, session = null) {
156
201
  connVerified: endMeta[1]?.connVerified,
157
202
  },
158
203
  };
159
- const base = { session, kind: 'member', memberId: member.id, sheet: plan.sheet };
204
+
205
+ }
206
+
207
+ /** One canonical member mapped into the display-space vocabulary the 2D canvas consumes. */
208
+ export function projectMember(member, plan, session = null) {
209
+ const a = worldToSheetPx(member.from, plan);
210
+ const b = worldToSheetPx(member.to, plan);
211
+ // Destructured so the emitted key ORDER is byte-identical to what this function built inline before the
212
+ // properties were extracted (meta keys, then wp, then ends, then col).
213
+ const { ends, col, ...meta } = memberProperties(member);
214
+ const projected = { ...meta, wp: [a, b], ends, col };
215
+ // `viewId` is the identity every command resolves its row by; `sheet` rides along for display only
216
+ // and must never be used as a lookup key (#938).
217
+ const base = { session, kind: 'member', memberId: member.id, viewId: planViewId(plan), sheet: plan.sheet };
160
218
  link(projected, base);
161
219
  link(projected.ends[0], { ...base, kind: 'end', end: 0 });
162
220
  link(projected.ends[1], { ...base, kind: 'end', end: 1 });
@@ -165,11 +223,14 @@ export function projectMember(member, plan, session = null) {
165
223
  return projected;
166
224
  }
167
225
 
168
- /** @param {any} model @param {string} sheet @param {{session?: any}} options */
169
- export function createV2Projection(model, sheet, options = {}) {
226
+ /** @param {any} model @param {string} viewId @param {{session?: any}} options */
227
+ export function createV2Projection(model, viewId, options = {}) {
170
228
  const { session = null } = options;
171
- const plan = (model.plans || []).find((p) => p?.sheet === sheet);
172
- if (!plan) throw new Error(`steel.model/v2 has no plan "${sheet}"`);
229
+ // BY VIEW ID (#938). This used to take the first row with a matching `sheet`, which silently picked
230
+ // one of five elevations on a shared page — and every coordinate this projection derives comes from
231
+ // that row's registration, so "one of five" is five different wrong pictures.
232
+ const plan = (model.plans || []).find((p) => planViewId(p) === viewId);
233
+ if (!plan) throw new Error(`steel.model/v2 has no drawing view "${viewId}"`);
173
234
  const projection = {
174
235
  ...clone(plan),
175
236
  modelGrid: clone(model.grid || null),
@@ -218,11 +279,12 @@ export function createV2Projection(model, sheet, options = {}) {
218
279
  // The sheet's own display-space content (segments, labels, callouts) is untouched: that is the drawing
219
280
  // itself, and it is well defined with or without a registration.
220
281
  if (refusal) projection.dims = [];
221
- link(projection, { session, kind: 'plan', sheet });
282
+ // `viewId` is the identity commands resolve back to a row; `sheet` rides along for display (#938).
283
+ link(projection, { session, kind: 'plan', viewId, sheet: plan.sheet });
222
284
  if (projection.grid) {
223
- link(projection.grid, { session, kind: 'grid', sheet });
285
+ link(projection.grid, { session, kind: 'grid', viewId, sheet: plan.sheet });
224
286
  for (const line of projection.grid.lines || []) link(line, {
225
- session, kind: 'grid-line', sheet, gridLineId: line.id,
287
+ session, kind: 'grid-line', viewId, sheet: plan.sheet, gridLineId: line.id,
226
288
  });
227
289
  }
228
290
 
@@ -230,7 +292,9 @@ export function createV2Projection(model, sheet, options = {}) {
230
292
  let patchCount = 0;
231
293
  const controller = {
232
294
  model,
233
- sheet,
295
+ /** The row this controller drives. `sheet` is retained for display and is NOT an identity (#938). */
296
+ viewId,
297
+ sheet: plan.sheet,
234
298
  plan: projection,
235
299
  get rebuildCount() { return rebuildCount; },
236
300
  get patchCount() { return patchCount; },
@@ -247,10 +311,10 @@ export function createV2Projection(model, sheet, options = {}) {
247
311
  return projection;
248
312
  },
249
313
  rebuild() {
250
- const fresh = createV2Projection(model, sheet, { session });
314
+ const fresh = createV2Projection(model, viewId, { session });
251
315
  for (const key of Object.keys(projection)) delete projection[key];
252
316
  Object.assign(projection, fresh.plan);
253
- link(projection, { session, kind: 'plan', sheet });
317
+ link(projection, { session, kind: 'plan', viewId, sheet: plan.sheet });
254
318
  rebuildCount += 1;
255
319
  return projection;
256
320
  },