@floless/app 0.174.0 → 0.175.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/autostart.mjs +117 -10
- package/dist/floless-server.cjs +2 -2
- package/dist/pdf-engine/floless_pdf/__init__.py +53 -0
- package/dist/pdf-engine/floless_pdf/backend_pdfium.py +823 -0
- package/dist/pdf-engine/floless_pdf/backend_pymupdf.py +245 -0
- package/dist/pdf-engine/floless_pdf/geometry.py +115 -0
- package/dist/pdf-engine/floless_pdf/images.py +75 -0
- package/dist/pdf-engine/floless_pdf/pages.py +136 -0
- package/dist/pdf-engine/floless_pdf/textrules.py +200 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -1
- package/dist/skills/floless-app-approval/SKILL.md +28 -3
- package/dist/skills/floless-app-knowledge/SKILL.md +3 -2
- package/dist/skills/floless-app-sketches/SKILL.md +71 -0
- package/dist/skills/floless-app-sketches/references/steel-plate.md +15 -0
- package/dist/skills/floless-app-steel-model/SKILL.md +14 -1
- package/dist/skills/floless-app-steel-model/references/elements.md +90 -23
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +18 -7
- package/dist/skills/floless-app-tweak-contract/SKILL.md +3 -2
- package/dist/web/agents.js +1 -1
- package/dist/web/app.css +120 -15
- package/dist/web/app.js +89 -38
- package/dist/web/aware-hold.js +10 -0
- package/dist/web/aware.js +405 -51
- package/dist/web/boot-watchdog.js +249 -0
- package/dist/web/card-details.js +88 -0
- package/dist/web/chat.css +29 -0
- package/dist/web/chat.js +430 -128
- package/dist/web/commands-connection-design.js +23 -0
- package/dist/web/commands-revit.js +3 -0
- package/dist/web/commands-shell.js +226 -10
- package/dist/web/commands-steel.js +95 -5
- package/dist/web/commands-tekla-parser.js +21 -1
- package/dist/web/connection-design-editor.html +71 -0
- package/dist/web/connection-design-editor.js +794 -61
- package/dist/web/connection-design-handles.js +9 -3
- package/dist/web/element-approval.js +74 -0
- package/dist/web/element-context.js +76 -6
- package/dist/web/element-geometry.js +8 -2
- package/dist/web/element-holds.js +68 -5
- package/dist/web/element-type-actions.js +22 -3
- package/dist/web/element-types.js +12 -5
- package/dist/web/element-words.js +15 -11
- package/dist/web/grid-place.js +51 -0
- package/dist/web/guide.js +2 -0
- package/dist/web/index.html +13 -16
- package/dist/web/instructor.js +5 -2
- package/dist/web/missed-routines.js +6 -1
- package/dist/web/model-change-findings.js +147 -32
- package/dist/web/model-change-review.js +435 -32
- package/dist/web/model-clash-check.css +100 -0
- package/dist/web/model-clash-check.js +681 -0
- package/dist/web/model-clip-box.js +204 -0
- package/dist/web/model-clip-list.js +153 -3
- package/dist/web/model-clip-session.js +3 -3
- package/dist/web/model-clip-three-overlay.js +135 -25
- package/dist/web/model-editor.css +2 -0
- package/dist/web/model-elements.js +273 -18
- package/dist/web/model-fit-checks.js +354 -0
- package/dist/web/model-spatial-panel.js +9 -3
- package/dist/web/model-spatial-tools.js +12 -3
- package/dist/web/model-tekla-selection.js +74 -0
- package/dist/web/model-view-query.js +70 -14
- package/dist/web/model-viewport-revit-adapter.js +8 -7
- package/dist/web/model-viewport-toolbar.js +8 -4
- package/dist/web/pages.js +78 -1
- package/dist/web/project-history.js +31 -1
- package/dist/web/revit-editor.css +34 -1
- package/dist/web/revit-editor.js +176 -55
- package/dist/web/run-history.js +8 -0
- package/dist/web/sketch-editor.js +141 -2
- package/dist/web/sketches.js +192 -6
- package/dist/web/start-place.js +46 -0
- package/dist/web/steel-3d-core.js +70 -0
- package/dist/web/steel-3d-view.js +288 -47
- package/dist/web/steel-change-review.css +29 -0
- package/dist/web/steel-custom-connection.js +6 -0
- package/dist/web/steel-editor.html +532 -33
- package/dist/web/steel-filter.html +8 -3
- package/dist/web/steel-model-checks.css +76 -0
- package/dist/web/steel-model-commands.js +1 -1
- package/dist/web/steel-model-v2-commands.js +17 -0
- package/dist/web/steel-view-generation.js +6 -2
- package/dist/web/teams.js +259 -19
- package/dist/web/tekla-editor.html +1 -0
- package/dist/web/terminal-requests.js +6 -0
- package/dist/web/vendor/connection-engine.js +890 -89
- package/dist/web/workspaces.js +630 -48
- package/package.json +4 -1
- package/preferences-file.mjs +27 -0
|
@@ -53,14 +53,17 @@ const fmtLen = (mm, env) => (traitsOf(env).unitSystem === 'imperial' ? `${fmtMm(
|
|
|
53
53
|
const S = {
|
|
54
54
|
read: null, etag: null, loading: true, loadError: '', busy: '', choosing: false, confirmAgain: false,
|
|
55
55
|
note: null, // { role, typed, nearest } after a section the catalogue lacks; { text } for any other asked question
|
|
56
|
-
open: { facts: true, members: true, design: false },
|
|
56
|
+
open: { facts: true, params: true, dims: false, members: true, design: false },
|
|
57
57
|
currentOnly: false, engine: null, engineError: '', sync: null, catalogue: {}, view: false, drawn: '',
|
|
58
58
|
handles: null, preview: null, previewKey: 0,
|
|
59
59
|
// Slice 2c: the conflict cards. `reveal` is the one card whose note or question is open ({ key, kind: 'proceed' | 'ask' });
|
|
60
60
|
// `notes` keeps what the person typed per card (kept through a failed save); `fixes` the engine's Fix-it answer per card;
|
|
61
61
|
// `msg` a sentence on a card after an action; `filed` the RFI a card filed; `kept` a failed build kept as it is.
|
|
62
|
-
cards: { reveal: null, notes: {}, fixes: {}, msg: {}, filed: {}, kept: false, questions: null, questionsError: '', busy: '', makeRoom: {} },
|
|
62
|
+
cards: { reveal: null, notes: {}, fixes: {}, msg: {}, filed: {}, kept: false, questions: null, questionsError: '', busy: '', makeRoom: {}, moved: {} },
|
|
63
63
|
earlier: null,
|
|
64
|
+
// Slice 2d: the per-session undo and redo lists (each entry the ops that undo an edit, and what it was), the open rule menu,
|
|
65
|
+
// a sentence on a panel row after a refused value, and the Add a dimension form.
|
|
66
|
+
undo: [], redo: [], undoNote: '', sending: false, epoch: 0, reloadAfterQueue: false, aiUndoAsk: null, menu: null, paramMsg: null, panelMsg: '', dimForm: { from: '', to: '', drives: '', msg: '' },
|
|
64
67
|
};
|
|
65
68
|
window.__cd = { state: S };
|
|
66
69
|
|
|
@@ -203,6 +206,8 @@ function ensureHandles() {
|
|
|
203
206
|
onIdle: () => { if (S.handlesPending) { S.handlesPending = false; drawHandles(S.read); } },
|
|
204
207
|
onSolve: (req) => solveOnServer(req),
|
|
205
208
|
onCommit: (edit) => commitEdit(edit),
|
|
209
|
+
// Slice 2d: right-click or Shift+F10 on a dimension opens the rule menu of the param it moves.
|
|
210
|
+
onMenu: (h, el) => openMenu(h.drives, el, 'canvas'),
|
|
206
211
|
});
|
|
207
212
|
return S.handles;
|
|
208
213
|
}
|
|
@@ -229,25 +234,53 @@ async function solveOnServer({ handleId, target }) {
|
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
/** Save a dragged value: one `set-param`, with the identity of this page's full expansion so the server can compare (spec section 3). */
|
|
232
|
-
|
|
237
|
+
function commitEdit(edit) {
|
|
238
|
+
// In turn with the panel's edits (sendOps), so a drag and a typed value never race each other for the same version. A drag is
|
|
239
|
+
// never dropped as stale: it already re-applies itself to a newer design (below), as it did before the queue.
|
|
240
|
+
return inTurn(() => commitEditOnce(edit), { droppable: false });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The identity of this page's full expansion of the design it holds NOW with `param` set to `value`. Worked out when the save runs
|
|
245
|
+
* at the head of the queue, never when the drag or Fix-it ended: an edit that went in ahead of it changed the design, and an
|
|
246
|
+
* identity from before that edit would only raise a false mismatch on the server. None when the page cannot expand it itself.
|
|
247
|
+
*/
|
|
248
|
+
function identityNow(param, value) {
|
|
249
|
+
const E = S.engine, L = S.read?.local;
|
|
250
|
+
// A page out of step with the server (its drags are checked there) has no expansion of its own worth comparing.
|
|
251
|
+
if (!E || !L || !S.sync?.ok || typeof E.withParamValue !== 'function' || typeof param !== 'string') return undefined;
|
|
252
|
+
try {
|
|
253
|
+
const out = E.expandDraft({ ...L, draft: E.withParamValue(L.draft, param, value) });
|
|
254
|
+
return out.result ? out.result.identity : undefined;
|
|
255
|
+
} catch (error) { console.warn('[connection-design] the page could not expand the edit itself; the server checks it alone', error); return undefined; }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function commitEditOnce({ param, value, identity: offered, handleId }, retried = false) {
|
|
233
259
|
if (!S.read?.exists) return { ok: false, message: 'There is no design to change yet. Choose a starting point first.' };
|
|
260
|
+
// A caller that had an identity to offer gets one worked out now, on the design this save goes out against (S.etag below).
|
|
261
|
+
const identity = offered && !retried ? identityNow(param, value) : undefined;
|
|
262
|
+
const epoch = S.epoch;
|
|
234
263
|
const r = await call(`${base}/edits${VIEW}`, { method: 'POST', body: { ops: [{ op: 'set-param', param, value }], ...(identity ? { identity } : {}) }, ifMatch: S.etag });
|
|
235
264
|
S.preview = null; S.previewActive = false; S.previewKey++;
|
|
236
265
|
if (r.status === 200 && r.body.ok) {
|
|
266
|
+
// The drag's value joins the undo list like any other edit (slice 2d).
|
|
267
|
+
if (r.body.inverse) { S.undo.push({ ops: r.body.inverse, label: r.body.summaries?.[0] || `${param} changed`, epoch }); S.redo = []; }
|
|
237
268
|
adopt(r.body); S.sync = checkEngine(S.read); S.note = null; S.drawn = '';
|
|
238
269
|
announce(`${r.body.summaries?.[0] || 'Changed'}. ${S.read.design.label.text}`);
|
|
239
270
|
paint();
|
|
240
271
|
return { ok: true, handleId };
|
|
241
272
|
}
|
|
242
273
|
if ((r.status === 412 || r.status === 428) && !retried) {
|
|
243
|
-
await load({ quiet: true });
|
|
274
|
+
await load({ quiet: true, now: true });
|
|
275
|
+
// Someone else's change is underneath now, so the earlier undo steps would lay over it: the list starts again from here.
|
|
276
|
+
newEpoch('The design changed elsewhere, so the undo list starts again from here.');
|
|
244
277
|
// The identity was worked out on the design as it was; on the newer one it would only raise a false mismatch, so it is left off.
|
|
245
278
|
announce('The design changed while you were dragging. Your value was applied to the newer version.');
|
|
246
|
-
return
|
|
279
|
+
return commitEditOnce({ param, value, handleId }, true);
|
|
247
280
|
}
|
|
248
281
|
S.note = { text: r.body.userMessage || r.body.error || 'The change could not be saved.' };
|
|
249
282
|
announce(S.note.text);
|
|
250
|
-
await load({ quiet: true });
|
|
283
|
+
await load({ quiet: true, now: true });
|
|
251
284
|
return { ok: false, message: `${S.note.text} The dimension is back at its saved value.` };
|
|
252
285
|
}
|
|
253
286
|
|
|
@@ -431,10 +464,13 @@ function renderInspect() {
|
|
|
431
464
|
if (S.open.decide === undefined) S.open.decide = true;
|
|
432
465
|
host.innerHTML = (conflicts.length ? section('decide', 'Needs your decision', asking ? String(asking) : '', decideHtml(read)) : '')
|
|
433
466
|
+ section('facts', 'Fit evidence', d.state === 'built' ? `${d.facts.length} check${d.facts.length === 1 ? '' : 's'}${fails ? `, ${fails} missed` : ''}` : '', factsHtml(read))
|
|
467
|
+
+ (d.panel ? section('params', 'Parameters', `${panelRows(read).length} value${panelRows(read).length === 1 ? '' : 's'}`, paramsHtml(read)) : '')
|
|
468
|
+
+ (d.panel ? section('dims', 'Dimensions', String((d.panel.dimensions || []).length), dimsHtml(read)) : '')
|
|
434
469
|
+ section('members', 'Members', `${d.rig.members.length} test member${d.rig.members.length === 1 ? '' : 's'}`, membersHtml(read))
|
|
435
470
|
+ section('design', 'Design', '', designHtml(read));
|
|
436
471
|
for (const h of host.querySelectorAll('.isec h2 button')) h.id = `sec-${h.dataset.toggle}-h`;
|
|
437
472
|
wireInspect();
|
|
473
|
+
wirePanel(host);
|
|
438
474
|
wireCards();
|
|
439
475
|
computeFixes(read);
|
|
440
476
|
}
|
|
@@ -563,6 +599,14 @@ function makeRoomHtml(key, offer) {
|
|
|
563
599
|
+ `<button type="button" data-act="cancel" data-key="${esc(key)}" data-command-id="connection-design.card-cancel">Cancel</button></div></div>`;
|
|
564
600
|
}
|
|
565
601
|
|
|
602
|
+
/** What changed since the person looked at a card whose decision met a newer design: the record's entries after the one they saw. */
|
|
603
|
+
function movedHtml(read, key) {
|
|
604
|
+
const m = S.cards.moved[key];
|
|
605
|
+
if (!m) return '';
|
|
606
|
+
const since = (read.design.history || []).filter((h) => h.rev > m.seenRev).map((h) => h.summary);
|
|
607
|
+
return since.length ? `<p class="note" data-moved="${esc(key)}">Since you looked: ${since.map(esc).join('; ')}.</p>` : '';
|
|
608
|
+
}
|
|
609
|
+
|
|
566
610
|
function revealHtml(read, c, key) {
|
|
567
611
|
const ui = S.cards, r = ui.reveal;
|
|
568
612
|
if (!r || r.key !== key) return '';
|
|
@@ -571,7 +615,8 @@ function revealHtml(read, c, key) {
|
|
|
571
615
|
return `<div class="reveal"><label for="note-${esc(key)}">What are you assuming, and who accepted it?</label>`
|
|
572
616
|
+ `<textarea id="note-${esc(key)}" data-note="${esc(key)}" rows="3" maxlength="1000" aria-describedby="note-${esc(key)}-hint" data-command-id="connection-design.proceed#${esc(key)}" data-command-instance-label="the note">${esc(note)}</textarea>`
|
|
573
617
|
+ `<p class="note" id="note-${esc(key)}-hint">This is written into the design’s record, and the label says the rule is missed as your assumption.<span class="count" data-count="${esc(key)}"${note.length >= 800 ? '' : ' hidden'}> ${note.length} / 1000</span></p>`
|
|
574
|
-
+ (
|
|
618
|
+
+ movedHtml(read, key)
|
|
619
|
+
+ (ui.makeRoom[key] && ui.makeRoom[key].etag === S.etag ? makeRoomHtml(key, ui.makeRoom[key]) : `<div class="row"><button type="button" class="primary" data-act="record" data-key="${esc(key)}" data-command-id="connection-design.proceed-record"${ui.busy === `record:${key}` ? ' aria-busy="true"' : ''}>${ui.moved[key] ? 'Record it on the design as it is now' : 'Record my assumption'}</button>`
|
|
575
620
|
+ `<button type="button" data-act="cancel" data-key="${esc(key)}" data-command-id="connection-design.card-cancel">Cancel</button></div>`) + '</div>';
|
|
576
621
|
}
|
|
577
622
|
// Ask the engineer: FloLess's own words, then File the RFI.
|
|
@@ -591,8 +636,24 @@ function revealHtml(read, c, key) {
|
|
|
591
636
|
}
|
|
592
637
|
|
|
593
638
|
/** The Fix-it value for each fact card, from the engine in this page (the same `fix` the solve route answers for chat). */
|
|
594
|
-
|
|
639
|
+
/** The value that makes one conflict's dimension meet its rule, on the design `read` (the page's engine, else the server's). */
|
|
640
|
+
async function workOutFix(read, c) {
|
|
595
641
|
const E = S.engine;
|
|
642
|
+
let fix = null, tried = false;
|
|
643
|
+
try {
|
|
644
|
+
if (E && S.sync?.ok) {
|
|
645
|
+
const made = E.createDragSession(read.local, c.handleId, read.displayUnits || 'ft-in');
|
|
646
|
+
if (made.ok && made.plan.write) { fix = made.session.fix(made.plan.write.value, c.factId); tried = true; }
|
|
647
|
+
} else {
|
|
648
|
+
// This page cannot use its own engine: the server works the same value out (the solve route's fix).
|
|
649
|
+
const r = await call(`${base}/solve`, { method: 'POST', body: { handleId: c.handleId, fix: true, factId: c.factId, units: read.displayUnits } });
|
|
650
|
+
if (r.status === 200 && r.body.ok && r.body.draggable) { fix = r.body.fix || null; tried = true; }
|
|
651
|
+
}
|
|
652
|
+
} catch (error) { console.error('[connection-design] Fix it could not be worked out', error); }
|
|
653
|
+
return { fix, tried };
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function computeFixes(read) {
|
|
596
657
|
for (const c of read.design.conflicts || []) {
|
|
597
658
|
if (c.kind !== 'fact' || !c.handleId) continue;
|
|
598
659
|
const key = cardKey(c);
|
|
@@ -601,17 +662,7 @@ function computeFixes(read) {
|
|
|
601
662
|
S.cards.fixes[key] = { sig, state: 'working' };
|
|
602
663
|
setTimeout(async () => {
|
|
603
664
|
if (S.cards.fixes[key]?.sig !== sig) return;
|
|
604
|
-
|
|
605
|
-
try {
|
|
606
|
-
if (E && S.sync?.ok) {
|
|
607
|
-
const made = E.createDragSession(read.local, c.handleId, read.displayUnits || 'ft-in');
|
|
608
|
-
if (made.ok && made.plan.write) { fix = made.session.fix(made.plan.write.value, c.factId); tried = true; }
|
|
609
|
-
} else {
|
|
610
|
-
// This page cannot use its own engine: the server works the same value out (the solve route's fix).
|
|
611
|
-
const r = await call(`${base}/solve`, { method: 'POST', body: { handleId: c.handleId, fix: true, factId: c.factId, units: read.displayUnits } });
|
|
612
|
-
if (r.status === 200 && r.body.ok && r.body.draggable) { fix = r.body.fix || null; tried = true; }
|
|
613
|
-
}
|
|
614
|
-
} catch (error) { console.error('[connection-design] Fix it could not be worked out', error); }
|
|
665
|
+
const { fix, tried } = await workOutFix(read, c);
|
|
615
666
|
if (S.cards.fixes[key]?.sig !== sig) return;
|
|
616
667
|
// Nothing tried is not "nothing passes": it says so. The signature stays, so the repaint below does not ask again;
|
|
617
668
|
// the next read (a new etag) works it out afresh.
|
|
@@ -646,29 +697,48 @@ async function loadQuestions() {
|
|
|
646
697
|
}
|
|
647
698
|
|
|
648
699
|
async function doFix(key) {
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
if (!c || !fix || fix.state !== 'done') return;
|
|
700
|
+
const shown = S.cards.fixes[key];
|
|
701
|
+
if (!shown || shown.state !== 'done') return;
|
|
652
702
|
S.cards.busy = `fix:${key}`;
|
|
653
|
-
|
|
703
|
+
// The value is the one that fixes the conflict on the design as it is when the change runs: worked out again if a change ahead
|
|
704
|
+
// of it landed first (the card showed the value for the design as it was then).
|
|
705
|
+
let applied = null;
|
|
706
|
+
const res = await inTurn(async () => {
|
|
707
|
+
const c = (S.read.design.conflicts || []).find((x) => cardKey(x) === key);
|
|
708
|
+
if (!c || !c.handleId) return { ok: false, message: 'That rule is met on the design as it is now, so there is nothing to fix.' };
|
|
709
|
+
let fix = shown.fix;
|
|
710
|
+
if (!shown.sig.startsWith(`${S.etag}|`)) {
|
|
711
|
+
fix = (await workOutFix(S.read, c)).fix;
|
|
712
|
+
if (!fix) return { ok: false, message: 'On the design as it is now, no value of this dimension meets the rule. Nothing was changed.' };
|
|
713
|
+
}
|
|
714
|
+
applied = fix;
|
|
715
|
+
return commitEditOnce({ param: fix.param, value: fix.x, identity: fix.identity, handleId: c.handleId });
|
|
716
|
+
});
|
|
654
717
|
S.cards.busy = '';
|
|
655
718
|
if (!res.ok) { S.cards.msg[key] = res.message; renderInspect(); focusIn(key, '[data-act="fix"]'); return; }
|
|
656
|
-
afterChange(`${
|
|
719
|
+
afterChange(`${applied.param} set to ${lenIn(applied.x, S.read.displayUnits)}. ${S.read.design.label.text}`);
|
|
657
720
|
}
|
|
658
721
|
|
|
659
722
|
async function doRestore(from, identity, key) {
|
|
660
723
|
S.cards.busy = `fix:${key}`;
|
|
661
|
-
const r = await call(`${base}/edits${VIEW}`, { method: 'POST', body: { ops: [{ op: 'restore', from, identity }] }, ifMatch: S.etag })
|
|
724
|
+
const r = await queuedCall(() => call(`${base}/edits${VIEW}`, { method: 'POST', body: { ops: [{ op: 'restore', from, identity }] }, ifMatch: S.etag }), {
|
|
725
|
+
answer: async (r) => {
|
|
726
|
+
if (r.status === 200 && r.body.ok) {
|
|
727
|
+
// A kept version put back is not undone by ordinary edits: the undo list starts again (History keeps every version).
|
|
728
|
+
newEpoch('Going back to a kept version cannot be undone here. History keeps every version.');
|
|
729
|
+
adopt(r.body); S.sync = checkEngine(S.read); S.drawn = ''; S.currentOnly = false; S.cards.kept = false;
|
|
730
|
+
} else if (r.status === 412 || r.status === 428 || r.body.code === 'restore-moved') await reloadInTurn();
|
|
731
|
+
return r;
|
|
732
|
+
},
|
|
733
|
+
});
|
|
662
734
|
S.cards.busy = '';
|
|
663
735
|
if (r.status === 200 && r.body.ok) {
|
|
664
|
-
adopt(r.body); S.sync = checkEngine(S.read); S.drawn = ''; S.currentOnly = false; S.cards.kept = false;
|
|
665
736
|
paint();
|
|
666
737
|
afterChange(`${r.body.summaries?.[0] || 'Put back'}. ${S.read.design.label.text}`);
|
|
667
738
|
return;
|
|
668
739
|
}
|
|
669
|
-
if (r.status === 412 || r.status === 428)
|
|
740
|
+
if (r.status === 412 || r.status === 428) S.cards.msg[key] = 'Someone else changed this design. Here it is as it is now; choose again.';
|
|
670
741
|
else S.cards.msg[key] = r.body.userMessage || r.body.error || 'That could not be put back.';
|
|
671
|
-
if (r.body.code === 'restore-moved') await load({ quiet: true });
|
|
672
742
|
renderInspect(); focusIn(key, '[data-act="restore"]');
|
|
673
743
|
}
|
|
674
744
|
|
|
@@ -691,11 +761,23 @@ async function doRecord(key, makeRoom) {
|
|
|
691
761
|
return;
|
|
692
762
|
}
|
|
693
763
|
S.cards.busy = makeRoom ? `room:${key}:${makeRoom}` : `record:${key}`; renderInspect();
|
|
694
|
-
|
|
764
|
+
// A decision accepts the design the person is looking at, so it carries THAT identity (the server answers "the design moved"
|
|
765
|
+
// if a change ahead of it altered what they accepted); only the version tag is read when it runs.
|
|
766
|
+
const seen = S.read.design.identity;
|
|
767
|
+
const seenRev = S.read.design.history?.at(-1)?.rev ?? 0;
|
|
768
|
+
let roomEtag = null;
|
|
769
|
+
const r = await queuedCall(() => call(`${base}/decisions${VIEW}`, { method: 'POST', body: { factId: key, note, identity: seen, ...(makeRoom ? { makeRoom } : {}) }, ifMatch: S.etag }), {
|
|
770
|
+
droppable: false,
|
|
771
|
+
answer: async (r) => {
|
|
772
|
+
if (r.status === 200 && r.body.ok) { adopt(r.body); S.sync = checkEngine(S.read); S.drawn = ''; S.earlier = null; }
|
|
773
|
+
else if (r.body.code === 'decisions-full' && r.body.makeRoom) roomEtag = S.etag; // the design the offer was worked out on
|
|
774
|
+
else if (r.status === 412 || r.status === 428 || r.body.code === 'design-moved' || r.body.code === 'nothing-to-accept') await reloadInTurn();
|
|
775
|
+
return r;
|
|
776
|
+
},
|
|
777
|
+
});
|
|
695
778
|
S.cards.busy = '';
|
|
696
779
|
if (r.status === 200 && r.body.ok) {
|
|
697
|
-
|
|
698
|
-
S.cards.reveal = null; delete S.cards.notes[key]; delete S.cards.msg[key]; delete S.cards.makeRoom[key];
|
|
780
|
+
S.cards.reveal = null; delete S.cards.notes[key]; delete S.cards.msg[key]; delete S.cards.makeRoom[key]; delete S.cards.moved[key];
|
|
699
781
|
paint();
|
|
700
782
|
const room = r.body.madeRoom;
|
|
701
783
|
const made = room ? (room.choice === 'new-version' ? `Started a new version of the decisions; ${room.archived} earlier ones are kept in the record. ` : `Folded ${room.archived} earlier decisions into one entry; they are kept in the record. `) : '';
|
|
@@ -706,17 +788,19 @@ async function doRecord(key, makeRoom) {
|
|
|
706
788
|
// The list is full: the card asks how to make room, with the note kept (plan addendum A). Never retried by itself.
|
|
707
789
|
if (r.body.code === 'decisions-full' && r.body.makeRoom) {
|
|
708
790
|
// Bound to the design it was worked out on: if the design changes first, the offer goes and Record asks again.
|
|
709
|
-
S.cards.makeRoom[key] = { ...r.body.makeRoom, etag:
|
|
791
|
+
S.cards.makeRoom[key] = { ...r.body.makeRoom, etag: roomEtag }; delete S.cards.msg[key];
|
|
710
792
|
renderInspect(); cardEl(key)?.querySelector('[data-act="make-room"]')?.focus();
|
|
711
793
|
return;
|
|
712
794
|
}
|
|
713
795
|
delete S.cards.makeRoom[key];
|
|
714
|
-
// The note stays; the card says what happened and the person chooses on what is there now.
|
|
796
|
+
// The note stays; the card says what happened and the person chooses on what is there now (read again inside its turn, above).
|
|
715
797
|
if (r.status === 412 || r.status === 428 || r.body.code === 'design-moved') {
|
|
716
|
-
|
|
717
|
-
|
|
798
|
+
S.cards.msg[key] = r.body.code === 'design-moved' ? `${r.body.userMessage || 'The design changed while you were deciding.'} Nothing was recorded; your note is still here.` :'Someone else changed this design. Here it is as it is now; your note is still here.';
|
|
799
|
+
// Nothing was recorded. The card lists what changed since the person looked and offers, in one step, to record the same note on
|
|
800
|
+
// the design as it is now (owner ruling 2026-11-23); recording it is still the person's click.
|
|
801
|
+
if (r.body.code === 'design-moved') S.cards.moved[key] = { seenRev };
|
|
718
802
|
} else if (r.body.code === 'nothing-to-accept') {
|
|
719
|
-
S.cards.reveal = null;
|
|
803
|
+
S.cards.reveal = null;
|
|
720
804
|
S.cards.msg[key] = r.body.userMessage || 'It meets the rule now, so there is nothing to accept.';
|
|
721
805
|
} else S.cards.msg[key] = `${r.body.userMessage || r.body.error || 'That could not be saved.'} Your note is still here.`;
|
|
722
806
|
renderInspect(); $(`note-${key}`)?.focus();
|
|
@@ -784,7 +868,7 @@ function wireCards() {
|
|
|
784
868
|
if (S.cards.reveal) { await loadQuestions(); renderInspect(); cardEl(key)?.querySelector('.question, [data-act="file"]')?.focus(); }
|
|
785
869
|
return;
|
|
786
870
|
}
|
|
787
|
-
if (act === 'cancel') { const kind = S.cards.reveal?.kind; S.cards.reveal = null; delete S.cards.msg[key]; delete S.cards.makeRoom[key]; renderInspect(); focusIn(key, `[data-act="${kind}"]`); return; }
|
|
871
|
+
if (act === 'cancel') { const kind = S.cards.reveal?.kind; S.cards.reveal = null; delete S.cards.msg[key]; delete S.cards.makeRoom[key]; delete S.cards.moved[key]; renderInspect(); focusIn(key, `[data-act="${kind}"]`); return; }
|
|
788
872
|
if (act === 'record') return doRecord(key);
|
|
789
873
|
if (act === 'make-room') return doRecord(key, b.dataset.choice);
|
|
790
874
|
if (act === 'file') return doFile(key, b.dataset.check, b.dataset.again === '1');
|
|
@@ -805,6 +889,580 @@ function wireCards() {
|
|
|
805
889
|
}
|
|
806
890
|
}
|
|
807
891
|
|
|
892
|
+
// ── the parameter panel, the rule menu, the dimensions and undo (slice 2d, spec section 7) ─────────
|
|
893
|
+
//
|
|
894
|
+
// Everything below draws what the server's panel says (read.design.panel): the groups, each param's state, value and rule in words,
|
|
895
|
+
// and each rule-menu choice already worked out into the edit ops the edits route takes. The page sends those ops as they are; the
|
|
896
|
+
// only rule text it composes is what a person types into "Write the rule", which the same checker in the bundled engine reads live.
|
|
897
|
+
|
|
898
|
+
const CHIP_WORDS = { pinned: 'fixed', derived: 'follows a rule', conflict: 'breaks a rule', assumed: 'your assumption' };
|
|
899
|
+
const CHIP_GLYPH = {
|
|
900
|
+
pinned: '<path d="M8 2v6M5 8h6M8 8v6"/>', derived: '<path d="M4.5 6.5h7M4.5 9.5h7"/>',
|
|
901
|
+
conflict: '<path d="M8 3v6"/><path d="M8 12v.1"/>', assumed: '<path d="M5 14V2.5h7l-1.6 2.6L12 7.7H5"/>',
|
|
902
|
+
};
|
|
903
|
+
const isLenKind = (p) => p.kind === 'length';
|
|
904
|
+
const unitsNow = () => S.read?.displayUnits || 'ft-in';
|
|
905
|
+
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
906
|
+
/** A number in the field the way the person reads it: inches for a feet-and-inches project, else millimetres; a count whole. */
|
|
907
|
+
const fieldValue = (p, mm) => (mm == null ? '' : p.kind === 'count' ? String(Math.round(mm)) : isLenKind(p) && unitsNow() === 'ft-in' ? String(r3(mm / IN_TO_MM)) : String(r3(mm)));
|
|
908
|
+
const valueText = (p, mm) => {
|
|
909
|
+
if (mm == null) return 'not worked out (the design does not build)';
|
|
910
|
+
if (p.kind === 'count') return `${Math.round(mm)}`;
|
|
911
|
+
if (!isLenKind(p)) return String(r3(mm));
|
|
912
|
+
return unitsNow() === 'ft-in' ? `${r3(mm / IN_TO_MM)} in (${fmtMm(mm)})` : fmtMm(mm);
|
|
913
|
+
};
|
|
914
|
+
const unitText = (p) => (p.kind === 'count' ? 'bolts' : !isLenKind(p) ? '' : unitsNow() === 'ft-in' ? 'in' : 'mm');
|
|
915
|
+
/** The snap grid a typed length lands on (spec section 4.5): 1/16 in for feet and inches, 1 mm otherwise. */
|
|
916
|
+
const snapMm = (mm) => { const g = unitsNow() === 'ft-in' ? IN_TO_MM / 16 : 1; return Math.round(mm / g) * g; };
|
|
917
|
+
|
|
918
|
+
/** What a pinned value shows: what the engine worked out, else what is stored (a value the expansion did not reach). */
|
|
919
|
+
const shownMm = (p) => p.valueMm ?? (typeof p.value === 'number' ? p.value : typeof p.default === 'number' ? p.default : null);
|
|
920
|
+
const panelRows = (read) => (read?.design?.panel?.groups || []).flatMap((g) => g.params);
|
|
921
|
+
const rowOf = (id) => panelRows(S.read).find((p) => p.id === id) || null;
|
|
922
|
+
|
|
923
|
+
function chipHtml(p) {
|
|
924
|
+
return `<span class="pill pchip ${esc(p.chip)}">${svg(CHIP_GLYPH[p.chip] || CHIP_GLYPH.pinned)}${esc(CHIP_WORDS[p.chip] || p.chip)}</span>`;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function valueControlHtml(p) {
|
|
928
|
+
const id = `pv-${p.id}`;
|
|
929
|
+
const label = `aria-label="${esc(p.label)}"`;
|
|
930
|
+
if (p.kind === 'enum' || p.kind === 'flag') {
|
|
931
|
+
const current = p.kind === 'flag' ? ((p.value ?? p.default) === true ? 'On' : 'Off') : String(p.value ?? p.default ?? '');
|
|
932
|
+
return `<div class="combo pchoice" data-choice="${esc(p.id)}"><input type="text" id="${esc(id)}" ${label} role="combobox" aria-expanded="false" aria-controls="pl-${esc(p.id)}" aria-autocomplete="none" readonly value="${esc(current)}" data-current="${esc(current)}" data-command-id="connection-design.param-value#${esc(p.id)}" data-command-instance-label="${esc(p.label)}" /><span class="caret" aria-hidden="true"></span></div>`;
|
|
933
|
+
}
|
|
934
|
+
if (p.kind === 'text') {
|
|
935
|
+
const v = String(p.value ?? p.default ?? '');
|
|
936
|
+
return `<input type="text" class="ptext" id="${esc(id)}" ${label} maxlength="200" value="${esc(v)}" data-current="${esc(v)}" data-text="${esc(p.id)}" data-command-id="connection-design.param-value#${esc(p.id)}" data-command-instance-label="${esc(p.label)}" />`;
|
|
937
|
+
}
|
|
938
|
+
if (p.state === 'pinned') {
|
|
939
|
+
return `<span class="pnum"><input type="text" inputmode="decimal" class="pval" id="${esc(id)}" ${label} value="${esc(fieldValue(p, shownMm(p)))}" data-current="${esc(fieldValue(p, shownMm(p)))}" data-num="${esc(p.id)}" data-command-id="connection-design.param-value#${esc(p.id)}" data-command-instance-label="${esc(p.label)}" /><span class="punit">${esc(unitText(p))}${isLenKind(p) && unitsNow() === 'ft-in' && p.valueMm != null ? ` · ${esc(fmtMm(p.valueMm))}` : ''}</span></span>`;
|
|
940
|
+
}
|
|
941
|
+
return `<span class="pderived">${esc(valueText(p, p.valueMm))}</span>`;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function paramRowHtml(p) {
|
|
945
|
+
const ai = p.changed && p.changed.by === 'ai';
|
|
946
|
+
const menu = p.menu ? `<button type="button" class="pmenu" data-menu="${esc(p.id)}" aria-haspopup="menu" aria-expanded="${S.menu?.param === p.id}" aria-label="Rules for ${esc(p.label)}" data-tip="Rules for this value (right-click, or Shift+F10)" data-command-id="connection-design.rule-menu#${esc(p.id)}" data-command-instance-label="${esc(p.label)}">${svg('<circle cx="4" cy="8" r=".6"/><circle cx="8" cy="8" r=".6"/><circle cx="12" cy="8" r=".6"/>')}</button>` : '';
|
|
947
|
+
const rule = p.ruleWords ? `<div class="prule" data-tip="${esc(p.rule)}">= ${esc(p.ruleWords)}</div>` : '';
|
|
948
|
+
const tag = ai ? `<div class="pai"><span class="pill pai-tag">changed by AI</span>${S.read.design.panel.recent?.inverse ? `<button type="button" class="link" data-act="undo-ai" data-command-id="connection-design.undo-ai#${esc(p.id)}" data-command-instance-label="${esc(p.label)}">Undo the AI’s change</button>` : ''}</div>` : '';
|
|
949
|
+
return `<div class="prow${ai ? ' changed-ai' : ''}" data-param="${esc(p.id)}" tabindex="-1"><div class="pl1"><span class="plabel">${esc(p.label.charAt(0).toUpperCase() + p.label.slice(1))}</span>${chipHtml(p)}${menu}</div>`
|
|
950
|
+
+ `<div class="pl2">${valueControlHtml(p)}</div>${rule}${tag}${S.paramMsg?.param === p.id ? `<p class="note pmsg" role="alert">${esc(S.paramMsg.text)}</p>` : ''}</div>`;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function paramsHtml(read) {
|
|
954
|
+
const panel = read.design.panel;
|
|
955
|
+
if (!panel || !panel.groups.length) return '<p class="note">This connection has no values to change.</p>';
|
|
956
|
+
const ro = read.design.state === 'newer-format';
|
|
957
|
+
return (ro ? '<p class="note">Made with a newer FloLess: its values are shown, and can be changed once FloLess is updated.</p>' : '')
|
|
958
|
+
+ (S.panelMsg ? `<p class="note pmsg" role="alert" data-panel-msg>${esc(S.panelMsg)}</p>` : '')
|
|
959
|
+
+ (S.aiUndoAsk ? `<div class="card warn" role="group" aria-label="Undo the AI’s change anyway?" data-ai-undo-ask><div>The AI’s change (${esc(S.aiUndoAsk.summary)}) is no longer the latest change: a later change came after it. Undo the AI’s change anyway, on top of the newer change?</div>`
|
|
960
|
+
+ '<div class="row"><button type="button" class="primary" data-act="ai-undo-keep" data-command-id="connection-design.undo-ai-keep">Keep it</button>'
|
|
961
|
+
+ '<button type="button" data-act="ai-undo-anyway" data-command-id="connection-design.undo-ai-anyway">Undo it anyway</button></div></div>' : '')
|
|
962
|
+
+ panel.groups.map((g) => `<div class="pgroup" role="group" aria-label="${esc(g.title)}"><div class="pghead">${esc(g.title)}</div>${g.params.map(paramRowHtml).join('')}</div>`).join('');
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function dimsHtml(read) {
|
|
966
|
+
const panel = read.design.panel;
|
|
967
|
+
const rows = (panel?.dimensions || []).map((d) => {
|
|
968
|
+
const v = d.valueMm != null ? (unitsNow() === 'ft-in' ? `${r3(d.valueMm / IN_TO_MM)} in` : fmtMm(d.valueMm)) : '';
|
|
969
|
+
const what = d.to === 'fact' ? `the rule line ${d.from.replace(/^fact:/, '')}` : `${d.from} to ${d.to}`;
|
|
970
|
+
return `<li class="drow" data-dim="${esc(d.id)}"><div class="pl1"><span class="plabel">${esc(d.id)}</span>${v ? `<span class="dval">${esc(v)}</span>` : ''}<button type="button" class="link" data-remove-dim="${esc(d.id)}" data-command-id="connection-design.dimension-remove#${esc(d.id)}" data-command-instance-label="${esc(d.id)}" aria-label="Remove dimension ${esc(d.id)}">Remove</button></div>`
|
|
971
|
+
+ `<div class="note">${esc(what)}${d.drives ? `; drives ${esc(d.drives)}` : '; measures only'}</div>${d.warning ? `<div class="note dwarn">${esc(d.warning)}</div>` : ''}</li>`;
|
|
972
|
+
}).join('');
|
|
973
|
+
const f = S.dimForm;
|
|
974
|
+
const params = panelRows(read).filter((p) => p.menu).map((p) => p.id);
|
|
975
|
+
return (rows ? `<ul class="dims">${rows}</ul>` : '<p class="note">No dimensions of your own yet.</p>')
|
|
976
|
+
+ `<div class="dform" role="group" aria-label="Add a dimension"><div class="pghead">Add a dimension</div>`
|
|
977
|
+
+ `<div class="field"><label for="dimFrom">From</label><div class="combo" data-suggest="anchors"><input type="text" id="dimFrom" role="combobox" aria-expanded="false" aria-autocomplete="list" autocomplete="off" spellcheck="false" placeholder="tab.v0, bolts.bolt0, fact:…" value="${esc(f.from)}" data-dimfield="from" data-command-id="connection-design.dimension-from" /></div></div>`
|
|
978
|
+
+ `<div class="field"><label for="dimTo">To</label><div class="combo" data-suggest="anchors"><input type="text" id="dimTo" role="combobox" aria-expanded="false" aria-autocomplete="list" autocomplete="off" spellcheck="false" placeholder="tab.v3, or fact for a rule line" value="${esc(f.to)}" data-dimfield="to" data-command-id="connection-design.dimension-to" /></div></div>`
|
|
979
|
+
+ `<div class="field"><label for="dimDrives">Drives (optional)</label><div class="combo" data-suggest="params"><input type="text" id="dimDrives" role="combobox" aria-expanded="false" aria-autocomplete="list" autocomplete="off" spellcheck="false" placeholder="${esc(params.slice(0, 3).join(', '))}" value="${esc(f.drives)}" data-dimfield="drives" data-command-id="connection-design.dimension-drives" /></div></div>`
|
|
980
|
+
+ (f.msg ? `<p class="note pmsg" role="alert">${esc(f.msg)}</p>` : '')
|
|
981
|
+
+ `<div class="row-actions"><button type="button" data-act="add-dim" data-command-id="connection-design.dimension-add">Add the dimension</button></div></div>`;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** A small themed listbox under an input: the anchor and param suggestions, and the choice of an option or a switch. */
|
|
985
|
+
function wireSuggest(host, names, { free = true, onPick } = {}) {
|
|
986
|
+
const input = host.querySelector('input');
|
|
987
|
+
let list = null, items = [], active = -1;
|
|
988
|
+
const close = () => { if (list) { list.remove(); list = null; } input.setAttribute('aria-expanded', 'false'); input.removeAttribute('aria-activedescendant'); active = -1; };
|
|
989
|
+
const paint = () => {
|
|
990
|
+
if (!list) return;
|
|
991
|
+
for (const [i, li] of [...list.children].entries()) li.setAttribute('aria-selected', i === active ? 'true' : 'false');
|
|
992
|
+
const cur = list.children[active];
|
|
993
|
+
if (cur) { input.setAttribute('aria-activedescendant', cur.id); cur.scrollIntoView?.({ block: 'nearest' }); }
|
|
994
|
+
};
|
|
995
|
+
const uid = `sg-${Math.random().toString(36).slice(2, 8)}`;
|
|
996
|
+
const open = () => {
|
|
997
|
+
const q = free && input.value !== input.dataset.current ? input.value.trim().toLowerCase() : '';
|
|
998
|
+
items = (q ? names.filter((n) => n.toLowerCase().includes(q)) : names).slice(0, 60);
|
|
999
|
+
if (!list) {
|
|
1000
|
+
list = document.createElement('ul'); list.id = uid; list.setAttribute('role', 'listbox');
|
|
1001
|
+
host.appendChild(list); input.setAttribute('aria-controls', uid);
|
|
1002
|
+
list.addEventListener('pointerdown', (e) => e.preventDefault());
|
|
1003
|
+
list.addEventListener('click', (e) => { const li = e.target.closest('li[data-name]'); if (li) pick(li.dataset.name); });
|
|
1004
|
+
}
|
|
1005
|
+
list.innerHTML = items.length ? items.map((n, i) => `<li role="option" id="${uid}-${i}" data-name="${esc(n)}" aria-selected="false"${n === input.dataset.current ? ' class="current"' : ''}>${esc(n)}</li>`).join('') : '<li class="none" role="option" aria-disabled="true">Nothing by that name.</li>';
|
|
1006
|
+
input.setAttribute('aria-expanded', 'true');
|
|
1007
|
+
active = items.length ? Math.max(0, items.indexOf(input.dataset.current)) : -1;
|
|
1008
|
+
paint();
|
|
1009
|
+
};
|
|
1010
|
+
const pick = (name) => { close(); input.value = name; onPick ? onPick(name) : input.dispatchEvent(new Event('change')); };
|
|
1011
|
+
input.addEventListener('click', () => { if (!list) open(); else close(); });
|
|
1012
|
+
if (free) input.addEventListener('input', () => open());
|
|
1013
|
+
input.addEventListener('keydown', (e) => {
|
|
1014
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); if (!list) open(); else { active = Math.min(items.length - 1, active + 1); paint(); } }
|
|
1015
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); if (list) { active = Math.max(0, active - 1); paint(); } }
|
|
1016
|
+
else if (e.key === 'Enter' && list && active >= 0) { e.preventDefault(); pick(items[active]); }
|
|
1017
|
+
else if (e.key === 'Escape' && list) { e.preventDefault(); e.stopPropagation(); close(); }
|
|
1018
|
+
});
|
|
1019
|
+
input.addEventListener('blur', () => { setTimeout(close, 120); });
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// ── sending edits, and the undo list ────────────────────────────────────────────────────────────────
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Send ops through the edits route and keep the undo list (spec section 7): each answer carries the ops that undo it, so undo and
|
|
1026
|
+
* redo are ordinary edits the design's record keeps. `kind` says which list the inverse goes on.
|
|
1027
|
+
*/
|
|
1028
|
+
// Edits go out one at a time, in the order the person made them: a change made while the last one is still saving waits its turn
|
|
1029
|
+
// (each is sent against the design the previous one produced) instead of being turned away. Only when the design changed
|
|
1030
|
+
// elsewhere are the waiting ones dropped, because they were made against a design that is no longer there; the page says so.
|
|
1031
|
+
// Every queued task works out ALL its inputs when it runs, never when it was queued (owner ruling 2026-11-23, "patch all sites,
|
|
1032
|
+
// root form"): which undo entry, a template's ops, the AI change to take back, a new dimension's id, a Fix-it value, the identity
|
|
1033
|
+
// and the version tag. Only what the person typed or picked (their intent) is taken at the moment they did it.
|
|
1034
|
+
let sendChain = Promise.resolve();
|
|
1035
|
+
let sendQueued = 0;
|
|
1036
|
+
let sendGeneration = 0;
|
|
1037
|
+
/** Counts the queued changes that have started: a reload whose answer comes back after one started is older than the page. */
|
|
1038
|
+
let writesStarted = 0;
|
|
1039
|
+
function inTurn(task, { droppable = true } = {}) {
|
|
1040
|
+
const generation = sendGeneration;
|
|
1041
|
+
sendQueued++; S.sending = true; renderUndo();
|
|
1042
|
+
const run = sendChain.then(() => {
|
|
1043
|
+
if (droppable && generation !== sendGeneration) return { ok: false, stale: true, message: S.panelMsg || 'The design changed elsewhere. Make the change again if you still want it.' };
|
|
1044
|
+
writesStarted++;
|
|
1045
|
+
return task();
|
|
1046
|
+
});
|
|
1047
|
+
sendChain = run.catch(() => {}).then(() => {
|
|
1048
|
+
sendQueued--; S.sending = sendQueued > 0; renderUndo();
|
|
1049
|
+
// A reload asked for while edits were on their way waits for them: read mid-queue, the page could not tell its own
|
|
1050
|
+
// changes from someone else's.
|
|
1051
|
+
if (!S.sending && S.reloadAfterQueue) { S.reloadAfterQueue = false; load({ quiet: true }); }
|
|
1052
|
+
});
|
|
1053
|
+
return run;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* The design was replaced, restored or changed elsewhere: undo entries made on the earlier one would lay its inverses over
|
|
1058
|
+
* this one, so both lists start again, and an entry from before (one already on its way) is refused when it runs.
|
|
1059
|
+
*/
|
|
1060
|
+
function newEpoch(note) {
|
|
1061
|
+
S.epoch++;
|
|
1062
|
+
S.undo = []; S.redo = []; S.aiUndoAsk = null;
|
|
1063
|
+
S.undoNote = note;
|
|
1064
|
+
}
|
|
1065
|
+
function sendOps(ops, opts = {}) { return inTurn(() => sendOnce(ops, opts)); }
|
|
1066
|
+
/**
|
|
1067
|
+
* Any other write to this design (put back a kept version, record a decision, start again, change a member) in the same queue:
|
|
1068
|
+
* `request` builds the call when it runs, so it goes out with the version tag the changes ahead of it produced, and `answer` takes
|
|
1069
|
+
* its answer in (adopts it, starts the undo list again, reads the design again) INSIDE the same turn, so the next queued change, an
|
|
1070
|
+
* Undo or a reload never runs on the design from before it. `request` may answer without calling the server (nothing to change on
|
|
1071
|
+
* the design as it is then). One dropped because the design changed elsewhere comes back as a 412, answered in the same turn.
|
|
1072
|
+
*/
|
|
1073
|
+
function queuedCall(request, { droppable = true, answer = (r) => r } = {}) {
|
|
1074
|
+
const generation = sendGeneration;
|
|
1075
|
+
return inTurn(async () => {
|
|
1076
|
+
const r = droppable && generation !== sendGeneration ? { status: 412, body: { ok: false } } : await request();
|
|
1077
|
+
return answer(r);
|
|
1078
|
+
}, { droppable: false });
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Inside the queue: show the design as it is now, after a write found it changed elsewhere. An undo list made on the earlier
|
|
1083
|
+
* version would lay its steps over that change, so it starts again, and the page says why.
|
|
1084
|
+
*/
|
|
1085
|
+
async function reloadInTurn() {
|
|
1086
|
+
const before = S.etag;
|
|
1087
|
+
await load({ quiet: true, now: true });
|
|
1088
|
+
if (!before || S.etag === before) return;
|
|
1089
|
+
// Changes still waiting were made against the design from before, so they are dropped, as when an edit meets the same.
|
|
1090
|
+
sendGeneration++;
|
|
1091
|
+
if (S.undo.length || S.redo.length) {
|
|
1092
|
+
newEpoch('The design changed elsewhere (in the chat or another window), so undo starts again from here.');
|
|
1093
|
+
announce(S.undoNote);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Send one edit. `undoOfAi` (with no ops) takes back that earlier AI change: the server applies the undo it recorded for it, so the
|
|
1099
|
+
* record's "taking back the AI's change" is always what was applied (master ruling 2026-11-23); the page never sends ops with it.
|
|
1100
|
+
*/
|
|
1101
|
+
async function sendOnce(ops, { label, kind = 'edit', focusParam, undoOfAi } = {}) {
|
|
1102
|
+
if (!S.read?.exists) return { ok: false, message: 'There is no design to change yet. Choose a starting point first.' };
|
|
1103
|
+
const epoch = S.epoch; // the design this edit was sent to: its undo entry belongs to that one, even if the answer comes back later
|
|
1104
|
+
const r = await call(`${base}/edits${VIEW}`, { method: 'POST', body: undoOfAi ? { undoOfAi } : { ops }, ifMatch: S.etag });
|
|
1105
|
+
if (r.status === 200 && r.body.ok) {
|
|
1106
|
+
const inv = r.body.inverse;
|
|
1107
|
+
const entry = inv ? { ops: inv, label: label || (r.body.summaries || []).join('; '), epoch } : null;
|
|
1108
|
+
if (kind === 'undo') { if (entry) S.redo.push(entry); else S.redo = []; }
|
|
1109
|
+
else { if (entry) S.undo.push(entry); else S.undo = []; if (kind === 'edit') S.redo = []; }
|
|
1110
|
+
if (!inv) S.undoNote = 'That change cannot be undone here. History keeps every version.';
|
|
1111
|
+
else S.undoNote = '';
|
|
1112
|
+
adopt(r.body); S.sync = checkEngine(S.read); S.drawn = ''; S.paramMsg = null; S.panelMsg = '';
|
|
1113
|
+
paint();
|
|
1114
|
+
const what = kind === 'undo' ? `Undid: ${label}` : kind === 'redo' ? `Redid: ${label}` : (r.body.summaries || []).join('. ');
|
|
1115
|
+
announce(`${what}. ${S.read.design.label.text}`);
|
|
1116
|
+
if (focusParam) setTimeout(() => focusRow(focusParam), 0);
|
|
1117
|
+
return { ok: true, body: r.body };
|
|
1118
|
+
}
|
|
1119
|
+
if (r.status === 412 || r.status === 428) {
|
|
1120
|
+
sendGeneration++;
|
|
1121
|
+
// Someone changed the design first (the chat, another window). The change is never laid over theirs unasked: the page shows the
|
|
1122
|
+
// design as it is now and the person makes the change again if they still want it. Undo starts again from here too.
|
|
1123
|
+
await load({ quiet: true, now: true });
|
|
1124
|
+
newEpoch('The design changed elsewhere, so the undo list starts again from here.');
|
|
1125
|
+
S.panelMsg = 'The design changed while you were working (in the chat or another window). It is shown as it is now; make the change again if you still want it.';
|
|
1126
|
+
S.open.params = true;
|
|
1127
|
+
paint();
|
|
1128
|
+
announce(S.panelMsg);
|
|
1129
|
+
return { ok: false, stale: true, message: S.panelMsg };
|
|
1130
|
+
}
|
|
1131
|
+
// The server's own words for the person (userMessage), never a developer's sentence; the raw answer stays in the console.
|
|
1132
|
+
if (r.status >= 500 || !r.body.userMessage) console.warn('[connection-design] an edit was not saved', r.status, r.body);
|
|
1133
|
+
const said = typeof globalThis.personText === 'function' ? globalThis.personText(r.body) : r.body.userMessage;
|
|
1134
|
+
return { ok: false, status: r.status, message: said || 'That could not be saved. Try again.', code: r.body.code };
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function focusRow(param) {
|
|
1138
|
+
const row = [...$('inspect').querySelectorAll('[data-param]')].find((el) => el.dataset.param === param);
|
|
1139
|
+
(row?.querySelector('input, .pmenu') || row)?.focus?.();
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Undo or redo. It stays usable while a change is still saving: WHICH change it takes back is chosen when it runs, after the ones
|
|
1144
|
+
* ahead of it have landed (10 to 20, then 30 typed, then Undo, puts back 20 and takes the 30 off the list).
|
|
1145
|
+
*/
|
|
1146
|
+
function undo(kind) {
|
|
1147
|
+
const list = () => (kind === 'undo' ? S.undo : S.redo);
|
|
1148
|
+
if (!list().length && !S.sending) return Promise.resolve({ ok: false });
|
|
1149
|
+
const say = (text) => { S.undoNote = text; paint(); announce(text); return { ok: false, message: text }; };
|
|
1150
|
+
return inTurn(async () => {
|
|
1151
|
+
const l = list();
|
|
1152
|
+
const entry = l[l.length - 1];
|
|
1153
|
+
if (!entry) return say(kind === 'undo' ? 'There is nothing to undo.' : 'There is nothing to redo.');
|
|
1154
|
+
if (entry.epoch !== S.epoch) { newEpoch(''); return say('That change belongs to an earlier design, so it is not put back on this one. The undo list starts again from here.'); }
|
|
1155
|
+
l.pop();
|
|
1156
|
+
const res = await sendOnce(entry.ops, { label: entry.label, kind });
|
|
1157
|
+
if (!res.ok && res.message) { if (!res.stale) l.push(entry); say(res.message); }
|
|
1158
|
+
return res;
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
function renderUndo() {
|
|
1163
|
+
const u = $('undoBtn'), r = $('redoBtn');
|
|
1164
|
+
if (!u || !r) return;
|
|
1165
|
+
const show = !!S.read?.exists;
|
|
1166
|
+
u.hidden = r.hidden = !show;
|
|
1167
|
+
const last = S.undo[S.undo.length - 1], next = S.redo[S.redo.length - 1];
|
|
1168
|
+
// While a change is still saving, Undo stays usable: it takes back whatever is the last change once that has landed.
|
|
1169
|
+
const pending = !!S.sending;
|
|
1170
|
+
u.setAttribute('aria-disabled', last || pending ? 'false' : 'true');
|
|
1171
|
+
r.setAttribute('aria-disabled', next || pending ? 'false' : 'true');
|
|
1172
|
+
u.setAttribute('aria-label', pending ? 'Undo the last change (one is still being saved)' : last ? `Undo: ${last.label}` : 'Undo: nothing to undo');
|
|
1173
|
+
r.setAttribute('aria-label', next && !pending ? `Redo: ${next.label}` : pending ? 'Redo (a change is still being saved)' : 'Redo: nothing to redo');
|
|
1174
|
+
u.setAttribute('data-tip', pending ? 'Undo the last change, once the one being saved has landed (Ctrl+Z)' : last ? `Undo: ${last.label} (Ctrl+Z)` : S.undoNote || 'Nothing to undo yet (Ctrl+Z)');
|
|
1175
|
+
r.setAttribute('data-tip', next && !pending ? `Redo: ${next.label} (Ctrl+Y)` : pending ? 'Redo, once the change being saved has landed (Ctrl+Y)' : 'Nothing to redo (Ctrl+Y)');
|
|
1176
|
+
const ai = $('aiPill');
|
|
1177
|
+
if (ai) ai.hidden = S.read?.design?.draft?.assisted !== 'ai';
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// ── the rule menu ───────────────────────────────────────────────────────────────────────────────────
|
|
1181
|
+
|
|
1182
|
+
/** Open the rule menu for a param, beside the element that asked (its row's button, or a dimension on the canvas). */
|
|
1183
|
+
function openMenu(param, anchor, from = 'row') {
|
|
1184
|
+
const p = rowOf(param);
|
|
1185
|
+
if (!p || !p.menu) {
|
|
1186
|
+
announce(p ? `${p.label} is a choice: pick its value in the panel.` : 'This dimension has no value of its own to give a rule; change the value it follows in the panel.');
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
S.menu = { param, from, anchor, write: false, tied: false, text: p.rule || '', msg: '' };
|
|
1190
|
+
S.open.params = true;
|
|
1191
|
+
renderMenu();
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function closeMenu(refocus = true) {
|
|
1195
|
+
const m = S.menu;
|
|
1196
|
+
S.menu = null;
|
|
1197
|
+
$('ruleMenu')?.remove();
|
|
1198
|
+
for (const b of document.querySelectorAll('.pmenu[aria-expanded="true"]')) b.setAttribute('aria-expanded', 'false');
|
|
1199
|
+
if (refocus && m) {
|
|
1200
|
+
const back = m.from === 'row' ? [...document.querySelectorAll('.pmenu')].find((b) => b.dataset.menu === m.param) : m.anchor;
|
|
1201
|
+
(back && document.contains(back) ? back : $('labelbar'))?.focus?.();
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/** The Instructor command each menu item carries (set on the element after it is drawn; see renderMenu). */
|
|
1206
|
+
const RULE_COMMANDS = Object.freeze({
|
|
1207
|
+
fixed: 'connection-design.rule-fixed', follow: 'connection-design.rule-follow', equal: 'connection-design.rule-equal',
|
|
1208
|
+
fill: 'connection-design.rule-fill', tied: 'connection-design.rule-tied', write: 'connection-design.rule-write',
|
|
1209
|
+
});
|
|
1210
|
+
function menuItemsHtml(p) {
|
|
1211
|
+
const m = p.menu, ui = S.menu;
|
|
1212
|
+
const item = (act, text, { sub = '', checked, unavailable = '' } = {}) => {
|
|
1213
|
+
const role = checked === undefined ? 'menuitem' : 'menuitemcheckbox';
|
|
1214
|
+
const why = unavailable ? `<span class="msub why" id="why-${esc(act)}">${esc(unavailable)}</span>` : sub ? `<span class="msub">${esc(sub)}</span>` : '';
|
|
1215
|
+
return `<button type="button" role="${role}" class="mitem" data-mact="${esc(act)}"${checked !== undefined ? ` aria-checked="${checked}"` : ''}${unavailable ? ` aria-disabled="true" aria-describedby="why-${esc(act)}"` : ''}><span class="mcheck" aria-hidden="true">${checked ? svg('<path d="m3.5 8.4 3 3 6-6.4"/>') : ''}</span><span class="mtext">${esc(text)}${why}</span></button>`;
|
|
1216
|
+
};
|
|
1217
|
+
const named = (id) => rowOf(id)?.label || id;
|
|
1218
|
+
const tpl = (act, title, t) => (!t ? '' : t.ok ? item(act, title, { sub: `${named(t.sets).charAt(0).toUpperCase() + named(t.sets).slice(1)} follows ${t.words}${t.pins.length ? `; the ${t.pins.map(named).join(' and the ')} is fixed at its value first` : ''}.` }) : item(act, title, { unavailable: `${t.why.replace(/ Write the rule, or describe it in chat\.$/, '')} Write the rule below, or describe it in the chat.` }));
|
|
1219
|
+
let html = item('fixed', 'Fixed at this value', { checked: m.fixed.current, ...(m.fixed.current ? { sub: 'it is fixed now' } : m.fixed.ops ? {} : { unavailable: m.fixed.why || 'Its value cannot be worked out now.' }) })
|
|
1220
|
+
+ (m.followRule ? item('follow', 'Follow its rule again', { sub: m.followRule.words }) : '')
|
|
1221
|
+
+ tpl('equal', 'Equal spacing', m.equalSpacing) + tpl('fill', 'Fill the length', m.fill);
|
|
1222
|
+
html += '<div role="separator" class="msep"></div><div class="mcap" aria-hidden="true">More rules</div>';
|
|
1223
|
+
html += item('tied', 'Tied to a member property', { sub: 'the depth, flange or web of a member' });
|
|
1224
|
+
if (ui.tied) {
|
|
1225
|
+
const sizes = S.read.design.panel.sizes || [];
|
|
1226
|
+
html += `<div class="msizes" role="group" aria-label="Member sizes">${sizes.map((s) => `<button type="button" role="menuitem" class="mitem msize" data-size="${esc(s.rule)}" data-command-id="connection-design.rule-tied-size#${esc(s.rule)}" data-command-instance-label="${esc(s.words)}"><span class="mcheck" aria-hidden="true"></span><span class="mtext">${esc(s.words.charAt(0).toUpperCase() + s.words.slice(1))}<span class="msub">${esc(valueText({ kind: 'length' }, s.valueMm))}</span></span></button>`).join('') || '<p class="note">No member sizes to tie to.</p>'}</div>`;
|
|
1227
|
+
}
|
|
1228
|
+
html += item('write', 'Write the rule');
|
|
1229
|
+
if (ui.write) {
|
|
1230
|
+
html += `<div class="mwrite"><label for="ruleText">Rule for ${esc(p.label)}</label><input type="text" id="ruleText" spellcheck="false" autocomplete="off" maxlength="512" value="${esc(ui.text)}" aria-describedby="ruleCheck" data-command-id="connection-design.rule-text" />`
|
|
1231
|
+
+ `<p class="note" id="ruleCheck" aria-live="polite"></p><div class="row-actions"><button type="button" class="primary" data-mact="apply" data-command-id="connection-design.rule-apply">Apply the rule</button><button type="button" data-mact="cancel-write" data-command-id="connection-design.card-cancel">Cancel</button></div></div>`;
|
|
1232
|
+
}
|
|
1233
|
+
if (ui.msg) html += `<p class="note mmsg" role="alert">${esc(ui.msg)}</p>`;
|
|
1234
|
+
return html;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
function renderMenu() {
|
|
1238
|
+
const ui = S.menu;
|
|
1239
|
+
if (!ui) return;
|
|
1240
|
+
const p = rowOf(ui.param);
|
|
1241
|
+
if (!p || !p.menu) { closeMenu(false); return; }
|
|
1242
|
+
let el = $('ruleMenu');
|
|
1243
|
+
const focused = el && document.activeElement && el.contains(document.activeElement) ? (document.activeElement.dataset.mact || document.activeElement.id || '') : '';
|
|
1244
|
+
if (!el) { el = document.createElement('div'); el.id = 'ruleMenu'; el.setAttribute('role', 'menu'); document.body.appendChild(el); wireMenu(el); }
|
|
1245
|
+
el.setAttribute('aria-label', `Rules for ${p.label}`);
|
|
1246
|
+
el.innerHTML = `<div class="mhead">${esc(p.label.charAt(0).toUpperCase() + p.label.slice(1))}<span class="msub">${esc(p.ruleWords ? `follows ${p.ruleWords}` : `fixed at ${valueText(p, p.valueMm)}`)}</span></div>${menuItemsHtml(p)}`;
|
|
1247
|
+
for (const b of el.querySelectorAll('.mitem[data-mact]')) { const id = RULE_COMMANDS[b.dataset.mact]; if (id) b.setAttribute('data-command-id', id); }
|
|
1248
|
+
for (const b of document.querySelectorAll('.pmenu')) b.setAttribute('aria-expanded', b.dataset.menu === ui.param ? 'true' : 'false');
|
|
1249
|
+
// Beside the button (or the dimension) that asked, kept inside the window.
|
|
1250
|
+
const anchor = ui.from === 'row' ? [...document.querySelectorAll('.pmenu')].find((b) => b.dataset.menu === ui.param) : ui.anchor;
|
|
1251
|
+
const vw = globalThis.innerWidth || 1280, vh = globalThis.innerHeight || 800;
|
|
1252
|
+
const rr = anchor && anchor.getBoundingClientRect ? anchor.getBoundingClientRect() : { left: vw / 2, right: vw / 2, top: 80, bottom: 80 };
|
|
1253
|
+
const w = el.offsetWidth || 280, h = el.offsetHeight || 300;
|
|
1254
|
+
let x = rr.right - w; if (x < 8) x = Math.min(rr.left, vw - w - 8);
|
|
1255
|
+
let y = rr.bottom + 6; if (y + h > vh - 8) y = Math.max(8, rr.top - h - 6);
|
|
1256
|
+
el.style.left = `${Math.max(8, x)}px`; el.style.top = `${y}px`;
|
|
1257
|
+
const input = $('ruleText');
|
|
1258
|
+
if (input) { checkRuleText(input.value); input.addEventListener('input', () => { S.menu.text = input.value; clearTimeout(S.ruleTimer); S.ruleTimer = setTimeout(() => checkRuleText(input.value), 200); }); }
|
|
1259
|
+
if (focused === 'ruleText') input?.focus();
|
|
1260
|
+
else (el.querySelector(focused ? `[data-mact="${focused}"]` : '.mitem') || el.querySelector('.mitem'))?.focus();
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/** The live check of a rule being written: the same words the server answers with, and its value on these members when it reads. */
|
|
1264
|
+
function checkRuleText(text) {
|
|
1265
|
+
const out = $('ruleCheck');
|
|
1266
|
+
if (!out || !S.menu) return null;
|
|
1267
|
+
const E = S.engine, L = S.read.local;
|
|
1268
|
+
if (!E || !L || typeof E.ruleIssue !== 'function') { out.textContent = 'FloLess checks the rule when you apply it.'; out.className = 'note'; return null; }
|
|
1269
|
+
const issue = text.trim() ? E.ruleIssue(L.draft, S.menu.param, text) : { message: 'Write the rule, for example (rows - 1) * pitch + 2 * edge.' };
|
|
1270
|
+
if (issue) { out.textContent = issue.message; out.className = 'note rbad'; return issue; }
|
|
1271
|
+
try {
|
|
1272
|
+
const draft = { ...L.draft, params: L.draft.params.map((q) => (q.id === S.menu.param ? (({ value: _v, ...rest }) => ({ ...rest, state: 'derived', rule: text.trim() }))(q) : q)) };
|
|
1273
|
+
const r = E.expandDraft({ ...L, draft }, { mode: 'layout', trace: true });
|
|
1274
|
+
const v = r.result && r.result.ok ? r.result.trace?.values?.[S.menu.param]?.value : null;
|
|
1275
|
+
const p = rowOf(S.menu.param);
|
|
1276
|
+
out.textContent = v != null ? `Reads as ${E.describeRule(text, L.draft)}. That gives ${valueText(p, v)}.` : `Reads as ${E.describeRule(text, L.draft)}. On these members the design would not build with it; it would be saved and say why.`;
|
|
1277
|
+
out.className = v != null ? 'note rgood' : 'note rwarn';
|
|
1278
|
+
} catch (error) { console.error('[connection-design] the rule could not be tried', error); out.textContent = 'FloLess checks the rule when you apply it.'; out.className = 'note'; }
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
async function menuAct(act, el) {
|
|
1283
|
+
const ui = S.menu, p = rowOf(ui?.param);
|
|
1284
|
+
if (!ui || !p) return;
|
|
1285
|
+
if (el?.getAttribute('aria-disabled') === 'true') { el.querySelector('.why')?.classList.add('flash'); announce(el.querySelector('.why')?.textContent || 'Not available here.'); return; }
|
|
1286
|
+
const m = p.menu;
|
|
1287
|
+
// A template's ops pin values as the design stands (equal spacing fixes the plate height at its value first), so they are read
|
|
1288
|
+
// from the design when the change runs, after any change ahead of it has landed, never from the menu as it was drawn.
|
|
1289
|
+
const TEMPLATE = { fixed: 'fixed', follow: 'followRule', equal: 'equalSpacing', fill: 'fill' };
|
|
1290
|
+
const run = async (key, labelOf) => {
|
|
1291
|
+
const res = await inTurn(async () => {
|
|
1292
|
+
const item = rowOf(p.id)?.menu?.[key];
|
|
1293
|
+
if (!item || !item.ops) return { ok: false, message: item?.why || `${p.label}: that rule is not available on the design as it is now. Nothing was changed.` };
|
|
1294
|
+
return sendOnce(item.ops, { label: labelOf(item), focusParam: p.id });
|
|
1295
|
+
});
|
|
1296
|
+
if (res.ok) closeMenu(false);
|
|
1297
|
+
else if (S.menu) { S.menu.msg = res.message; renderMenu(); }
|
|
1298
|
+
return res;
|
|
1299
|
+
};
|
|
1300
|
+
if (act === 'fixed') { if (m.fixed.current) { closeMenu(); return; } return run(TEMPLATE.fixed, () => `fix ${p.label}`); }
|
|
1301
|
+
if (act === 'follow') return run(TEMPLATE.follow, () => `${p.label} follows its rule again`);
|
|
1302
|
+
if (act === 'equal') return run(TEMPLATE.equal, (item) => `equal spacing for ${item.sets}`);
|
|
1303
|
+
if (act === 'fill') return run(TEMPLATE.fill, (item) => `fill the length with ${item.sets}`);
|
|
1304
|
+
if (act === 'tied') { ui.tied = !ui.tied; ui.write = false; renderMenu(); return; }
|
|
1305
|
+
if (act === 'write') { ui.write = !ui.write; ui.tied = false; renderMenu(); if (ui.write) $('ruleText')?.focus(); return; }
|
|
1306
|
+
if (act === 'cancel-write') { ui.write = false; renderMenu(); return; }
|
|
1307
|
+
if (act === 'apply') {
|
|
1308
|
+
const text = $('ruleText')?.value ?? ui.text;
|
|
1309
|
+
const issue = checkRuleText(text);
|
|
1310
|
+
if (issue) { $('ruleText')?.focus(); announce(issue.message); return; }
|
|
1311
|
+
// The server checks it again with the same words; a rule it cannot save is answered, and nothing is saved.
|
|
1312
|
+
const res = await sendOps([{ op: 'set-rule', param: p.id, rule: text.trim() }], { label: `${p.label} follows ${text.trim()}`, focusParam: p.id });
|
|
1313
|
+
if (res.ok) closeMenu(false);
|
|
1314
|
+
else { ui.msg = res.message; renderMenu(); $('ruleText')?.focus(); }
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function wireMenu(el) {
|
|
1319
|
+
el.addEventListener('click', (e) => {
|
|
1320
|
+
const size = e.target.closest('[data-size]');
|
|
1321
|
+
if (size) { const p = rowOf(S.menu.param); sendOps([{ op: 'set-rule', param: p.id, rule: size.dataset.size }], { label: `${p.label} follows ${size.dataset.size}`, focusParam: p.id }).then((res) => { if (res.ok) closeMenu(false); else if (S.menu) { S.menu.msg = res.message; renderMenu(); } }); return; }
|
|
1322
|
+
const b = e.target.closest('[data-mact]');
|
|
1323
|
+
if (b) menuAct(b.dataset.mact, b);
|
|
1324
|
+
});
|
|
1325
|
+
el.addEventListener('keydown', (e) => {
|
|
1326
|
+
if (e.target.id === 'ruleText') {
|
|
1327
|
+
if (e.key === 'Enter') { e.preventDefault(); menuAct('apply'); }
|
|
1328
|
+
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); S.menu.write = false; renderMenu(); el.querySelector('[data-mact="write"]')?.focus(); }
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
const items = [...el.querySelectorAll('.mitem')];
|
|
1332
|
+
const i = items.indexOf(document.activeElement);
|
|
1333
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); items[(i + 1) % items.length]?.focus(); }
|
|
1334
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); items[(i - 1 + items.length) % items.length]?.focus(); }
|
|
1335
|
+
else if (e.key === 'Home') { e.preventDefault(); items[0]?.focus(); }
|
|
1336
|
+
else if (e.key === 'End') { e.preventDefault(); items[items.length - 1]?.focus(); }
|
|
1337
|
+
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeMenu(); }
|
|
1338
|
+
else if (e.key === 'Tab') { closeMenu(false); }
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
document.addEventListener('pointerdown', (e) => {
|
|
1343
|
+
if (S.menu && !e.target.closest('#ruleMenu') && !e.target.closest('.pmenu')) closeMenu(false);
|
|
1344
|
+
}, true);
|
|
1345
|
+
// Escape closes the menu wherever the focus is (a click inside it can leave the focus on the page).
|
|
1346
|
+
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && S.menu && !e.defaultPrevented) { e.preventDefault(); closeMenu(); } });
|
|
1347
|
+
|
|
1348
|
+
// ── wiring the panel ────────────────────────────────────────────────────────────────────────────────
|
|
1349
|
+
|
|
1350
|
+
async function commitNumber(input) {
|
|
1351
|
+
const p = rowOf(input.dataset.num);
|
|
1352
|
+
if (!p || input.value === input.dataset.current) return;
|
|
1353
|
+
const typed = Number(String(input.value).replace(',', '.').trim());
|
|
1354
|
+
if (!input.value.trim() || !Number.isFinite(typed)) { S.paramMsg = { param: p.id, text: 'That is not a number. Nothing was changed.' }; input.value = input.dataset.current; renderInspect(); focusRow(p.id); return; }
|
|
1355
|
+
let mm = p.kind === 'count' ? typed : isLenKind(p) && unitsNow() === 'ft-in' ? typed * IN_TO_MM : typed;
|
|
1356
|
+
if (isLenKind(p)) mm = snapMm(mm);
|
|
1357
|
+
const was = input.dataset.current;
|
|
1358
|
+
input.dataset.current = input.value; // Enter then blur is one change, not two
|
|
1359
|
+
const res = await sendOps([{ op: 'set-param', param: p.id, value: mm }], { label: `${p.label} ${valueText(p, mm)}`, focusParam: p.id });
|
|
1360
|
+
if (!res.ok) { input.dataset.current = was; S.paramMsg = { param: p.id, text: `${res.message} Nothing was changed.` }; renderInspect(); focusRow(p.id); }
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
function wirePanel(host) {
|
|
1364
|
+
for (const b of host.querySelectorAll('.pmenu')) {
|
|
1365
|
+
b.addEventListener('click', () => (S.menu?.param === b.dataset.menu ? closeMenu() : openMenu(b.dataset.menu, b)));
|
|
1366
|
+
}
|
|
1367
|
+
for (const row of host.querySelectorAll('.prow')) {
|
|
1368
|
+
row.addEventListener('contextmenu', (e) => { if (!rowOf(row.dataset.param)?.menu) return; e.preventDefault(); openMenu(row.dataset.param, row.querySelector('.pmenu')); });
|
|
1369
|
+
row.addEventListener('keydown', (e) => { if ((e.key === 'F10' && e.shiftKey) || e.key === 'ContextMenu') { e.preventDefault(); openMenu(row.dataset.param, row.querySelector('.pmenu')); } });
|
|
1370
|
+
}
|
|
1371
|
+
for (const input of host.querySelectorAll('input[data-num]')) {
|
|
1372
|
+
input.addEventListener('keydown', (e) => {
|
|
1373
|
+
if (e.key === 'Enter') { e.preventDefault(); commitNumber(input); }
|
|
1374
|
+
else if (e.key === 'Escape') { input.value = input.dataset.current; }
|
|
1375
|
+
});
|
|
1376
|
+
input.addEventListener('blur', () => { if (input.value !== input.dataset.current) commitNumber(input); });
|
|
1377
|
+
}
|
|
1378
|
+
for (const input of host.querySelectorAll('input[data-text]')) {
|
|
1379
|
+
const commit = async () => {
|
|
1380
|
+
const p = rowOf(input.dataset.text);
|
|
1381
|
+
if (!p || input.value.trim() === input.dataset.current) return;
|
|
1382
|
+
const was = input.dataset.current;
|
|
1383
|
+
input.dataset.current = input.value.trim(); // Enter then blur is one change, not two
|
|
1384
|
+
const res = await sendOps([{ op: 'set-param', param: p.id, value: input.value }], { label: `${p.label} “${input.value.trim()}”`, focusParam: p.id });
|
|
1385
|
+
if (!res.ok) { input.dataset.current = was; S.paramMsg = { param: p.id, text: `${res.message} Nothing was changed.` }; renderInspect(); focusRow(p.id); }
|
|
1386
|
+
};
|
|
1387
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); commit(); } else if (e.key === 'Escape') input.value = input.dataset.current; });
|
|
1388
|
+
input.addEventListener('blur', commit);
|
|
1389
|
+
}
|
|
1390
|
+
for (const c of host.querySelectorAll('[data-choice]')) {
|
|
1391
|
+
const p = rowOf(c.dataset.choice);
|
|
1392
|
+
if (!p) continue;
|
|
1393
|
+
const names = p.kind === 'flag' ? ['On', 'Off'] : [...(p.options || [])];
|
|
1394
|
+
wireSuggest(c, names, {
|
|
1395
|
+
free: false,
|
|
1396
|
+
onPick: (name) => {
|
|
1397
|
+
const input = c.querySelector('input');
|
|
1398
|
+
if (name === input.dataset.current) return;
|
|
1399
|
+
const was = input.dataset.current;
|
|
1400
|
+
input.dataset.current = name; // a second pick before this one saves is compared with this pick, so a quick reversal is sent too
|
|
1401
|
+
const value = p.kind === 'flag' ? name === 'On' : name;
|
|
1402
|
+
sendOps([{ op: 'set-param', param: p.id, value }], { label: `${p.label} ${name}`, focusParam: p.id }).then((res) => { if (!res.ok) { input.dataset.current = was; S.paramMsg = { param: p.id, text: `${res.message} Nothing was changed.` }; renderInspect(); } });
|
|
1403
|
+
},
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
for (const b of host.querySelectorAll('[data-act="undo-ai"]')) b.addEventListener('click', () => {
|
|
1407
|
+
// The person asked to take back THIS AI change (the one highlighted now); its undo is read when the task runs, and only if it
|
|
1408
|
+
// is still the latest change, so a change that landed ahead of it is never undone in its place.
|
|
1409
|
+
const asked = S.read.design.panel.recent;
|
|
1410
|
+
if (!asked?.inverse) return;
|
|
1411
|
+
inTurn(async () => {
|
|
1412
|
+
const now = S.read.design.panel.recent;
|
|
1413
|
+
if (!now || now.by !== 'ai' || now.rev !== asked.rev || !now.inverse) {
|
|
1414
|
+
// A later change came after it: nothing refuses, it asks (owner ruling 2026-11-23). Keep is the default; undoing anyway
|
|
1415
|
+
// has the server apply exactly that AI change's recorded undo, and the record says it went on top of the later change.
|
|
1416
|
+
S.aiUndoAsk = { rev: asked.rev, summary: asked.summary };
|
|
1417
|
+
return { ok: false, asked: true };
|
|
1418
|
+
}
|
|
1419
|
+
return sendOnce(null, { label: 'the AI’s change', kind: 'edit', undoOfAi: now.rev });
|
|
1420
|
+
}).then((res) => {
|
|
1421
|
+
if (res.asked) { renderInspect(); $('inspect').querySelector('[data-act="ai-undo-keep"]')?.focus(); announce('A later change came after the AI’s change. Keep it, or undo it anyway on top of the newer change.'); return; }
|
|
1422
|
+
if (!res.ok && !res.stale) { S.panelMsg = `${res.message} The AI’s change is still there.`; renderInspect(); announce(S.panelMsg); }
|
|
1423
|
+
});
|
|
1424
|
+
});
|
|
1425
|
+
host.querySelector('[data-act="ai-undo-keep"]')?.addEventListener('click', () => { S.aiUndoAsk = null; renderInspect(); announce('The AI’s change is kept.'); });
|
|
1426
|
+
host.querySelector('[data-act="ai-undo-anyway"]')?.addEventListener('click', () => {
|
|
1427
|
+
const ask = S.aiUndoAsk;
|
|
1428
|
+
if (!ask) return;
|
|
1429
|
+
S.aiUndoAsk = null;
|
|
1430
|
+
inTurn(() => sendOnce(null, { label: 'the AI’s change, on top of a later change', kind: 'edit', undoOfAi: ask.rev }))
|
|
1431
|
+
.then((res) => { if (!res.ok && !res.stale) { S.panelMsg = `${res.message} The AI’s change is still there.`; renderInspect(); announce(S.panelMsg); } });
|
|
1432
|
+
});
|
|
1433
|
+
// Dimensions.
|
|
1434
|
+
for (const c of host.querySelectorAll('[data-suggest]')) {
|
|
1435
|
+
const names = c.dataset.suggest === 'anchors' ? [...(S.read.design.panel.anchors || []), 'fact'] : panelRows(S.read).filter((p) => p.menu).map((p) => p.id);
|
|
1436
|
+
wireSuggest(c, names);
|
|
1437
|
+
const input = c.querySelector('input');
|
|
1438
|
+
const keep = () => { S.dimForm[input.dataset.dimfield] = input.value; };
|
|
1439
|
+
input.addEventListener('input', keep); input.addEventListener('change', keep);
|
|
1440
|
+
}
|
|
1441
|
+
for (const b of host.querySelectorAll('[data-remove-dim]')) {
|
|
1442
|
+
b.addEventListener('click', async () => {
|
|
1443
|
+
const res = await sendOps([{ op: 'remove-dimension', id: b.dataset.removeDim }], { label: `remove dimension ${b.dataset.removeDim}` });
|
|
1444
|
+
if (!res.ok && !res.stale) { S.dimForm.msg = `${res.message} Nothing was removed.`; renderInspect(); }
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
host.querySelector('[data-act="add-dim"]')?.addEventListener('click', async () => {
|
|
1448
|
+
const f = S.dimForm;
|
|
1449
|
+
const from = f.from.trim(), to = f.to.trim(), drives = f.drives.trim();
|
|
1450
|
+
if (!from || !to) { f.msg = 'Name the two points the dimension runs between, for example tab.v0 and tab.v3.'; renderInspect(); $('dimFrom')?.focus(); return; }
|
|
1451
|
+
S.dimForm = { from: '', to: '', drives: '', msg: '' }; // taken: the next dimension can be written while this one saves
|
|
1452
|
+
// The new dimension's id is the next free one on the design when it is added, so two added in quick succession never share one.
|
|
1453
|
+
const res = await inTurn(() => {
|
|
1454
|
+
const taken = new Set((S.read.design.panel.dimensions || []).map((d) => d.id));
|
|
1455
|
+
let n = taken.size + 1; while (taken.has(`d-${n}`)) n++;
|
|
1456
|
+
return sendOnce([{ op: 'add-dimension', id: `d-${n}`, from, to, ...(drives ? { drives } : {}) }], { label: `add dimension d-${n}` });
|
|
1457
|
+
});
|
|
1458
|
+
if (res.ok) { renderInspect(); return; }
|
|
1459
|
+
// Not added: the two points come back to the form (unless the next ones are already being written), with the reason.
|
|
1460
|
+
const blank = !S.dimForm.from && !S.dimForm.to && !S.dimForm.drives;
|
|
1461
|
+
S.dimForm = { ...(blank ? { from, to, drives } : S.dimForm), msg: `${res.message} Nothing was added.` };
|
|
1462
|
+
renderInspect();
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
|
|
808
1466
|
// ── the section combobox ───────────────────────────────────────────────────────────────────────────
|
|
809
1467
|
|
|
810
1468
|
async function catalogueFor(env) {
|
|
@@ -870,14 +1528,31 @@ function adopt(res) {
|
|
|
870
1528
|
S.etag = res.etag;
|
|
871
1529
|
}
|
|
872
1530
|
|
|
873
|
-
async function load({ quiet = false } = {}) {
|
|
1531
|
+
async function load({ quiet = false, now = false } = {}) {
|
|
874
1532
|
if (!PROJECT) return;
|
|
1533
|
+
// A reload while this page's own changes are on their way waits until they have landed (`now` is the queue itself asking).
|
|
1534
|
+
if (S.sending && !now) { S.reloadAfterQueue = true; return; }
|
|
1535
|
+
const before = S.etag;
|
|
1536
|
+
const started = writesStarted;
|
|
875
1537
|
if (!quiet) { S.loading = true; S.loadError = ''; paint(); }
|
|
876
1538
|
const r = await call(base + VIEW);
|
|
1539
|
+
// One of this page's own changes started while the answer was on its way: the answer may be older than what the page now holds,
|
|
1540
|
+
// so it is thrown away and the design is read again once the queue is empty (`now` reads are the queue's own, so none overlap).
|
|
1541
|
+
if (!now && writesStarted !== started) {
|
|
1542
|
+
S.loading = false;
|
|
1543
|
+
if (S.sending) S.reloadAfterQueue = true; else await load({ quiet: true });
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
877
1546
|
S.loading = false;
|
|
878
1547
|
if (r.status === 200 && r.body.ok) {
|
|
879
1548
|
S.loadError = '';
|
|
880
1549
|
if (r.body.exists) adopt(r.body); else { S.read = { exists: false, ...r.body }; S.etag = null; }
|
|
1550
|
+
if (before && S.etag !== before && !now) {
|
|
1551
|
+
// Undoing on top of someone else's change would silently overwrite it: the lists start again, and the page says why.
|
|
1552
|
+
const had = S.undo.length || S.redo.length;
|
|
1553
|
+
newEpoch(had ? 'The design changed elsewhere (in the chat or another window), so undo starts again from here.' : '');
|
|
1554
|
+
if (had) announce(S.undoNote);
|
|
1555
|
+
}
|
|
881
1556
|
S.sync = S.read.exists ? checkEngine(S.read) : null;
|
|
882
1557
|
} else {
|
|
883
1558
|
S.loadError = r.body.userMessage || r.body.error || 'The design could not be read.';
|
|
@@ -888,18 +1563,28 @@ async function load({ quiet = false } = {}) {
|
|
|
888
1563
|
|
|
889
1564
|
function paint() {
|
|
890
1565
|
$('mainArea').setAttribute('aria-busy', S.loading ? 'true' : 'false');
|
|
891
|
-
renderHeader(); renderLabel(); renderInspect(); renderEmpty(); chips(); banner(); drawCanvas();
|
|
1566
|
+
renderHeader(); renderLabel(); renderInspect(); renderEmpty(); chips(); banner(); drawCanvas(); renderUndo();
|
|
1567
|
+
if (S.menu) renderMenu();
|
|
892
1568
|
}
|
|
893
1569
|
|
|
894
1570
|
async function seed(preset, replace) {
|
|
895
1571
|
S.busy = preset; renderEmpty();
|
|
896
|
-
const r = await call(`${base}/seed${VIEW}`, { method: 'POST', body: replace ? { preset, replace: true } : { preset }, ifMatch: replace ? S.etag : undefined })
|
|
1572
|
+
const r = await queuedCall(() => call(`${base}/seed${VIEW}`, { method: 'POST', body: replace ? { preset, replace: true } : { preset }, ifMatch: replace ? S.etag : undefined }), {
|
|
1573
|
+
answer: async (r) => {
|
|
1574
|
+
if (r.status === 200 && r.body.ok) {
|
|
1575
|
+
// A different starting point is a different design: the earlier one's undo steps would lay its values over this one, so
|
|
1576
|
+
// the lists end here, before an Undo queued behind it can run.
|
|
1577
|
+
newEpoch('');
|
|
1578
|
+
adopt(r.body); S.sync = checkEngine(S.read); S.drawn = '';
|
|
1579
|
+
} else if (r.status === 412 || r.status === 428) await reloadInTurn();
|
|
1580
|
+
return r;
|
|
1581
|
+
},
|
|
1582
|
+
});
|
|
897
1583
|
S.busy = '';
|
|
898
1584
|
if (r.status === 200 && r.body.ok) {
|
|
899
|
-
|
|
1585
|
+
S.choosing = false; S.confirmAgain = false; S.note = null;
|
|
900
1586
|
announce(`Started ${PRESET_TITLE[preset] || preset}. ${S.read.design.label.text}`);
|
|
901
1587
|
} else if (r.status === 412 || r.status === 428) {
|
|
902
|
-
await load({ quiet: true });
|
|
903
1588
|
S.note = { text: 'The design changed since you last looked. It is shown as it is now; choose again if you still want to start over.' };
|
|
904
1589
|
} else {
|
|
905
1590
|
S.note = { text: r.body.userMessage || r.body.error || 'The design could not be started.' };
|
|
@@ -907,19 +1592,36 @@ async function seed(preset, replace) {
|
|
|
907
1592
|
paint();
|
|
908
1593
|
}
|
|
909
1594
|
|
|
910
|
-
|
|
1595
|
+
/** The member's section as the design holds it NOW: the "already that section" check runs when the change runs, not when it was picked. */
|
|
1596
|
+
function sectionIs(role, designation) {
|
|
1597
|
+
const rig = S.read?.design?.rig;
|
|
1598
|
+
const current = rig?.members.find((m) => m.id === rig.bindings[role]);
|
|
1599
|
+
return !!current && norm(current.profile) === norm(designation);
|
|
1600
|
+
}
|
|
1601
|
+
const NOTHING_TO_CHANGE = Object.freeze({ status: 200, body: Object.freeze({ ok: true, unchanged: true }) });
|
|
1602
|
+
|
|
1603
|
+
async function changeSection(role, designation) {
|
|
911
1604
|
if (!S.read?.exists) return;
|
|
912
|
-
const current = S.read.design.rig.members.find((m) => m.id === S.read.design.rig.bindings[role]);
|
|
913
|
-
if (current && norm(current.profile) === norm(designation)) { S.note = null; paint(); return; }
|
|
914
1605
|
S.busy = `section:${role}`; $('inspect').setAttribute('aria-busy', 'true');
|
|
915
|
-
|
|
1606
|
+
// The person picked this section: it is applied to the design as it is when the change runs (a pick of B then straight back to A
|
|
1607
|
+
// ends on A). A design changed elsewhere first is read again and the pick applied to it once, inside the same turn.
|
|
1608
|
+
const put = () => call(`${base}/rig${VIEW}`, { method: 'PUT', body: { sections: { [role]: designation } }, ifMatch: S.etag });
|
|
1609
|
+
const r = await queuedCall(async () => {
|
|
1610
|
+
if (sectionIs(role, designation)) return NOTHING_TO_CHANGE;
|
|
1611
|
+
const first = await put();
|
|
1612
|
+
if (first.status !== 412 && first.status !== 428) return first;
|
|
1613
|
+
await reloadInTurn();
|
|
1614
|
+
return sectionIs(role, designation) ? NOTHING_TO_CHANGE : put();
|
|
1615
|
+
}, {
|
|
1616
|
+
droppable: false,
|
|
1617
|
+
answer: (r) => { if (r.status === 200 && r.body.ok && !r.body.unchanged) { adopt(r.body); S.sync = checkEngine(S.read); } return r; },
|
|
1618
|
+
});
|
|
916
1619
|
S.busy = '';
|
|
917
1620
|
if (r.status === 200 && r.body.ok) {
|
|
918
|
-
|
|
919
|
-
announce(`${ROLE_WORDS[role] || role} is now ${designation}. ${S.read.design.label.text}`);
|
|
920
|
-
} else if (
|
|
921
|
-
|
|
922
|
-
return changeSection(role, designation, true);
|
|
1621
|
+
S.note = null;
|
|
1622
|
+
if (!r.body.unchanged) announce(`${ROLE_WORDS[role] || role} is now ${designation}. ${S.read.design.label.text}`);
|
|
1623
|
+
} else if (r.status === 412 || r.status === 428) {
|
|
1624
|
+
S.note = { role, text: 'The design changed elsewhere twice while this section was being applied. It is shown as it is now; pick the section again if you still want it.' };
|
|
923
1625
|
} else if (r.body.code === 'unknown-section') {
|
|
924
1626
|
S.note = { role, typed: designation, nearest: (r.body.nearest && r.body.nearest[role]) || [] };
|
|
925
1627
|
} else {
|
|
@@ -930,27 +1632,38 @@ async function changeSection(role, designation, retried = false) {
|
|
|
930
1632
|
}
|
|
931
1633
|
|
|
932
1634
|
async function changeEnd(at) {
|
|
933
|
-
if (!S.read?.exists
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1635
|
+
if (!S.read?.exists) return;
|
|
1636
|
+
// Whether the connection already sits there is checked when the change runs (end then straight back to start ends at the start).
|
|
1637
|
+
const r = await queuedCall(async () => (S.read?.design?.rig?.at === at ? NOTHING_TO_CHANGE : call(`${base}/rig${VIEW}`, { method: 'PUT', body: { at }, ifMatch: S.etag })), {
|
|
1638
|
+
answer: async (r) => {
|
|
1639
|
+
if (r.status === 200 && r.body.ok && !r.body.unchanged) { adopt(r.body); S.sync = checkEngine(S.read); }
|
|
1640
|
+
else if (r.status === 412 || r.status === 428) await reloadInTurn();
|
|
1641
|
+
return r;
|
|
1642
|
+
},
|
|
1643
|
+
});
|
|
1644
|
+
if (r.status === 200 && r.body.ok) { S.note = null; if (!r.body.unchanged) announce(`Connection now sits at the ${at === 'end0' ? 'start' : 'end'} of the beam. ${S.read.design.label.text}`); }
|
|
1645
|
+
else if (r.status !== 412 && r.status !== 428) S.note = { text: r.body.userMessage || r.body.error || 'The end could not be changed.' };
|
|
938
1646
|
paint();
|
|
939
1647
|
}
|
|
940
1648
|
|
|
941
1649
|
async function refreshDrift(update) {
|
|
942
1650
|
if (!update) { S.read.design.rigDrift = []; paint(); return; }
|
|
943
|
-
const r = await call(`${base}/rig${VIEW}`, { method: 'PUT', body: { refresh: true }, ifMatch: S.etag })
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1651
|
+
const r = await queuedCall(() => call(`${base}/rig${VIEW}`, { method: 'PUT', body: { refresh: true }, ifMatch: S.etag }), {
|
|
1652
|
+
answer: async (r) => {
|
|
1653
|
+
if (r.status === 200 && r.body.ok) { adopt(r.body); S.sync = checkEngine(S.read); }
|
|
1654
|
+
else if (r.status === 412 || r.status === 428) await reloadInTurn();
|
|
1655
|
+
return r;
|
|
1656
|
+
},
|
|
1657
|
+
});
|
|
1658
|
+
// A saved update was adopted, and a design changed elsewhere read again, inside its turn; only a refusal is left to say.
|
|
1659
|
+
if (!(r.status === 200 && r.body.ok) && r.status !== 412 && r.status !== 428) S.note = { text: r.body.userMessage || r.body.error || 'The sections could not be updated.' };
|
|
947
1660
|
paint();
|
|
948
1661
|
}
|
|
949
1662
|
|
|
950
1663
|
function wireInspect() {
|
|
951
1664
|
const host = $('inspect');
|
|
952
1665
|
for (const b of host.querySelectorAll('[data-toggle]')) b.addEventListener('click', () => { S.open[b.dataset.toggle] = !S.open[b.dataset.toggle]; renderInspect(); host.querySelector(`[data-toggle="${b.dataset.toggle}"]`)?.focus(); });
|
|
953
|
-
for (const c of host.querySelectorAll('.combo')) wireCombo(c);
|
|
1666
|
+
for (const c of host.querySelectorAll('.combo[data-role]')) wireCombo(c);
|
|
954
1667
|
for (const b of host.querySelectorAll('[data-at]')) b.addEventListener('click', () => changeEnd(b.dataset.at));
|
|
955
1668
|
for (const b of host.querySelectorAll('[data-pick]')) b.addEventListener('click', () => changeSection(b.dataset.role, b.dataset.pick));
|
|
956
1669
|
host.querySelector('[data-act="toggle-current"]')?.addEventListener('click', () => { S.currentOnly = !S.currentOnly; drawCanvas(); chips(); renderInspect(); });
|
|
@@ -995,6 +1708,14 @@ function probe() {
|
|
|
995
1708
|
dimensions: S.handles ? S.handles.probe() : null, previewing: !!S.preview,
|
|
996
1709
|
conflicts: read?.design?.conflicts ?? [], cards: [...document.querySelectorAll('#inspect [data-card]')].map((el) => ({ key: el.dataset.card, text: el.textContent.replace(/\s+/g, ' ').trim() })),
|
|
997
1710
|
fixes: Object.fromEntries(Object.entries(S.cards.fixes).map(([k, v]) => [k, { state: v.state, x: v.fix?.x ?? null }])),
|
|
1711
|
+
// Slice 2d: the panel as drawn, the open menu, and the undo lists.
|
|
1712
|
+
params: [...document.querySelectorAll('#inspect [data-param]')].map((el) => ({
|
|
1713
|
+
id: el.dataset.param, chip: el.querySelector('.pchip')?.textContent.trim() ?? null, value: el.querySelector('input')?.value ?? el.querySelector('.pderived')?.textContent ?? null,
|
|
1714
|
+
rule: el.querySelector('.prule')?.textContent ?? null, ai: el.classList.contains('changed-ai'), msg: el.querySelector('.pmsg')?.textContent ?? null,
|
|
1715
|
+
})),
|
|
1716
|
+
menu: S.menu ? { param: S.menu.param, from: S.menu.from, items: [...document.querySelectorAll('#ruleMenu .mitem')].map((b) => ({ act: b.dataset.mact || b.dataset.size, text: b.textContent.replace(/\s+/g, ' ').trim(), unavailable: b.getAttribute('aria-disabled') === 'true', checked: b.getAttribute('aria-checked') })), check: document.getElementById('ruleCheck')?.textContent ?? null, msg: document.querySelector('#ruleMenu .mmsg')?.textContent ?? null } : null,
|
|
1717
|
+
undo: S.undo.map((u) => u.label), redo: S.redo.map((u) => u.label), sending: !!S.sending, epoch: S.epoch,
|
|
1718
|
+
declared: S.read?.design?.panel?.dimensions ?? [], assisted: S.read?.design?.draft?.assisted ?? null,
|
|
998
1719
|
};
|
|
999
1720
|
}
|
|
1000
1721
|
|
|
@@ -1014,6 +1735,18 @@ window.addEventListener('message', (e) => {
|
|
|
1014
1735
|
}
|
|
1015
1736
|
});
|
|
1016
1737
|
|
|
1738
|
+
// Ctrl+Z / Ctrl+Y / Ctrl+Shift+Z undo and redo the page's edits; a text field keeps its own undo.
|
|
1739
|
+
document.addEventListener('keydown', (e) => {
|
|
1740
|
+
if (!(e.ctrlKey || e.metaKey) || e.altKey) return;
|
|
1741
|
+
const t = e.target;
|
|
1742
|
+
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;
|
|
1743
|
+
const k = e.key.toLowerCase();
|
|
1744
|
+
if (k === 'z' && !e.shiftKey) { e.preventDefault(); undo('undo'); }
|
|
1745
|
+
else if (k === 'y' || (k === 'z' && e.shiftKey)) { e.preventDefault(); undo('redo'); }
|
|
1746
|
+
});
|
|
1747
|
+
$('undoBtn')?.addEventListener('click', () => { if ($('undoBtn').getAttribute('aria-disabled') !== 'true') undo('undo'); });
|
|
1748
|
+
$('redoBtn')?.addEventListener('click', () => { if ($('redoBtn').getAttribute('aria-disabled') !== 'true') undo('redo'); });
|
|
1749
|
+
|
|
1017
1750
|
(async function boot() {
|
|
1018
1751
|
if (!PROJECT) {
|
|
1019
1752
|
$('labelLead').textContent = 'Open this page from a Connection Design project.';
|