@floless/app 0.134.0 → 0.134.2

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.
@@ -148,7 +148,7 @@
148
148
 
149
149
  const IN_MM = 25.4;
150
150
 
151
- import { dispatchV2ProjectionCommand } from './steel-model-v2-commands.js';
151
+ import { V2CommandError, dispatchV2ProjectionCommand } from './steel-model-v2-commands.js';
152
152
  import { gridLabelPatch, mmPerPx } from './grid-core.js';
153
153
 
154
154
  /** Display-pixel scale for one plan — the shared `mmPerPx`, not a fourth copy to keep in lock-step. */
@@ -778,6 +778,27 @@ export function createModelCommands(contract, { activePlan, defaultTosIn, mintId
778
778
  member.wp[i] = pt;
779
779
  };
780
780
 
781
+ /**
782
+ * Move a member's work points in WORLD MM — the 3D Profile Position gizmo's reference-line handles
783
+ * (slice 3b.1). Unlike every other endpoint primitive here this takes no plan pixels, because the 3D
784
+ * view has no sheet scale to build them from (`modelReadsV2().scaleOf()` throws by design) and the v2
785
+ * model already stores world mm. See `moveWorkPoints` in steel-model-v2-commands.js for the validation
786
+ * it performs inside its single transaction.
787
+ *
788
+ * THROWS on a non-v2 target rather than falling through. Every other primitive here has a legacy body
789
+ * to fall back to; there is no legacy world-mm store, so a silent no-op would swallow a committed move
790
+ * and leave the user looking at a live preview of an edit that never happened.
791
+ */
792
+ const moveWorkPoints = (member, spec) => {
793
+ if (dispatchV2ProjectionCommand(member, 'moveWorkPoints', [spec])) return;
794
+ // A V2CommandError, deliberately, not a plain Error: `edit()` catches only that name and re-throws
795
+ // everything else. A plain throw would escape the pointer handler, skip the caller's
796
+ // restore-the-preview branch, and leave the user looking at a live preview of an edit that never
797
+ // happened — which is the exact failure this refusal exists to prevent. (Found in review.)
798
+ throw new V2CommandError('move-points-unsupported',
799
+ 'That member can’t be moved this way — it isn’t stored in the current model format.');
800
+ };
801
+
781
802
  const cloneOnto = (src, plan, off) => {
782
803
  const c = clone(src);
783
804
  translate([c], off);
@@ -788,7 +809,7 @@ export function createModelCommands(contract, { activePlan, defaultTosIn, mintId
788
809
 
789
810
  return {
790
811
  translate, clone, addMembers, removeMembers, replaceEndpoints, setEndpointsInPlace, setEndpoint,
791
- retargetTos,
812
+ moveWorkPoints, retargetTos,
792
813
 
793
814
  /**
794
815
  * The model half of `cmApplyOffsets` (the editor's `function cmApplyOffsets`), in display pixels.
@@ -6,6 +6,12 @@
6
6
  */
7
7
 
8
8
  import { validateSchemaSubset } from './json-schema-subset.js';
9
+ /**
10
+ * Validate ONE value against a schema node — the same subset interpreter, re-exported so a caller can ask
11
+ * the schema about a single row instead of restating its rules in JavaScript. Pass a node that carries
12
+ * `$defs` (e.g. `{...schema.$defs.dim3, $defs: schema.$defs}`) so local `$ref`s still resolve.
13
+ */
14
+ export { validateSchemaSubset };
9
15
  import { axisLabelsFor, parseSpacings } from './grid-core.js';
10
16
  import { positionBasisIssue,POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
11
17
  export const POSITION_BASIS_CLIENT_VALIDATION_VERSION=POSITION_BASIS_CAPABILITY_VERSION;
@@ -16,6 +16,7 @@ import { axisLabelsFor, gridLabelPatch, parseSpacings } from './grid-core.js';
16
16
  import {
17
17
  basisFromAxes, effectiveDepthPosition, effectiveWidthPosition, outlineFor, partFrame,
18
18
  positionOffsetVector, reversePlacement, sectionExtents,
19
+ quantizeMm, requiredDepthPin,
19
20
  POSITION_BASIS_CAPABILITY_VERSION,
20
21
  } from './steel-3d-core.js';
21
22
  export const POSITION_BASIS_COMMAND_VERSION=POSITION_BASIS_CAPABILITY_VERSION;
@@ -31,6 +32,38 @@ const known = (z, label) => {
31
32
  };
32
33
  const elev = (inches) => ({ known: Math.round(Number(inches) * IN_MM * 1e9) / 1e9 });
33
34
 
35
+ /*
36
+ * The drag-start snapshot `moveWorkPoints` compares against — every field the gizmo's availability, its
37
+ * frozen preview, or the depth-face pin actually consumes.
38
+ *
39
+ * It is NOT just the endpoints. A gesture computed against a beam is invalid if the member became a
40
+ * column, or grew a brace type, or had its profile/section swapped, or was re-based into another
41
+ * authoring frame — each of those changes what the preview showed or what the pin should be, and none of
42
+ * them moves an endpoint. The authoring BASIS is checked separately by its own generation counter in the
43
+ * editor; this covers the member.
44
+ *
45
+ * Serialisation is STABLE-KEY, not bare JSON.stringify: `section` and `positionBasis` are nested objects,
46
+ * and a key order that differs while the value is identical must compare EQUAL. Rejecting that would
47
+ * refuse a perfectly valid move for a reason no user could ever act on.
48
+ */
49
+ const FINGERPRINT_KEYS = [
50
+ 'role', 'memberType', 'brace', 'position', 'positionH', 'positionOffset', 'positionHOffset',
51
+ 'positionBasis', 'rot', 'profile', 'section',
52
+ ];
53
+ function stableKey(v) {
54
+ if (v === null || typeof v !== 'object') return JSON.stringify(v ?? null);
55
+ if (Array.isArray(v)) return `[${v.map(stableKey).join(',')}]`;
56
+ return `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${stableKey(v[k])}`).join(',')}}`;
57
+ }
58
+ export function memberFingerprint(member) {
59
+ const out = { from: clone(member.from), to: clone(member.to) };
60
+ for (const k of FINGERPRINT_KEYS) if (member[k] !== undefined) out[k] = clone(member[k]);
61
+ return out;
62
+ }
63
+ export function memberFingerprintKey(fp) {
64
+ return stableKey(fp);
65
+ }
66
+
34
67
  export class V2CommandError extends Error {
35
68
  constructor(code, message, details = []) {
36
69
  super(message);
@@ -482,6 +515,96 @@ export function createV2CommandSession(model, options = {}) {
482
515
  });
483
516
  },
484
517
 
518
+ /*
519
+ * Move a member's WORK POINTS in world mm — the write path for the 3D Profile Position gizmo's
520
+ * reference-line handles (slice 3b.1).
521
+ *
522
+ * WHY NOT setEndpointPx. That one takes PLAN PIXELS and needs a sheet to invert them through. The 3D
523
+ * gizmo has neither: `modelReadsV2().scaleOf()` deliberately THROWS ("a member has no owning-sheet
524
+ * scale - it is stored in world mm"), so there is no ptPerFt to build a px argument with, and
525
+ * round-tripping world -> px -> world for a model that already stores world mm would only lose
526
+ * precision. This is the honest primitive for a world-mm mover.
527
+ *
528
+ * WHY IT VALIDATES RATHER THAN TRUSTS. It is a facade the whole editor can reach, and it can DESTROY
529
+ * geometry, so it re-derives every precondition inside the transaction instead of believing its
530
+ * caller. `session.transact` clones the model into a draft and commits only on success, so any throw
531
+ * here rolls the whole thing back - which is also why the endpoints and the depth-face pin must land
532
+ * in ONE call: as two transactions, the first could commit and the second throw, and edit() skips
533
+ * pushUndo on a caught V2CommandError, leaving a mutated model with no undo entry.
534
+ *
535
+ * @param {string} memberId
536
+ * @param {{points:{from?:{x,y,z}, to?:{x,y,z}}, expect:object, position?:string}} spec
537
+ * points world mm; at least one endpoint, and at least one must actually CHANGE
538
+ * expect the drag-start fingerprint (see `memberFingerprint`) - optimistic concurrency
539
+ * position the depth-face pin, REQUIRED exactly when this move would fold the effective face
540
+ */
541
+ moveWorkPoints(memberId, spec) {
542
+ return session.transact('move work points', (doc) => {
543
+ const member = memberById(doc, memberId);
544
+ const points = spec && spec.points;
545
+ if (!points || (!points.from && !points.to)) {
546
+ throw new V2CommandError('move-points-missing', 'That move didn’t name a work point to move.');
547
+ }
548
+ // (a) DRIFT. The gesture was computed against a frozen snapshot; if anything the gizmo's
549
+ // availability, preview or pin semantics depend on has changed since, the move is stale and would
550
+ // silently overwrite someone else's edit. Exact comparison on purpose: a tolerance here would
551
+ // deliberately permit an intervening write to be clobbered.
552
+ const now = memberFingerprint(member);
553
+ if (!spec.expect || memberFingerprintKey(spec.expect) !== memberFingerprintKey(now)) {
554
+ throw new V2CommandError('move-points-stale',
555
+ 'That member changed while you were dragging — nothing was moved.');
556
+ }
557
+ // (b) UNKNOWN ELEVATION. `known` throws 'elevation-unknown', which edit() already renders as
558
+ // "the elevation is unknown. Enter the TOS first." A mover may not INVENT an elevation by
559
+ // materialising {unknown:true} into {known:...}, so this reads the CURRENT stored z of every
560
+ // endpoint it is about to write, not the one the caller believes is there.
561
+ // (c) FINITENESS of everything coming in.
562
+ const next = {};
563
+ for (const [key, index] of [['from', 0], ['to', 1]]) {
564
+ const p = points[key];
565
+ if (!p) { const cur = endpoint(member, index); next[key] = [cur.x, cur.y, known(cur.z, `${memberId}.${key}`)]; continue; }
566
+ known(endpoint(member, index).z, `${memberId}.${key}`);
567
+ for (const axis of ['x', 'y', 'z']) {
568
+ // `typeof === 'number'` deliberately, NOT Number(v): `Number(null)`, `Number('')` and
569
+ // `Number([])` are all 0, so a null coordinate would coerce silently to zero and TELEPORT the
570
+ // work point to the model origin. Caught by this file's own non-finite test.
571
+ if (typeof p[axis] !== 'number' || !Number.isFinite(p[axis])) {
572
+ throw new V2CommandError('move-points-invalid', 'That move produced a coordinate the model can’t store.');
573
+ }
574
+ }
575
+ next[key] = [quantizeMm(p.x), quantizeMm(p.y), quantizeMm(p.z)];
576
+ }
577
+ const before = {
578
+ from: [member.from.x, member.from.y, known(member.from.z, `${memberId}.from`)],
579
+ to: [member.to.x, member.to.y, known(member.to.z, `${memberId}.to`)],
580
+ };
581
+ const same = (a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
582
+ if (same(next.from, before.from) && same(next.to, before.to)) {
583
+ // Without this, `moveWorkPoints` is a bare placement mutation wearing a move's clothes: a caller
584
+ // could pass the current endpoints and any `position` it liked.
585
+ throw new V2CommandError('move-points-inert', 'That move doesn’t change either work point.');
586
+ }
587
+ // (d) THE PIN IS VERIFIED, NOT ACCEPTED. `effectiveDepthPosition` folds an UNSET depth face at
588
+ // dz > horiz * 0.5774, so a move past ~30 degrees flips which face the profile hangs from and the
589
+ // steel jumps. The commit must carry the drag-start face exactly when that would happen - and the
590
+ // caller does not get to decide: this recomputes it from the CURRENT member and the QUANTISED
591
+ // candidate points, through the same shared helper the editor predicts with.
592
+ const need = requiredDepthPin(member, before, next);
593
+ if (spec.position !== need.pin) {
594
+ throw new V2CommandError('move-points-pin',
595
+ need.pin === undefined
596
+ ? 'That move doesn’t change the depth face, so it can’t set one.'
597
+ : `That move tips the member past the point where its profile would flip, so it has to pin the depth face to “${need.pin}”.`);
598
+ }
599
+ for (const [key, index] of [['from', 0], ['to', 1]]) {
600
+ const [x, y, z] = next[key];
601
+ setEndpoint(member, index, { x, y, z: { known: z } });
602
+ }
603
+ if (need.pin !== undefined) member.position = need.pin;
604
+ return { changedIds: [memberId] };
605
+ });
606
+ },
607
+
485
608
  addMemberPx(sheet, projected) {
486
609
  return session.transact('add member', (doc) => {
487
610
  const id = projected.id && !(doc.members || []).some((m) => m.id === projected.id)
@@ -978,6 +1101,7 @@ export function dispatchV2ProjectionCommand(target, operation, args = []) {
978
1101
  case 'setEndpoint': s.setEndpointPx(link.sheet, link.memberId, args[0], args[1]); return true;
979
1102
  case 'setEndpointsInPlace': s.setEndpointsPx(link.sheet, link.memberId, args[0], args[1]); return true;
980
1103
  case 'replaceEndpoints': s.setEndpointsPx(link.sheet, link.memberId, args[0][0], args[0][1]); return true;
1104
+ case 'moveWorkPoints': s.moveWorkPoints(link.memberId, args[0]); return true; // world mm, no sheet — the 3D gizmo's reference-line handles (slice 3b.1)
981
1105
  case 'translate':
982
1106
  s.translatePx(link.sheet, args[0].map((m) => projectionLink(m)?.memberId).filter(Boolean), args[1]);
983
1107
  return true;