@floless/app 0.156.0 → 0.158.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/cli-actions.mjs +28 -5
- package/dist/floless-server.cjs +110947 -67461
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +82 -17
- package/dist/skills/floless-app-knowledge/SKILL.md +34 -2
- package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +23 -7
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
- package/dist/skills/floless-app-report-issue/SKILL.md +3 -3
- package/dist/skills/floless-app-rfi/SKILL.md +40 -6
- package/dist/skills/floless-app-routines/SKILL.md +9 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +35 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +51 -1
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +46 -10
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +864 -47
- package/dist/web/agents.js +28 -8
- package/dist/web/app.css +620 -17
- package/dist/web/app.js +110 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +921 -220
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +263 -1
- package/dist/web/chat.js +2660 -86
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +1059 -8
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +143 -8
- package/dist/web/instructor.js +4 -4
- package/dist/web/kb-categories.js +351 -0
- package/dist/web/kb-graph-worker.js +73 -0
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/pages.js +978 -39
- package/dist/web/panels.js +5 -2
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/run-page-view.js +353 -0
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +681 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/tab-signal.js +323 -0
- package/dist/web/terminal-requests.js +103 -13
- package/dist/web/tool-updates.js +1 -0
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +2883 -146
- package/launch-starting-page.mjs +181 -0
- package/launch.mjs +97 -12
- package/package.json +5 -1
package/dist/web/workspaces.js
CHANGED
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
* ========================================================================== */
|
|
14
14
|
(() => {
|
|
15
15
|
const bridge = window.flolessBridge || {};
|
|
16
|
-
const api = bridge.api || (async (path, opts) => {
|
|
17
|
-
|
|
16
|
+
const api = bridge.api || (async (path, opts = {}) => {
|
|
17
|
+
await globalThis.flolessStartupAdmission?.admit(path, { method: opts?.method, signal: opts?.signal });
|
|
18
|
+
const { timeoutMs, ...requestOptions } = opts;
|
|
19
|
+
if (!requestOptions.signal && Number.isFinite(timeoutMs)) requestOptions.signal = AbortSignal.timeout(timeoutMs);
|
|
20
|
+
const res = await fetch(path, { headers: { 'content-type': 'application/json' }, ...requestOptions });
|
|
18
21
|
const body = await res.json().catch(() => ({
|
|
19
22
|
ok: false,
|
|
20
23
|
code: 'response-unreadable',
|
|
@@ -375,6 +378,8 @@
|
|
|
375
378
|
const $revitReassure = document.getElementById('ws-source-reassure');
|
|
376
379
|
let revitSourceState = null;
|
|
377
380
|
let revitActiveOperation = null;
|
|
381
|
+
// How the Source step's last Cancel or Try again ended, for a chat card that pressed it (modelSourceStep): the route's own answer.
|
|
382
|
+
let sourceControlOutcome = null;
|
|
378
383
|
// The Source card an import leaves ("…It is not approved yet.") stays true only until that model is approved.
|
|
379
384
|
let revitSourceAwaitsApproval = false;
|
|
380
385
|
// Every paint of the Source pane counts, so a late answer can tell that something newer was painted.
|
|
@@ -414,11 +419,19 @@
|
|
|
414
419
|
description: 'PDF or image',
|
|
415
420
|
accept: { 'application/pdf': ['.pdf'], 'image/*': ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp'] },
|
|
416
421
|
}];
|
|
417
|
-
|
|
422
|
+
const STEEL_DRAWING_FILE_TYPES = [{ description: 'PDF drawing sets', accept: { 'application/pdf': ['.pdf'] } }];
|
|
423
|
+
function validateSteelDrawingFiles(templateId, files) {
|
|
424
|
+
if (templateId !== 'steel-model' || files.every((file) => /\.pdf$/i.test(file.name))) return true;
|
|
425
|
+
showToast('Steel Model reads PDF drawing sets. Nothing was attached because the selection contains a non-PDF file. Choose PDF drawings instead.', 'warn');
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
async function pickDrawingFiles(fallbackInput, templateId) {
|
|
429
|
+
const steel = templateId === 'steel-model';
|
|
430
|
+
if (fallbackInput) fallbackInput.accept = steel ? '.pdf' : '.pdf,image/*';
|
|
418
431
|
if (window.showOpenFilePicker) {
|
|
419
432
|
const wasFocused = pageHasFocus(), startedAt = Date.now();
|
|
420
433
|
try {
|
|
421
|
-
const handles = await window.showOpenFilePicker({ multiple: true, types: DRAWING_FILE_TYPES });
|
|
434
|
+
const handles = await window.showOpenFilePicker({ multiple: true, types: steel ? STEEL_DRAWING_FILE_TYPES : DRAWING_FILE_TYPES, excludeAcceptAllOption: steel });
|
|
422
435
|
return Promise.all(handles.map((h) => h.getFile()));
|
|
423
436
|
} catch (err) {
|
|
424
437
|
if (chooserEndedWithoutChoice(err, wasFocused, startedAt)) return []; // a cancel is silent; a refusal said so
|
|
@@ -645,6 +658,8 @@
|
|
|
645
658
|
*/
|
|
646
659
|
let exportsRenderGen = 0;
|
|
647
660
|
let exportState = null; // kind → { path, exportedAt } after a successful list; null = unknown/failed
|
|
661
|
+
// #2449: { version, hash } of the approved version exportState's files came from, from the SAME listing; null = unknown.
|
|
662
|
+
let exportStateFrom = null;
|
|
648
663
|
/*
|
|
649
664
|
* THE UNITS THE SERVER SAYS THIS PROJECT'S BILL IS IN — from the same response the card is built
|
|
650
665
|
* from, refreshed every time the card is. `null` until it has answered.
|
|
@@ -736,10 +751,10 @@
|
|
|
736
751
|
{
|
|
737
752
|
kind: 'drawing',
|
|
738
753
|
headline: 'Steel model from drawings',
|
|
739
|
-
capability: 'PDF
|
|
740
|
-
sub: 'Turn
|
|
741
|
-
label: 'Pick drawings',
|
|
742
|
-
dropHint: 'Click or drop
|
|
754
|
+
capability: 'PDF drawing set → 3D steel model',
|
|
755
|
+
sub: 'Turn a PDF drawing set into a 3D model you can review and export.',
|
|
756
|
+
label: 'Pick PDF drawings',
|
|
757
|
+
dropHint: 'Click or drop PDFs',
|
|
743
758
|
},
|
|
744
759
|
],
|
|
745
760
|
editor: '/steel-editor.html',
|
|
@@ -748,9 +763,9 @@
|
|
|
748
763
|
{ key: 'knowledge', label: 'Knowledge' }, // per-project KB — the job's context, consulted by everything
|
|
749
764
|
{ key: 'drawings', label: 'Drawing Filter' },
|
|
750
765
|
{ key: 'model', label: 'Model' },
|
|
766
|
+
{ key: 'pages', label: 'Pages' }, // #2262: stored, versioned HTML Pages; #2568: just before Exports (both are output)
|
|
751
767
|
{ key: 'exports', label: 'Exports' },
|
|
752
768
|
{ key: 'history', label: 'History' },
|
|
753
|
-
{ key: 'pages', label: 'Pages' }, // #2262: stored, versioned HTML Pages (every app)
|
|
754
769
|
],
|
|
755
770
|
diff: true, // steel semantic diff expander
|
|
756
771
|
exports: [
|
|
@@ -799,9 +814,9 @@
|
|
|
799
814
|
{ key: 'knowledge', label: 'Knowledge' }, // KB is project-level — every workspace app gets it
|
|
800
815
|
{ key: 'drawings', label: 'Source' }, // reuse the 'drawings' frame slot; label "Source"
|
|
801
816
|
{ key: 'model', label: 'Traced' }, // reuse the 'model' frame slot; label "Traced"
|
|
817
|
+
{ key: 'pages', label: 'Pages' }, // #2262: stored, versioned HTML Pages; #2568: just before Exports (both are output)
|
|
802
818
|
{ key: 'exports', label: 'Exports' },
|
|
803
819
|
{ key: 'history', label: 'History' },
|
|
804
|
-
{ key: 'pages', label: 'Pages' }, // #2262: stored, versioned HTML Pages (every app)
|
|
805
820
|
],
|
|
806
821
|
diff: false,
|
|
807
822
|
exports: [
|
|
@@ -956,6 +971,33 @@
|
|
|
956
971
|
},
|
|
957
972
|
},
|
|
958
973
|
},
|
|
974
|
+
'floless-general': {
|
|
975
|
+
// A General project (#2470) is a blank project for any work: no drawing, no model, no module, so it
|
|
976
|
+
// is in the base plan. `floless-general` is a project type FloLess owns, not an installed workflow,
|
|
977
|
+
// so its card is always there (installedWorkspaceAppEntries) and nothing has to be set up. It has no
|
|
978
|
+
// editor and no model: it opens on Knowledge, and its header has nothing to approve while it holds
|
|
979
|
+
// no model (renderApprovalHeader). Last on the landing: the card for the work no other card fits.
|
|
980
|
+
sourceless: true,
|
|
981
|
+
cardIcon: '<rect x="3" y="7.5" width="18" height="12" rx="1.5"/><path d="M9 7.5v-2A1.5 1.5 0 0 1 10.5 4h3A1.5 1.5 0 0 1 15 5.5v2"/><path d="M3 12.5h18"/><path d="M11 12.5v2h2v-2"/>', // a briefcase: the job, whatever it is
|
|
982
|
+
displayName: 'General',
|
|
983
|
+
projectCapability: 'workflows, knowledge, chat',
|
|
984
|
+
createActions: [{
|
|
985
|
+
kind: 'general-project',
|
|
986
|
+
headline: 'General project',
|
|
987
|
+
capability: 'Workflows, knowledge, chat',
|
|
988
|
+
sub: 'Start with nothing but a name. Add knowledge, pages and workflows as you go.',
|
|
989
|
+
label: 'New General project…',
|
|
990
|
+
dropWarn: 'General starts from a name, not a file, so nothing was uploaded. Click the card to make the project, then add files on its Knowledge page.',
|
|
991
|
+
}],
|
|
992
|
+
editor: null,
|
|
993
|
+
filter: null,
|
|
994
|
+
steps: [
|
|
995
|
+
{ key: 'knowledge', label: 'Knowledge' },
|
|
996
|
+
{ key: 'pages', label: 'Pages' },
|
|
997
|
+
],
|
|
998
|
+
diff: false,
|
|
999
|
+
exports: [],
|
|
1000
|
+
},
|
|
959
1001
|
};
|
|
960
1002
|
// A project names its app by the LIVE id, which a rename or a duplicate moves off the descriptor
|
|
961
1003
|
// keys above — so resolve through the lineage ROOT the server ships beside it (`templateId`, derived
|
|
@@ -1073,6 +1115,8 @@
|
|
|
1073
1115
|
if (['ready', 'failed', 'not-applicable'].includes(coreDefaults)) missingCoreRoots.add(root);
|
|
1074
1116
|
}
|
|
1075
1117
|
}
|
|
1118
|
+
// A General project needs nothing installed, so its card is always offered (#2470).
|
|
1119
|
+
if (!byRoot.has('floless-general')) byRoot.set('floless-general', ['floless-general']);
|
|
1076
1120
|
return Object.keys(WORKSPACE_APPS).filter((root) => byRoot.has(root)).map((root) => {
|
|
1077
1121
|
// Sorted, so which app a card targets is stable across loads rather than dependent on the
|
|
1078
1122
|
// order `aware app list` happened to return. The canonical install wins when present: it is
|
|
@@ -1122,6 +1166,11 @@
|
|
|
1122
1166
|
* still preliminary.
|
|
1123
1167
|
*/
|
|
1124
1168
|
let projectContractLifecycle = 'unknown';
|
|
1169
|
+
// A General project (#2470) has no Model, Exports or History step, so nothing the person clicks would
|
|
1170
|
+
// ever re-ask a lifecycle check that timed out or failed. It re-asks by itself, a few times, further
|
|
1171
|
+
// apart each time; then the header says it could not check rather than "Checking…" forever.
|
|
1172
|
+
const SOURCELESS_PRESENCE_RETRIES = 3;
|
|
1173
|
+
let sourcelessPresence = { projectId: null, openSeq: 0, tries: 0, gaveUp: false, timer: null };
|
|
1125
1174
|
let exportsHasModel = false;
|
|
1126
1175
|
// A project may open on Model/Exports/History while its lifecycle probe is still in flight. Keep
|
|
1127
1176
|
// the most recently requested destination until the probe settles so the latest click counts.
|
|
@@ -1146,11 +1195,36 @@
|
|
|
1146
1195
|
|
|
1147
1196
|
function renderApprovalHeader() {
|
|
1148
1197
|
if (!$approveBtn) return;
|
|
1198
|
+
// A General project (#2470) has nothing of its own to approve, so the button is withheld rather than
|
|
1199
|
+
// left as a permanently dead "Review unavailable". Only once the lifecycle answer CONFIRMS there is no
|
|
1200
|
+
// model: while it is unknown (still checking, or the check failed) the button stays and shows its usual
|
|
1201
|
+
// checking or retry state, and should a model ever be there (an imported folder that carried one) it
|
|
1202
|
+
// says what it always does. Workflows in the project keep their own Compile/Approve and drift gate.
|
|
1203
|
+
const sourceless = !!(typeof current !== 'undefined' && current && wsDescOf(current)?.sourceless);
|
|
1204
|
+
$approveBtn.hidden = sourceless && projectContractLifecycle === 'absent';
|
|
1149
1205
|
const s = approvalState;
|
|
1150
1206
|
let label = 'Review & approve';
|
|
1151
1207
|
let tip = APPROVE_TIP;
|
|
1152
1208
|
let unavailable = false;
|
|
1153
|
-
if (
|
|
1209
|
+
if (sourceless) {
|
|
1210
|
+
// A General project has no Drawing Filter and no workflow to approve with, so no model-specific
|
|
1211
|
+
// branch below applies. The button is hidden once the check confirms there is no model.
|
|
1212
|
+
const gaveUp = sourcelessPresence.gaveUp && sourcelessPresence.projectId === current.id;
|
|
1213
|
+
if (exportsHasModel) {
|
|
1214
|
+
label = 'Review unavailable';
|
|
1215
|
+
// A step that exists: a project of the model's own type, made from its drawings or source.
|
|
1216
|
+
tip = 'This General project holds a model that came in with an imported folder, and a General project cannot approve a model. To review and approve it, create a project of the model’s type on the Workspaces page and read its drawings or source there.';
|
|
1217
|
+
} else if (projectContractLifecycle === 'unknown') {
|
|
1218
|
+
label = gaveUp ? 'Couldn’t check project' : 'Checking project…';
|
|
1219
|
+
tip = gaveUp
|
|
1220
|
+
? 'FloLess couldn’t confirm whether this project holds a model. Click to check again.'
|
|
1221
|
+
: 'Checking whether this project holds a model.';
|
|
1222
|
+
} else {
|
|
1223
|
+
label = 'Review unavailable';
|
|
1224
|
+
tip = 'A General project has nothing of its own to approve.';
|
|
1225
|
+
}
|
|
1226
|
+
unavailable = true;
|
|
1227
|
+
} else if (s.status === 'waiting-for-model-read') {
|
|
1154
1228
|
const tekla = isTeklaParserProject();
|
|
1155
1229
|
label = tekla ? 'Review after read' : 'Review after import';
|
|
1156
1230
|
tip = tekla
|
|
@@ -1446,6 +1520,7 @@
|
|
|
1446
1520
|
if (freshVisit) setLandingQuery('');
|
|
1447
1521
|
$project.hidden = !ws || !current;
|
|
1448
1522
|
$spine.hidden = !ws || !current;
|
|
1523
|
+
window.flolessProjectAccess?.setProject(ws && current ? current : null);
|
|
1449
1524
|
if (!ws && !$projMenu.hidden) closeProjMenu();
|
|
1450
1525
|
if (ws && !current) loadProjects();
|
|
1451
1526
|
// Name the tab after what's actually on screen. aware.js is the single writer of
|
|
@@ -1495,12 +1570,16 @@
|
|
|
1495
1570
|
$workflowTab.removeAttribute('aria-disabled');
|
|
1496
1571
|
$workflowTab.removeAttribute('data-blocked-reason');
|
|
1497
1572
|
}
|
|
1573
|
+
// The tab's own icon and label, kept on the tab while the spinner stands in for them and put back when it is done.
|
|
1574
|
+
// Taken on the first call, whichever way it goes: leaving for Workspaces calls this with false before Workflows
|
|
1575
|
+
// has ever opened, and taking them only on true then wiped the icon for good.
|
|
1576
|
+
$workflowTab.idleNodes ??= [...$workflowTab.childNodes];
|
|
1498
1577
|
if (opening) {
|
|
1499
1578
|
$workflowTab.setAttribute('aria-label', 'Opening Workflows');
|
|
1500
1579
|
$workflowTab.innerHTML = '<span class="rtn-spinner" aria-hidden="true"></span><span>Opening Workflows…</span>';
|
|
1501
1580
|
} else {
|
|
1502
1581
|
$workflowTab.removeAttribute('aria-label');
|
|
1503
|
-
$workflowTab.
|
|
1582
|
+
$workflowTab.replaceChildren(...$workflowTab.idleNodes);
|
|
1504
1583
|
}
|
|
1505
1584
|
}
|
|
1506
1585
|
async function setMode(m) {
|
|
@@ -1526,7 +1605,11 @@
|
|
|
1526
1605
|
await bridge.refreshCurrentWorkflow();
|
|
1527
1606
|
} catch (error) {
|
|
1528
1607
|
if (sequence === modeChangeSequence) {
|
|
1529
|
-
|
|
1608
|
+
// A module refusal (Revit or Tekla access not confirmed) is not FloLess failing to reach the
|
|
1609
|
+
// workflow, and trying again will not fix it: say what the server says to do instead. A lapsed
|
|
1610
|
+
// FloLess sign-in is not FloLess being unreachable either: say to sign in again.
|
|
1611
|
+
showToast(bridge.moduleRefusalText?.(error) || bridge.accountAccessText?.(error)
|
|
1612
|
+
|| 'We couldn’t refresh this workflow because FloLess could not reach it. Try again.', 'warn');
|
|
1530
1613
|
}
|
|
1531
1614
|
return;
|
|
1532
1615
|
} finally {
|
|
@@ -1867,7 +1950,26 @@
|
|
|
1867
1950
|
if (!$wsExports.hidden) safeRenderExports('after a units change');
|
|
1868
1951
|
});
|
|
1869
1952
|
|
|
1953
|
+
/**
|
|
1954
|
+
* Relay a change to the open project's editor frame (#2482). The editor has no event stream of its own: one more
|
|
1955
|
+
* long-lived connection per tab took two open tabs past the browser's six per server, and every other request then
|
|
1956
|
+
* waited, so the page looked offline. Only frames about the project on screen go, to that frame's origin.
|
|
1957
|
+
*/
|
|
1958
|
+
function tellModelFrame(frame) {
|
|
1959
|
+
const project = typeof current !== 'undefined' ? current : null;
|
|
1960
|
+
const f = typeof frames !== 'undefined' ? frames.model : null;
|
|
1961
|
+
if (!project || !f || !f.dataset.loaded) return;
|
|
1962
|
+
try { f.contentWindow?.postMessage({ type: 'floless:project-event', projectId: project.id, frame }, location.origin); }
|
|
1963
|
+
catch { /* the frame is between documents */ }
|
|
1964
|
+
}
|
|
1965
|
+
window.addEventListener('floless:contract-changed', (e) => {
|
|
1966
|
+
const m = (e && e.detail) || {};
|
|
1967
|
+
if (current && m.project === current.id) tellModelFrame(m);
|
|
1968
|
+
});
|
|
1870
1969
|
window.addEventListener('floless:projects-changed', (e) => {
|
|
1970
|
+
// Sent after the event stream reconnects too (aware.js), with no detail: frames may have been missed, so the
|
|
1971
|
+
// editor reads again.
|
|
1972
|
+
if (!e || !e.detail || !Object.keys(e.detail).length) tellModelFrame({ type: 'resync' });
|
|
1871
1973
|
const m = (e && e.detail) || {};
|
|
1872
1974
|
if (m.kind === 'metadata' && typeof m.registrationId === 'string') {
|
|
1873
1975
|
refreshRegisteredProject(m);
|
|
@@ -2427,6 +2529,7 @@
|
|
|
2427
2529
|
const createCommand = action.kind === 'tekla-source' ? 'data-command-id="shell.project-create-tekla-read" '
|
|
2428
2530
|
: action.kind === 'rvt' ? 'data-command-id="shell.project-create-revit-read" '
|
|
2429
2531
|
: action.kind === 'drawing-check-profile' ? 'data-command-id="shell.project-create-drawing-check-profile" '
|
|
2532
|
+
: action.kind === 'general-project' ? 'data-command-id="shell.project-create-general" '
|
|
2430
2533
|
: action.kind !== 'drawing' ? ''
|
|
2431
2534
|
: entry.templateId === 'steel-model' ? 'data-command-id="shell.project-create-steel-from-drawings" '
|
|
2432
2535
|
: entry.templateId === 'vectorize' ? 'data-command-id="shell.project-create-trace-from-drawing" '
|
|
@@ -2482,7 +2585,11 @@
|
|
|
2482
2585
|
*/
|
|
2483
2586
|
function thumbBandHtml(p, displayApp) {
|
|
2484
2587
|
const kind = `<span class="ws-kind">${escapeHtml(displayApp)}</span>`;
|
|
2485
|
-
|
|
2588
|
+
// A General project (#2470) has no drawing or model to picture, so its band shows the card's own mark.
|
|
2589
|
+
const sourceless = wsDescOf(p)?.sourceless ? wsDescOf(p).cardIcon : '';
|
|
2590
|
+
if (!p.thumbnailTag) {
|
|
2591
|
+
return `<span class="ws-thumb">${kind}${sourceless ? `<svg class="ws-thumb-mark" viewBox="0 0 24 24" aria-hidden="true" focusable="false">${sourceless}</svg>` : '▦'}</span>`;
|
|
2592
|
+
}
|
|
2486
2593
|
return `<button type="button" class="ws-thumb" data-thumb="${escapeAttr(p.id)}" ` +
|
|
2487
2594
|
`aria-label="${escapeAttr(`View the thumbnail of “${p.name}” larger`)}" data-tip="View this thumbnail larger">` +
|
|
2488
2595
|
`<img alt="" loading="lazy">${kind}<span class="ws-thumb-expand" aria-hidden="true">⤢</span></button>`;
|
|
@@ -3150,7 +3257,7 @@
|
|
|
3150
3257
|
return;
|
|
3151
3258
|
}
|
|
3152
3259
|
let files;
|
|
3153
|
-
try { files = await pickDrawingFiles($seedFile); } // keep native picker in the click activation
|
|
3260
|
+
try { files = await pickDrawingFiles($seedFile, templateId); } // keep native picker in the click activation
|
|
3154
3261
|
catch { showToast('Couldn’t open the drawing picker. Try again.', 'warn'); return; }
|
|
3155
3262
|
if (!files.length) return;
|
|
3156
3263
|
if (workspaceWorkflowKnownMissing(appId)) {
|
|
@@ -3168,6 +3275,9 @@
|
|
|
3168
3275
|
// their page counts and the proposed checklist can be shown. The setup dialog asks only the
|
|
3169
3276
|
// folder and the client's name.
|
|
3170
3277
|
createFromDrawing(appId, templateId, [], { kind: 'drawing-check-profile', sourceLabel: 'Client profile', returnFocus: seed });
|
|
3278
|
+
} else if (seed.dataset.seedAction === 'general-project') {
|
|
3279
|
+
// A General project starts from nothing but its name and folder (#2470).
|
|
3280
|
+
createFromDrawing(appId, templateId, [], { kind: 'general-project', sourceLabel: 'Blank project', returnFocus: seed });
|
|
3171
3281
|
} else {
|
|
3172
3282
|
// Unreachable today, and it must not be SILENT the day it isn't: an unhandled kind still
|
|
3173
3283
|
// renders a full dashed, focusable card, so without this the first person to add one gets a
|
|
@@ -3357,11 +3467,13 @@
|
|
|
3357
3467
|
if (!project || !failedOperationId || isTeklaParserProject(project)) return;
|
|
3358
3468
|
try {
|
|
3359
3469
|
const started = await api(`/api/model-imports/${encodeURIComponent(failedOperationId)}/retry`, { method: 'POST', body: '{}' });
|
|
3470
|
+
sourceControlOutcome = { verb: 'retry', projectId: project.id, operationId: failedOperationId, ok: true };
|
|
3360
3471
|
revitActiveOperation = started.operation;
|
|
3361
3472
|
paintRevitSourceState('Replacing source RVT…', 'Reading the already stored RVT again…');
|
|
3362
3473
|
paintRevitSourceActions('active', true);
|
|
3363
3474
|
pollRevitImport(started.operation.operationId, project.id);
|
|
3364
3475
|
} catch (error) {
|
|
3476
|
+
sourceControlOutcome = { verb: 'retry', projectId: project.id, operationId: failedOperationId, ok: false };
|
|
3365
3477
|
paintRevitSourceState('Couldn’t retry the RVT', `${error && error.message || error} The existing model was not changed.`);
|
|
3366
3478
|
paintRevitSourceActions('failed', revitSourceState?.canReplace === true, revitActiveOperation?.failure?.retryable !== false, revitActiveOperation);
|
|
3367
3479
|
}
|
|
@@ -3380,11 +3492,13 @@
|
|
|
3380
3492
|
? `/api/tekla-imports/${encodeURIComponent(operationId)}/cancel`
|
|
3381
3493
|
: `/api/model-imports/${encodeURIComponent(operationId)}/cancel`;
|
|
3382
3494
|
await api(cancelPath, { method: 'POST', body: '{}' });
|
|
3495
|
+
sourceControlOutcome = { verb: 'cancel', projectId, operationId, ok: true };
|
|
3383
3496
|
revitActiveOperation = null;
|
|
3384
3497
|
paintRevitSourceState('Replacement cancelled', 'The existing model was not changed.');
|
|
3385
3498
|
paintRevitSourceActions('ready', true);
|
|
3386
3499
|
$revitReplace?.focus();
|
|
3387
3500
|
} catch (error) {
|
|
3501
|
+
sourceControlOutcome = { verb: 'cancel', projectId, operationId, ok: false };
|
|
3388
3502
|
const status = error && error.status;
|
|
3389
3503
|
showToast(status === 403
|
|
3390
3504
|
? `We couldn’t cancel this import because ${isTeklaParserProject() ? 'Tekla Parser' : 'Revit'} access is not available for this account. Check your account access, then try again.`
|
|
@@ -3449,7 +3563,10 @@
|
|
|
3449
3563
|
const name = zone.querySelector('.ws-seed-headline')?.textContent || 'This card';
|
|
3450
3564
|
const other = (card) => (card && card !== name ? card : null);
|
|
3451
3565
|
const revit = files.some((file) => /\.rvt$/i.test(file.name)) && other(cardFor('rvt'));
|
|
3452
|
-
const
|
|
3566
|
+
const drawingCard = files.some((file) => isDrawingFile(file) && !/\.pdf$/i.test(file.name))
|
|
3567
|
+
? $landing.querySelector('[data-seed-drop-kind="drawing"]:not([data-seed-template="steel-model"]) .ws-seed-headline')?.textContent
|
|
3568
|
+
: cardFor('drawing');
|
|
3569
|
+
const drawing = files.some(isDrawingFile) && other(drawingCard);
|
|
3453
3570
|
const tekla = (folderCount || files.some((file) => /\.zip$/i.test(file.name))) && other(cardFor('tekla-source'));
|
|
3454
3571
|
const next = revit ? `Drop it on ${revit} instead.`
|
|
3455
3572
|
: drawing ? `Drop it on ${drawing} instead.`
|
|
@@ -3559,7 +3676,8 @@
|
|
|
3559
3676
|
return;
|
|
3560
3677
|
}
|
|
3561
3678
|
const drawings = files.filter(isDrawingFile);
|
|
3562
|
-
if (!drawings.length) { showToast(misdropMessage(zone, DRAWING_FORMATS, files, folderCount), 'warn'); return; }
|
|
3679
|
+
if (!drawings.length) { showToast(misdropMessage(zone, templateId === 'steel-model' ? 'PDF drawing sets' : DRAWING_FORMATS, files, folderCount), 'warn'); return; }
|
|
3680
|
+
if (!validateSteelDrawingFiles(templateId, files)) return;
|
|
3563
3681
|
if (workspaceWorkflowKnownMissing(appId)) { showToast(missingWorkspaceWorkflowMessage(templateId), 'warn'); return; }
|
|
3564
3682
|
const skippedFiles = files.length - drawings.length;
|
|
3565
3683
|
const skipped = [
|
|
@@ -3667,17 +3785,12 @@
|
|
|
3667
3785
|
if (userMessage) return userMessage;
|
|
3668
3786
|
const raw = String(error && error.body?.error || error && error.message || error || '');
|
|
3669
3787
|
const code = String(error && (error.code || error.body?.code) || '');
|
|
3788
|
+
// This attachment refusal is authored for the person, including the PDF count/size remedy.
|
|
3789
|
+
if (code === 'steel-pdf-required') return raw;
|
|
3670
3790
|
// Account access can expire while this dialog is open, before the folder chooser
|
|
3671
3791
|
// or project creation runs. Name that cause without blaming the selected folder.
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
if (access?.reason === 'session-expired') return 'Your FloLess sign-in has expired. Sign in again, then try again.';
|
|
3675
|
-
if (access?.reason === 'signed-out') return 'You are signed out of FloLess. Sign in again, then try again.';
|
|
3676
|
-
if (access?.reason === 'seat-taken') return 'Your FloLess session has ended. Sign in again, then try again.';
|
|
3677
|
-
if (access?.state === 'expired') return 'Your FloLess subscription has expired. Renew your subscription, then try again.';
|
|
3678
|
-
if (access?.reason === 'no-subscription') return 'This account does not have a FloLess subscription. Sign in with a subscribed account or subscribe, then try again.';
|
|
3679
|
-
return 'Sign in to FloLess to check your account access, then try again.';
|
|
3680
|
-
}
|
|
3792
|
+
const access = bridge.accountAccessText?.(error);
|
|
3793
|
+
if (access) return access;
|
|
3681
3794
|
// A setup refusal with no sentence for the person (#1965 review, round 3). The code covers several
|
|
3682
3795
|
// causes — the parser's setup has not finished, or a check refused this project while its card shows
|
|
3683
3796
|
// the ready state — so the sentence names none of them, only the card that shows what is left to do.
|
|
@@ -3747,7 +3860,9 @@
|
|
|
3747
3860
|
// never be the one shown as chosen and sent.
|
|
3748
3861
|
// Setup kinds that create a project only — no AI Chat intake, no drawing-intake task. The two model
|
|
3749
3862
|
// sources are read by FloLess itself; a Drawing Checker profile starts empty and is built on its page.
|
|
3750
|
-
const NO_CHAT_SETUP_KINDS = ['rvt', 'tekla-source', 'drawing-check-profile'];
|
|
3863
|
+
const NO_CHAT_SETUP_KINDS = ['rvt', 'tekla-source', 'drawing-check-profile', 'general-project'];
|
|
3864
|
+
// Setup kinds that start from no file at all: a Drawing Checker profile and a General project.
|
|
3865
|
+
const NO_FILE_SETUP_KINDS = ['drawing-check-profile', 'general-project'];
|
|
3751
3866
|
function projectSetupProvider(state) {
|
|
3752
3867
|
if (!state || NO_CHAT_SETUP_KINDS.includes(state.kind)) return null;
|
|
3753
3868
|
const runtimes = bridge.chatProviderRuntimes?.() || [];
|
|
@@ -3873,6 +3988,10 @@
|
|
|
3873
3988
|
$projectSetupCreateOnly.classList.toggle('primary', !provider);
|
|
3874
3989
|
$projectSetupTitle.textContent = `New ${descDisplayName(state.templateId)} project`;
|
|
3875
3990
|
$projectSetupSourceName.textContent = state.sourceLabel || state.files[0]?.name || (state.kind === 'rvt' ? 'Revit model' : 'Drawing set');
|
|
3991
|
+
// A General project has no source to name, only where it starts from.
|
|
3992
|
+
const $sourceKicker = $projectSetupSourceName.previousElementSibling;
|
|
3993
|
+
if ($sourceKicker) $sourceKicker.textContent = state.kind === 'general-project' ? 'Starting point' : 'Source';
|
|
3994
|
+
$projectSetupSourceName.parentElement?.setAttribute('aria-label', state.kind === 'general-project' ? 'Starting point' : 'Selected source drawings');
|
|
3876
3995
|
$projectSetupCreateOnly.textContent = state.busy ? 'Creating…' : (NO_CHAT_SETUP_KINDS.includes(state.kind) ? 'Create project' : 'Create project only');
|
|
3877
3996
|
$projectSetupSourceCount.textContent = state.files.length > 1 ? `+ ${state.files.length - 1} more` : '';
|
|
3878
3997
|
$projectSetupFolder.textContent = state.directory
|
|
@@ -4005,12 +4124,13 @@
|
|
|
4005
4124
|
await importTeklaIntoProject(project, state.teklaSource, state.appId);
|
|
4006
4125
|
return;
|
|
4007
4126
|
}
|
|
4008
|
-
if (state.kind === 'drawing-check-profile') {
|
|
4127
|
+
if (state.kind === 'drawing-check-profile' || state.kind === 'general-project') {
|
|
4009
4128
|
projects.unshift(project);
|
|
4010
4129
|
track('workspace_project_created', { app: state.appId });
|
|
4011
4130
|
setProjectSetupBusy(false);
|
|
4012
4131
|
closeProjectSetup({ restoreFocus: false });
|
|
4013
|
-
|
|
4132
|
+
// A General project opens on Knowledge: the job's context, and the first thing to add.
|
|
4133
|
+
await openProject(project.id, state.kind === 'general-project' ? 'knowledge' : 'model');
|
|
4014
4134
|
return;
|
|
4015
4135
|
}
|
|
4016
4136
|
projects.unshift(project);
|
|
@@ -4099,8 +4219,9 @@
|
|
|
4099
4219
|
*/
|
|
4100
4220
|
async function createFromDrawing(appId, templateId, files, { kind = 'drawings', sourceLabel = '', teklaSource = null, returnFocus = null } = {}) {
|
|
4101
4221
|
if (!$projectSetup || projectSetupState) return false;
|
|
4102
|
-
// A Drawing Checker profile
|
|
4103
|
-
if (!Array.isArray(files) || (!files.length && kind
|
|
4222
|
+
// A Drawing Checker profile and a General project start with no source file: what goes in them comes later.
|
|
4223
|
+
if (!Array.isArray(files) || (!files.length && !NO_FILE_SETUP_KINDS.includes(kind))) return false;
|
|
4224
|
+
if (kind === 'drawings' && !validateSteelDrawingFiles(templateId, files)) return false;
|
|
4104
4225
|
if (kind === 'drawings' && files.length > 20) {
|
|
4105
4226
|
showToast('Choose up to 20 drawings for a new project.', 'warn');
|
|
4106
4227
|
return false;
|
|
@@ -4945,9 +5066,13 @@
|
|
|
4945
5066
|
const nav = opts || {};
|
|
4946
5067
|
// Latest navigation wins from the first line: an older open still waiting on a lookup must not replace a newer one.
|
|
4947
5068
|
const navToken = ++openNavSeq;
|
|
5069
|
+
// A caller acting for someone (a chat card's "Open in the model", #2450) can be overtaken by that
|
|
5070
|
+
// person's next click, which may not open a project at all. Until this open changes anything, it
|
|
5071
|
+
// also gives way when its caller says it is no longer wanted.
|
|
5072
|
+
const unwanted = () => navToken !== openNavSeq || (typeof nav.stillWanted === 'function' && !nav.stillWanted());
|
|
4948
5073
|
let p = projects.find((x) => x.id === id);
|
|
4949
5074
|
if (!p) { try { p = (await api('/api/projects')).projects.find((x) => x.id === id); } catch { /* fall through */ } }
|
|
4950
|
-
if (
|
|
5075
|
+
if (unwanted()) return STAYED_IN_PROJECT;
|
|
4951
5076
|
if (!p) { showToast('Project not found — it may have been archived.', 'warn'); return loadProjects(); }
|
|
4952
5077
|
if (window.flolessWorkspaceRoot?.current()?.available === false) {
|
|
4953
5078
|
if (p.registrationId) window.flolessProjectReconciliation?.openRegistration(p.registrationId);
|
|
@@ -4971,7 +5096,7 @@
|
|
|
4971
5096
|
return;
|
|
4972
5097
|
}
|
|
4973
5098
|
if (!nav.skipLeaveGuard && current && current.id !== p.id && !(await leaveOpenProject(nav.returnFocus))) return STAYED_IN_PROJECT;
|
|
4974
|
-
if (
|
|
5099
|
+
if (unwanted()) return STAYED_IN_PROJECT;
|
|
4975
5100
|
if (current?.uuid !== p.uuid) revisionNoteEditorGeneration++;
|
|
4976
5101
|
current = p;
|
|
4977
5102
|
// #1890: a new workspace conversation suggests this project's units (the one opened last).
|
|
@@ -4988,6 +5113,7 @@
|
|
|
4988
5113
|
if (pendingPresenceToast) pendingPresenceToast();
|
|
4989
5114
|
pendingPresenceToast = null;
|
|
4990
5115
|
exportState = null;
|
|
5116
|
+
exportStateFrom = null;
|
|
4991
5117
|
exportUnits = null; // a new project's units arrive with its export listing; never inherit the last one's
|
|
4992
5118
|
renderReadinessState = null;
|
|
4993
5119
|
let sourceStateProbe = null;
|
|
@@ -5032,13 +5158,17 @@
|
|
|
5032
5158
|
// would open an empty pane, so it lands on its Checker step. Scoped to Drawing Checker on purpose:
|
|
5033
5159
|
// Revit and Tekla keep their existing behaviour for a carried-over step.
|
|
5034
5160
|
if (isDrawingCheckProject(p) && !d.steps.some((step) => step.key === initialStep)) initialStep = 'model';
|
|
5161
|
+
// A sourceless project (General, #2470) has no Model, Drawings, Exports or History step; a step carried
|
|
5162
|
+
// over from another project lands on its first step instead of a pane it does not have.
|
|
5163
|
+
if (d.sourceless && !d.steps.some((step) => step.key === initialStep)) initialStep = d.steps[0].key;
|
|
5035
5164
|
if ((d.filter || isModelSourceProject(p)) && ['model', 'exports', 'history'].includes(initialStep)) {
|
|
5036
5165
|
pendingPresenceStep = { projectId: p.id, step: initialStep };
|
|
5037
5166
|
}
|
|
5038
5167
|
// The LIVE app id, deliberately: the frames address the server with it (contract reads, saves),
|
|
5039
5168
|
// and after a rename only the live id resolves. Only the descriptor came from the lineage root.
|
|
5040
5169
|
const qs = `?app=${encodeURIComponent(p.app)}&project=${encodeURIComponent(p.id)}`;
|
|
5041
|
-
|
|
5170
|
+
// No editor (a General project): the model frame stays blank and hidden, never `null?app=…`.
|
|
5171
|
+
frames.model.dataset.want = d.editor ? `${d.editor}${qs}` : '';
|
|
5042
5172
|
frames.drawings.dataset.want = d.filter ? `${d.filter}${qs}` : '';
|
|
5043
5173
|
renderStepTabs(); // paint the tab labels for THIS app before the first step shows
|
|
5044
5174
|
disposeModelEditorFrame('project-open');
|
|
@@ -5126,6 +5256,7 @@
|
|
|
5126
5256
|
function applyModelPresence(present) {
|
|
5127
5257
|
projectContractLifecycle = present;
|
|
5128
5258
|
exportsHasModel = present === 'model';
|
|
5259
|
+
retrySourcelessPresence(present);
|
|
5129
5260
|
renderApprovalHeader();
|
|
5130
5261
|
applyStageGating();
|
|
5131
5262
|
// A lifecycle probe may resolve after the saved-filter card already painted under `unknown`.
|
|
@@ -5134,6 +5265,47 @@
|
|
|
5134
5265
|
if (currentStep === 'drawings' && lastRevState === 'pending') retireRevisionCardForStrip(revCardReq);
|
|
5135
5266
|
}
|
|
5136
5267
|
|
|
5268
|
+
/** Re-ask a General project's lifecycle after a check that settled `unknown` (see SOURCELESS_PRESENCE_RETRIES). */
|
|
5269
|
+
function retrySourcelessPresence(present) {
|
|
5270
|
+
const project = current;
|
|
5271
|
+
if (!project || !wsDescOf(project)?.sourceless) return;
|
|
5272
|
+
// A fresh count per open: "open the project again to check again" is how the person retries.
|
|
5273
|
+
if (sourcelessPresence.projectId !== project.id || sourcelessPresence.openSeq !== openNavSeq) {
|
|
5274
|
+
clearTimeout(sourcelessPresence.timer);
|
|
5275
|
+
sourcelessPresence = { projectId: project.id, openSeq: openNavSeq, tries: 0, gaveUp: false, timer: null };
|
|
5276
|
+
}
|
|
5277
|
+
if (present !== 'unknown') {
|
|
5278
|
+
// A definite answer ends any retry still waiting, so it can never supersede this answer later.
|
|
5279
|
+
clearTimeout(sourcelessPresence.timer);
|
|
5280
|
+
sourcelessPresence = { ...sourcelessPresence, tries: 0, gaveUp: false, timer: null };
|
|
5281
|
+
return;
|
|
5282
|
+
}
|
|
5283
|
+
if (sourcelessPresence.tries >= SOURCELESS_PRESENCE_RETRIES) {
|
|
5284
|
+
if (!sourcelessPresence.gaveUp) console.warn('[workspaces] gave up checking whether a General project holds a model', { projectId: project.id, tries: sourcelessPresence.tries });
|
|
5285
|
+
sourcelessPresence.gaveUp = true;
|
|
5286
|
+
return;
|
|
5287
|
+
}
|
|
5288
|
+
sourcelessPresence.tries += 1;
|
|
5289
|
+
clearTimeout(sourcelessPresence.timer);
|
|
5290
|
+
const openSeq = sourcelessPresence.openSeq;
|
|
5291
|
+
sourcelessPresence.timer = setTimeout(() => {
|
|
5292
|
+
// Only for the same open of the same project: leaving and reopening starts its own count.
|
|
5293
|
+
if (current && current.id === project.id && openNavSeq === openSeq && sourcelessPresence.openSeq === openSeq) {
|
|
5294
|
+
refreshModelPresence(project.id, project.app, true).catch((e) => console.error('[workspaces] could not re-check model presence', e));
|
|
5295
|
+
}
|
|
5296
|
+
}, 2000 * sourcelessPresence.tries);
|
|
5297
|
+
}
|
|
5298
|
+
|
|
5299
|
+
/** "Check again" on a General project whose checks gave up. Returns whether it applied. */
|
|
5300
|
+
function recheckSourcelessPresence() {
|
|
5301
|
+
const project = current;
|
|
5302
|
+
if (!project || !wsDescOf(project)?.sourceless || !sourcelessPresence.gaveUp || sourcelessPresence.projectId !== project.id) return false;
|
|
5303
|
+
sourcelessPresence = { ...sourcelessPresence, tries: 0, gaveUp: false, timer: null };
|
|
5304
|
+
renderApprovalHeader();
|
|
5305
|
+
refreshModelPresence(project.id, project.app, true).catch((e) => console.error('[workspaces] could not re-check model presence', e));
|
|
5306
|
+
return true;
|
|
5307
|
+
}
|
|
5308
|
+
|
|
5137
5309
|
/**
|
|
5138
5310
|
* Hand the saved-checkpoint status to the stage strip, which owns Done / Now / Next for it, and
|
|
5139
5311
|
* report whether the hand-off happened.
|
|
@@ -5206,6 +5378,7 @@
|
|
|
5206
5378
|
exportSourcesState = { status: 'unavailable', data: null, selected: null, open: false };
|
|
5207
5379
|
closeApprovalReview();
|
|
5208
5380
|
exportState = null;
|
|
5381
|
+
exportStateFrom = null;
|
|
5209
5382
|
exportUnits = null; // a new project's units arrive with its export listing; never inherit the last one's
|
|
5210
5383
|
renderReadinessState = null;
|
|
5211
5384
|
resetRevisionState();
|
|
@@ -5248,6 +5421,12 @@
|
|
|
5248
5421
|
b.setAttribute('data-command-id', `shell.workspace-step#${label}`);
|
|
5249
5422
|
}
|
|
5250
5423
|
});
|
|
5424
|
+
// #2568: the tabs read in the kind's own `steps` order (the markup holds every kind's tabs once). The tablist holds
|
|
5425
|
+
// nothing but tabs, so moving a button within it changes only its place, never its state or listeners.
|
|
5426
|
+
for (const st of d.steps) {
|
|
5427
|
+
const b = $stepTabs.querySelector(`button[data-step="${st.key}"]`);
|
|
5428
|
+
if (b) $stepTabs.append(b);
|
|
5429
|
+
}
|
|
5251
5430
|
}
|
|
5252
5431
|
|
|
5253
5432
|
// Everything the server refuses on write is refused again on read. A progress record is replayed
|
|
@@ -5893,7 +6072,7 @@
|
|
|
5893
6072
|
? 'Drawing read not started · Open Requests — if Start in AI Chat is shown, choose it; otherwise copy the request into Claude Code or Codex. Then return to review and save the Drawing Filter.'
|
|
5894
6073
|
: projectContractLifecycle === 'filter-checkpoint'
|
|
5895
6074
|
? 'Drawing read needs restarting · The earlier drawing request is no longer available. Attach the drawing set again in Drawing Filter to restart the read.'
|
|
5896
|
-
: 'Start in Drawing Filter by attaching a PDF
|
|
6075
|
+
: 'Start in Drawing Filter by attaching a PDF drawing set. The Model, Exports, and History stages unlock after the first steel model is created.';
|
|
5897
6076
|
paintStageGuidance(guidance, failedInitial || unavailableInitial ? 'failed' : 'info');
|
|
5898
6077
|
if (waitingForInitial && revCardReq?.prepassReady && !revCardReq?.filterCheckpointCurrent) {
|
|
5899
6078
|
appendStageGuidanceFilterAction();
|
|
@@ -5976,6 +6155,13 @@
|
|
|
5976
6155
|
const show = k === s && (k !== 'drawings' || drawingsHasFrame);
|
|
5977
6156
|
f.hidden = !show;
|
|
5978
6157
|
if (show && !f.dataset.loaded && f.dataset.want) { f.src = f.dataset.want; f.dataset.loaded = '1'; }
|
|
6158
|
+
// Coming back to an editor that stayed loaded while hidden: tell it, so it can read again what changed on
|
|
6159
|
+
// another step meanwhile (the Drawing Checker's references after a Knowledge change, #2482). Others ignore it.
|
|
6160
|
+
else if (show && k === 'model' && f.dataset.loaded) {
|
|
6161
|
+
const project = typeof current !== 'undefined' ? current : null;
|
|
6162
|
+
try { if (project) f.contentWindow?.postMessage({ type: 'floless:step-shown', step: s, projectId: project.id }, location.origin); }
|
|
6163
|
+
catch { /* the frame is between documents */ }
|
|
6164
|
+
}
|
|
5979
6165
|
}
|
|
5980
6166
|
if (window.flolessLeftPane) {
|
|
5981
6167
|
window.flolessLeftPane.setWorkspaceModelVisible(s === 'model');
|
|
@@ -5992,7 +6178,17 @@
|
|
|
5992
6178
|
// extracted and evaluated on its own by workspace-instructor-handoff.test.ts, and a closure
|
|
5993
6179
|
// variable it cannot see is a ReferenceError there. It sits at the end of the step-tabs row now
|
|
5994
6180
|
// (the breadcrumb row that used to hold it is gone), and is a Drawings-step control either way.
|
|
5995
|
-
{ const a = document.getElementById('ws-attach-revision');
|
|
6181
|
+
{ const a = document.getElementById('ws-attach-revision');
|
|
6182
|
+
const steel = d === WORKSPACE_APPS['steel-model'];
|
|
6183
|
+
if (a) {
|
|
6184
|
+
a.hidden = s !== 'drawings' || d?.serverAuthorizedOnly === true;
|
|
6185
|
+
a.dataset.tip = steel
|
|
6186
|
+
? 'Attach revised PDF drawings — your terminal AI reads them into a new version'
|
|
6187
|
+
: 'Attach a revised drawing set (PDF or image) — your terminal AI reads it into a new version';
|
|
6188
|
+
}
|
|
6189
|
+
const input = document.getElementById('ws-revision-file');
|
|
6190
|
+
if (input) input.accept = steel ? '.pdf' : '.pdf,image/*';
|
|
6191
|
+
}
|
|
5996
6192
|
renderRevisionCard(); // reflect any pending/failed revision read (card shows only on the Drawings step)
|
|
5997
6193
|
// The conversion offer is Model-step scoped, and re-derived on every entry rather than cached:
|
|
5998
6194
|
// the project's contract can change under this shell (a revision read, another tab, the editor's
|
|
@@ -6071,6 +6267,14 @@
|
|
|
6071
6267
|
|| !['clean', 'dirty', 'saving', 'error', 'conflict'].includes(message.state)) return;
|
|
6072
6268
|
modelContractSaveState = { projectId: current.id, appId: current.app, state: message.state, generation: message.generation };
|
|
6073
6269
|
});
|
|
6270
|
+
// The Drawing Checker's "Use the design set" sends a person to this project's Knowledge step, where the design
|
|
6271
|
+
// set lives (epic #2399 0d-dc). Only from the editor frame of the project on screen, and only to Knowledge.
|
|
6272
|
+
window.addEventListener('message', (event) => {
|
|
6273
|
+
const message = event.data;
|
|
6274
|
+
if (event.origin !== location.origin || event.source !== frames.model?.contentWindow
|
|
6275
|
+
|| !message || message.type !== 'floless:open-knowledge' || !current || message.projectId !== current.id) return;
|
|
6276
|
+
setStep('knowledge');
|
|
6277
|
+
});
|
|
6074
6278
|
const approvalPhaseText = {
|
|
6075
6279
|
saving: 'Saving model edits…', comparing: 'Comparing changes…', approving: 'Approving and compiling…',
|
|
6076
6280
|
reconciling: 'Reconciling approval…', approved: 'Approved', failed: 'Nothing was approved.', stale: 'The review changed.',
|
|
@@ -6462,7 +6666,10 @@
|
|
|
6462
6666
|
const accepted = res && res.version && res.version.approval && res.version.approval.acceptedImportFindings;
|
|
6463
6667
|
const headline = accepted ? importFindingsCopy(accepted).approved(Number.isInteger(n) ? n : null)
|
|
6464
6668
|
: `Approved${Number.isInteger(n) ? ` as v${n}` : ''}.`;
|
|
6465
|
-
|
|
6669
|
+
// #2449: an approval resting on connection assumptions (or one whose record could not be read) is never announced
|
|
6670
|
+
// as a plain approval either; the server's own sentence, the same one History shows.
|
|
6671
|
+
const assumed = res && res.connectionAssumptions && typeof res.connectionAssumptions.note === 'string' ? res.connectionAssumptions.note : '';
|
|
6672
|
+
showToast(`${headline} ${assumed ? `${assumed} ` : ''}${pending ? `${pending} change${pending === 1 ? ' remains' : 's remain'} pending${saved ? ' in Saved work' : ''}; approved exports omit them unless you explicitly choose DRAFT.` : 'No changes remain pending.'}`, 'ok');
|
|
6466
6673
|
track('workspace_project_approved', { app: project.app });
|
|
6467
6674
|
if (bridge.markWorkspaceApproved && wsDescOf(project)?.docGuide) bridge.markWorkspaceApproved(project.app);
|
|
6468
6675
|
if (!$wsExports.hidden) safeRenderExports('after approving this version');
|
|
@@ -6473,7 +6680,7 @@
|
|
|
6473
6680
|
: 'No changes remain pending.';
|
|
6474
6681
|
// The footer described the decision ("…will be approved…"); the decision has happened.
|
|
6475
6682
|
$approvalCounts.textContent = '';
|
|
6476
|
-
$approvalBody.innerHTML = `<div class="approval-notice approval-notice-success"><b>${escapeHtml(headline)}</b> The approved model and compiled workflow are ready.${revisionNoteStatus ? ' ' + escapeHtml(revisionNoteStatus) : ''}${accepted ? ' The findings stay listed in the Audit tab.' : ''}</div>`;
|
|
6683
|
+
$approvalBody.innerHTML = `<div class="approval-notice approval-notice-success"><b>${escapeHtml(headline)}</b> The approved model and compiled workflow are ready.${assumed ? ' ' + escapeHtml(assumed) : ''}${revisionNoteStatus ? ' ' + escapeHtml(revisionNoteStatus) : ''}${accepted ? ' The findings stay listed in the Audit tab.' : ''}</div>`;
|
|
6477
6684
|
setApprovalPhase('approved', accepted ? headline : `Approved${Number.isInteger(n) ? ` as v${n}` : ''}`);
|
|
6478
6685
|
$approvalClose.focus();
|
|
6479
6686
|
}
|
|
@@ -6905,6 +7112,8 @@
|
|
|
6905
7112
|
});
|
|
6906
7113
|
$approveBtn?.addEventListener('click', () => {
|
|
6907
7114
|
if ($approveBtn.getAttribute('aria-disabled') === 'true') {
|
|
7115
|
+
// "Couldn’t check project" on a General project: the click is the "check again" its tip offers.
|
|
7116
|
+
if (recheckSourcelessPresence()) return;
|
|
6908
7117
|
// Re-ask only where the answer can differ. A failed probe can; so can `no-contract`, which stops
|
|
6909
7118
|
// being true the moment anything writes a model — and the writers we know about say so
|
|
6910
7119
|
// explicitly, but this is the backstop for the ones we do not (another tab, the terminal AI, a
|
|
@@ -7028,6 +7237,9 @@
|
|
|
7028
7237
|
let lastStepHeadHtml = null; // same repaint-iff-changed contract as lastRefsHtml
|
|
7029
7238
|
let lastViewKey = null; // identity of what the viewer host is currently showing
|
|
7030
7239
|
let kbFocusSourceId = null; // consumed once after a repaint, to restore focus to a filename button
|
|
7240
|
+
// The design set the person just changed from this screen: the first repaint that shows it (whichever read lands it,
|
|
7241
|
+
// this screen's own or the change event's) brings it into view and keeps keyboard focus in the column.
|
|
7242
|
+
let kbFocusDesignSet = null; // { sourceId } | null
|
|
7031
7243
|
let kbAdjustBusy = null; // project id of an in-flight Adjust submit (or null) — scoped to the
|
|
7032
7244
|
// project so switching away can't strand another project's box; also the
|
|
7033
7245
|
// re-entry guard (no duplicate queue). See kbAdjustActive.
|
|
@@ -7049,7 +7261,8 @@
|
|
|
7049
7261
|
* has a non-empty draft. Self-heals — the moment it's none of those, the next tick repaints fresh. */
|
|
7050
7262
|
function kbAdjustActive() {
|
|
7051
7263
|
if (kbAdjustBusy && current && kbAdjustBusy === current.id) return true;
|
|
7052
|
-
|
|
7264
|
+
// By its own input: the design set's sheet index is a .kb-adjust disclosure too, and comes first (#2399 0b).
|
|
7265
|
+
const det = $wsKnowledge.querySelector('#kb-adjust-input')?.closest('.kb-adjust');
|
|
7053
7266
|
if (!det) return false;
|
|
7054
7267
|
if (det.contains(document.activeElement)) return true;
|
|
7055
7268
|
const ta = det.querySelector('#kb-adjust-input');
|
|
@@ -7092,6 +7305,7 @@
|
|
|
7092
7305
|
kbGraphIndex = null;
|
|
7093
7306
|
lastStepHeadHtml = null;
|
|
7094
7307
|
$wsKnowledge.querySelector('.kb-g-overview')?.remove(); // and the button already on screen goes now
|
|
7308
|
+
kbGraphStopWorker(); // #2491 R6.9: a layout still running for the previous project is dropped
|
|
7095
7309
|
}
|
|
7096
7310
|
|
|
7097
7311
|
function stopKnowledgePoll() { if (knowledgePoll) { clearInterval(knowledgePoll); knowledgePoll = null; } }
|
|
@@ -7112,12 +7326,15 @@
|
|
|
7112
7326
|
async function loadKnowledgeState(proj) {
|
|
7113
7327
|
// Each read is bounded (#1604): the 3-second poll skips its ticks while a render is out, so a
|
|
7114
7328
|
// request that never answered would stop the column refreshing for good.
|
|
7115
|
-
const bounded = () => ({
|
|
7116
|
-
const [status, reqs, company] = await Promise.all([
|
|
7329
|
+
const bounded = () => ({ timeoutMs: 90_000 });
|
|
7330
|
+
const [status, reqs, company, designSet] = await Promise.all([
|
|
7117
7331
|
api(kbUrl(proj.id, '/status'), bounded()),
|
|
7118
7332
|
api('/api/requests', bounded()).catch(() => []),
|
|
7119
7333
|
api(`/api/company-knowledge?projectId=${encodeURIComponent(proj.id)}`, bounded())
|
|
7120
7334
|
.catch((error) => ({ configured: false, loadError: String((error && error.message) || error) })),
|
|
7335
|
+
// #2399 slice 0b: a design set that cannot be read is said as such, never as "none".
|
|
7336
|
+
api(`/api/projects/${encodeURIComponent(proj.id)}/design-set`, bounded())
|
|
7337
|
+
.catch(() => ({ status: 'unknown', revision: 0, warnings: [{ code: 'unreadable', message: 'FloLess could not read the design set just now.' }] })),
|
|
7121
7338
|
]);
|
|
7122
7339
|
const list = Array.isArray(reqs) ? reqs : (reqs.requests || []);
|
|
7123
7340
|
const manifest = status.manifest || { revision: 0, currentGeneration: null, sources: [] };
|
|
@@ -7126,8 +7343,11 @@
|
|
|
7126
7343
|
sources: Array.isArray(manifest.sources) ? manifest.sources : [],
|
|
7127
7344
|
currentGeneration: status.currentGeneration || null,
|
|
7128
7345
|
organize: status.organize || null,
|
|
7346
|
+
// #2491 R6.9: the person's categories and where each reference sits.
|
|
7347
|
+
categories: status.categories || { v: 1, revision: 0, categories: [], placements: {}, state: 'absent' },
|
|
7129
7348
|
queued: list.filter((r) => r && r.type === 'knowledge-organize' && r.project === proj.id),
|
|
7130
7349
|
company,
|
|
7350
|
+
designSet,
|
|
7131
7351
|
};
|
|
7132
7352
|
}
|
|
7133
7353
|
|
|
@@ -7152,11 +7372,40 @@
|
|
|
7152
7372
|
: `${(n / (1024 * 1024)).toFixed(1)} MB`);
|
|
7153
7373
|
function kbIcon(mime) {
|
|
7154
7374
|
const m = String(mime || '');
|
|
7375
|
+
// #2491 R6.3: Word, Excel and email, in the same glyph family. Matched on the exact stored types (the server
|
|
7376
|
+
// stores one canonical type per kind, macro-enabled files included).
|
|
7377
|
+
if (m === KB_MIME_DOCX) return { cls: 'doc', glyph: '▥' };
|
|
7378
|
+
if (m === KB_MIME_XLSX) return { cls: 'sheet', glyph: '◧' };
|
|
7379
|
+
if (m === KB_MIME_EML || m === KB_MIME_MSG) return { cls: 'mail', glyph: '◩' };
|
|
7155
7380
|
if (m.includes('pdf')) return { cls: 'pdf', glyph: '▤' };
|
|
7156
7381
|
if (m.startsWith('image/')) return { cls: 'img', glyph: '▣' };
|
|
7157
7382
|
if (m.includes('csv')) return { cls: 'sheet', glyph: '◧' };
|
|
7158
7383
|
return { cls: 'txt', glyph: '▦' };
|
|
7159
7384
|
}
|
|
7385
|
+
// #2491 R6.3: the office formats whose TEXT FloLess reads; the original is only ever downloaded.
|
|
7386
|
+
const KB_MIME_DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
7387
|
+
const KB_MIME_XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
7388
|
+
const KB_MIME_MSG = 'application/vnd.ms-outlook';
|
|
7389
|
+
const KB_MIME_EML = 'message/rfc822';
|
|
7390
|
+
const KB_OFFICE_MIMES = new Set([KB_MIME_DOCX, KB_MIME_XLSX, KB_MIME_MSG, KB_MIME_EML]);
|
|
7391
|
+
const kbIsEmail = (mime) => mime === KB_MIME_EML || mime === KB_MIME_MSG;
|
|
7392
|
+
/** The row's text-read chips: nothing when it was read in full. Literal copy; reasons live in the viewer. */
|
|
7393
|
+
function kbTextChips(s) {
|
|
7394
|
+
if (s.kind !== 'file' || !KB_OFFICE_MIMES.has(s.mime)) return '';
|
|
7395
|
+
const t = s.text;
|
|
7396
|
+
const state = t ? t.state : 'pending';
|
|
7397
|
+
const chip = state === 'partial'
|
|
7398
|
+
? '<span class="kb-chip new" data-tip="FloLess could read only part of this file’s text. Open it to see what was missed.">partly read</span>'
|
|
7399
|
+
: state === 'failed'
|
|
7400
|
+
? '<span class="kb-chip err" data-tip="FloLess couldn’t read this file’s text. The file is kept. Open it for the reason.">text not read</span>'
|
|
7401
|
+
: state === 'pending'
|
|
7402
|
+
? '<span class="kb-chip" data-tip="FloLess reads this file’s text when you Organize or open it.">not read yet</span>'
|
|
7403
|
+
: '';
|
|
7404
|
+
const macros = t && t.macros
|
|
7405
|
+
? '<span class="kb-chip" data-tip="Contains macros. FloLess only reads its text and never runs them.">macros</span>' : '';
|
|
7406
|
+
return chip + macros;
|
|
7407
|
+
}
|
|
7408
|
+
|
|
7160
7409
|
// Literal chip copy per state (never interpolated from the server); unknown state falls back escaped.
|
|
7161
7410
|
const KB_CHIP = {
|
|
7162
7411
|
new: ['new', 'new'],
|
|
@@ -7191,8 +7440,272 @@
|
|
|
7191
7440
|
return `<span class="kb-chip ${cls}">${escapeHtml(state)}</span>`;
|
|
7192
7441
|
}
|
|
7193
7442
|
|
|
7194
|
-
|
|
7443
|
+
// ── The project's design set (#2399 slice 0b) ───────────────────────────────────────────────────
|
|
7444
|
+
// One reference marked as the drawing set the job is built from. FloLess never reads a title block: the sheet index
|
|
7445
|
+
// is supplied by the person's AI and always labelled "not checked". Every warning the server gives is shown as it
|
|
7446
|
+
// gave it, and none blocks anything.
|
|
7447
|
+
const KB_DRAWING_MIMES = new Set(['application/pdf', 'image/png', 'image/jpeg', 'image/webp']);
|
|
7448
|
+
const KEY_DESIGN_SET = 'the design set'; // design-set-store.ts: the revision a stale screen is caught by
|
|
7449
|
+
const KB_DS_SUPPLIER = { chat: 'your AI', cli: 'your terminal AI', person: 'you' };
|
|
7450
|
+
const KEY_DS_PROJECT = 'the project'; // design-set-store.ts KEY_PROJECT
|
|
7451
|
+
const KEY_DS_REFERENCE = 'the chosen reference'; // design-set-store.ts KEY_DESIGN_REFERENCE
|
|
7452
|
+
/** The design-set revision this screen shows, written into each control it draws (never read from newer state). */
|
|
7453
|
+
const kbDsRev = (st) => (st && st.designSet && typeof st.designSet.revisionKey === 'string' && st.designSet.status !== 'unknown'
|
|
7454
|
+
? st.designSet.revisionKey : '(unreadable)');
|
|
7455
|
+
function kbActiveDesignSet(st) {
|
|
7456
|
+
const ds = st && st.designSet;
|
|
7457
|
+
return ds && (ds.status === 'registered' || ds.status === 'changed') && ds.designSet ? ds.designSet : null;
|
|
7458
|
+
}
|
|
7459
|
+
function kbIsDesignSet(s, st) {
|
|
7460
|
+
const active = kbActiveDesignSet(st);
|
|
7461
|
+
return !!active && active.sourceId === s.sourceId && active.blobSha256 === s.blobSha256;
|
|
7462
|
+
}
|
|
7463
|
+
/** "Use as design set" on a drawing row that is not the design set. Hidden, never disabled, everywhere else. */
|
|
7464
|
+
function kbDesignSetUse(s, st) {
|
|
7465
|
+
if (!st || !st.designSet) return '';
|
|
7466
|
+
if (s.kind === 'observation' || !s.useAsKb || !KB_DRAWING_MIMES.has(s.mime) || kbIsDesignSet(s, st)) return '';
|
|
7467
|
+
const name = s.filename || 'untitled';
|
|
7468
|
+
return '<div class="kb-ds-use-line"><button type="button" class="kb-link kb-ds-use" ' +
|
|
7469
|
+
`data-kb-ds-use="${escapeAttr(s.sourceId)}" data-kb-ds-rev="${escapeAttr(kbDsRev(st))}" data-kb-ds-blob="${escapeAttr(s.blobSha256)}" data-command-id="shell.kb-design-set-use" ` +
|
|
7470
|
+
`aria-label="Use “${escapeAttr(name)}” as the design set" data-tip="Mark this as the drawing set the job is built from">Use as design set</button></div>`;
|
|
7471
|
+
}
|
|
7472
|
+
// ── The design set as issues (#2399 slice 0c) ───────────────────────────────────────────────────
|
|
7473
|
+
// Each issue is one release of the drawings (Rev C, IFC), listed like the revision block of a title sheet: newest
|
|
7474
|
+
// first, one current. Nothing here deletes: a file or an issue is withdrawn and restored, and a file removed from the
|
|
7475
|
+
// references stays in its issue ("Copy kept"). Every sentence the server gives is shown as it gave it.
|
|
7476
|
+
const KB_DS_FILES_SHOWN = 5;
|
|
7477
|
+
const KB_DS_ORIGIN = { 'drawing-filter': 'Added from the Drawing Filter', 'project-intake': 'Added with the first upload', v1: 'Chosen as the design set before issues', knowledge: '' };
|
|
7478
|
+
const KB_DS_PRESENCE = {
|
|
7479
|
+
removed: ['Copy kept', 'Removed from your references. The design set kept its copy.'],
|
|
7480
|
+
replaced: ['Replaced', 'The reference now holds another file. The design set kept the one it was issued with.'],
|
|
7481
|
+
missing: ['File missing', 'The stored copy of this file is gone. Add the file again.'],
|
|
7482
|
+
};
|
|
7483
|
+
let kbDsOpen = null; // { projectId, ids: Set<issueId> } — which issues are expanded (the current one by default)
|
|
7484
|
+
let kbDsShowAll = new Set(); // issue ids whose whole file list is shown
|
|
7485
|
+
let kbDsPanel = null; // { kind: 'add'|'rename'|'read', issueId?, plan?, error? } — the inline panel that is open
|
|
7486
|
+
let kbDsFocus = null; // { issueId, control } — what takes focus after the repaint an action causes
|
|
7487
|
+
|
|
7488
|
+
/** Issue files as viewer rows, so a file whose reference was removed still previews from its issue. */
|
|
7489
|
+
function kbIssueFileRows(st) {
|
|
7490
|
+
const out = [];
|
|
7491
|
+
const issues = (st && st.designSet && st.designSet.issues) || [];
|
|
7492
|
+
for (const issue of issues) {
|
|
7493
|
+
for (const f of issue.files || []) {
|
|
7494
|
+
out.push({ sourceId: `ds:${issue.issueId}:${f.index}`, blobSha256: f.blobSha256, filename: f.filename, mime: f.mime, bytes: f.bytes,
|
|
7495
|
+
kind: 'issue-file', rawUrl: current ? `/api/projects/${encodeURIComponent(current.id)}/design-set/issues/${encodeURIComponent(issue.issueId)}/files/${f.index}` : '' });
|
|
7496
|
+
}
|
|
7497
|
+
}
|
|
7498
|
+
return out;
|
|
7499
|
+
}
|
|
7500
|
+
/** A viewer row by id: a reference, or an issue file. */
|
|
7501
|
+
function kbViewRow(st, id) {
|
|
7502
|
+
return (st.sources || []).find((s) => s.sourceId === id) || kbIssueFileRows(st).find((r) => r.sourceId === id) || null;
|
|
7503
|
+
}
|
|
7504
|
+
/** Is this reference a file of any issue (by its row, or by the bytes it holds)? Those are listed under their issue. */
|
|
7505
|
+
function kbInDesignSet(s, st) {
|
|
7506
|
+
const issues = (st && st.designSet && st.designSet.issues) || [];
|
|
7507
|
+
return issues.some((i) => (i.files || []).some((f) => f.sourceId === s.sourceId && f.blobSha256 === s.blobSha256));
|
|
7508
|
+
}
|
|
7509
|
+
function kbDsIsOpen(issue, st) {
|
|
7510
|
+
const proj = current && current.id;
|
|
7511
|
+
if (!kbDsOpen || kbDsOpen.projectId !== proj) kbDsOpen = { projectId: proj, ids: new Set(issue.current ? [issue.issueId] : []) };
|
|
7512
|
+
return kbDsOpen.ids.has(issue.issueId) || (issue.current && !kbDsOpen.touched);
|
|
7513
|
+
}
|
|
7514
|
+
function kbDsUses(f) {
|
|
7515
|
+
if (f.usedBy === 'unknown') return '<span class="kb-chip" data-tip="FloLess could not check which reads used this file">Use unknown</span>';
|
|
7516
|
+
const versions = (Array.isArray(f.usedBy) ? f.usedBy : []).filter((u) => u.version).map((u) => u.version);
|
|
7517
|
+
if (!versions.length) return '';
|
|
7518
|
+
const v = versions.slice(0, 2).map((n) => `v${n}`).join(', ') + (versions.length > 2 ? ` +${versions.length - 2}` : '');
|
|
7519
|
+
return `<span class="kb-chip" data-tip="${escapeAttr(`Model ${versions.length === 1 ? 'version' : 'versions'} ${versions.join(', ')} ${versions.length === 1 ? 'was' : 'were'} read from this file and keep their own copy`)}">Used by ${escapeHtml(v)}</span>`;
|
|
7520
|
+
}
|
|
7521
|
+
|
|
7522
|
+
function kbIssueFileRow(f, issue, st) {
|
|
7523
|
+
const row = (st.sources || []).find((s) => s.sourceId === f.sourceId && s.blobSha256 === f.blobSha256);
|
|
7524
|
+
const openId = row ? row.sourceId : `ds:${issue.issueId}:${f.index}`;
|
|
7525
|
+
const isOpen = viewer.mode === 'file' && viewer.sourceId === openId;
|
|
7526
|
+
const ico = kbIcon(f.mime);
|
|
7527
|
+
const name = f.filename || 'untitled';
|
|
7528
|
+
const p = KB_DS_PRESENCE[f.presence];
|
|
7529
|
+
// The file as the Instructor names this row: its issue and number, and its name for the person.
|
|
7530
|
+
const fileKey = `${issue.issueId}:${f.index}`;
|
|
7531
|
+
const fileLabel = ` data-command-instance-label="${escapeAttr(`“${name}” of ${issue.label}`)}"`;
|
|
7532
|
+
const chips = (f.withdrawn ? '<span class="kb-chip kb-chip-wd">Withdrawn</span>' : '') +
|
|
7533
|
+
(p ? `<span class="kb-chip kb-chip-presence" data-tip="${escapeAttr(p[1])}">${p[0]}</span>` : '') + kbDsUses(f);
|
|
7534
|
+
// A file still in use has a ✕ (Withdraw, or remove its reference); a withdrawn one has Restore. Neither is shown disabled.
|
|
7535
|
+
// A file in use has a ✕ (Withdraw, or remove its reference). A withdrawn one has Restore, and keeps a ✕ to remove its
|
|
7536
|
+
// reference while the reference is there — its knowledge-base switch stays too. Nothing is shown disabled.
|
|
7537
|
+
const restore = f.withdrawn
|
|
7538
|
+
? `<button type="button" class="kb-link kb-ds-frestore" data-kb-ds-frestore="${f.index}" data-kb-ds-issue="${escapeAttr(issue.issueId)}" data-kb-ds-rev="${escapeAttr(kbDsRev(st))}" data-command-id="shell.kb-design-file-restore#${escapeAttr(fileKey)}"${fileLabel} aria-label="Restore “${escapeAttr(name)}” to ${escapeAttr(issue.label)}" data-tip="Put this file back into use in the issue">Restore</button>`
|
|
7539
|
+
: '';
|
|
7540
|
+
const x = !f.withdrawn || row
|
|
7541
|
+
? `<button type="button" class="kb-x" data-kb-ds-fx="${f.index}" data-kb-ds-issue="${escapeAttr(issue.issueId)}" data-kb-ds-rev="${escapeAttr(kbDsRev(st))}"${row ? ` data-kb-ds-row="${escapeAttr(row.sourceId)}"` : ''}${f.withdrawn ? ' data-kb-ds-fwd' : ''} data-command-id="shell.kb-design-file-remove#${escapeAttr(fileKey)}"${fileLabel} aria-label="${f.withdrawn ? 'Remove the reference' : 'Withdraw or remove'} “${escapeAttr(name)}”" data-tip="${f.withdrawn ? 'Remove this file from your references; the design set keeps its copy' : 'Withdraw this file from the issue'}">✕</button>`
|
|
7542
|
+
: '';
|
|
7543
|
+
const act = restore + x;
|
|
7544
|
+
return `<li class="kb-ds-file${f.withdrawn ? ' wd' : ''}"${isOpen ? ' aria-current="true"' : ''}>` +
|
|
7545
|
+
`<span class="kb-fico ${ico.cls}" aria-hidden="true">${ico.glyph}</span>` +
|
|
7546
|
+
`<div class="kb-fbody"><button type="button" class="kb-fname" data-kb-open="${escapeAttr(openId)}" data-command-id="shell.kb-design-file-preview#${escapeAttr(fileKey)}"${fileLabel} data-tip="Preview “${escapeAttr(name)}”">${escapeHtml(name)}</button>` +
|
|
7547
|
+
(chips ? `<div class="kb-fmeta">${chips}${p ? `<span class="sr-only">${escapeHtml(p[1])}</span>` : ''}</div>` : '') + '</div>' +
|
|
7548
|
+
(row ? `<button type="button" class="kb-toggle" role="switch" aria-checked="${row.useAsKb ? 'true' : 'false'}" data-kb-toggle data-kb-toggle-id="${escapeAttr(row.sourceId)}" data-command-id="shell.kb-design-file-knowledge#${escapeAttr(fileKey)}"${fileLabel} ` +
|
|
7549
|
+
`aria-label="Use “${escapeAttr(name)}” as knowledge" data-tip="${row.useAsKb ? 'Included in the knowledge base — click to exclude' : 'Not in the knowledge base — click to include it when you organize'}"></button>` : '') +
|
|
7550
|
+
act + '</li>';
|
|
7551
|
+
}
|
|
7552
|
+
|
|
7553
|
+
function kbIssuePanel(issue, st) {
|
|
7554
|
+
if (!kbDsPanel || kbDsPanel.issueId !== issue.issueId) return '';
|
|
7555
|
+
const err = kbDsPanel.error ? `<div class="kb-ds-err" role="alert">${escapeHtml(kbDsPanel.error)}${kbDsPanel.openRequests ? ' <button type="button" class="kb-link" data-kb-ds-requests data-command-id="shell.requests-open">Open Requests</button>' : ''}</div>` : '';
|
|
7556
|
+
if (kbDsPanel.kind === 'rename') {
|
|
7557
|
+
return `<div class="kb-ds-panel" role="group" aria-labelledby="kb-ds-ph-${escapeAttr(issue.issueId)}">` +
|
|
7558
|
+
`<div class="kb-ds-ph" id="kb-ds-ph-${escapeAttr(issue.issueId)}">Rename this issue</div>` +
|
|
7559
|
+
'<label class="kb-ds-lbl" for="kb-ds-label">Label</label>' +
|
|
7560
|
+
`<input class="kb-adjust-input kb-ds-in" id="kb-ds-label" data-command-id="shell.kb-design-panel-label" maxlength="60" value="${escapeAttr(kbDsPanel.label ?? issue.label)}" autocomplete="off">` +
|
|
7561
|
+
'<label class="kb-ds-lbl" for="kb-ds-date">Issue date <span class="kb-ds-opt">(optional, YYYY-MM-DD)</span></label>' +
|
|
7562
|
+
`<input class="kb-adjust-input kb-ds-in" id="kb-ds-date" data-command-id="shell.kb-design-panel-date" maxlength="10" inputmode="numeric" placeholder="2026-10-17" value="${escapeAttr(kbDsPanel.date ?? (issue.issuedOn || ''))}" autocomplete="off">` +
|
|
7563
|
+
err + '<div class="kb-ds-pact"><button type="button" class="btn-mini" data-kb-ds-cancel data-command-id="shell.kb-design-panel-cancel">Cancel</button>' +
|
|
7564
|
+
`<button type="button" class="btn-mini primary" data-kb-ds-rename-go="${escapeAttr(issue.issueId)}" data-kb-ds-rev="${escapeAttr(kbDsPanel.rev || kbDsRev(st))}" data-command-id="shell.kb-design-issue-rename-save">Save</button></div></div>`;
|
|
7565
|
+
}
|
|
7566
|
+
if (kbDsPanel.kind === 'read') {
|
|
7567
|
+
const plan = kbDsPanel.plan;
|
|
7568
|
+
if (!plan) return '<div class="kb-ds-panel"><div class="kb-fmeta">Checking the files…</div></div>';
|
|
7569
|
+
const chosen = kbDsPanel.chosen || new Set(plan.included.map((f) => f.index));
|
|
7570
|
+
const already = Array.isArray(plan.alreadyRead) ? new Set(plan.alreadyRead) : new Set();
|
|
7571
|
+
const byIndex = new Map((issue.files || []).map((f) => [f.index, f]));
|
|
7572
|
+
// Files that can still be chosen for this read are ticks; the rest are listed with the server's reason.
|
|
7573
|
+
const CHOOSABLE = new Set(['over-limit', 'not-chosen', 'read-before']);
|
|
7574
|
+
const left = new Map(plan.skipped.map((s) => [s.index, s]));
|
|
7575
|
+
const usable = (issue.files || []).filter((f) => !left.has(f.index) || CHOOSABLE.has(left.get(f.index).code) || chosen.has(f.index));
|
|
7576
|
+
const items = usable.map((f) => {
|
|
7577
|
+
const id = `kb-ds-r-${f.index}`;
|
|
7578
|
+
const note = already.has(f.index) ? ' <span class="kb-ds-opt">already read</span>' : '';
|
|
7579
|
+
return `<li><input type="checkbox" id="${id}" data-kb-ds-pick="${f.index}" data-command-id="shell.kb-design-read-pick#${escapeAttr(`${issue.issueId}:${f.index}`)}" data-command-instance-label="${escapeAttr(`“${f.filename}”`)}"${chosen.has(f.index) ? ' checked' : ''}>` +
|
|
7580
|
+
`<label for="${id}">${escapeHtml(f.filename)}${note}</label></li>`;
|
|
7581
|
+
}).join('');
|
|
7582
|
+
const out = plan.skipped.filter((s) => !usable.some((f) => f.index === s.index))
|
|
7583
|
+
.map((s) => `<li><span class="kb-ds-num">${escapeHtml((byIndex.get(s.index) || s).filename)}</span> — ${escapeHtml(s.reason)}</li>`).join('');
|
|
7584
|
+
const n = chosen.size;
|
|
7585
|
+
const over = n > 40 ? '<div class="kb-ds-note">Only 40 files are read at a time, so the first 40 you ticked are read now. Read the rest next: the files no read has covered yet are ticked by default.</div>' : '';
|
|
7586
|
+
return `<div class="kb-ds-panel" role="group" aria-labelledby="kb-ds-ph-${escapeAttr(issue.issueId)}">` +
|
|
7587
|
+
`<div class="kb-ds-ph" id="kb-ds-ph-${escapeAttr(issue.issueId)}">Read “${escapeHtml(issue.label)}” into the model</div>` +
|
|
7588
|
+
`<div class="kb-ds-note">FloLess queues one drawing read for your AI. It proposes changes to the model, and nothing is applied until you review them.${plan.beingRead.length ? ' A read of some of these files is still open in Requests.' : ''}${plan.alreadyRead === 'unknown' ? ' FloLess could not check which files were read before.' : ''}</div>` +
|
|
7589
|
+
`<div class="kb-ds-lbl">Will be read (${Math.min(n, 40)})</div><ul class="kb-ds-picks" role="list">${items || '<li class="kb-ds-opt">No file of this issue can be read just now.</li>'}</ul>` +
|
|
7590
|
+
(out ? `<div class="kb-ds-lbl">Left out</div><ul class="kb-ds-out" role="list">${out}</ul>` : '') + over + err +
|
|
7591
|
+
'<div class="kb-ds-pact"><button type="button" class="btn-mini" data-kb-ds-cancel data-command-id="shell.kb-design-panel-cancel">Cancel</button>' +
|
|
7592
|
+
(n ? `<button type="button" class="btn-mini primary" data-kb-ds-read-go="${escapeAttr(issue.issueId)}" data-command-id="shell.kb-design-issue-read-go">Read ${Math.min(n, 40)} file${Math.min(n, 40) === 1 ? '' : 's'}</button>` : '') +
|
|
7593
|
+
'</div></div>';
|
|
7594
|
+
}
|
|
7595
|
+
return '';
|
|
7596
|
+
}
|
|
7597
|
+
|
|
7598
|
+
function kbIssueRow(issue, st, canRead) {
|
|
7599
|
+
const open = kbDsIsOpen(issue, st);
|
|
7600
|
+
const files = issue.files || [];
|
|
7601
|
+
const active = files.filter((f) => !f.withdrawn).length;
|
|
7602
|
+
const date = issue.issuedOn ? `<span class="kb-ds-date">${escapeHtml(issue.issuedOn)}</span>` : '';
|
|
7603
|
+
const count = `${active} file${active === 1 ? '' : 's'}${active !== files.length ? ` of ${files.length}` : ''}`;
|
|
7604
|
+
const chips = (issue.current ? '<span class="kb-chip run">Current</span>' : '') + (issue.withdrawn ? '<span class="kb-chip kb-chip-wd">Withdrawn</span>' : '');
|
|
7605
|
+
const all = kbDsShowAll.has(issue.issueId);
|
|
7606
|
+
const shown = all ? files : files.slice(0, KB_DS_FILES_SHOWN);
|
|
7607
|
+
const more = files.length > shown.length
|
|
7608
|
+
? `<button type="button" class="kb-link" data-kb-ds-all="${escapeAttr(issue.issueId)}" data-command-id="shell.kb-design-issue-files-all">Show all ${files.length} files</button>` : '';
|
|
7609
|
+
const warnings = (issue.warnings || []).map((w) => {
|
|
7610
|
+
const use = w.sourceId && (st.sources || []).some((x) => x.sourceId === w.sourceId)
|
|
7611
|
+
? ` <button type="button" class="kb-link" data-kb-ds-use="${escapeAttr(w.sourceId)}" data-kb-ds-rev="${escapeAttr(kbDsRev(st))}" `
|
|
7612
|
+
+ `data-kb-ds-blob="${escapeAttr((st.sources || []).find((x) => x.sourceId === w.sourceId)?.blobSha256 || '')}" data-command-id="shell.kb-design-set-use" `
|
|
7613
|
+
+ 'data-tip="Use the file that was added again as the design set">Use this one</button>' : '';
|
|
7614
|
+
return `<div class="kb-ds-warn-line" role="status"><span class="kb-ds-bang" aria-hidden="true">!</span><span>${escapeHtml(w.message)}${use}</span></div>`;
|
|
7615
|
+
}).join('');
|
|
7616
|
+
const n = (issue.sheets || []).length;
|
|
7617
|
+
const who = KB_DS_SUPPLIER[issue.sheetsSuppliedBy] || 'your AI';
|
|
7618
|
+
const byFile = new Map(files.map((f) => [f.index, f.filename]));
|
|
7619
|
+
const index = n
|
|
7620
|
+
? '<details class="kb-adjust kb-ds-index"><summary class="kb-adjust-summary" data-command-id="shell.kb-design-set-index">' +
|
|
7621
|
+
`<span class="kb-adjust-caret" aria-hidden="true">▸</span>Sheet index (${n})<span class="kb-chip new">not checked</span></summary>` +
|
|
7622
|
+
'<ol class="kb-ds-sheets" role="list" tabindex="0" aria-label="Sheet index">' + issue.sheets.map((sh) =>
|
|
7623
|
+
`<li><span class="kb-ds-num">${escapeHtml(sh.number)}</span> · ${escapeHtml(sh.title || 'untitled')} · p.${escapeHtml(String(sh.page))}${files.length > 1 ? ` <span class="kb-ds-opt">${escapeHtml(byFile.get(sh.file || 0) || '')}</span>` : ''}</li>`).join('') + '</ol>' +
|
|
7624
|
+
`<div class="kb-ds-foot">Supplied by ${escapeHtml(who)}. FloLess does not read title blocks, so check it against the drawings.</div></details>`
|
|
7625
|
+
: '';
|
|
7626
|
+
const origin = KB_DS_ORIGIN[issue.origin && issue.origin.kind] || '';
|
|
7627
|
+
const id = escapeAttr(issue.issueId);
|
|
7628
|
+
const rev = escapeAttr(kbDsRev(st));
|
|
7629
|
+
const actions = '<div class="kb-ds-actions">' +
|
|
7630
|
+
(canRead && active && !issue.withdrawn ? `<button type="button" class="kb-link" data-kb-ds-read="${id}" data-command-id="shell.kb-design-issue-read" data-tip="Choose which files of this issue your AI reads into the model">Read into the model</button>` : '') +
|
|
7631
|
+
(!issue.current ? `<button type="button" class="kb-link" data-kb-ds-current="${id}" data-kb-ds-rev="${rev}" data-command-id="shell.kb-design-issue-current" data-tip="Make this the issue the job is built from">Make current</button>` : '') +
|
|
7632
|
+
`<button type="button" class="kb-link kb-ds-more" data-kb-ds-more="${id}" data-kb-ds-rev="${rev}" aria-haspopup="menu" data-command-id="shell.kb-design-issue-more" data-tip="Rename, index or withdraw this issue">More…</button>` +
|
|
7633
|
+
'</div>';
|
|
7634
|
+
return `<details class="kb-ds-issue${issue.current ? ' current' : ''}${issue.withdrawn ? ' wd' : ''}" data-kb-ds-issue-id="${id}"${open ? ' open' : ''}>` +
|
|
7635
|
+
`<summary class="kb-ds-sum" data-command-id="shell.kb-design-issue-open"><span class="kb-adjust-caret" aria-hidden="true">▸</span>` +
|
|
7636
|
+
`<span class="kb-ds-line1"><span class="kb-ds-label">${escapeHtml(issue.label)}</span>${date}<span class="kb-ds-count">${escapeHtml(count)}</span></span>` +
|
|
7637
|
+
(chips ? `<span class="kb-ds-line2">${chips}</span>` : '') + '</summary>' +
|
|
7638
|
+
'<div class="kb-ds-body">' +
|
|
7639
|
+
(origin ? `<div class="kb-ds-origin">${escapeHtml(origin)}</div>` : '') + warnings +
|
|
7640
|
+
`<ul class="kb-ds-files" role="list">${shown.map((f) => kbIssueFileRow(f, issue, st)).join('')}</ul>${more}` +
|
|
7641
|
+
index + actions + kbIssuePanel(issue, st) +
|
|
7642
|
+
'</div></details>';
|
|
7643
|
+
}
|
|
7644
|
+
|
|
7645
|
+
/** The references a new issue can be made of: every drawing file in the project's knowledge. */
|
|
7646
|
+
function kbDsAddable(st) {
|
|
7647
|
+
return (st.sources || []).filter((s) => s.kind !== 'observation' && KB_DRAWING_MIMES.has(s.mime));
|
|
7648
|
+
}
|
|
7649
|
+
function kbAddIssuePanel(st) {
|
|
7650
|
+
if (!kbDsPanel || kbDsPanel.kind !== 'add') return '';
|
|
7651
|
+
// Every drawing can go into a new release, including one already in an earlier issue (it may be unchanged); the
|
|
7652
|
+
// drawings in no issue yet are ticked to start with.
|
|
7653
|
+
const drawings = kbDsAddable(st);
|
|
7654
|
+
const issues = (st.designSet && st.designSet.issues) || [];
|
|
7655
|
+
const chosen = kbDsPanel.chosen || new Set(drawings.filter((s) => !kbInDesignSet(s, st)).map((s) => s.sourceId));
|
|
7656
|
+
const inIssue = (s) => issues.filter((i) => (i.files || []).some((f) => f.sourceId === s.sourceId && f.blobSha256 === s.blobSha256)).map((i) => i.label);
|
|
7657
|
+
const list = drawings.length
|
|
7658
|
+
? '<ul class="kb-ds-picks" role="list">' + drawings.map((s, i) => {
|
|
7659
|
+
const where = inIssue(s);
|
|
7660
|
+
return `<li><input type="checkbox" id="kb-ds-a-${i}" data-kb-ds-add-pick="${escapeAttr(s.sourceId)}" data-command-id="shell.kb-design-add-pick#${escapeAttr(s.sourceId)}" data-command-instance-label="${escapeAttr(`“${s.filename || 'untitled'}”`)}"${chosen.has(s.sourceId) ? ' checked' : ''}>` +
|
|
7661
|
+
`<label for="kb-ds-a-${i}">${escapeHtml(s.filename || 'untitled')}${where.length ? ` <span class="kb-ds-opt">in ${escapeHtml(where.slice(0, 2).join(', '))}</span>` : ''}</label></li>`;
|
|
7662
|
+
}).join('') + '</ul>'
|
|
7663
|
+
: '<div class="kb-ds-note">There are no drawings in this project yet. Upload the drawings of this issue.</div>';
|
|
7664
|
+
const err = kbDsPanel.error ? `<div class="kb-ds-err" role="alert">${escapeHtml(kbDsPanel.error)}</div>` : '';
|
|
7665
|
+
return '<div class="kb-ds-panel" role="group" aria-labelledby="kb-ds-ph-add">' +
|
|
7666
|
+
'<div class="kb-ds-ph" id="kb-ds-ph-add">Add an issue</div>' +
|
|
7667
|
+
'<div class="kb-ds-lbl">Drawings in this issue</div>' + list +
|
|
7668
|
+
'<button type="button" class="kb-link" data-kb-ds-upload data-command-id="shell.add-knowledge" data-tip="Pick drawing files from your computer; they are ticked here when they arrive">Upload new files…</button>' +
|
|
7669
|
+
(drawings.length ? '<label class="kb-ds-lbl" for="kb-ds-label">Label <span class="kb-ds-opt">(for example Rev C or IFC)</span></label>' +
|
|
7670
|
+
`<input class="kb-adjust-input kb-ds-in" id="kb-ds-label" data-command-id="shell.kb-design-panel-label" maxlength="60" placeholder="Issue ${((st.designSet && st.designSet.issues) || []).length + 1}" value="${escapeAttr(kbDsPanel.label || '')}" autocomplete="off">` +
|
|
7671
|
+
'<label class="kb-ds-lbl" for="kb-ds-date">Issue date <span class="kb-ds-opt">(optional, YYYY-MM-DD)</span></label>' +
|
|
7672
|
+
`<input class="kb-adjust-input kb-ds-in" id="kb-ds-date" data-command-id="shell.kb-design-panel-date" maxlength="10" inputmode="numeric" placeholder="2026-10-17" value="${escapeAttr(kbDsPanel.date || '')}" autocomplete="off">` : '') +
|
|
7673
|
+
err + '<div class="kb-ds-pact"><button type="button" class="btn-mini" data-kb-ds-cancel data-command-id="shell.kb-design-panel-cancel">Cancel</button>' +
|
|
7674
|
+
(drawings.length ? `<button type="button" class="btn-mini primary" data-kb-ds-add-go data-kb-ds-rev="${escapeAttr(kbDsPanel.rev || kbDsRev(st))}" data-command-id="shell.kb-design-issue-add-save">Add issue</button>` : '') +
|
|
7675
|
+
'</div></div>';
|
|
7676
|
+
}
|
|
7677
|
+
|
|
7678
|
+
function kbDesignSetStrip(st) {
|
|
7679
|
+
const ds = st && st.designSet;
|
|
7680
|
+
if (!ds) return '';
|
|
7681
|
+
const head = (extra) => `<div class="kb-ds-head"><span class="kb-adjust-label" id="kb-ds-title">Design set</span>${extra || ''}</div>`;
|
|
7682
|
+
if (ds.status === 'unknown') {
|
|
7683
|
+
// Said in the server's words; a broken record also offers Clear (it is moved aside, never lost).
|
|
7684
|
+
const why = (ds.warnings || [])[0];
|
|
7685
|
+
const broken = why && why.code === 'design-set-unreadable';
|
|
7686
|
+
return `<section class="kb-src kb-ds" role="region" aria-labelledby="kb-ds-title">${head()}` +
|
|
7687
|
+
`<div class="kb-fmeta">${escapeHtml(why ? why.message : 'FloLess could not read the design set just now. It tries again when this step refreshes.')}</div>` +
|
|
7688
|
+
(broken ? `<div class="kb-ds-actions"><button type="button" class="kb-link" data-kb-ds-clear data-kb-ds-rev="(unreadable)" data-command-id="shell.kb-design-set-clear" data-tip="Replace the unreadable record with no design set. The old record is kept aside and no reference is removed.">Clear</button></div>` : '') +
|
|
7689
|
+
'</section>';
|
|
7690
|
+
}
|
|
7691
|
+
const issues = ds.issues || [];
|
|
7692
|
+
const canRead = !!(current && (current.templateId || current.app) === 'steel-model');
|
|
7693
|
+
const add = !kbDsPanel || kbDsPanel.kind !== 'add'
|
|
7694
|
+
? '<button type="button" class="kb-link kb-ds-add" data-kb-ds-add data-command-id="shell.kb-design-issue-add" data-tip="Group drawings into an issue, such as Rev C or IFC">Add issue</button>' : '';
|
|
7695
|
+
const body = issues.length
|
|
7696
|
+
? issues.map((issue) => kbIssueRow(issue, st, canRead)).join('')
|
|
7697
|
+
: (kbDsPanel && kbDsPanel.kind === 'add' ? '' : '<div class="kb-ds-note">No drawings issued yet. Add an issue to track a release such as Rev C or IFC.</div>');
|
|
7698
|
+
// Warnings about the record itself (an earlier one set aside) belong to no issue: said above the issues, always.
|
|
7699
|
+
const recordWarnings = (ds.warnings || []).filter((w) => !w.issueId).map((w) =>
|
|
7700
|
+
`<div class="kb-ds-warn-line" role="status"><span class="kb-ds-bang" aria-hidden="true">!</span><span>${escapeHtml(w.message)}</span></div>`).join('');
|
|
7701
|
+
return `<section class="kb-src kb-ds${ds.status === 'changed' ? ' changed' : ''}" role="region" aria-labelledby="kb-ds-title">` +
|
|
7702
|
+
head(add) + '<div class="kb-ds-sub">Each issue is one release of the drawings.</div>' + recordWarnings +
|
|
7703
|
+
kbAddIssuePanel(st) + body + '</section>';
|
|
7704
|
+
}
|
|
7705
|
+
|
|
7706
|
+
function kbSourceRow(s, st, depth) {
|
|
7195
7707
|
const on = !!s.useAsKb;
|
|
7708
|
+
const sel = kbSel.selected.has(s.sourceId);
|
|
7196
7709
|
const ico = kbIcon(s.mime);
|
|
7197
7710
|
const chip = KB_CHIP[s.state] || ['new', escapeHtml(String(s.state || 'new'))];
|
|
7198
7711
|
const name = s.filename || 'untitled';
|
|
@@ -7206,13 +7719,16 @@
|
|
|
7206
7719
|
// exclusions. `aria-current` (not `aria-selected`, which is invalid on a generic role and would
|
|
7207
7720
|
// fail aria-allowed-attr) marks the row whose file is on screen.
|
|
7208
7721
|
const isOpen = viewer.mode === 'file' && viewer.sourceId === s.sourceId;
|
|
7209
|
-
return `<div class="kb-src${on ? '' : ' off'}${s.state === 'error' ? ' state-error' : ''}"` +
|
|
7722
|
+
return `<div class="kb-src${on ? '' : ' off'}${s.state === 'error' ? ' state-error' : ''}${sel ? ' selected' : ''}" draggable="true"` +
|
|
7723
|
+
(depth != null ? ` style="--kb-depth:${depth}"` : '') +
|
|
7210
7724
|
` data-source-id="${escapeAttr(s.sourceId)}"${isOpen ? ' aria-current="true"' : ''}>` +
|
|
7211
7725
|
`<span class="kb-fico ${ico.cls}" aria-hidden="true">${ico.glyph}</span>` +
|
|
7212
7726
|
`<div class="kb-fbody">` +
|
|
7213
|
-
`<button type="button" class="kb-fname" data-kb-open="${escapeAttr(s.sourceId)}" ` +
|
|
7214
|
-
`data-tip="Preview “${escapeAttr(name)}”">${escapeHtml(name)}</button>` +
|
|
7215
|
-
`<div class="kb-fmeta">${escapeHtml(meta)}<span class="kb-chip ${chip[0]}">${chip[1]}</span>${imported}${kbCompanyChip(s, st)}
|
|
7727
|
+
`<button type="button" class="kb-fname" data-kb-open="${escapeAttr(s.sourceId)}" data-command-id="shell.kb-reference#${escapeAttr(s.sourceId)}" data-command-instance-label="${escapeAttr(name)}" ` +
|
|
7728
|
+
`data-tip="Preview “${escapeAttr(name)}” · Ctrl or Shift to select, Ctrl+A for all">${escapeHtml(name)}${sel ? '<span class="kb-sr"> (selected)</span>' : ''}</button>` +
|
|
7729
|
+
`<div class="kb-fmeta">${escapeHtml(meta)}<span class="kb-chip ${chip[0]}">${chip[1]}</span>${kbTextChips(s)}${imported}${kbCompanyChip(s, st)}` +
|
|
7730
|
+
`${kbIsDesignSet(s, st) ? '<span class="kb-chip run kb-chip-ds">design set</span>' : ''}</div>` +
|
|
7731
|
+
kbDesignSetUse(s, st) +
|
|
7216
7732
|
err +
|
|
7217
7733
|
`</div>` +
|
|
7218
7734
|
`<button type="button" class="kb-toggle" role="switch" aria-checked="${on ? 'true' : 'false'}" data-kb-toggle ` +
|
|
@@ -7222,6 +7738,599 @@
|
|
|
7222
7738
|
`</div>`;
|
|
7223
7739
|
}
|
|
7224
7740
|
|
|
7741
|
+
|
|
7742
|
+
// ── #2491 R6.9: categories, multi-select, Move to…, drag and drop ─────────────────────────────────────
|
|
7743
|
+
// The pure half is web/kb-categories.js (kbc*); this is the DOM half. Categories are the person's: every change here is
|
|
7744
|
+
// the person's own click, which the server checks (an AI can only suggest one on a card). Each change carries the
|
|
7745
|
+
// categories' revision this screen drew and the project's incarnation, so a change made meanwhile elsewhere is never
|
|
7746
|
+
// overwritten — the server says so in words and this screen reloads.
|
|
7747
|
+
const KB_CAT_KEY = 'the categories', KB_PROJECT_KEY = 'the project';
|
|
7748
|
+
const KB_REFS_MIME = 'application/x-floless-kb-refs';
|
|
7749
|
+
let kbSel = { selected: new Set(), anchor: null };
|
|
7750
|
+
let kbSelProject = null;
|
|
7751
|
+
let kbCatCollapsed = new Set(); // categories the person folded (new ones start open), per project
|
|
7752
|
+
let kbCatCollapsedProject = null;
|
|
7753
|
+
let kbCatEdit = null; // { mode: 'new' | 'rename', id?, parentId?, then?: { sourceIds } } — the inline name box
|
|
7754
|
+
let kbCatFocus = null; // { cat: id } | { row: sourceId } — focus to restore after the next repaint
|
|
7755
|
+
let kbCatBusy = false;
|
|
7756
|
+
|
|
7757
|
+
function kbCats(st) {
|
|
7758
|
+
const c = st && st.categories;
|
|
7759
|
+
return c && Array.isArray(c.categories) ? c : { v: 1, revision: 0, categories: [], placements: {}, state: 'absent' };
|
|
7760
|
+
}
|
|
7761
|
+
const kbCatUsable = (st) => { const c = kbCats(st); return c.state !== 'damaged' && c.state !== 'newer'; };
|
|
7762
|
+
function kbCatCollapsedFor(proj) {
|
|
7763
|
+
if (!proj) return new Set();
|
|
7764
|
+
if (kbCatCollapsedProject !== proj.id) {
|
|
7765
|
+
kbCatCollapsedProject = proj.id;
|
|
7766
|
+
try { kbCatCollapsed = new Set(JSON.parse(localStorage.getItem(`floless:kb-cat-folded:${proj.id}`) || '[]')); }
|
|
7767
|
+
catch { kbCatCollapsed = new Set(); }
|
|
7768
|
+
}
|
|
7769
|
+
return kbCatCollapsed;
|
|
7770
|
+
}
|
|
7771
|
+
function kbCatSaveCollapsed() {
|
|
7772
|
+
if (!current) return;
|
|
7773
|
+
try { localStorage.setItem(`floless:kb-cat-folded:${current.id}`, JSON.stringify([...kbCatCollapsed])); } catch { /* private mode */ }
|
|
7774
|
+
}
|
|
7775
|
+
function kbSelFor(proj, st) {
|
|
7776
|
+
if (!proj || kbSelProject !== proj.id) { kbSelProject = proj ? proj.id : null; kbSel = { selected: new Set(), anchor: null }; }
|
|
7777
|
+
if (st) kbSel = kbcPrune(kbSel, st.sources.map((s) => s.sourceId));
|
|
7778
|
+
return kbSel;
|
|
7779
|
+
}
|
|
7780
|
+
function kbAnnounce(text) {
|
|
7781
|
+
const live = $wsKnowledge.querySelector('#kb-drop-live');
|
|
7782
|
+
if (!live) return;
|
|
7783
|
+
live.textContent = '';
|
|
7784
|
+
setTimeout(() => { live.textContent = text; }, 30);
|
|
7785
|
+
}
|
|
7786
|
+
/** The refs column keeps the inline name box while someone types in it: a poll must not repaint under it. */
|
|
7787
|
+
function kbCatEditActive() {
|
|
7788
|
+
// Only while an edit is open: once it is saved or cancelled the box is stale, and the repaint must remove it even
|
|
7789
|
+
// though it still holds focus.
|
|
7790
|
+
const box = $wsKnowledge.querySelector('.kb-cat-edit');
|
|
7791
|
+
return !!kbCatEdit && !!box && (box.contains(document.activeElement) || kbCatBusy);
|
|
7792
|
+
}
|
|
7793
|
+
|
|
7794
|
+
function kbCatEditHtml(depth) {
|
|
7795
|
+
const e = kbCatEdit;
|
|
7796
|
+
const verb = e.mode === 'rename' ? 'Rename' : e.then ? 'Create and move' : 'Create';
|
|
7797
|
+
const value = e.mode === 'rename' ? escapeAttr(e.name || '') : '';
|
|
7798
|
+
return `<div class="kb-cat-edit" style="--kb-depth:${depth}">` +
|
|
7799
|
+
`<input type="text" class="kb-cat-input" maxlength="80" value="${value}" aria-label="${e.mode === 'rename' ? 'New name for the category' : 'Name of the new category'}" placeholder="Category name" data-command-id="shell.kb-category-name">` +
|
|
7800
|
+
`<button type="button" class="primary kb-cat-save" data-kb-cat-save data-command-id="shell.kb-category-save">${verb}</button>` +
|
|
7801
|
+
'<button type="button" class="kb-cat-cancel" data-kb-cat-cancel data-command-id="shell.kb-category-cancel">Cancel</button></div>';
|
|
7802
|
+
}
|
|
7803
|
+
|
|
7804
|
+
function kbCatRowHtml(item, file) {
|
|
7805
|
+
const isU = item.kind === 'uncategorized';
|
|
7806
|
+
const id = isU ? 'uncategorized' : item.id;
|
|
7807
|
+
const chev = '<svg class="kb-cat-chev" viewBox="0 0 16 16" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg>';
|
|
7808
|
+
const editing = kbCatEdit && kbCatEdit.mode === 'rename' && kbCatEdit.id === item.id;
|
|
7809
|
+
if (editing) return kbCatEditHtml(item.depth);
|
|
7810
|
+
const name = escapeHtml(item.name);
|
|
7811
|
+
const tip = item.name.length > 28 ? ` data-tip="${escapeAttr(isU ? item.name : kbcLabel(file, item.id))}"` : '';
|
|
7812
|
+
return `<div class="kb-cat${isU ? ' kb-uncat' : ''}${item.open ? ' open' : ''}" style="--kb-depth:${item.depth}" data-kb-drop-cat="${escapeAttr(id)}">` +
|
|
7813
|
+
`<button type="button" class="kb-cat-toggle" data-kb-cat-toggle="${escapeAttr(id)}" aria-expanded="${item.open ? 'true' : 'false'}"${tip} data-command-id="shell.kb-category-toggle#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(item.name)}">` +
|
|
7814
|
+
`${chev}<span class="kb-cat-name">${name}</span><span class="kb-cat-count" aria-label="${item.count} reference${item.count === 1 ? '' : 's'}">(${item.count})</span></button>` +
|
|
7815
|
+
(isU ? '' : `<button type="button" class="kb-cat-more" data-kb-cat-menu="${escapeAttr(item.id)}" aria-label="More for ${escapeAttr(item.name)}" aria-haspopup="menu" data-tip="Rename, move or delete" data-command-id="shell.kb-category-menu#${escapeAttr(item.id)}" data-command-instance-label="${escapeAttr(item.name)}">⋯</button>`) +
|
|
7816
|
+
'</div>' +
|
|
7817
|
+
(item.open && item.empty ? `<div class="kb-cat-empty" style="--kb-depth:${item.depth + 1}">${isU ? 'Nothing here.' : 'Empty. Drag references here.'}</div>` : '');
|
|
7818
|
+
}
|
|
7819
|
+
|
|
7820
|
+
/** The References list as a tree (once the first category exists), with the inline name box where it was asked for. */
|
|
7821
|
+
function kbTreeHtml(st, rows) {
|
|
7822
|
+
const file = kbCats(st);
|
|
7823
|
+
const folded = kbCatCollapsedFor(current);
|
|
7824
|
+
const open = new Set(['uncategorized', ...file.categories.map((c) => c.id)].filter((id) => !folded.has(id)));
|
|
7825
|
+
const items = kbcTreeItems(file, rows, open);
|
|
7826
|
+
let html = '';
|
|
7827
|
+
for (const item of items) {
|
|
7828
|
+
if (item.kind === 'row') { html += kbSourceRow(item.row, st, item.depth); continue; }
|
|
7829
|
+
html += kbCatRowHtml(item, file);
|
|
7830
|
+
if (kbCatEdit && kbCatEdit.mode === 'new' && kbCatEdit.parentId && kbCatEdit.parentId === item.id && item.open) html += kbCatEditHtml(item.depth + 1);
|
|
7831
|
+
}
|
|
7832
|
+
if (kbCatEdit && kbCatEdit.mode === 'new' && !kbCatEdit.parentId) html = kbCatEditHtml(0) + html;
|
|
7833
|
+
return `<div class="kb-tree" role="group" aria-label="References by category">${html}</div>`;
|
|
7834
|
+
}
|
|
7835
|
+
|
|
7836
|
+
/** The bar under the list while references are selected. */
|
|
7837
|
+
function kbSelBarHtml(st) {
|
|
7838
|
+
const n = kbSelFor(current, st).selected.size;
|
|
7839
|
+
if (!n) return '';
|
|
7840
|
+
return '<div class="kb-selbar" role="region" aria-label="Selected references">' +
|
|
7841
|
+
`<span class="kb-selbar-n">${n} selected</span>` +
|
|
7842
|
+
'<button type="button" class="kb-selbar-move" data-kb-move-sel aria-haspopup="menu" data-command-id="shell.kb-move-to#selection" data-command-instance-label="the selected references">Move to…</button>' +
|
|
7843
|
+
'<button type="button" class="kb-selbar-clear" data-kb-sel-clear data-command-id="shell.kb-select-clear">Clear</button></div>';
|
|
7844
|
+
}
|
|
7845
|
+
|
|
7846
|
+
/** The categories file could not be read, or a newer FloLess wrote it: say so, and offer to start again. */
|
|
7847
|
+
function kbCatUnavailableHtml(st) {
|
|
7848
|
+
const c = kbCats(st);
|
|
7849
|
+
if (kbCatUsable(st)) return '';
|
|
7850
|
+
const why = c.state === 'newer'
|
|
7851
|
+
? 'Your categories were saved by a newer FloLess, so this one shows every reference without them.'
|
|
7852
|
+
: 'Your categories could not be read, so every reference is shown without them.';
|
|
7853
|
+
return `<div class="kb-cat-warn" role="status"><span>${why} You can update FloLess, or start again with no categories (the saved ones are kept aside).</span>` +
|
|
7854
|
+
'<button type="button" data-kb-cat-reset data-command-id="shell.kb-category-reset">Start again</button></div>';
|
|
7855
|
+
}
|
|
7856
|
+
|
|
7857
|
+
function kbCatExpected(st) {
|
|
7858
|
+
return { [KB_CAT_KEY]: String(kbCats(st).revision || 0), [KB_PROJECT_KEY]: current && current.uuid ? current.uuid : '' };
|
|
7859
|
+
}
|
|
7860
|
+
/** One category change against what this screen drew. The server's own sentence is shown when it refuses. */
|
|
7861
|
+
async function kbCatPost(tail, body, done) {
|
|
7862
|
+
const proj = current;
|
|
7863
|
+
if (!proj || kbCatBusy) return null;
|
|
7864
|
+
kbCatBusy = true;
|
|
7865
|
+
try {
|
|
7866
|
+
const res = await api(kbUrl(proj.id, tail), { method: 'POST', body: JSON.stringify({ expected: kbCatExpected(knowledgeState), ...body }) });
|
|
7867
|
+
if (current !== proj) return null;
|
|
7868
|
+
if (knowledgeState && res && res.categories) knowledgeState.categories = res.categories;
|
|
7869
|
+
if (done) done(res);
|
|
7870
|
+
kbInvalidateRefs();
|
|
7871
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
7872
|
+
return res;
|
|
7873
|
+
} catch (err) {
|
|
7874
|
+
const said = err && err.body && typeof err.body.error === 'string' ? err.body.error : '';
|
|
7875
|
+
showToast(said || 'FloLess could not change your categories just now. Try again.', 'warn');
|
|
7876
|
+
// Changed elsewhere since the name box opened: close it, so the person sees the newer names before naming again.
|
|
7877
|
+
if (body.expected && err && err.body && err.body.code === 'knowledge-categories-changed') kbCatEdit = null;
|
|
7878
|
+
return null;
|
|
7879
|
+
} finally {
|
|
7880
|
+
kbCatBusy = false;
|
|
7881
|
+
if (current === proj) renderKnowledge();
|
|
7882
|
+
}
|
|
7883
|
+
}
|
|
7884
|
+
function kbCatOps(ops, announce, focus, expected) {
|
|
7885
|
+
return kbCatPost('/categories', expected ? { ops, expected } : { ops }, (res) => {
|
|
7886
|
+
if (announce) kbAnnounce(typeof announce === 'function' ? announce(res) : announce);
|
|
7887
|
+
if (focus) kbCatFocus = typeof focus === 'function' ? focus(res) : focus;
|
|
7888
|
+
});
|
|
7889
|
+
}
|
|
7890
|
+
function kbPlace(sourceIds, categoryId) {
|
|
7891
|
+
const st = knowledgeState;
|
|
7892
|
+
const where = categoryId ? kbcLabel(kbCats(st), categoryId) : 'Uncategorized';
|
|
7893
|
+
const n = sourceIds.length;
|
|
7894
|
+
return kbCatPost('/sources/place', { sourceIds, categoryId: categoryId || null }, (res) => {
|
|
7895
|
+
const moved = (res.placed || []).length;
|
|
7896
|
+
const missing = (res.missing || []).length;
|
|
7897
|
+
kbAnnounce(`Moved ${moved} reference${moved === 1 ? '' : 's'} to ${where}.${missing ? ` ${missing} ${missing === 1 ? 'was' : 'were'} no longer here.` : ''}`);
|
|
7898
|
+
if (categoryId) {
|
|
7899
|
+
// Keep the moved items in view: open the category and its ancestors.
|
|
7900
|
+
const file = res.categories || kbCats(st);
|
|
7901
|
+
for (const id of [...kbcAncestors(file, categoryId), categoryId]) kbCatCollapsed.delete(id);
|
|
7902
|
+
kbCatSaveCollapsed();
|
|
7903
|
+
}
|
|
7904
|
+
kbSel = { selected: new Set(), anchor: null };
|
|
7905
|
+
if (n) kbCatFocus = { row: sourceIds[0] };
|
|
7906
|
+
});
|
|
7907
|
+
}
|
|
7908
|
+
|
|
7909
|
+
function kbCatPop(anchor, html, label, role) {
|
|
7910
|
+
kbCloseConfirm();
|
|
7911
|
+
const box = anchor.closest('.kb-refs-body');
|
|
7912
|
+
if (!box) return null;
|
|
7913
|
+
const pop = document.createElement('div');
|
|
7914
|
+
pop.className = `hist-confirm${role === 'menu' ? ' kb-ds-menu kb-cat-menu' : ''}`;
|
|
7915
|
+
pop.setAttribute('role', role || 'dialog');
|
|
7916
|
+
pop.setAttribute('aria-label', label);
|
|
7917
|
+
pop.innerHTML = html;
|
|
7918
|
+
box.appendChild(pop);
|
|
7919
|
+
const cr = box.getBoundingClientRect();
|
|
7920
|
+
const br = anchor.getBoundingClientRect();
|
|
7921
|
+
// Below the control when it fits in view, else above it (the selection bar sits at the bottom edge).
|
|
7922
|
+
const below = br.bottom - cr.top + box.scrollTop + 6;
|
|
7923
|
+
const fits = br.bottom + 6 + pop.offsetHeight <= cr.bottom;
|
|
7924
|
+
pop.style.top = `${fits ? below : Math.max(box.scrollTop + 4, br.top - cr.top + box.scrollTop - pop.offsetHeight - 6)}px`;
|
|
7925
|
+
pop.style.left = `${Math.max(8, Math.min(br.left - cr.left, box.clientWidth - pop.offsetWidth - 8))}px`;
|
|
7926
|
+
document.addEventListener('mousedown', kbOnDocDown, true);
|
|
7927
|
+
pop.kbAnchor = anchor;
|
|
7928
|
+
return pop;
|
|
7929
|
+
}
|
|
7930
|
+
|
|
7931
|
+
/** Move to…: for references (the selection, or one row) or for a category (where it sits). */
|
|
7932
|
+
function kbShowMoveMenu(anchor, what) {
|
|
7933
|
+
const st = knowledgeState;
|
|
7934
|
+
const file = kbCats(st);
|
|
7935
|
+
const choices = kbcMenuChoices(file, what.categoryId || null);
|
|
7936
|
+
const currentAt = what.categoryId
|
|
7937
|
+
? (file.categories.find((c) => c.id === what.categoryId) || {}).parentId || null
|
|
7938
|
+
: (what.sourceIds.length === 1 ? kbcPlacement(file, what.sourceIds[0]) : undefined);
|
|
7939
|
+
const n = what.sourceIds ? what.sourceIds.length : 0;
|
|
7940
|
+
const title = what.categoryId ? `Move “${escapeHtml(kbcLabel(file, what.categoryId))}” to` : `Move ${n === 1 ? 'this reference' : `${n} references`} to`;
|
|
7941
|
+
const items = choices.filter((c) => c.allowed).map((c) =>
|
|
7942
|
+
`<button type="button" role="menuitemradio" aria-checked="${c.id === currentAt ? 'true' : 'false'}" class="kb-ds-mi kb-move-mi" style="--kb-depth:${c.id ? c.depth + 1 : 0}"` +
|
|
7943
|
+
` data-kb-move-go="${escapeAttr(c.id || '')}" data-command-id="shell.kb-move-to-go#${escapeAttr(c.id || 'uncategorized')}" data-command-instance-label="${escapeAttr(c.name)}">${escapeHtml(c.name)}</button>`).join('');
|
|
7944
|
+
const pop = kbCatPop(anchor, `<div class="kb-move-title">${title}</div>${items}` +
|
|
7945
|
+
`<button type="button" role="menuitem" class="kb-ds-mi kb-move-new" data-kb-move-new data-command-id="shell.kb-category-new">New category…</button>`,
|
|
7946
|
+
what.categoryId ? 'Move category' : 'Move references', 'menu');
|
|
7947
|
+
if (!pop) return;
|
|
7948
|
+
pop.kbWhat = what;
|
|
7949
|
+
const first = pop.querySelector('[aria-checked="true"]') || pop.querySelector('.kb-ds-mi');
|
|
7950
|
+
if (first) first.focus();
|
|
7951
|
+
}
|
|
7952
|
+
|
|
7953
|
+
function kbShowCatMenu(btn) {
|
|
7954
|
+
const id = btn.dataset.kbCatMenu;
|
|
7955
|
+
const file = kbCats(knowledgeState);
|
|
7956
|
+
const cat = file.categories.find((c) => c.id === id);
|
|
7957
|
+
if (!cat) return;
|
|
7958
|
+
const sibs = kbcChildren(file, cat.parentId || null);
|
|
7959
|
+
const at = sibs.findIndex((c) => c.id === id);
|
|
7960
|
+
const pop = kbCatPop(btn,
|
|
7961
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-kb-cat-rename="${escapeAttr(id)}" data-command-id="shell.kb-category-rename#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Rename…</button>` +
|
|
7962
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-kb-cat-sub="${escapeAttr(id)}" data-command-id="shell.kb-category-new-sub#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">New subcategory…</button>` +
|
|
7963
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-kb-cat-move="${escapeAttr(id)}" data-command-id="shell.kb-move-to#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Move to…</button>` +
|
|
7964
|
+
(at > 0 ? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-cat-up="${escapeAttr(id)}" data-command-id="shell.kb-category-up#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Move up</button>` : '') +
|
|
7965
|
+
(at < sibs.length - 1 ? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-cat-down="${escapeAttr(id)}" data-command-id="shell.kb-category-down#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Move down</button>` : '') +
|
|
7966
|
+
`<button type="button" role="menuitem" class="kb-ds-mi danger" data-kb-cat-delete="${escapeAttr(id)}" data-command-id="shell.kb-category-delete#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Delete…</button>`,
|
|
7967
|
+
`More for ${cat.name}`, 'menu');
|
|
7968
|
+
const first = pop && pop.querySelector('.kb-ds-mi');
|
|
7969
|
+
if (first) first.focus();
|
|
7970
|
+
}
|
|
7971
|
+
|
|
7972
|
+
function kbShowCatDelete(anchor, id) {
|
|
7973
|
+
const st = knowledgeState;
|
|
7974
|
+
const file = kbCats(st);
|
|
7975
|
+
const cat = file.categories.find((c) => c.id === id);
|
|
7976
|
+
if (!cat) return;
|
|
7977
|
+
const body = kbCatDeleteSentence(file, st.sources, id);
|
|
7978
|
+
const pop = kbCatPop(anchor,
|
|
7979
|
+
`<div class="hc-title">Delete “${escapeHtml(cat.name)}”?</div><div class="hc-body">${body}</div>` +
|
|
7980
|
+
'<div class="hc-act"><button type="button" class="hc-cancel" data-command-id="shell.kb-category-cancel">Cancel</button>' +
|
|
7981
|
+
`<button type="button" class="hc-go danger" data-kb-cat-delete-go="${escapeAttr(id)}" data-command-id="shell.kb-category-delete#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Delete category</button></div>`,
|
|
7982
|
+
`Delete ${cat.name}`, 'dialog');
|
|
7983
|
+
const cancel = pop && pop.querySelector('.hc-cancel');
|
|
7984
|
+
if (cancel) cancel.focus();
|
|
7985
|
+
}
|
|
7986
|
+
|
|
7987
|
+
/** What deleting a category does, in words: its own references and its subcategories (with theirs) move up a level. */
|
|
7988
|
+
function kbCatDeleteSentence(file, rows, id) {
|
|
7989
|
+
const cat = file.categories.find((c) => c.id === id);
|
|
7990
|
+
const n = (rows || []).filter((r) => kbcPlacement(file, r.sourceId) === id).length;
|
|
7991
|
+
const subs = kbcChildren(file, id).length;
|
|
7992
|
+
const refs = `${n} reference${n === 1 ? '' : 's'}`;
|
|
7993
|
+
const kids = `${subs} subcategor${subs === 1 ? 'y' : 'ies'}`;
|
|
7994
|
+
if (!n && !subs) return 'It is empty. No reference is deleted.';
|
|
7995
|
+
if (cat && cat.parentId) {
|
|
7996
|
+
const to = `“${escapeHtml(kbcLabel(file, cat.parentId))}”`;
|
|
7997
|
+
return `Its ${[n ? refs : '', subs ? kids : ''].filter(Boolean).join(' and ')} move up to ${to}. No reference is deleted.`;
|
|
7998
|
+
}
|
|
7999
|
+
if (n && subs) return `Its ${refs} move to Uncategorized and its ${kids} to the top level. No reference is deleted.`;
|
|
8000
|
+
return n ? `Its ${refs} move to Uncategorized. No reference is deleted.` : `Its ${kids} move to the top level. No reference is deleted.`;
|
|
8001
|
+
}
|
|
8002
|
+
|
|
8003
|
+
function kbCatStartEdit(edit) {
|
|
8004
|
+
kbCloseConfirm();
|
|
8005
|
+
// The box saves against the categories as they were when it opened: a change made meanwhile elsewhere is refused, not overwritten.
|
|
8006
|
+
kbCatEdit = { ...edit, expected: kbCatExpected(knowledgeState) };
|
|
8007
|
+
if (edit.parentId) { kbCatCollapsed.delete(edit.parentId); kbCatSaveCollapsed(); }
|
|
8008
|
+
kbInvalidateRefs();
|
|
8009
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8010
|
+
const input = $wsKnowledge.querySelector('.kb-cat-input');
|
|
8011
|
+
if (input) { input.focus(); input.select(); }
|
|
8012
|
+
}
|
|
8013
|
+
function kbCatEndEdit(focus) {
|
|
8014
|
+
kbCatEdit = null;
|
|
8015
|
+
kbCatFocus = focus || null;
|
|
8016
|
+
kbInvalidateRefs();
|
|
8017
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8018
|
+
}
|
|
8019
|
+
async function kbCatSaveEdit() {
|
|
8020
|
+
const input = $wsKnowledge.querySelector('.kb-cat-input');
|
|
8021
|
+
const e = kbCatEdit;
|
|
8022
|
+
if (!input || !e) return;
|
|
8023
|
+
const name = input.value.replace(/\s+/g, ' ').trim();
|
|
8024
|
+
if (!name) { showToast('Give the category a name.', 'warn'); input.focus(); return; }
|
|
8025
|
+
if (e.mode === 'rename') {
|
|
8026
|
+
const res = await kbCatOps([{ op: 'rename', id: e.id, name }], `Renamed the category to ${name}.`, { cat: e.id }, e.expected);
|
|
8027
|
+
if (res) kbCatEdit = null;
|
|
8028
|
+
} else {
|
|
8029
|
+
const res = await kbCatOps([{ op: 'create', tempId: 'new', name, parentId: e.parentId || null }], `Created the category ${name}.`, (r) => ({ cat: r.created && r.created.new }), e.expected);
|
|
8030
|
+
if (res) {
|
|
8031
|
+
kbCatEdit = null;
|
|
8032
|
+
const id = res.created && res.created.new;
|
|
8033
|
+
if (e.then && e.then.sourceIds && id) await kbPlace(e.then.sourceIds, id);
|
|
8034
|
+
if (e.then && e.then.categoryId && id) await kbCatOps([{ op: 'move', id: e.then.categoryId, parentId: id }], `Moved the category into ${name}.`, { cat: e.then.categoryId });
|
|
8035
|
+
}
|
|
8036
|
+
}
|
|
8037
|
+
kbInvalidateRefs();
|
|
8038
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8039
|
+
}
|
|
8040
|
+
|
|
8041
|
+
/** Restore focus after a repaint, to the item that was acted on (or its neighbour when it is gone). */
|
|
8042
|
+
function kbCatRestoreFocus(refsHost) {
|
|
8043
|
+
const f = kbCatFocus;
|
|
8044
|
+
if (!f) return;
|
|
8045
|
+
kbCatFocus = null;
|
|
8046
|
+
const el = f.cat ? refsHost.querySelector(`[data-kb-cat-toggle="${CSS.escape(f.cat)}"]`)
|
|
8047
|
+
: f.row ? refsHost.querySelector(`[data-kb-open="${CSS.escape(f.row)}"]`)
|
|
8048
|
+
: f.selbar ? refsHost.querySelector('[data-kb-move-sel]') : null;
|
|
8049
|
+
const fallback = refsHost.querySelector('.kb-cat-toggle, .kb-fname');
|
|
8050
|
+
(el || fallback)?.focus({ preventScroll: false });
|
|
8051
|
+
}
|
|
8052
|
+
|
|
8053
|
+
/** The visible references in order — Shift+click ranges and the arrow keys walk this. */
|
|
8054
|
+
const kbVisibleRows = () => [...$wsKnowledge.querySelectorAll('.kb-refs-body .kb-src[data-source-id]')].map((el) => el.dataset.sourceId);
|
|
8055
|
+
const kbFocusables = () => [...$wsKnowledge.querySelectorAll('.kb-refs-body .kb-cat-toggle, .kb-refs-body .kb-fname')];
|
|
8056
|
+
|
|
8057
|
+
function kbSelectClick(sourceId, e) {
|
|
8058
|
+
kbSel = kbcSelect(kbSelFor(current, knowledgeState), sourceId, { toggle: e.ctrlKey || e.metaKey, shift: e.shiftKey }, kbVisibleRows());
|
|
8059
|
+
kbCatFocus = { row: sourceId };
|
|
8060
|
+
kbInvalidateRefs();
|
|
8061
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8062
|
+
const n = kbSel.selected.size;
|
|
8063
|
+
kbAnnounce(n ? `${n} selected.` : 'Nothing selected.');
|
|
8064
|
+
}
|
|
8065
|
+
|
|
8066
|
+
/** The click handler's category half; true when it handled the click. */
|
|
8067
|
+
function kbCatClick(e) {
|
|
8068
|
+
const t = e.target;
|
|
8069
|
+
const toggle = t.closest('[data-kb-cat-toggle]');
|
|
8070
|
+
if (toggle) {
|
|
8071
|
+
const id = toggle.dataset.kbCatToggle;
|
|
8072
|
+
const folded = kbCatCollapsedFor(current);
|
|
8073
|
+
if (folded.has(id)) folded.delete(id); else folded.add(id);
|
|
8074
|
+
kbCatSaveCollapsed();
|
|
8075
|
+
kbCatFocus = { cat: id };
|
|
8076
|
+
kbInvalidateRefs();
|
|
8077
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8078
|
+
return true;
|
|
8079
|
+
}
|
|
8080
|
+
const menu = t.closest('[data-kb-cat-menu]');
|
|
8081
|
+
if (menu) { kbShowCatMenu(menu); return true; }
|
|
8082
|
+
const rename = t.closest('[data-kb-cat-rename]');
|
|
8083
|
+
if (rename) {
|
|
8084
|
+
const cat = kbCats(knowledgeState).categories.find((c) => c.id === rename.dataset.kbCatRename);
|
|
8085
|
+
if (cat) kbCatStartEdit({ mode: 'rename', id: cat.id, name: cat.name });
|
|
8086
|
+
return true;
|
|
8087
|
+
}
|
|
8088
|
+
const sub = t.closest('[data-kb-cat-sub]');
|
|
8089
|
+
if (sub) { kbCatStartEdit({ mode: 'new', parentId: sub.dataset.kbCatSub }); return true; }
|
|
8090
|
+
const up = t.closest('[data-kb-cat-up], [data-kb-cat-down]');
|
|
8091
|
+
if (up) {
|
|
8092
|
+
const id = up.dataset.kbCatUp || up.dataset.kbCatDown;
|
|
8093
|
+
kbCloseConfirm();
|
|
8094
|
+
const ops = kbcReorderOps(kbCats(knowledgeState), id, up.hasAttribute('data-kb-cat-up') ? -1 : 1);
|
|
8095
|
+
if (ops) kbCatOps(ops, `Moved ${kbcLabel(kbCats(knowledgeState), id)} ${up.hasAttribute('data-kb-cat-up') ? 'up' : 'down'}.`, { cat: id });
|
|
8096
|
+
return true;
|
|
8097
|
+
}
|
|
8098
|
+
const catMove = t.closest('[data-kb-cat-move]');
|
|
8099
|
+
if (catMove) {
|
|
8100
|
+
const id = catMove.dataset.kbCatMove;
|
|
8101
|
+
const anchor = $wsKnowledge.querySelector(`[data-kb-cat-menu="${CSS.escape(id)}"]`) || catMove;
|
|
8102
|
+
kbShowMoveMenu(anchor, { categoryId: id });
|
|
8103
|
+
return true;
|
|
8104
|
+
}
|
|
8105
|
+
const del = t.closest('[data-kb-cat-delete]');
|
|
8106
|
+
if (del) {
|
|
8107
|
+
const id = del.dataset.kbCatDelete;
|
|
8108
|
+
kbShowCatDelete($wsKnowledge.querySelector(`[data-kb-cat-menu="${CSS.escape(id)}"]`) || del, id);
|
|
8109
|
+
return true;
|
|
8110
|
+
}
|
|
8111
|
+
const delGo = t.closest('[data-kb-cat-delete-go]');
|
|
8112
|
+
if (delGo) {
|
|
8113
|
+
const id = delGo.dataset.kbCatDeleteGo;
|
|
8114
|
+
const file = kbCats(knowledgeState);
|
|
8115
|
+
const cat = file.categories.find((c) => c.id === id);
|
|
8116
|
+
const parent = cat && cat.parentId ? kbcLabel(file, cat.parentId) : 'Uncategorized';
|
|
8117
|
+
const n = knowledgeState.sources.filter((r) => kbcPlacement(file, r.sourceId) === id).length;
|
|
8118
|
+
kbCloseConfirm();
|
|
8119
|
+
kbCatOps([{ op: 'delete', id }], `Deleted the category ${cat ? cat.name : ''}.${n ? ` ${n} reference${n === 1 ? '' : 's'} moved up to ${parent}.` : ''}`,
|
|
8120
|
+
cat && cat.parentId ? { cat: cat.parentId } : null);
|
|
8121
|
+
return true;
|
|
8122
|
+
}
|
|
8123
|
+
const newCat = t.closest('[data-kb-cat-new]');
|
|
8124
|
+
if (newCat) { kbCatStartEdit({ mode: 'new', parentId: null }); return true; }
|
|
8125
|
+
if (t.closest('[data-kb-cat-save]')) { kbCatSaveEdit(); return true; }
|
|
8126
|
+
if (t.closest('[data-kb-cat-cancel]')) {
|
|
8127
|
+
const e2 = kbCatEdit;
|
|
8128
|
+
kbCatEndEdit(e2 && e2.mode === 'rename' ? { cat: e2.id } : null);
|
|
8129
|
+
return true;
|
|
8130
|
+
}
|
|
8131
|
+
if (t.closest('[data-kb-cat-reset]')) { kbCatPost('/categories', { reset: true }, () => kbAnnounce('Started again with no categories. The old ones are kept aside.')); return true; }
|
|
8132
|
+
const moveSel = t.closest('[data-kb-move-sel]');
|
|
8133
|
+
if (moveSel) { kbShowMoveMenu(moveSel, { sourceIds: [...kbSelFor(current, knowledgeState).selected] }); return true; }
|
|
8134
|
+
const rowMove = t.closest('[data-kb-row-move]');
|
|
8135
|
+
if (rowMove) {
|
|
8136
|
+
const id = rowMove.dataset.kbRowMove;
|
|
8137
|
+
const anchor = $wsKnowledge.querySelector(`[data-kb-open="${CSS.escape(id)}"]`) || rowMove;
|
|
8138
|
+
const sel = kbSelFor(current, knowledgeState).selected;
|
|
8139
|
+
kbShowMoveMenu(anchor, { sourceIds: sel.has(id) ? [...sel] : [id] });
|
|
8140
|
+
return true;
|
|
8141
|
+
}
|
|
8142
|
+
if (t.closest('[data-kb-sel-clear]')) {
|
|
8143
|
+
kbSel = { selected: new Set(), anchor: null };
|
|
8144
|
+
kbAnnounce('Nothing selected.');
|
|
8145
|
+
kbInvalidateRefs();
|
|
8146
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8147
|
+
const first = $wsKnowledge.querySelector('.kb-refs-body .kb-fname');
|
|
8148
|
+
if (first) first.focus();
|
|
8149
|
+
return true;
|
|
8150
|
+
}
|
|
8151
|
+
const go = t.closest('[data-kb-move-go]');
|
|
8152
|
+
if (go) {
|
|
8153
|
+
const pop = go.closest('.hist-confirm');
|
|
8154
|
+
const what = pop && pop.kbWhat;
|
|
8155
|
+
const to = go.dataset.kbMoveGo || null;
|
|
8156
|
+
kbCloseConfirm();
|
|
8157
|
+
if (what && what.categoryId) {
|
|
8158
|
+
const file = kbCats(knowledgeState);
|
|
8159
|
+
kbCatOps([{ op: 'move', id: what.categoryId, parentId: to }], `Moved ${kbcLabel(file, what.categoryId)} to ${to ? kbcLabel(file, to) : 'the top level'}.`, { cat: what.categoryId });
|
|
8160
|
+
if (to) { kbCatCollapsed.delete(to); kbCatSaveCollapsed(); }
|
|
8161
|
+
} else if (what && what.sourceIds) kbPlace(what.sourceIds, to);
|
|
8162
|
+
return true;
|
|
8163
|
+
}
|
|
8164
|
+
const moveNew = t.closest('[data-kb-move-new]');
|
|
8165
|
+
if (moveNew) {
|
|
8166
|
+
const pop = moveNew.closest('.hist-confirm');
|
|
8167
|
+
const what = pop && pop.kbWhat;
|
|
8168
|
+
kbCatStartEdit({ mode: 'new', parentId: null, then: what || null });
|
|
8169
|
+
return true;
|
|
8170
|
+
}
|
|
8171
|
+
// Selection: Ctrl/Cmd or Shift on a row (its name included) selects instead of opening.
|
|
8172
|
+
const row = t.closest('.kb-src[data-source-id]');
|
|
8173
|
+
if (row && (e.ctrlKey || e.metaKey || e.shiftKey) && !t.closest('[data-kb-toggle], [data-kb-remove], .kb-ds-mi, [data-company-promote]')) {
|
|
8174
|
+
e.preventDefault();
|
|
8175
|
+
kbSelectClick(row.dataset.sourceId, e);
|
|
8176
|
+
return true;
|
|
8177
|
+
}
|
|
8178
|
+
return false;
|
|
8179
|
+
}
|
|
8180
|
+
|
|
8181
|
+
function kbShowRowMenu(fname) {
|
|
8182
|
+
const row = fname.closest('.kb-src[data-source-id]');
|
|
8183
|
+
if (!row) return;
|
|
8184
|
+
const id = row.dataset.sourceId;
|
|
8185
|
+
const name = fname.textContent || 'this reference';
|
|
8186
|
+
const tog = row.querySelector('[data-kb-toggle]');
|
|
8187
|
+
const on = tog && tog.getAttribute('aria-checked') === 'true';
|
|
8188
|
+
const src = knowledgeState && knowledgeState.sources.find((x) => x.sourceId === id);
|
|
8189
|
+
const promote = src && src.kind === 'file';
|
|
8190
|
+
const pop = kbCatPop(fname,
|
|
8191
|
+
(kbCats(knowledgeState).categories.length ? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-row-move="${escapeAttr(id)}" data-command-id="shell.kb-move-to#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">Move to…</button>` : '') +
|
|
8192
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-kb-row-act="toggle" data-kb-row-id="${escapeAttr(id)}" data-command-id="shell.kb-category-row-toggle#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">${on ? 'Exclude from the knowledge base' : 'Include in the knowledge base'}</button>` +
|
|
8193
|
+
(promote ? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-row-act="promote" data-kb-row-id="${escapeAttr(id)}" data-command-id="shell.company-promote-source#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">Promote to company…</button>` : '') +
|
|
8194
|
+
`<button type="button" role="menuitem" class="kb-ds-mi danger" data-kb-row-act="remove" data-kb-row-id="${escapeAttr(id)}" data-command-id="shell.kb-category-row-remove#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">Remove…</button>`,
|
|
8195
|
+
`More for ${name}`, 'menu');
|
|
8196
|
+
const first = pop && pop.querySelector('.kb-ds-mi');
|
|
8197
|
+
if (first) first.focus();
|
|
8198
|
+
}
|
|
8199
|
+
|
|
8200
|
+
/** The keyboard half: arrows walk the list, Space selects, Ctrl+A selects every visible row, Alt+arrows reorder a category, Delete asks, the menu key opens a menu. */
|
|
8201
|
+
function kbCatKeydown(e) {
|
|
8202
|
+
const t = e.target;
|
|
8203
|
+
if (t.classList && t.classList.contains('kb-cat-input')) {
|
|
8204
|
+
if (e.key === 'Enter') { e.preventDefault(); kbCatSaveEdit(); return true; }
|
|
8205
|
+
if (e.key === 'Escape') { e.preventDefault(); const e2 = kbCatEdit; kbCatEndEdit(e2 && e2.mode === 'rename' ? { cat: e2.id } : null); return true; }
|
|
8206
|
+
return false;
|
|
8207
|
+
}
|
|
8208
|
+
const pop = t.closest && t.closest('.kb-cat-menu, .hist-confirm');
|
|
8209
|
+
if (pop && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
|
|
8210
|
+
const items = [...pop.querySelectorAll('.kb-ds-mi')];
|
|
8211
|
+
const at = items.indexOf(t);
|
|
8212
|
+
if (at >= 0) { e.preventDefault(); items[(at + (e.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length].focus(); return true; }
|
|
8213
|
+
}
|
|
8214
|
+
if (pop && e.key === 'Escape') {
|
|
8215
|
+
// Back to the control that opened it (the menu button, the row, the category, or the selection bar).
|
|
8216
|
+
const el = pop.kbAnchor;
|
|
8217
|
+
kbCloseConfirm();
|
|
8218
|
+
if (el && el.isConnected) el.focus();
|
|
8219
|
+
e.preventDefault();
|
|
8220
|
+
return true;
|
|
8221
|
+
}
|
|
8222
|
+
// Ctrl/Cmd+A anywhere in References (not in a text box) selects every visible reference, like a file list.
|
|
8223
|
+
if ((e.key === 'a' || e.key === 'A') && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && t.closest
|
|
8224
|
+
&& t.closest('.kb-refs-body') && !t.closest('input, textarea, [contenteditable="true"]')) {
|
|
8225
|
+
const rows = kbVisibleRows();
|
|
8226
|
+
// Never the browser's own select-all here: with every category folded it would select the whole page's text.
|
|
8227
|
+
e.preventDefault();
|
|
8228
|
+
if (!rows.length) { kbAnnounce('No references are shown to select. Open a category to see its references.'); return true; }
|
|
8229
|
+
kbSel = kbcSelectAll(kbSelFor(current, knowledgeState), rows);
|
|
8230
|
+
// The repaint replaces the focused control; bring focus back to the same row or category so Escape and the arrows still work.
|
|
8231
|
+
const cat = t.closest('[data-kb-cat-toggle]'), row = t.closest('.kb-src[data-source-id]');
|
|
8232
|
+
kbCatFocus = cat ? { cat: cat.dataset.kbCatToggle } : row ? { row: row.dataset.sourceId } : null;
|
|
8233
|
+
kbInvalidateRefs();
|
|
8234
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
8235
|
+
kbAnnounce(`All ${rows.length} selected.`);
|
|
8236
|
+
return true;
|
|
8237
|
+
}
|
|
8238
|
+
const catBtn = t.closest && t.closest('.kb-cat-toggle');
|
|
8239
|
+
const fname = t.closest && t.closest('.kb-refs-body .kb-fname');
|
|
8240
|
+
// Escape clears the selection from anywhere in the list, a selected name included (where a Ctrl+click leaves focus).
|
|
8241
|
+
if (e.key === 'Escape' && kbSel.selected.size && t.closest && t.closest('.kb-refs-body')) { $wsKnowledge.querySelector('[data-kb-sel-clear]')?.click(); return true; }
|
|
8242
|
+
if (!catBtn && !fname) return false;
|
|
8243
|
+
const menuKey = e.key === 'ContextMenu' || (e.key === 'F10' && e.shiftKey);
|
|
8244
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
8245
|
+
if (catBtn && e.altKey) {
|
|
8246
|
+
const id = catBtn.dataset.kbCatToggle;
|
|
8247
|
+
if (id === 'uncategorized') return true;
|
|
8248
|
+
e.preventDefault();
|
|
8249
|
+
const dir = e.key === 'ArrowUp' ? -1 : 1;
|
|
8250
|
+
const ops = kbcReorderOps(kbCats(knowledgeState), id, dir);
|
|
8251
|
+
if (ops) kbCatOps(ops, `Moved ${kbcLabel(kbCats(knowledgeState), id)} ${dir < 0 ? 'up' : 'down'}.`, { cat: id });
|
|
8252
|
+
return true;
|
|
8253
|
+
}
|
|
8254
|
+
const all = kbFocusables();
|
|
8255
|
+
const at = all.indexOf(catBtn || fname);
|
|
8256
|
+
const next = all[at + (e.key === 'ArrowDown' ? 1 : -1)];
|
|
8257
|
+
if (next) { e.preventDefault(); next.focus(); if (e.shiftKey && fname && next.classList.contains('kb-fname')) kbSelectClick(next.closest('.kb-src').dataset.sourceId, { shiftKey: true }); }
|
|
8258
|
+
return true;
|
|
8259
|
+
}
|
|
8260
|
+
if (catBtn && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
|
|
8261
|
+
const id = catBtn.dataset.kbCatToggle;
|
|
8262
|
+
const open = catBtn.getAttribute('aria-expanded') === 'true';
|
|
8263
|
+
if ((e.key === 'ArrowRight') !== open) { e.preventDefault(); catBtn.click(); }
|
|
8264
|
+
return true;
|
|
8265
|
+
}
|
|
8266
|
+
if (fname && e.key === ' ') { e.preventDefault(); kbSelectClick(fname.closest('.kb-src').dataset.sourceId, { ctrlKey: true }); return true; }
|
|
8267
|
+
if (e.key === 'Delete') {
|
|
8268
|
+
e.preventDefault();
|
|
8269
|
+
if (catBtn) { const id = catBtn.dataset.kbCatToggle; if (id !== 'uncategorized') kbShowCatDelete(catBtn, id); }
|
|
8270
|
+
else fname.closest('.kb-src').querySelector('[data-kb-remove]')?.click();
|
|
8271
|
+
return true;
|
|
8272
|
+
}
|
|
8273
|
+
if (menuKey) {
|
|
8274
|
+
e.preventDefault();
|
|
8275
|
+
if (catBtn) { const more = catBtn.parentElement.querySelector('[data-kb-cat-menu]'); if (more) kbShowCatMenu(more); }
|
|
8276
|
+
else kbShowRowMenu(fname);
|
|
8277
|
+
return true;
|
|
8278
|
+
}
|
|
8279
|
+
return false;
|
|
8280
|
+
}
|
|
8281
|
+
|
|
8282
|
+
/** A row menu's choices act through the row's own controls, so they keep every rule those controls have. */
|
|
8283
|
+
function kbRowAct(btn) {
|
|
8284
|
+
const id = btn.dataset.kbRowId;
|
|
8285
|
+
const row = $wsKnowledge.querySelector(`.kb-src[data-source-id="${CSS.escape(id)}"]`);
|
|
8286
|
+
kbCloseConfirm();
|
|
8287
|
+
if (!row) return;
|
|
8288
|
+
const act = btn.dataset.kbRowAct;
|
|
8289
|
+
if (act === 'promote') {
|
|
8290
|
+
const src = knowledgeState && knowledgeState.sources.find((x) => x.sourceId === id);
|
|
8291
|
+
if (src) openCompanyKnowledge({ sourceId: src.sourceId, filename: src.filename || 'untitled', mime: src.mime }, row.querySelector('.kb-fname'));
|
|
8292
|
+
return;
|
|
8293
|
+
}
|
|
8294
|
+
const target = act === 'toggle' ? row.querySelector('[data-kb-toggle]') : row.querySelector('[data-kb-remove]');
|
|
8295
|
+
if (target) target.click();
|
|
8296
|
+
}
|
|
8297
|
+
|
|
8298
|
+
// Drag and drop. A drag carries the selection when the dragged row is in it, else just that row. Files from the desktop
|
|
8299
|
+
// dropped on a category are added straight into it (the server files them only for the person's own drop).
|
|
8300
|
+
let kbDragIds = null;
|
|
8301
|
+
let kbDragHover = null; // { el, timer }
|
|
8302
|
+
function kbDragChip(n, name) {
|
|
8303
|
+
const chip = document.createElement('div');
|
|
8304
|
+
chip.className = 'kb-drag-chip';
|
|
8305
|
+
chip.textContent = n === 1 ? name : `${n} references`;
|
|
8306
|
+
document.body.appendChild(chip);
|
|
8307
|
+
setTimeout(() => chip.remove(), 0);
|
|
8308
|
+
return chip;
|
|
8309
|
+
}
|
|
8310
|
+
function kbDropTargetOf(e) {
|
|
8311
|
+
const el = e.target.closest && e.target.closest('[data-kb-drop-cat]');
|
|
8312
|
+
return el && el.closest('.kb-refs-body') ? el : null;
|
|
8313
|
+
}
|
|
8314
|
+
/** Open a folded category during a drag without repainting the column (the dragged row must survive). */
|
|
8315
|
+
function kbCatExpandInPlace(id) {
|
|
8316
|
+
const head = $wsKnowledge.querySelector(`.kb-cat[data-kb-drop-cat="${CSS.escape(id)}"]`);
|
|
8317
|
+
if (!head || !knowledgeState) return;
|
|
8318
|
+
const file = kbCats(knowledgeState);
|
|
8319
|
+
const rows = knowledgeState.sources.filter((r) => !kbInDesignSet(r, knowledgeState) && kbcPlacement(file, r.sourceId) === id);
|
|
8320
|
+
const depth = Number((head.getAttribute('style') || '').match(/--kb-depth:(d+)/)?.[1] || 0);
|
|
8321
|
+
head.classList.add('open');
|
|
8322
|
+
head.querySelector('.kb-cat-toggle')?.setAttribute('aria-expanded', 'true');
|
|
8323
|
+
head.insertAdjacentHTML('afterend', rows.map((r) => kbSourceRow(r, knowledgeState, depth + 1)).join(''));
|
|
8324
|
+
}
|
|
8325
|
+
|
|
8326
|
+
function kbClearDropHover() {
|
|
8327
|
+
if (!kbDragHover) return;
|
|
8328
|
+
kbDragHover.el.classList.remove('drop-target');
|
|
8329
|
+
kbDragHover.el.removeAttribute('data-drop-label');
|
|
8330
|
+
clearTimeout(kbDragHover.timer);
|
|
8331
|
+
kbDragHover = null;
|
|
8332
|
+
}
|
|
8333
|
+
|
|
7225
8334
|
/**
|
|
7226
8335
|
* #2131: a queued organize whose start met work already changing the project. Only what was recorded is said — when
|
|
7227
8336
|
* the AI last tried and who held the project — never that it starts by itself: nothing here can tell whether that AI
|
|
@@ -7323,49 +8432,6 @@
|
|
|
7323
8432
|
// way across re-renders (no visual jitter on a poll tick / repaint) without needing a persisted
|
|
7324
8433
|
// layout. The force pass then relaxes overlaps via simple repulsion + edge-spring + centering.
|
|
7325
8434
|
function kbHash(s) { let h = 2166136261; for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); } return h >>> 0; }
|
|
7326
|
-
function kbLayout(nodes, edges) {
|
|
7327
|
-
const W = 600, H = 440, N = nodes.length;
|
|
7328
|
-
const iters = N <= 60 ? 300 : N <= 150 ? 150 : 60;
|
|
7329
|
-
const R = Math.min(W, H) / 2 - 40;
|
|
7330
|
-
const pos = nodes.map((n, i) => { const ang = i * 2.399963 + (kbHash(n.id) % 628) / 100; const rad = 18 + (N > 1 ? (i / (N - 1)) * R : 0);
|
|
7331
|
-
return { id: n.id, x: W / 2 + Math.cos(ang) * rad, y: H / 2 + Math.sin(ang) * rad }; });
|
|
7332
|
-
const idx = new Map(pos.map((p, i) => [p.id, i]));
|
|
7333
|
-
const K = 140;
|
|
7334
|
-
for (let it = 0; it < iters; it++) {
|
|
7335
|
-
const fx = new Array(N).fill(0), fy = new Array(N).fill(0);
|
|
7336
|
-
for (let i = 0; i < N; i++) for (let j = i + 1; j < N; j++) {
|
|
7337
|
-
let dx = pos[i].x - pos[j].x, dy = pos[i].y - pos[j].y; const d2 = dx * dx + dy * dy || 0.01, d = Math.sqrt(d2), rep = 9000 / d2;
|
|
7338
|
-
fx[i] += dx / d * rep; fy[i] += dy / d * rep; fx[j] -= dx / d * rep; fy[j] -= dy / d * rep; }
|
|
7339
|
-
for (const e of edges) { const i = idx.get(e.a), j = idx.get(e.b); if (i == null || j == null) continue;
|
|
7340
|
-
let dx = pos[j].x - pos[i].x, dy = pos[j].y - pos[i].y; const d = Math.sqrt(dx * dx + dy * dy) || 0.01, s = (d - K) * 0.02;
|
|
7341
|
-
fx[i] += dx / d * s; fy[i] += dy / d * s; fx[j] -= dx / d * s; fy[j] -= dy / d * s; }
|
|
7342
|
-
for (let i = 0; i < N; i++) { fx[i] += (W / 2 - pos[i].x) * 0.01; fy[i] += (H / 2 - pos[i].y) * 0.01;
|
|
7343
|
-
pos[i].x = Math.max(24, Math.min(W - 24, pos[i].x + Math.max(-20, Math.min(20, fx[i]))));
|
|
7344
|
-
pos[i].y = Math.max(24, Math.min(H - 24, pos[i].y + Math.max(-20, Math.min(20, fy[i])))); }
|
|
7345
|
-
}
|
|
7346
|
-
return { pos, idx, W, H };
|
|
7347
|
-
}
|
|
7348
|
-
|
|
7349
|
-
// Node fields are ALL escaped (title/slug/type are LLM-derived). Each node carries an aria-label AND
|
|
7350
|
-
// a type-bearing data-tip so its taxonomy is available to AT + sighted users, not encoded by colour
|
|
7351
|
-
// alone (WCAG 1.4.1). An invisible r=16 hit circle widens the click/focus target behind the r=9 dot.
|
|
7352
|
-
function kbGraphSvg(graph) {
|
|
7353
|
-
if (!graph || !graph.nodes.length) return graph && graph.truncated ? kbGraphTruncatedEmpty() : kbGraphEmpty(knowledgeState);
|
|
7354
|
-
const { pos, idx, W, H } = kbLayout(graph.nodes, graph.edges);
|
|
7355
|
-
const lines = graph.edges.map((e) => { const a = pos[idx.get(e.a)], b = pos[idx.get(e.b)];
|
|
7356
|
-
return (a && b) ? `<line class="kb-g-edge" x1="${a.x.toFixed(1)}" y1="${a.y.toFixed(1)}" x2="${b.x.toFixed(1)}" y2="${b.y.toFixed(1)}"/>` : ''; }).join('');
|
|
7357
|
-
const dots = graph.nodes.map((n, i) => { const p = pos[i];
|
|
7358
|
-
return `<g class="kb-g-node kb-g-${escapeAttr(n.type)}" tabindex="0" role="button" aria-label="${escapeAttr(n.title + ', ' + n.type)}" data-kb-node="${escapeAttr(n.slug)}" data-tip="${escapeAttr(n.title + ' · ' + n.type)}" data-pos="${p.x.toFixed(1)},${p.y.toFixed(1)}" transform="translate(${p.x.toFixed(1)},${p.y.toFixed(1)})">` +
|
|
7359
|
-
`<circle class="kb-g-hit" r="16"/><circle class="kb-g-dot" r="9"/><text x="13" y="4">${escapeHtml(n.title)}</text></g>`; }).join('');
|
|
7360
|
-
const legend = '<div class="kb-g-legend"><span class="kb-gleg src">Source</span><span class="kb-gleg con">Concept</span><span class="kb-gleg per">Person</span></div>';
|
|
7361
|
-
const note = graph.truncated ? `<div class="kb-view-note">Showing ${graph.nodes.length} — graph truncated (some pages omitted)</div>` : '';
|
|
7362
|
-
// No header of its own: the step's single full-width band above the split names this pane, and
|
|
7363
|
-
// the Overview button moved there so it survives opening a page. See kbStepHeadHtml.
|
|
7364
|
-
return '<section class="kb-col kb-graph">' +
|
|
7365
|
-
'<div class="kb-graph-sub">' + legend + '<span class="kb-g-hint">Click a node to open its page · scroll to zoom · drag to pan</span></div>' +
|
|
7366
|
-
`<div class="kb-graph-body"><svg viewBox="0 0 ${W} ${H}" data-vb-base="0 0 ${W} ${H}" class="kb-graph-svg" role="group" aria-label="Knowledge graph">${lines}${dots}</svg>` +
|
|
7367
|
-
`<button type="button" class="kb-g-fit" data-kb-fit hidden data-tip="Zoom to fit (Home)" aria-label="Zoom to fit">⤢ Fit</button></div>${note}</section>`;
|
|
7368
|
-
}
|
|
7369
8435
|
// View-only pan/zoom: we mutate the live SVG viewBox, never re-layout. The base 0 0 W H box IS the
|
|
7370
8436
|
// fit; the Fit button + Home key restore it, and it shows only while zoomed/panned. Zoom resets on a
|
|
7371
8437
|
// generation re-render (rare) — ponytail: persisting it across re-layouts isn't worth the state.
|
|
@@ -7417,7 +8483,8 @@
|
|
|
7417
8483
|
// loading + error REUSE the file viewer's own message idiom (.kb-view-msg / .kb-view-spin /
|
|
7418
8484
|
// .kb-view-ico.err / .primary Retry) so the graph's "can't show content yet" states look identical
|
|
7419
8485
|
// to the file preview's — one learned pattern, not a second near-duplicate.
|
|
7420
|
-
|
|
8486
|
+
/** The first layout is still being worked out; `note` (the loading line with Stop) shows above it, so a big map can be stopped. */
|
|
8487
|
+
function kbGraphLoading(note = '') { return '<section class="kb-col">' + note + '<div class="kb-view-msg"><div class="kb-view-spin" role="status" aria-label="Building graph"></div><div class="kb-view-msg-title">Building graph…</div></div></section>'; }
|
|
7421
8488
|
function kbGraphError() { return '<section class="kb-col"><div class="kb-view-msg"><span class="kb-view-ico err" aria-hidden="true">⚠</span><div class="kb-view-msg-title">Couldn’t load the graph.</div><div class="kb-view-act"><button type="button" class="primary" data-kb-graph-retry>↻ Retry</button></div></div></section>'; }
|
|
7422
8489
|
// Whitelist the LLM-derived page type into a SAFE single class token — never interpolate it raw (a
|
|
7423
8490
|
// space would inject extra classes). Same discipline as KB_CHIP; an unknown type falls back to the
|
|
@@ -7541,7 +8608,10 @@
|
|
|
7541
8608
|
const alive = () => epoch === viewEpoch && key === lastViewKey &&
|
|
7542
8609
|
current && current.id === proj.id && !$wsKnowledge.hidden;
|
|
7543
8610
|
|
|
7544
|
-
|
|
8611
|
+
// #2491 R6.3: a Word, Excel or email file shows the TEXT FloLess read from it — never its bytes.
|
|
8612
|
+
if (!row.rawUrl && KB_OFFICE_MIMES.has(row.mime)) { await kbLoadOfficeText(proj, row, alive); return; }
|
|
8613
|
+
|
|
8614
|
+
const url = row.rawUrl || kbRawUrl(proj.id, row.sourceId);
|
|
7545
8615
|
const ac = new AbortController();
|
|
7546
8616
|
kbTextAbort = ac;
|
|
7547
8617
|
|
|
@@ -7564,30 +8634,278 @@
|
|
|
7564
8634
|
}
|
|
7565
8635
|
|
|
7566
8636
|
if (row.mime === 'application/pdf') kbPaintPdf(row, url);
|
|
7567
|
-
else if (row.mime === 'image/png' || row.mime === 'image/jpeg') kbPaintImage(row, url, alive);
|
|
8637
|
+
else if (row.mime === 'image/png' || row.mime === 'image/jpeg' || row.mime === 'image/webp') kbPaintImage(row, url, alive);
|
|
7568
8638
|
else kbPaintText(row, url, ac, alive);
|
|
7569
8639
|
}
|
|
7570
8640
|
|
|
7571
8641
|
// ── Stage C: the knowledge graph + page viewer ──────────────────────────────────
|
|
7572
8642
|
// Same alive()/epoch/key contract as kbLoadPreview above — the render only happens if nothing else
|
|
7573
8643
|
// (a new epoch, a changed key, a project switch, or leaving the pane) superseded this fetch meanwhile.
|
|
8644
|
+
// ── #2491 R6.9: the knowledge map — streamed, laid out off the main thread, coloured by the person's categories ──
|
|
8645
|
+
// The pure half is web/kb-categories.js (kbg*). This screen holds the whole map of the current generation: it asks for
|
|
8646
|
+
// chunks until there is no next, keeps links by slug until both ends have arrived, and filters and colours it itself
|
|
8647
|
+
// from the current categories, so a move in the tree recolours the map without asking the server again.
|
|
8648
|
+
let kbGm = null; // { projId, model, layoutKey, pos: Map(id → {x,y}), w, h, stopped, error, loading }
|
|
8649
|
+
const kbGo = { hiddenCats: new Set(), hiddenTypes: new Set(), search: '', neighbourOf: null, list: false };
|
|
8650
|
+
let kbGWorker = null, kbGEpoch = 0, kbGFocus = null;
|
|
8651
|
+
|
|
8652
|
+
function kbGraphResetOpts() {
|
|
8653
|
+
kbGo.hiddenCats = new Set(); kbGo.hiddenTypes = new Set(); kbGo.search = ''; kbGo.neighbourOf = null;
|
|
8654
|
+
}
|
|
8655
|
+
function kbGraphStopWorker() {
|
|
8656
|
+
if (kbGWorker) { try { kbGWorker.terminate(); } catch { /* gone */ } kbGWorker = null; }
|
|
8657
|
+
kbGEpoch += 1;
|
|
8658
|
+
}
|
|
8659
|
+
|
|
7574
8660
|
async function kbLoadGraph(proj) {
|
|
7575
8661
|
const epoch = viewEpoch, key = lastViewKey;
|
|
7576
8662
|
const alive = () => epoch === viewEpoch && key === lastViewKey && current && current.id === proj.id && !$wsKnowledge.hidden;
|
|
7577
8663
|
const ac = new AbortController(); kbTextAbort = ac;
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
if (!alive()) return;
|
|
7584
|
-
kbGraphIndex = body.graph.index || null; // feeds the step header's ✦ Overview button
|
|
7585
|
-
const h = kbViewHost(); if (h) h.innerHTML = kbGraphSvg(body.graph);
|
|
8664
|
+
const want = knowledgeState && knowledgeState.currentGeneration ? knowledgeState.currentGeneration.generationId : null;
|
|
8665
|
+
// The same generation, already complete: draw it again (recoloured from the current categories), no fetch.
|
|
8666
|
+
if (kbGm && kbGm.projId === proj.id && kbGm.model.generationId === want && kbGm.model.done && !kbGm.error) {
|
|
8667
|
+
kbGraphIndex = kbGm.model.index || null;
|
|
8668
|
+
kbGraphRender(true);
|
|
7586
8669
|
if (knowledgeState) kbPaintStepHead(knowledgeState);
|
|
8670
|
+
return;
|
|
8671
|
+
}
|
|
8672
|
+
// "Load the rest" after Stop carries on from the last chunk that arrived, keeping what is already drawn.
|
|
8673
|
+
const resume = !!(kbGm && kbGm.resume && kbGm.projId === proj.id && kbGm.model.generationId === want
|
|
8674
|
+
&& kbGm.next !== null && kbGm.next !== undefined && !kbGm.error);
|
|
8675
|
+
if (!kbGm || kbGm.projId !== proj.id) kbGraphResetOpts();
|
|
8676
|
+
kbGraphStopWorker();
|
|
8677
|
+
if (resume) Object.assign(kbGm, { stopped: false, loading: true, resume: false });
|
|
8678
|
+
else kbGm = { projId: proj.id, model: kbgCreate(null), layoutKey: null, pos: new Map(), w: 600, h: 440, stopped: false, error: null, loading: true, next: null };
|
|
8679
|
+
try {
|
|
8680
|
+
let generation = resume ? kbGm.model.generationId : null; let cursor = resume ? kbGm.next : 0; let restarts = 0;
|
|
8681
|
+
for (;;) {
|
|
8682
|
+
const q = generation ? `?generation=${encodeURIComponent(generation)}&cursor=${cursor}` : '';
|
|
8683
|
+
const r = await fetch(`/api/projects/${encodeURIComponent(proj.id)}/knowledge/graph${q}`, { signal: ac.signal, cache: 'no-store' });
|
|
8684
|
+
if (!r.ok) throw new Error(`graph ${r.status}`);
|
|
8685
|
+
const body = await r.json();
|
|
8686
|
+
if (!body || !body.graph) throw new Error('bad graph envelope');
|
|
8687
|
+
if (!alive()) return;
|
|
8688
|
+
const g = body.graph;
|
|
8689
|
+
if (g.restart) {
|
|
8690
|
+
// Organized again while the map was coming in: start over on the new generation (a few times at most).
|
|
8691
|
+
if (++restarts > 3) throw new Error('the map kept changing');
|
|
8692
|
+
generation = g.generationId; cursor = 0;
|
|
8693
|
+
kbGm.model = kbgCreate(generation); kbGm.pos = new Map(); kbGm.layoutKey = null;
|
|
8694
|
+
continue;
|
|
8695
|
+
}
|
|
8696
|
+
if (!Array.isArray(g.nodes)) throw new Error('bad graph envelope');
|
|
8697
|
+
if (!generation) { generation = g.generationId; kbGm.model = kbgCreate(generation); }
|
|
8698
|
+
kbgMerge(kbGm.model, g);
|
|
8699
|
+
kbGm.next = g.next ?? null;
|
|
8700
|
+
kbGraphIndex = kbGm.model.index || null;
|
|
8701
|
+
kbGm.loading = g.next !== null && g.next !== undefined && !kbGm.stopped;
|
|
8702
|
+
kbGraphRender(!kbGm.loading);
|
|
8703
|
+
if (knowledgeState) kbPaintStepHead(knowledgeState);
|
|
8704
|
+
if (!kbGm.loading) break;
|
|
8705
|
+
cursor = g.next;
|
|
8706
|
+
}
|
|
7587
8707
|
} catch (err) {
|
|
7588
8708
|
if (err && err.name === 'AbortError') return;
|
|
7589
|
-
if (alive()) { kbGraphIndex = null; const h = kbViewHost(); if (h) h.innerHTML = kbGraphError(); if (knowledgeState) kbPaintStepHead(knowledgeState); }
|
|
8709
|
+
if (alive()) { kbGraphIndex = null; if (kbGm) kbGm.error = String(err && err.message || err); const h = kbViewHost(); if (h) h.innerHTML = kbGraphError(); if (knowledgeState) kbPaintStepHead(knowledgeState); }
|
|
8710
|
+
}
|
|
8711
|
+
}
|
|
8712
|
+
|
|
8713
|
+
/** Lay out what is drawn now, off the main thread; a newer request (or closing the map) drops the older one. */
|
|
8714
|
+
function kbGraphLayout(view, done) {
|
|
8715
|
+
kbGraphStopWorker();
|
|
8716
|
+
const epoch = kbGEpoch;
|
|
8717
|
+
const ids = view.nodes.map((n) => n.id);
|
|
8718
|
+
const index = new Map(ids.map((id, i) => [id, i]));
|
|
8719
|
+
const edges = new Int32Array(view.edges.length * 2);
|
|
8720
|
+
view.edges.forEach(([a, b], i) => { edges[i * 2] = index.get(a); edges[i * 2 + 1] = index.get(b); });
|
|
8721
|
+
const seeds = Uint32Array.from(ids, (id) => kbHash(id));
|
|
8722
|
+
const finish = (x, y, w, h) => {
|
|
8723
|
+
if (epoch !== kbGEpoch || !kbGm) return;
|
|
8724
|
+
kbGm.pos = new Map(ids.map((id, i) => [id, { x: x[i], y: y[i] }]));
|
|
8725
|
+
kbGm.w = w; kbGm.h = h;
|
|
8726
|
+
done();
|
|
8727
|
+
};
|
|
8728
|
+
try {
|
|
8729
|
+
kbGWorker = new Worker('/kb-graph-worker.js');
|
|
8730
|
+
kbGWorker.onmessage = (ev) => { const m = ev.data || {}; if (m.epoch === epoch) { finish(m.x, m.y, m.w, m.h); kbGraphStopWorker(); } };
|
|
8731
|
+
kbGWorker.onerror = () => { kbGraphStopWorker(); if (kbGm) { kbGm.error = 'layout'; const h = kbViewHost(); if (h && viewer.mode === 'graph') h.innerHTML = kbGraphError(); } };
|
|
8732
|
+
kbGWorker.postMessage({ epoch, n: ids.length, edges, seeds }, [edges.buffer, seeds.buffer]);
|
|
8733
|
+
} catch {
|
|
8734
|
+
kbGraphStopWorker();
|
|
8735
|
+
if (kbGm) { kbGm.error = 'layout'; const h = kbViewHost(); if (h && viewer.mode === 'graph') h.innerHTML = kbGraphError(); }
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
|
|
8739
|
+
const KB_TYPE_LABEL = { source: 'Source', concept: 'Concept', person: 'Person' };
|
|
8740
|
+
function kbGraphNodeHtml(n, view, file) {
|
|
8741
|
+
const p = kbGm.pos.get(n.id);
|
|
8742
|
+
if (!p) return '';
|
|
8743
|
+
const m = view.member.get(n.id) || { cats: [], grouped: false };
|
|
8744
|
+
const cats = m.cats.slice(0, 3);
|
|
8745
|
+
const col = kbgColour(file, cats[0] || null);
|
|
8746
|
+
const label = n.kind === 'document' ? (n.filename || 'document') : (n.title || n.slug);
|
|
8747
|
+
const where = !m.grouped ? 'Not yet grouped' : m.cats.map((c) => (c === 'uncategorized' ? 'Uncategorized' : kbcLabel(file, c))).join(', ');
|
|
8748
|
+
const more = m.cats.length > 3 ? ` (+${m.cats.length - 3})` : '';
|
|
8749
|
+
// A document removed since the map was loaded is shown as gone at once: the cached map keeps the old flag.
|
|
8750
|
+
const gone = n.kind === 'document' && (n.present === false || !!(knowledgeState && !knowledgeState.sources.some((s) => s.sourceId === n.sourceId)));
|
|
8751
|
+
const kind = n.kind === 'document' ? (gone ? 'document, no longer in Knowledge' : 'document') : (KB_TYPE_LABEL[n.type] || 'Concept').toLowerCase() + ' page';
|
|
8752
|
+
const tip = `${label} · ${kind} · ${where}${more}`;
|
|
8753
|
+
const match = view.matchSet.has(n.id) ? ' match' : '';
|
|
8754
|
+
const cls = `kb-g-node ${n.kind === 'document' ? 'kb-g-doc' : 'kb-g-page kb-g-' + escapeAttr(n.type || 'concept')}${m.grouped ? '' : ' ungrouped'}${gone ? ' gone' : ''}${col.hatch ? ' hatch' : ''}${match}`;
|
|
8755
|
+
const act = n.kind === 'document' ? `data-kb-doc="${escapeAttr(n.sourceId)}"` : `data-kb-node="${escapeAttr(n.slug)}"`;
|
|
8756
|
+
const shape = n.kind === 'document'
|
|
8757
|
+
? '<rect class="kb-g-dot" x="-7" y="-7" width="14" height="14" rx="3"/>'
|
|
8758
|
+
: '<circle class="kb-g-dot" r="8"/>';
|
|
8759
|
+
const rings = cats.slice(1).map((c, i) => `<circle class="kb-g-ring" r="${11 + i * 3}" style="--kbg-c:var(${kbgColour(file, c).token})"/>`).join('');
|
|
8760
|
+
return `<g class="${cls}" tabindex="0" role="button" ${act} data-command-id="shell.kb-graph-open#${escapeAttr(n.id)}" data-command-instance-label="${escapeAttr(label)}" data-kb-gid="${escapeAttr(n.id)}" aria-label="${escapeAttr(tip)}" data-tip="${escapeAttr(tip)}"` +
|
|
8761
|
+
` style="--kbg-c:var(${col.token})" transform="translate(${p.x.toFixed(1)},${p.y.toFixed(1)})">` +
|
|
8762
|
+
`<circle class="kb-g-hit" r="16"/>${rings}${shape}<text x="13" y="4">${escapeHtml(label.length > 40 ? label.slice(0, 39) + '…' : label)}</text></g>`;
|
|
8763
|
+
}
|
|
8764
|
+
|
|
8765
|
+
function kbGraphControlsHtml(view, file) {
|
|
8766
|
+
const legend = kbgLegend(kbGm.model, file).map((c) =>
|
|
8767
|
+
`<button type="button" class="kb-gchip${c.hatch ? ' hatch' : ''}${c.dashed ? ' dashed' : ''}" aria-pressed="${kbGo.hiddenCats.has(c.id) ? 'false' : 'true'}" data-kb-gcat="${escapeAttr(c.id)}"` +
|
|
8768
|
+
` style="--kbg-c:var(${c.token})" data-command-id="shell.kb-graph-filter#${escapeAttr('cat-' + c.id)}" data-command-instance-label="${escapeAttr(c.name)}" data-tip="Show or hide ${escapeAttr(c.name)}"><span class="kb-gsw" aria-hidden="true"></span>${escapeHtml(c.name)} <span class="kb-gn">${c.n}</span></button>`).join('');
|
|
8769
|
+
const types = ['source', 'concept', 'person'].map((t) =>
|
|
8770
|
+
`<button type="button" class="kb-gchip kb-gtype" aria-pressed="${kbGo.hiddenTypes.has(t) ? 'false' : 'true'}" data-kb-gtype="${t}" data-command-id="shell.kb-graph-filter#${escapeAttr('type-' + t)}" data-command-instance-label="${escapeAttr(KB_TYPE_LABEL[t] + ' pages')}">${KB_TYPE_LABEL[t]} pages</button>`).join('');
|
|
8771
|
+
const hidden = kbGo.hiddenCats.size || kbGo.hiddenTypes.size;
|
|
8772
|
+
const found = kbGo.search ? `<span class="kb-gfound" role="status">${view.matches.length} found</span>` : '';
|
|
8773
|
+
return '<div class="kb-graph-sub kb-graph-ctl">' +
|
|
8774
|
+
`<div class="kb-g-legend" role="group" aria-label="Show categories">${legend}${hidden ? '<button type="button" class="kb-link" data-kb-gall data-command-id="shell.kb-graph-filter#all" data-command-instance-label="every category">Show all</button>' : ''}</div>` +
|
|
8775
|
+
`<div class="kb-g-types" role="group" aria-label="Show page types">${types}</div>` +
|
|
8776
|
+
'<div class="kb-g-tools">' +
|
|
8777
|
+
`<input type="search" class="kb-gsearch" placeholder="Find on the map" aria-label="Find on the map" value="${escapeAttr(kbGo.search)}" data-command-id="shell.kb-graph-search">${found}` +
|
|
8778
|
+
`<button type="button" class="kb-gneigh" role="switch" aria-checked="${kbGo.neighbourOf ? 'true' : 'false'}" data-kb-gneigh data-command-id="shell.kb-graph-neighbourhood"` +
|
|
8779
|
+
` data-tip="${kbGo.neighbourOf ? 'Show the whole map again' : 'Focus or hover a node first, then show only it and its neighbours'}">Only neighbours</button>` +
|
|
8780
|
+
'<span class="kb-gseg" role="group" aria-label="Show as">' +
|
|
8781
|
+
`<button type="button" aria-pressed="${kbGo.list ? 'false' : 'true'}" data-kb-glist="0" data-command-id="shell.kb-graph-list-toggle#${escapeAttr('map')}" data-command-instance-label="${escapeAttr('Map')}">Map</button>` +
|
|
8782
|
+
`<button type="button" aria-pressed="${kbGo.list ? 'true' : 'false'}" data-kb-glist="1" data-command-id="shell.kb-graph-list-toggle#${escapeAttr('list')}" data-command-instance-label="${escapeAttr('List')}">List</button></span>` +
|
|
8783
|
+
'</div></div>';
|
|
8784
|
+
}
|
|
8785
|
+
|
|
8786
|
+
function kbGraphNotesHtml(view, file) {
|
|
8787
|
+
const m = kbGm.model;
|
|
8788
|
+
const notes = [];
|
|
8789
|
+
if (kbGm.loading) notes.push(`<span>Loading more… ${m.nodes.size.toLocaleString()} of about ${Math.max(m.total, m.nodes.size).toLocaleString()} pages and documents.</span> <button type="button" class="kb-link" data-kb-gstop data-command-id="shell.kb-graph-load-more">Stop</button>`);
|
|
8790
|
+
else if (kbGm.stopped && !m.done) notes.push(`<span>Stopped at ${m.nodes.size.toLocaleString()} of about ${m.total.toLocaleString()}.</span> <button type="button" class="kb-link" data-kb-gmore data-command-id="shell.kb-graph-load-more">Load the rest</button>`);
|
|
8791
|
+
if (view.capped) {
|
|
8792
|
+
const tops = kbcChildren(file, null).slice(0, 6).map((c) => `<button type="button" class="kb-link" data-kb-gonly="${escapeAttr(c.id)}" data-command-id="shell.kb-graph-show-category#${escapeAttr(c.id)}" data-command-instance-label="${escapeAttr(c.name)}">${escapeHtml(c.name)}</button>`).join(' · ');
|
|
8793
|
+
notes.push(`<span>Showing ${view.capped.shown.toLocaleString()} of ${view.capped.total.toLocaleString()} items.${tops ? ' Pick one category to see all of it:' : ' Hide some page types to see the rest.'}</span> ${tops}`);
|
|
8794
|
+
}
|
|
8795
|
+
if (m.truncated) notes.push('<span>Some knowledge pages could not be read, so the map is incomplete.</span>');
|
|
8796
|
+
if (m.done && !m.grouped && m.nodes.size) notes.push('<span>This knowledge base was organized before categories. Organize again to group its pages by your categories.</span>');
|
|
8797
|
+
if (view.pending && m.done) notes.push(`<span>${view.pending} link${view.pending === 1 ? '' : 's'} point to pages that are not on the map.</span>`);
|
|
8798
|
+
return notes.length ? `<div class="kb-view-note kb-gnotes" role="status">${notes.join('<br>')}</div>` : '';
|
|
8799
|
+
}
|
|
8800
|
+
|
|
8801
|
+
/** The same nodes as an accessible list, grouped by category. */
|
|
8802
|
+
function kbGraphListHtml(view, file) {
|
|
8803
|
+
const groups = new Map();
|
|
8804
|
+
for (const n of view.nodes) {
|
|
8805
|
+
const m = view.member.get(n.id);
|
|
8806
|
+
// Under the first of its categories that is shown (a page drawn from two can be listed under either).
|
|
8807
|
+
const key = !m || !m.grouped ? 'ungrouped' : (m.cats.find((c) => !kbGo.hiddenCats.has(c)) || m.cats[0] || 'uncategorized');
|
|
8808
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
8809
|
+
groups.get(key).push(n);
|
|
8810
|
+
}
|
|
8811
|
+
const name = (k) => (k === 'ungrouped' ? 'Not yet grouped' : k === 'uncategorized' ? 'Uncategorized' : kbcLabel(file, k));
|
|
8812
|
+
const order = [...kbcChildren(file, null).map((c) => c.id), 'uncategorized', 'ungrouped'].filter((k) => groups.has(k));
|
|
8813
|
+
return '<div class="kb-glist">' + order.map((k) => `<section class="kb-glist-g"><h4>${escapeHtml(name(k))} <span class="kb-gn">${groups.get(k).length}</span></h4><ul>` +
|
|
8814
|
+
groups.get(k).sort((a, b) => String(a.title || a.filename).localeCompare(String(b.title || b.filename))).map((n) => {
|
|
8815
|
+
const act = n.kind === 'document' ? `data-kb-doc="${escapeAttr(n.sourceId)}"` : `data-kb-node="${escapeAttr(n.slug)}"`;
|
|
8816
|
+
const kind = n.kind === 'document' ? 'document' : `${(KB_TYPE_LABEL[n.type] || 'Concept').toLowerCase()} page`;
|
|
8817
|
+
return `<li><button type="button" class="kb-glist-i${view.matchSet.has(n.id) ? ' match' : ''}" ${act} data-command-id="shell.kb-graph-open#${escapeAttr(n.id)}" data-command-instance-label="${escapeAttr(n.title || n.filename || n.slug)}">${escapeHtml(n.title || n.filename || n.slug)}<span class="kb-gk">${kind}</span></button></li>`;
|
|
8818
|
+
}).join('') + '</ul></section>').join('') + '</div>';
|
|
8819
|
+
}
|
|
8820
|
+
|
|
8821
|
+
/** Paint the map: controls, notes, and the drawing (laid out first when what is drawn changed). */
|
|
8822
|
+
function kbGraphRender(final) {
|
|
8823
|
+
const host = kbViewHost();
|
|
8824
|
+
if (!host || viewer.mode !== 'graph' || !kbGm) return;
|
|
8825
|
+
const file = kbCats(knowledgeState);
|
|
8826
|
+
const view = kbgView(kbGm.model, file, kbGo);
|
|
8827
|
+
view.matchSet = new Set(view.matches);
|
|
8828
|
+
kbGm.view = view; // what is drawn now, even while its layout is still being computed (the announcement reads it)
|
|
8829
|
+
if (!kbGm.model.nodes.size && !kbGm.loading) { host.innerHTML = kbGm.model.truncated ? kbGraphTruncatedEmpty() : kbGraphEmpty(knowledgeState); return; }
|
|
8830
|
+
const layoutKey = view.nodes.map((n) => n.id).join('\n') + '|' + view.edges.length;
|
|
8831
|
+
const paint = () => {
|
|
8832
|
+
const h = kbViewHost();
|
|
8833
|
+
if (!h || viewer.mode !== 'graph' || !kbGm) return;
|
|
8834
|
+
const focusId = document.activeElement && document.activeElement.dataset ? document.activeElement.dataset.kbGid : null;
|
|
8835
|
+
const searchHad = document.activeElement && document.activeElement.classList && document.activeElement.classList.contains('kb-gsearch');
|
|
8836
|
+
const W = Math.round(kbGm.w), H = Math.round(kbGm.h);
|
|
8837
|
+
const lines = view.edges.map(([a, b]) => { const p = kbGm.pos.get(a), q = kbGm.pos.get(b);
|
|
8838
|
+
return p && q ? `<line class="kb-g-edge" data-a="${escapeAttr(a)}" data-b="${escapeAttr(b)}" x1="${p.x.toFixed(1)}" y1="${p.y.toFixed(1)}" x2="${q.x.toFixed(1)}" y2="${q.y.toFixed(1)}"/>` : ''; }).join('');
|
|
8839
|
+
const dots = view.nodes.map((n) => kbGraphNodeHtml(n, view, file)).join('');
|
|
8840
|
+
const defs = '<defs><pattern id="kbg-hatch" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><line x1="0" y1="0" x2="0" y2="4" class="kb-g-hatchline"/></pattern></defs>';
|
|
8841
|
+
const body = kbGo.list ? kbGraphListHtml(view, file)
|
|
8842
|
+
: `<div class="kb-graph-body"><svg viewBox="0 0 ${W} ${H}" data-vb-base="0 0 ${W} ${H}" class="kb-graph-svg" role="group" aria-label="Knowledge map, ${view.nodes.length} items">${defs}${lines}${dots}</svg>` +
|
|
8843
|
+
'<button type="button" class="kb-g-fit" data-kb-fit hidden data-tip="Zoom to fit (Home)" aria-label="Zoom to fit" data-command-id="shell.kb-graph-fit">⤢ Fit</button></div>';
|
|
8844
|
+
h.innerHTML = '<section class="kb-col kb-graph">' + kbGraphControlsHtml(view, file) + kbGraphNotesHtml(view, file) + body + '</section>';
|
|
8845
|
+
kbGm.view = view;
|
|
8846
|
+
const back = (kbGFocus || focusId) && h.querySelector(`[data-kb-gid="${CSS.escape(kbGFocus || focusId)}"]`);
|
|
8847
|
+
if (back) back.focus({ preventScroll: true });
|
|
8848
|
+
kbGFocus = null;
|
|
8849
|
+
if (searchHad) { const s = h.querySelector('.kb-gsearch'); if (s) { s.focus(); s.setSelectionRange(s.value.length, s.value.length); } }
|
|
8850
|
+
};
|
|
8851
|
+
if (kbGo.list || layoutKey === kbGm.layoutKey) { paint(); return; }
|
|
8852
|
+
// While chunks are still arriving, lay out only now and then; the final chunk always lays out.
|
|
8853
|
+
if (!final && kbGm.layoutKey && kbGm.lastLayoutAt && Date.now() - kbGm.lastLayoutAt < 1500) { paint(); return; }
|
|
8854
|
+
kbGm.lastLayoutAt = Date.now();
|
|
8855
|
+
if (!kbGm.pos.size) host.innerHTML = kbGraphLoading(kbGraphNotesHtml(view, file));
|
|
8856
|
+
kbGraphLayout(view, () => { if (kbGm) kbGm.layoutKey = layoutKey; paint(); });
|
|
8857
|
+
}
|
|
8858
|
+
|
|
8859
|
+
/** The map's controls; true when handled. */
|
|
8860
|
+
function kbGraphClick(e) {
|
|
8861
|
+
const t = e.target;
|
|
8862
|
+
const cat = t.closest('[data-kb-gcat]');
|
|
8863
|
+
if (cat) { const id = cat.dataset.kbGcat; if (kbGo.hiddenCats.has(id)) kbGo.hiddenCats.delete(id); else kbGo.hiddenCats.add(id); kbGraphRender(true); kbAnnounceGraph(); return true; }
|
|
8864
|
+
const type = t.closest('[data-kb-gtype]');
|
|
8865
|
+
if (type) { const id = type.dataset.kbGtype; if (kbGo.hiddenTypes.has(id)) kbGo.hiddenTypes.delete(id); else kbGo.hiddenTypes.add(id); kbGraphRender(true); kbAnnounceGraph(); return true; }
|
|
8866
|
+
if (t.closest('[data-kb-gall]')) { kbGo.hiddenCats.clear(); kbGo.hiddenTypes.clear(); kbGraphRender(true); kbAnnounceGraph(); return true; }
|
|
8867
|
+
const only = t.closest('[data-kb-gonly]');
|
|
8868
|
+
if (only) {
|
|
8869
|
+
const keep = only.dataset.kbGonly;
|
|
8870
|
+
kbGo.hiddenCats = new Set([...kbcChildren(kbCats(knowledgeState), null).map((c) => c.id), 'uncategorized', 'ungrouped'].filter((id) => id !== keep));
|
|
8871
|
+
kbGraphRender(true); kbAnnounceGraph(); return true;
|
|
8872
|
+
}
|
|
8873
|
+
if (t.closest('[data-kb-gneigh]')) {
|
|
8874
|
+
const focused = document.activeElement && document.activeElement.dataset ? document.activeElement.dataset.kbGid : null;
|
|
8875
|
+
kbGo.neighbourOf = kbGo.neighbourOf ? null : (kbGm && kbGm.lastNode) || focused || null;
|
|
8876
|
+
if (!kbGo.neighbourOf && !kbGm.lastNode) showToast('Point at a page or document on the map first, then choose Only neighbours.', 'warn');
|
|
8877
|
+
kbGFocus = kbGo.neighbourOf;
|
|
8878
|
+
kbGraphRender(true); kbAnnounceGraph(); return true;
|
|
8879
|
+
}
|
|
8880
|
+
const seg = t.closest('[data-kb-glist]');
|
|
8881
|
+
if (seg) { kbGo.list = seg.dataset.kbGlist === '1'; kbGraphRender(true); const b = kbViewHost()?.querySelector(`[data-kb-glist="${kbGo.list ? 1 : 0}"]`); if (b) b.focus(); return true; }
|
|
8882
|
+
if (t.closest('[data-kb-gstop]')) { if (kbGm) { kbGm.stopped = true; } kbAbortPreview(); if (kbGm) { kbGm.loading = false; kbGraphRender(true); } return true; }
|
|
8883
|
+
if (t.closest('[data-kb-gmore]')) { lastViewKey = null; if (kbGm) kbGm.resume = true; if (knowledgeState) paintKnowledge(knowledgeState); return true; }
|
|
8884
|
+
const doc = t.closest('[data-kb-doc]');
|
|
8885
|
+
if (doc) {
|
|
8886
|
+
const id = doc.dataset.kbDoc;
|
|
8887
|
+
if (knowledgeState && knowledgeState.sources.some((s) => s.sourceId === id)) { setViewer({ mode: 'file', sourceId: id }); kbFocusSourceId = id; paintKnowledge(knowledgeState); }
|
|
8888
|
+
else showToast('That document is no longer in Knowledge. Organize again to update the map.', 'warn');
|
|
8889
|
+
return true;
|
|
7590
8890
|
}
|
|
8891
|
+
return false;
|
|
8892
|
+
}
|
|
8893
|
+
function kbAnnounceGraph() {
|
|
8894
|
+
const v = kbGm && kbGm.view;
|
|
8895
|
+
if (v) kbAnnounce(`Showing ${v.nodes.length} item${v.nodes.length === 1 ? '' : 's'} on the map.`);
|
|
8896
|
+
}
|
|
8897
|
+
/** Hover or focus a node: its neighbours stand out, the rest steps back. */
|
|
8898
|
+
function kbGraphHighlight(id) {
|
|
8899
|
+
const svg = kbGraphSvgEl();
|
|
8900
|
+
if (!svg) return;
|
|
8901
|
+
svg.querySelectorAll('.near, .lit').forEach((el) => el.classList.remove('near', 'lit'));
|
|
8902
|
+
svg.classList.toggle('kb-hl', !!id);
|
|
8903
|
+
if (!id || !kbGm || !kbGm.view) return;
|
|
8904
|
+
kbGm.lastNode = id;
|
|
8905
|
+
const near = kbGm.view.adj.get(id) || new Set();
|
|
8906
|
+
svg.querySelector(`[data-kb-gid="${CSS.escape(id)}"]`)?.classList.add('near');
|
|
8907
|
+
for (const n of near) svg.querySelector(`[data-kb-gid="${CSS.escape(n)}"]`)?.classList.add('near');
|
|
8908
|
+
svg.querySelectorAll('.kb-g-edge').forEach((l) => { if (l.dataset.a === id || l.dataset.b === id) l.classList.add('lit'); });
|
|
7591
8909
|
}
|
|
7592
8910
|
/** `generationId` (optional) pins the read to one published generation — a workflow citation opens
|
|
7593
8911
|
* the page AS IT READ when the workflow was built. Without it the route serves the current generation,
|
|
@@ -7655,7 +8973,7 @@
|
|
|
7655
8973
|
}
|
|
7656
8974
|
if (!stillOurs()) return;
|
|
7657
8975
|
|
|
7658
|
-
const fresh = st
|
|
8976
|
+
const fresh = kbViewRow(st, row.sourceId);
|
|
7659
8977
|
if (!fresh) {
|
|
7660
8978
|
// The row is gone. Repaint the column too — merely closing the viewer would leave it listed,
|
|
7661
8979
|
// because nothing else is polling.
|
|
@@ -7694,6 +9012,197 @@
|
|
|
7694
9012
|
img.src = url;
|
|
7695
9013
|
}
|
|
7696
9014
|
|
|
9015
|
+
/** Read a response body as UTF-8, stopping at KB_TEXT_CAP. Null when aborted or the connection dropped. */
|
|
9016
|
+
async function kbReadCapped(res) {
|
|
9017
|
+
const chunks = [];
|
|
9018
|
+
let total = 0;
|
|
9019
|
+
let truncated = false;
|
|
9020
|
+
const reader = res.body.getReader();
|
|
9021
|
+
for (;;) {
|
|
9022
|
+
const { done, value } = await reader.read();
|
|
9023
|
+
if (done) break;
|
|
9024
|
+
chunks.push(value);
|
|
9025
|
+
total += value.length;
|
|
9026
|
+
if (total >= KB_TEXT_CAP) { truncated = true; await reader.cancel(); break; }
|
|
9027
|
+
}
|
|
9028
|
+
const flat = new Uint8Array(Math.min(total, KB_TEXT_CAP));
|
|
9029
|
+
let at = 0;
|
|
9030
|
+
for (const c of chunks) {
|
|
9031
|
+
if (at >= flat.length) break;
|
|
9032
|
+
flat.set(c.subarray(0, Math.min(c.length, flat.length - at)), at);
|
|
9033
|
+
at += c.length;
|
|
9034
|
+
}
|
|
9035
|
+
return { text: new TextDecoder('utf-8').decode(flat), truncated };
|
|
9036
|
+
}
|
|
9037
|
+
|
|
9038
|
+
/**
|
|
9039
|
+
* #2491 R6.3 (spec §10, §14 finding 8, §14.1): the text FloLess read from a Word, Excel or email reference. GET only
|
|
9040
|
+
* (it reads the text when it was not read yet, so the state comes from its headers, never from a HEAD). The text goes
|
|
9041
|
+
* in with textContent like any stored text; nothing a document says ever reaches innerHTML.
|
|
9042
|
+
*/
|
|
9043
|
+
async function kbLoadOfficeText(proj, row, alive) {
|
|
9044
|
+
const name = row.filename || 'untitled';
|
|
9045
|
+
const unread = !row.text || row.text.state === 'pending';
|
|
9046
|
+
if (unread) {
|
|
9047
|
+
kbPaintView(row, '<div class="kb-view-msg" role="status"><span class="kb-view-spin" aria-hidden="true"></span>' +
|
|
9048
|
+
`<div class="kb-view-msg-sub">Reading the text of “${escapeHtml(name)}”… Large workbooks can take a few seconds.</div></div>`);
|
|
9049
|
+
}
|
|
9050
|
+
const ac = new AbortController();
|
|
9051
|
+
kbTextAbort = ac;
|
|
9052
|
+
let res;
|
|
9053
|
+
try { res = await fetch(kbUrl(proj.id, `/sources/${encodeURIComponent(row.sourceId)}/text`), { signal: ac.signal, cache: 'no-store' }); }
|
|
9054
|
+
catch (err) {
|
|
9055
|
+
if (err && err.name === 'AbortError') return;
|
|
9056
|
+
if (alive()) kbPaintError(row, 'Lost the connection while loading it.');
|
|
9057
|
+
return;
|
|
9058
|
+
}
|
|
9059
|
+
if (!alive()) return;
|
|
9060
|
+
if (res.status === 404) { await kbHandleMissing(proj, row, alive); return; }
|
|
9061
|
+
if (!res.ok) {
|
|
9062
|
+
kbPaintError(row, res.status === 402 ? 'Your session needs refreshing — sign in again and retry.' : 'The server hit an error trying to read it.');
|
|
9063
|
+
return;
|
|
9064
|
+
}
|
|
9065
|
+
const state = res.headers.get('X-FloLess-Text-State') || 'pending';
|
|
9066
|
+
const macros = res.headers.get('X-FloLess-Text-Macros') === '1';
|
|
9067
|
+
const bytes = Number(res.headers.get('X-FloLess-Text-Bytes')) || 0;
|
|
9068
|
+
let warnings = [];
|
|
9069
|
+
try { warnings = JSON.parse(decodeURIComponent(res.headers.get('X-FloLess-Text-Warnings') || '%5B%5D')); } catch { warnings = []; }
|
|
9070
|
+
if (!Array.isArray(warnings)) warnings = [];
|
|
9071
|
+
warnings = warnings.filter((w) => typeof w === 'string').slice(0, 20);
|
|
9072
|
+
let read;
|
|
9073
|
+
try { read = await kbReadCapped(res); }
|
|
9074
|
+
catch (err) {
|
|
9075
|
+
if (err && err.name === 'AbortError') return;
|
|
9076
|
+
if (alive()) kbPaintError(row, 'Lost the connection while reading it.');
|
|
9077
|
+
return;
|
|
9078
|
+
}
|
|
9079
|
+
if (!alive()) return;
|
|
9080
|
+
kbPaintOfficeText(proj, row, { state, macros, bytes, warnings, text: read.text, truncated: read.truncated });
|
|
9081
|
+
}
|
|
9082
|
+
|
|
9083
|
+
function kbPaintOfficeText(proj, row, t) {
|
|
9084
|
+
const name = row.filename || 'untitled';
|
|
9085
|
+
const raw = kbRawUrl(proj.id, row.sourceId);
|
|
9086
|
+
const download = `<a class="kb-link kb-text-download" href="${escapeAttr(raw)}" download="${escapeAttr(name)}" data-command-id="shell.kb-text-download" ` +
|
|
9087
|
+
`aria-label="Download the original of “${escapeAttr(name)}”" data-tip="Download the original file">Download original</a>`;
|
|
9088
|
+
const reasons = t.warnings.length ? `<ul class="kb-text-reasons">${t.warnings.map((w) => `<li>${escapeHtml(w)}</li>`).join('')}</ul>` : '';
|
|
9089
|
+
const choices = (primary) =>
|
|
9090
|
+
`<button type="button" class="${primary ? 'primary' : ''}" data-kb-text-replace="${escapeAttr(row.sourceId)}" data-command-id="shell.kb-text-replace-open" ` +
|
|
9091
|
+
'data-tip="Choose a new copy of this file; this one is removed once the new one is added">Replace file…</button>' +
|
|
9092
|
+
`<button type="button" data-kb-text-paste="${escapeAttr(row.sourceId)}" data-command-id="shell.kb-text-paste-note" ` +
|
|
9093
|
+
'data-tip="Paste the file’s text yourself; FloLess keeps it as a text note beside this file">Paste its text as a note</button>';
|
|
9094
|
+
const macroLine = t.macros ? '<div class="kb-text-macros">Contains macros. FloLess only reads its text and never runs them.</div>' : '';
|
|
9095
|
+
if (t.state === 'failed' || (t.state === 'pending' && !t.text)) {
|
|
9096
|
+
const failed = t.state === 'failed';
|
|
9097
|
+
kbPaintView(row,
|
|
9098
|
+
'<div class="kb-view-msg" role="status"><span class="kb-view-ico err" aria-hidden="true">⚠</span>' +
|
|
9099
|
+
`<div class="kb-view-msg-title">${failed ? 'Couldn’t read the text in this file.' : 'FloLess hasn’t read this file’s text yet.'}</div>` +
|
|
9100
|
+
`<div class="kb-view-msg-sub">${failed ? '' : 'It reads it when you Organize, or try again now. '}The original file is kept.</div>` +
|
|
9101
|
+
reasons + macroLine +
|
|
9102
|
+
`<div class="kb-view-act">${failed ? choices(true) : '<button type="button" class="primary" data-kb-retry data-command-id="shell.kb-text-retry">↻ Try again</button>' + choices(false)}${download}</div>` +
|
|
9103
|
+
'<div class="kb-paste-host"></div></div>');
|
|
9104
|
+
return;
|
|
9105
|
+
}
|
|
9106
|
+
const lead = kbIsEmail(row.mime) ? 'Text FloLess read from this email; attachments are listed by name only.' : 'Text FloLess read from this file.';
|
|
9107
|
+
const banner = t.state === 'partial'
|
|
9108
|
+
? '<div class="kb-text-banner" role="status"><div class="kb-text-banner-title">Some of this file’s text couldn’t be read.</div>' +
|
|
9109
|
+
reasons + '<div class="kb-text-banner-sub">FloLess kept the original.</div>' +
|
|
9110
|
+
`<div class="kb-view-act">${choices(false)}</div><div class="kb-paste-host"></div></div>`
|
|
9111
|
+
: '';
|
|
9112
|
+
const notice = t.truncated
|
|
9113
|
+
? `<div class="kb-view-note">Showing the first ${escapeHtml(kbBytes(KB_TEXT_CAP))} of ${escapeHtml(kbBytes(t.bytes))} of text.</div>` : '';
|
|
9114
|
+
kbPaintView(row,
|
|
9115
|
+
`<div class="kb-text-strip" role="note"><span>${escapeHtml(lead)}</span>${download}</div>` + macroLine + banner +
|
|
9116
|
+
`<pre class="kb-view-pre" tabindex="0" role="region" aria-label="Text read from “${escapeAttr(name)}”"></pre>${notice}`);
|
|
9117
|
+
const pre = kbViewHost() && kbViewHost().querySelector('.kb-view-pre');
|
|
9118
|
+
// FloLess's own provenance line (a digest and a reader version) is for the AI, not the person: shown from line 2.
|
|
9119
|
+
const shown = t.text.startsWith('<!-- floless:extracted-text ') ? t.text.slice(t.text.indexOf('\n') + 1) : t.text;
|
|
9120
|
+
if (pre) pre.textContent = shown; // the escaping guarantee: a document's "<script>" stays literal text
|
|
9121
|
+
}
|
|
9122
|
+
|
|
9123
|
+
/** Paste its text as a note: a small panel in the viewer; the note is added as "<name>.txt" beside the file. */
|
|
9124
|
+
function kbOpenPasteNote(sourceId) {
|
|
9125
|
+
const host = kbViewHost() && kbViewHost().querySelector('.kb-paste-host');
|
|
9126
|
+
const row = knowledgeState && knowledgeState.sources.find((s) => s.sourceId === sourceId);
|
|
9127
|
+
if (!host || !row) return;
|
|
9128
|
+
host.innerHTML = '<div class="kb-paste">' +
|
|
9129
|
+
'<label class="kb-ds-lbl" for="kb-paste-text">The file’s text</label>' +
|
|
9130
|
+
'<textarea id="kb-paste-text" class="kb-adjust-input kb-paste-area" data-command-id="shell.kb-text-paste-input" rows="8" ' +
|
|
9131
|
+
'placeholder="Paste the text here. FloLess keeps it as a text note beside this file."></textarea>' +
|
|
9132
|
+
'<div class="kb-view-act"><button type="button" data-kb-paste-cancel data-command-id="shell.kb-text-paste-cancel">Cancel</button>' +
|
|
9133
|
+
`<button type="button" class="primary" data-kb-paste-go="${escapeAttr(sourceId)}" data-command-id="shell.kb-text-paste-save">Add note</button></div></div>`;
|
|
9134
|
+
const area = host.querySelector('textarea');
|
|
9135
|
+
if (area) area.focus({ preventScroll: false });
|
|
9136
|
+
}
|
|
9137
|
+
|
|
9138
|
+
async function kbPasteNote(sourceId) {
|
|
9139
|
+
const proj = current;
|
|
9140
|
+
const row = knowledgeState && knowledgeState.sources.find((s) => s.sourceId === sourceId);
|
|
9141
|
+
const area = kbViewHost() && kbViewHost().querySelector('#kb-paste-text');
|
|
9142
|
+
const text = area ? area.value : '';
|
|
9143
|
+
if (!proj || !row) return;
|
|
9144
|
+
if (!text.trim()) { showToast('Paste some text first.', 'warn'); if (area) area.focus(); return; }
|
|
9145
|
+
const base = String(row.filename || 'untitled').replace(/\.[^.]+$/, '');
|
|
9146
|
+
const name = `${base} (text).txt`;
|
|
9147
|
+
const dataUrl = `data:text/plain;base64,${btoa(unescape(encodeURIComponent(text)))}`;
|
|
9148
|
+
try {
|
|
9149
|
+
await api(kbUrl(proj.id, '/sources'), { method: 'POST',
|
|
9150
|
+
body: JSON.stringify({ files: [{ name, dataUrl }], ...(proj.uuid ? { expectedProjectUuid: proj.uuid } : {}) }) });
|
|
9151
|
+
if (current !== proj) return;
|
|
9152
|
+
showToast(`Added “${name}” as a note`, 'ok');
|
|
9153
|
+
} catch (err) {
|
|
9154
|
+
console.error('[workspaces] adding a pasted note failed', err);
|
|
9155
|
+
showToast(err && err.body && err.body.code === 'project-changed'
|
|
9156
|
+
? 'This project was replaced while the note was being added, so nothing was added. Open the project and paste it again.'
|
|
9157
|
+
: (err && err.body && err.body.reason) || 'Couldn’t add the note. Check your connection, then add it again.', 'warn');
|
|
9158
|
+
}
|
|
9159
|
+
if (current === proj) renderKnowledge();
|
|
9160
|
+
}
|
|
9161
|
+
|
|
9162
|
+
/** Replace file…: upload the chosen file; once it is in, remove the reference it replaces. */
|
|
9163
|
+
let kbReplaceTarget = null;
|
|
9164
|
+
async function kbReplaceWith(file) {
|
|
9165
|
+
const proj = current;
|
|
9166
|
+
const old = kbReplaceTarget;
|
|
9167
|
+
kbReplaceTarget = null;
|
|
9168
|
+
if (!proj || !old || !file) return;
|
|
9169
|
+
if (file.size > KB_MAX_FILE_BYTES) { showToast(`“${file.name}” is too large (max ${KB_MB(KB_MAX_FILE_BYTES)} MB)`, 'warn'); return; }
|
|
9170
|
+
let upload;
|
|
9171
|
+
try { upload = await readFileAsSnapshot(file); } catch { showToast('Could not read the selected file', 'warn'); return; }
|
|
9172
|
+
if (current !== proj) return;
|
|
9173
|
+
let added = null;
|
|
9174
|
+
try {
|
|
9175
|
+
// Per-file outcome, so a file FloLess cannot take is explained in its own words and nothing is removed.
|
|
9176
|
+
const res = await api(kbUrl(proj.id, '/sources'), { method: 'POST',
|
|
9177
|
+
body: JSON.stringify({ files: [upload], partial: true, ...(proj.uuid ? { expectedProjectUuid: proj.uuid } : {}) }) });
|
|
9178
|
+
const result = (res.results || [])[0];
|
|
9179
|
+
added = (res.sources || [])[0] || null;
|
|
9180
|
+
if (!added) {
|
|
9181
|
+
showToast(`Couldn’t replace “${old.filename}”: ${(result && result.reason) || 'the new file could not be added.'} The original is still there.`, 'warn');
|
|
9182
|
+
if (current === proj) renderKnowledge();
|
|
9183
|
+
return;
|
|
9184
|
+
}
|
|
9185
|
+
await api(kbUrl(proj.id, `/sources/${encodeURIComponent(old.sourceId)}`), { method: 'DELETE' });
|
|
9186
|
+
if (current !== proj) return;
|
|
9187
|
+
setViewer({ mode: 'file', sourceId: added.sourceId });
|
|
9188
|
+
kbFocusSourceId = added.sourceId;
|
|
9189
|
+
showToast(`Replaced “${old.filename}” with “${added.filename}”`, 'ok');
|
|
9190
|
+
} catch (err) {
|
|
9191
|
+
console.error('[workspaces] replacing a knowledge file failed', err);
|
|
9192
|
+
if (added && current === proj) {
|
|
9193
|
+
// The new file is in; only the old one could not be removed. Say so, and show the new one.
|
|
9194
|
+
setViewer({ mode: 'file', sourceId: added.sourceId });
|
|
9195
|
+
kbFocusSourceId = added.sourceId;
|
|
9196
|
+
showToast(`Added “${added.filename}”, but couldn’t remove “${old.filename}”. Remove it from the list.`, 'warn');
|
|
9197
|
+
} else {
|
|
9198
|
+
showToast(err && err.body && err.body.code === 'project-changed'
|
|
9199
|
+
? 'This project was replaced while the file was being read, so nothing changed.'
|
|
9200
|
+
: 'Couldn’t replace the file. The original is still there. Check your connection, then try again.', 'warn');
|
|
9201
|
+
}
|
|
9202
|
+
}
|
|
9203
|
+
if (current === proj) renderKnowledge();
|
|
9204
|
+
}
|
|
9205
|
+
|
|
7697
9206
|
/** Text is read as a stream and STOPPED at 256 KB. The upload cap is 100 MB per file, so an uncapped
|
|
7698
9207
|
* <pre> would hang the tab; cancelling the reader also stops the server-side read. The bytes go in
|
|
7699
9208
|
* with textContent — never innerHTML, never markdown, never a parsed CSV table. */
|
|
@@ -7747,15 +9256,25 @@
|
|
|
7747
9256
|
}
|
|
7748
9257
|
|
|
7749
9258
|
function kbColumn(st) {
|
|
7750
|
-
|
|
7751
|
-
const
|
|
7752
|
-
|
|
7753
|
-
|
|
9259
|
+
// #2399 slice 0c: a file of an issue is listed under its issue, not again here; the list says how many went there.
|
|
9260
|
+
const loose = st.sources.filter((source) => !kbInDesignSet(source, st));
|
|
9261
|
+
const inSet = st.sources.length - loose.length;
|
|
9262
|
+
const jump = inSet ? `<button type="button" class="kb-link kb-ds-jump" data-kb-ds-jump data-command-id="shell.kb-design-set-jump" data-tip="Go to the Design set">${inSet} more in the design set</button>` : '';
|
|
9263
|
+
// #2491 R6.9: once the first category exists the list is a tree; until then it is exactly the flat list, plus a way to
|
|
9264
|
+
// make one. A categories file that cannot be read shows every reference flat and says so.
|
|
9265
|
+
kbSelFor(current, st);
|
|
9266
|
+
const tree = kbCatUsable(st) && kbCats(st).categories.length > 0;
|
|
9267
|
+
const newCat = kbCatUsable(st) && loose.length && !(kbCatEdit && kbCatEdit.mode === 'new' && !kbCatEdit.parentId)
|
|
9268
|
+
? '<button type="button" class="kb-link kb-cat-new" data-kb-cat-new data-command-id="shell.kb-category-new" data-tip="Group references into categories">+ New category</button>' : '';
|
|
9269
|
+
const flatEdit = !tree && kbCatEdit && kbCatEdit.mode === 'new' ? kbCatEditHtml(0) : '';
|
|
9270
|
+
const body = kbCatUnavailableHtml(st) + (loose.length
|
|
9271
|
+
? (tree ? kbTreeHtml(st, loose) : flatEdit + loose.map((source) => kbSourceRow(source, st)).join(''))
|
|
9272
|
+
: (inSet ? '' : '<div class="kb-empty">No references yet — drop files above (PDF, Word, Excel, email, pictures or text), or ask your terminal AI to add them.</div>')) + newCat + jump + kbSelBarHtml(st);
|
|
7754
9273
|
return '<section class="kb-col">' +
|
|
7755
|
-
'<div class="kb-refs-body">' +
|
|
7756
|
-
'<button type="button" class="kb-drop" id="kb-drop" data-command-id="shell.add-knowledge" data-tip="Drop files here, or click to pick them">' +
|
|
9274
|
+
'<div class="kb-refs-body">' + kbDesignSetStrip(st) +
|
|
9275
|
+
'<button type="button" class="kb-drop" id="kb-drop" data-command-id="shell.add-knowledge" data-tip="Drop PDF, Word, Excel, email (.msg, .eml), picture or text files here, or click to pick them">' +
|
|
7757
9276
|
'<span class="di" aria-hidden="true">⤓</span><span class="dt">Drop references here</span>' +
|
|
7758
|
-
'<span class="ds">PDF ·
|
|
9277
|
+
'<span class="ds">PDF · Word · Excel · email · images · text</span>' +
|
|
7759
9278
|
'</button>' + body +
|
|
7760
9279
|
'</div>' + kbFoot(st) + '</section>';
|
|
7761
9280
|
}
|
|
@@ -7814,6 +9333,8 @@
|
|
|
7814
9333
|
$wsKnowledge.innerHTML = kbStepHeadHtml(knowledgeState) +
|
|
7815
9334
|
'<div class="kb-split">' +
|
|
7816
9335
|
'<div class="kb-refs-host" id="kb-refs-host"></div>' +
|
|
9336
|
+
// Outside the repainted host: the drop zone's "Choose files" announcement must outlive a poll repaint.
|
|
9337
|
+
'<div class="kb-live" id="kb-drop-live" aria-live="polite"></div>' +
|
|
7817
9338
|
'<div class="kb-refs-stub" aria-hidden="true"><span class="vertical-label">References</span></div>' +
|
|
7818
9339
|
'<div class="pane-rail kb-rail">' +
|
|
7819
9340
|
'<div class="resize-handle" data-kb-rail-resize role="separator" tabindex="0" aria-orientation="vertical" aria-controls="kb-refs-host" aria-label="Resize References panel" data-command-id="shell.knowledge-refs-resize" data-tip="Drag to resize · double-click to reset"></div>' +
|
|
@@ -7942,14 +9463,16 @@
|
|
|
7942
9463
|
const curGen = st.currentGeneration ? st.currentGeneration.generationId : '';
|
|
7943
9464
|
return 'page:' + (viewer.generationId || curGen) + ':' + curGen + ':' + (viewer.slug || '');
|
|
7944
9465
|
}
|
|
7945
|
-
const row = viewer.mode === 'file' ? st
|
|
9466
|
+
const row = viewer.mode === 'file' ? kbViewRow(st, viewer.sourceId) : null;
|
|
7946
9467
|
const gen = viewer.mode === 'graph' && st.currentGeneration ? st.currentGeneration.generationId : '';
|
|
7947
|
-
|
|
9468
|
+
// The text state too (#2491): a Word, Excel or email file whose text lands while it is open repaints with it.
|
|
9469
|
+
const text = row && row.text ? `${row.text.state}:${row.text.blobSha256 || ''}` : '';
|
|
9470
|
+
return [current && current.id, viewer.mode, viewer.sourceId || '', row ? row.blobSha256 : '', text, gen].join('|');
|
|
7948
9471
|
}
|
|
7949
9472
|
|
|
7950
9473
|
function paintKnowledge(st) {
|
|
7951
9474
|
// The previewed source may have been removed under us (by this tab or the terminal AI).
|
|
7952
|
-
if (viewer.mode === 'file' && !st
|
|
9475
|
+
if (viewer.mode === 'file' && !kbViewRow(st, viewer.sourceId)) {
|
|
7953
9476
|
setViewer({ mode: 'graph', sourceId: null });
|
|
7954
9477
|
}
|
|
7955
9478
|
kbEnsureShell();
|
|
@@ -7966,7 +9489,7 @@
|
|
|
7966
9489
|
// DOM; suppressing the repaint while it's active (kbAdjustActive) is simpler and safer than
|
|
7967
9490
|
// snapshotting/restoring every piece. lastRefsHtml is left stale, so the next tick (once the box is
|
|
7968
9491
|
// inactive) catches the column up to the latest state.
|
|
7969
|
-
if (html !== lastRefsHtml && !kbAdjustActive()) {
|
|
9492
|
+
if (html !== lastRefsHtml && !kbAdjustActive() && !kbDsPanelBusy() && !kbCatEditActive() && !kbDragIds && !kbDragHover) {
|
|
7970
9493
|
const oldBody = refsHost.querySelector('.kb-refs-body');
|
|
7971
9494
|
const scrollTop = oldBody ? oldBody.scrollTop : 0;
|
|
7972
9495
|
refsHost.innerHTML = html;
|
|
@@ -7981,9 +9504,20 @@
|
|
|
7981
9504
|
if (btn) btn.focus();
|
|
7982
9505
|
kbFocusSourceId = null;
|
|
7983
9506
|
}
|
|
9507
|
+
kbDsRestoreFocus(refsHost);
|
|
9508
|
+
kbCatRestoreFocus(refsHost);
|
|
9509
|
+
const shown = kbActiveDesignSet(st);
|
|
9510
|
+
if (kbFocusDesignSet && (shown ? shown.sourceId : null) === kbFocusDesignSet.sourceId) {
|
|
9511
|
+
const target = refsHost.querySelector('.kb-ds .kb-fname, .kb-ds button') || refsHost.querySelector('#kb-drop');
|
|
9512
|
+
if (newBody) newBody.scrollTop = 0;
|
|
9513
|
+
if (target) target.focus({ preventScroll: true });
|
|
9514
|
+
kbFocusDesignSet = null;
|
|
9515
|
+
}
|
|
7984
9516
|
}
|
|
7985
9517
|
|
|
7986
9518
|
const key = kbViewKey(st);
|
|
9519
|
+
// #2491 R6.9: a category change recolours the open map from the current categories (no reload, no re-layout).
|
|
9520
|
+
if (key === lastViewKey && viewer.mode === 'graph' && kbGm && kbGm.catRev !== kbCats(st).revision) { kbGm.catRev = kbCats(st).revision; kbGraphRender(true); }
|
|
7987
9521
|
if (key !== lastViewKey) {
|
|
7988
9522
|
// The key can change WITHOUT setViewer() — e.g. a poll swaps a row's blobSha256 under an open
|
|
7989
9523
|
// preview. Abort and bump the epoch here too, or the superseded download keeps streaming (its
|
|
@@ -7991,7 +9525,7 @@
|
|
|
7991
9525
|
kbAbortPreview();
|
|
7992
9526
|
lastViewKey = key;
|
|
7993
9527
|
if (viewer.mode === 'file') {
|
|
7994
|
-
const row = st
|
|
9528
|
+
const row = kbViewRow(st, viewer.sourceId);
|
|
7995
9529
|
if (row) {
|
|
7996
9530
|
if (viewHost) viewHost.innerHTML = kbViewShell(row, kbViewLoading(row));
|
|
7997
9531
|
kbLoadPreview(current, row);
|
|
@@ -8130,12 +9664,177 @@
|
|
|
8130
9664
|
`<div class="company-entry-meta">Latest v${latestNumber} · ${escapeHtml(latest.filename)} · ${escapeHtml(kbBytes(latest.bytes))}` +
|
|
8131
9665
|
(latest.provenance && latest.provenance.projectName
|
|
8132
9666
|
? ` · from ${escapeHtml(latest.provenance.projectName)}` : '') + '</div></div>' +
|
|
8133
|
-
`<div class="company-entry-actions">${action}
|
|
9667
|
+
`<div class="company-entry-actions">${action}` +
|
|
9668
|
+
(state.taxonomy && Array.isArray(state.taxonomy.categories) && state.taxonomy.categories.length ? `<button type="button" data-company-move="${escapeAttr(entry.librarySourceId)}" aria-haspopup="menu" data-command-id="shell.kb-move-to#${escapeAttr(entry.librarySourceId)}" data-command-instance-label="${escapeAttr(entry.displayName)}" data-tip="Move to another company category">Move to…</button>` : '') +
|
|
9669
|
+
`<button type="button" class="company-remove" ` +
|
|
8134
9670
|
`data-company-stage-remove="${escapeAttr(entry.librarySourceId)}" data-command-id="shell.company-remove" ` +
|
|
8135
9671
|
`data-command-instance="${escapeAttr(entry.librarySourceId)}" data-command-instance-label="${escapeAttr(entry.displayName)}" ` +
|
|
8136
9672
|
'data-tip="Remove this entry from company knowledge">Remove…</button></div></article>';
|
|
8137
9673
|
}
|
|
8138
9674
|
|
|
9675
|
+
// #2491 R6.9: the company library's own categories. The dialog lists shared references by category, with New
|
|
9676
|
+
// category, Rename, Delete and a Move to… on each entry (no drag in a dialog). Each change carries the categories'
|
|
9677
|
+
// revision and the company folder this dialog drew, so a change made meanwhile elsewhere is never overwritten.
|
|
9678
|
+
let companyCatEdit = null; // { mode: 'new' | 'rename', id?, parentId?, name? }
|
|
9679
|
+
const companyTax = (state) => (state && state.taxonomy && Array.isArray(state.taxonomy.categories) ? state.taxonomy : { v: 1, revision: 0, categories: [], placements: {}, state: 'absent' });
|
|
9680
|
+
function companyCatEditHtml(depth) {
|
|
9681
|
+
const e = companyCatEdit;
|
|
9682
|
+
return `<div class="kb-cat-edit company-cat-edit" style="--kb-depth:${depth}"><input type="text" class="kb-cat-input company-cat-input" maxlength="80" value="${e.mode === 'rename' ? escapeAttr(e.name || '') : ''}"` +
|
|
9683
|
+
` aria-label="${e.mode === 'rename' ? 'New name for the company category' : 'Name of the new company category'}" placeholder="Category name" data-command-id="shell.kb-category-name">` +
|
|
9684
|
+
`<button type="button" class="primary" data-company-cat-save data-command-id="shell.kb-category-save">${e.mode === 'rename' ? 'Rename' : 'Create'}</button>` +
|
|
9685
|
+
'<button type="button" data-company-cat-cancel data-command-id="shell.kb-category-cancel">Cancel</button></div>';
|
|
9686
|
+
}
|
|
9687
|
+
function companyListHtml(entries, state) {
|
|
9688
|
+
const tax = companyTax(state);
|
|
9689
|
+
const usable = tax.state !== 'damaged' && tax.state !== 'newer';
|
|
9690
|
+
const head = '<div class="company-section-head"><div class="company-section-label">Shared references</div>' +
|
|
9691
|
+
(usable ? '<button type="button" class="kb-link" data-company-cat-new data-command-id="shell.kb-category-new" data-tip="Group shared references into categories">+ New category</button>' : '') + '</div>';
|
|
9692
|
+
const warn = usable ? '' : `<div class="kb-cat-warn" role="status"><span>${tax.state === 'newer' ? 'The company categories were saved by a newer FloLess' : 'The company categories could not be read'}, so the shared references are listed without them. You can start again with no categories (the saved ones are kept aside).</span>` +
|
|
9693
|
+
'<button type="button" data-company-cat-reset data-command-id="shell.kb-category-reset">Start again</button></div>';
|
|
9694
|
+
const topEdit = companyCatEdit && companyCatEdit.mode === 'new' && !companyCatEdit.parentId ? companyCatEditHtml(0) : '';
|
|
9695
|
+
if (!usable || !tax.categories.length) return head + warn + topEdit + entries.map((entry) => companyEntryHtml(entry, state)).join('');
|
|
9696
|
+
const byId = new Map(entries.map((e) => [e.librarySourceId, e]));
|
|
9697
|
+
const all = new Set(['uncategorized', ...tax.categories.map((c) => c.id)]);
|
|
9698
|
+
const items = kbcTreeItems(tax, entries.map((e) => ({ sourceId: e.librarySourceId })), all);
|
|
9699
|
+
let html = '';
|
|
9700
|
+
for (const item of items) {
|
|
9701
|
+
if (item.kind === 'row') { const e = byId.get(item.row.sourceId); if (e) html += `<div class="company-cat-row" style="--kb-depth:${item.depth}">${companyEntryHtml(e, state)}</div>`; continue; }
|
|
9702
|
+
if (companyCatEdit && companyCatEdit.mode === 'rename' && companyCatEdit.id === item.id) { html += companyCatEditHtml(item.depth); continue; }
|
|
9703
|
+
const isU = item.kind === 'uncategorized';
|
|
9704
|
+
html += `<div class="company-cat${isU ? ' kb-uncat' : ''}" style="--kb-depth:${item.depth}"><span class="kb-cat-name">${escapeHtml(item.name)}</span><span class="kb-cat-count">(${item.count})</span>` +
|
|
9705
|
+
(isU ? '' : `<button type="button" class="kb-cat-more" data-company-cat-menu="${escapeAttr(item.id)}" aria-haspopup="menu" aria-label="More for ${escapeAttr(item.name)}" data-tip="Rename, add a subcategory or delete" data-command-id="shell.kb-category-menu#${escapeAttr(item.id)}" data-command-instance-label="${escapeAttr(item.name)}">⋯</button>`) + '</div>';
|
|
9706
|
+
if (companyCatEdit && companyCatEdit.mode === 'new' && companyCatEdit.parentId === item.id) html += companyCatEditHtml(item.depth + 1);
|
|
9707
|
+
}
|
|
9708
|
+
return head + topEdit + html;
|
|
9709
|
+
}
|
|
9710
|
+
async function companyCatPost(path, body, okMsg) {
|
|
9711
|
+
const state = companyKnowledgeState;
|
|
9712
|
+
if (companyKnowledgeBusy || !state || !state.available) return null;
|
|
9713
|
+
companyKnowledgeBusy = true; companySetError('');
|
|
9714
|
+
try {
|
|
9715
|
+
const res = await api(path, { method: 'POST', body: JSON.stringify({ expected: companyCatExpected(state), ...body }) });
|
|
9716
|
+
companyCatEdit = null;
|
|
9717
|
+
if (okMsg) showToast(okMsg, 'ok');
|
|
9718
|
+
return res;
|
|
9719
|
+
} catch (error) {
|
|
9720
|
+
const said = error && error.body && typeof error.body.error === 'string' && /^[A-Z]/.test(error.body.error) ? error.body.error : '';
|
|
9721
|
+
companySetError(said || 'FloLess could not change the company categories just now. Try again.');
|
|
9722
|
+
if (body.expected && error && error.body && error.body.code === 'knowledge-categories-changed') companyCatEdit = null;
|
|
9723
|
+
return null;
|
|
9724
|
+
} finally {
|
|
9725
|
+
companyKnowledgeBusy = false;
|
|
9726
|
+
try { await loadCompanyKnowledge(companyKnowledgeProjectId); } catch { /* the error line says what happened */ }
|
|
9727
|
+
renderCompanyKnowledge();
|
|
9728
|
+
}
|
|
9729
|
+
}
|
|
9730
|
+
/** What a company category change is checked against: the categories' revision and the company folder. */
|
|
9731
|
+
function companyCatExpected(state) {
|
|
9732
|
+
return { [KB_CAT_KEY]: String(companyTax(state).revision || 0), 'the company folder': `${state.companyId}|${state.path}` };
|
|
9733
|
+
}
|
|
9734
|
+
/** Open the company name box, remembering the categories it was opened on (see kbCatStartEdit). */
|
|
9735
|
+
function companyCatStartEdit(edit) {
|
|
9736
|
+
companyCatEdit = companyKnowledgeState ? { ...edit, expected: companyCatExpected(companyKnowledgeState) } : edit;
|
|
9737
|
+
renderCompanyKnowledge();
|
|
9738
|
+
const i = $companyKnowledgeList.querySelector('.company-cat-input');
|
|
9739
|
+
if (i) { i.focus(); i.select(); }
|
|
9740
|
+
}
|
|
9741
|
+
function companyCatSave() {
|
|
9742
|
+
const input = $companyKnowledgeList.querySelector('.company-cat-input');
|
|
9743
|
+
const e = companyCatEdit;
|
|
9744
|
+
if (!input || !e) return;
|
|
9745
|
+
const name = input.value.replace(/\s+/g, ' ').trim();
|
|
9746
|
+
if (!name) { companySetError('Give the category a name.'); input.focus(); return; }
|
|
9747
|
+
const pinned = e.expected ? { expected: e.expected } : {};
|
|
9748
|
+
if (e.mode === 'rename') companyCatPost('/api/company-knowledge/categories', { ops: [{ op: 'rename', id: e.id, name }], ...pinned }, `Renamed the company category to ${name}.`);
|
|
9749
|
+
else companyCatPost('/api/company-knowledge/categories', { ops: [{ op: 'create', name, parentId: e.parentId || null }], ...pinned }, `Created the company category ${name}.`);
|
|
9750
|
+
}
|
|
9751
|
+
function companyPop(anchor, html, label) {
|
|
9752
|
+
$companyKnowledgeList.querySelector('.company-pop')?.remove();
|
|
9753
|
+
const pop = document.createElement('div');
|
|
9754
|
+
pop.className = 'company-pop kb-ds-menu kb-cat-menu';
|
|
9755
|
+
pop.setAttribute('role', 'menu');
|
|
9756
|
+
pop.setAttribute('aria-label', label);
|
|
9757
|
+
pop.innerHTML = html;
|
|
9758
|
+
$companyKnowledgeList.appendChild(pop);
|
|
9759
|
+
const lr = $companyKnowledgeList.getBoundingClientRect(), br = anchor.getBoundingClientRect();
|
|
9760
|
+
// Below the button when it fits inside the dialog's visible area, else above it — never clipped by the scroll area.
|
|
9761
|
+
let clip = $companyKnowledgeList.parentElement;
|
|
9762
|
+
while (clip && clip !== document.body && !/(auto|scroll|hidden)/.test(getComputedStyle(clip).overflowY)) clip = clip.parentElement;
|
|
9763
|
+
const limit = Math.min(window.innerHeight, clip ? clip.getBoundingClientRect().bottom : window.innerHeight) - 8;
|
|
9764
|
+
const fits = br.bottom + 4 + pop.offsetHeight <= limit;
|
|
9765
|
+
pop.style.top = `${fits ? br.bottom - lr.top + $companyKnowledgeList.scrollTop + 4 : br.top - lr.top + $companyKnowledgeList.scrollTop - pop.offsetHeight - 4}px`;
|
|
9766
|
+
pop.style.left = `${Math.max(4, Math.min(br.right - lr.left - pop.offsetWidth, $companyKnowledgeList.clientWidth - pop.offsetWidth - 4))}px`;
|
|
9767
|
+
pop.dataset.back = anchor.dataset.companyCatMenu || anchor.dataset.companyMove || '';
|
|
9768
|
+
pop.querySelector('.kb-ds-mi')?.focus();
|
|
9769
|
+
return pop;
|
|
9770
|
+
}
|
|
9771
|
+
function companyMoveMenu(btn) {
|
|
9772
|
+
const state = companyKnowledgeState;
|
|
9773
|
+
const tax = companyTax(state);
|
|
9774
|
+
const id = btn.dataset.companyMove;
|
|
9775
|
+
const entry = state.sources.find((e) => e.librarySourceId === id);
|
|
9776
|
+
const now = kbcPlacement(tax, id);
|
|
9777
|
+
const items = kbcMenuChoices(tax, null).map((c) => `<button type="button" role="menuitemradio" aria-checked="${c.id === now ? 'true' : 'false'}" class="kb-ds-mi kb-move-mi" style="--kb-depth:${c.id ? c.depth + 1 : 0}" data-company-move-go="${escapeAttr(c.id || '')}" data-company-move-id="${escapeAttr(id)}" data-command-id="shell.kb-move-to-go#${escapeAttr(c.id || 'uncategorized')}" data-command-instance-label="${escapeAttr(c.name)}">${escapeHtml(c.name)}</button>`).join('');
|
|
9778
|
+
companyPop(btn, `<div class="kb-move-title">Move “${escapeHtml(entry ? entry.displayName : 'this reference')}” to</div>${items}`, 'Move shared reference');
|
|
9779
|
+
}
|
|
9780
|
+
function companyCatMenu(btn) {
|
|
9781
|
+
const id = btn.dataset.companyCatMenu;
|
|
9782
|
+
const cat = companyTax(companyKnowledgeState).categories.find((c) => c.id === id);
|
|
9783
|
+
const name = cat ? cat.name : 'this category';
|
|
9784
|
+
companyPop(btn, `<button type="button" role="menuitem" class="kb-ds-mi" data-company-cat-rename="${escapeAttr(id)}" data-command-id="shell.kb-category-rename#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">Rename…</button>` +
|
|
9785
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-company-cat-sub="${escapeAttr(id)}" data-command-id="shell.kb-category-new-sub#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">New subcategory…</button>` +
|
|
9786
|
+
`<button type="button" role="menuitem" class="kb-ds-mi danger" data-company-cat-delete="${escapeAttr(id)}" data-command-id="shell.kb-category-delete#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(name)}">Delete…</button>`, 'Company category');
|
|
9787
|
+
}
|
|
9788
|
+
function companyCatDelete(btn) {
|
|
9789
|
+
const id = btn.dataset.companyCatDelete;
|
|
9790
|
+
const state = companyKnowledgeState;
|
|
9791
|
+
const tax = companyTax(state);
|
|
9792
|
+
const cat = tax.categories.find((c) => c.id === id);
|
|
9793
|
+
if (!cat) return;
|
|
9794
|
+
const rows = state.sources.filter((e) => !e.removedAt).map((e) => ({ sourceId: e.librarySourceId }));
|
|
9795
|
+
const anchor = $companyKnowledgeList.querySelector(`[data-company-cat-menu="${CSS.escape(id)}"]`) || btn;
|
|
9796
|
+
const pop = companyPop(anchor, `<div class="hc-title">Delete “${escapeHtml(cat.name)}”?</div><div class="hc-body">${kbCatDeleteSentence(tax, rows, id).replace('No reference is deleted.', 'No shared reference is deleted.')}</div>` +
|
|
9797
|
+
'<div class="hc-act"><button type="button" class="hc-cancel kb-ds-mi" data-company-pop-close data-command-id="shell.kb-category-cancel">Cancel</button>' +
|
|
9798
|
+
`<button type="button" class="hc-go danger" data-company-cat-delete-go="${escapeAttr(id)}" data-command-id="shell.kb-category-delete#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(cat.name)}">Delete category</button></div>`, `Delete ${cat.name}`);
|
|
9799
|
+
pop.setAttribute('role', 'dialog');
|
|
9800
|
+
pop.classList.remove('kb-ds-menu');
|
|
9801
|
+
pop.classList.add('hist-confirm');
|
|
9802
|
+
}
|
|
9803
|
+
/** The dialog's category clicks; true when handled. */
|
|
9804
|
+
function companyCatClick(event) {
|
|
9805
|
+
const t = event.target;
|
|
9806
|
+
if (t.closest('[data-company-cat-new]')) { companyCatStartEdit({ mode: 'new', parentId: null }); return true; }
|
|
9807
|
+
const menu = t.closest('[data-company-cat-menu]');
|
|
9808
|
+
if (menu) { companyCatMenu(menu); return true; }
|
|
9809
|
+
const move = t.closest('[data-company-move]');
|
|
9810
|
+
if (move) { companyMoveMenu(move); return true; }
|
|
9811
|
+
const rename = t.closest('[data-company-cat-rename]');
|
|
9812
|
+
if (rename) {
|
|
9813
|
+
const cat = companyTax(companyKnowledgeState).categories.find((c) => c.id === rename.dataset.companyCatRename);
|
|
9814
|
+
if (cat) companyCatStartEdit({ mode: 'rename', id: cat.id, name: cat.name });
|
|
9815
|
+
return true;
|
|
9816
|
+
}
|
|
9817
|
+
const sub = t.closest('[data-company-cat-sub]');
|
|
9818
|
+
if (sub) { companyCatStartEdit({ mode: 'new', parentId: sub.dataset.companyCatSub }); return true; }
|
|
9819
|
+
const del = t.closest('[data-company-cat-delete]');
|
|
9820
|
+
if (del) { companyCatDelete(del); return true; }
|
|
9821
|
+
const delGo = t.closest('[data-company-cat-delete-go]');
|
|
9822
|
+
if (delGo) { const cat = companyTax(companyKnowledgeState).categories.find((c) => c.id === delGo.dataset.companyCatDeleteGo); companyCatPost('/api/company-knowledge/categories', { ops: [{ op: 'delete', id: delGo.dataset.companyCatDeleteGo }] }, `Deleted the company category ${cat ? cat.name : ''}.`); return true; }
|
|
9823
|
+
const go = t.closest('[data-company-move-go]');
|
|
9824
|
+
if (go) {
|
|
9825
|
+
const to = go.dataset.companyMoveGo || null;
|
|
9826
|
+
const tax = companyTax(companyKnowledgeState);
|
|
9827
|
+
companyCatPost('/api/company-knowledge/place', { librarySourceIds: [go.dataset.companyMoveId], categoryId: to }, `Moved it to ${to ? kbcLabel(tax, to) : 'Uncategorized'}.`);
|
|
9828
|
+
return true;
|
|
9829
|
+
}
|
|
9830
|
+
if (t.closest('[data-company-cat-save]')) { companyCatSave(); return true; }
|
|
9831
|
+
if (t.closest('[data-company-cat-cancel]')) { companyCatEdit = null; renderCompanyKnowledge(); return true; }
|
|
9832
|
+
if (t.closest('[data-company-pop-close]')) { $companyKnowledgeList.querySelector('.company-pop')?.remove(); return true; }
|
|
9833
|
+
if (t.closest('[data-company-cat-reset]')) { companyCatPost('/api/company-knowledge/categories', { reset: true }, 'Started the company categories again. The old ones are kept aside.'); return true; }
|
|
9834
|
+
if (!t.closest('.company-pop')) $companyKnowledgeList.querySelector('.company-pop')?.remove();
|
|
9835
|
+
return false;
|
|
9836
|
+
}
|
|
9837
|
+
|
|
8139
9838
|
function renderCompanyKnowledge() {
|
|
8140
9839
|
const state = companyKnowledgeState;
|
|
8141
9840
|
$companyKnowledgeFolder.innerHTML = companyFolderHtml(state);
|
|
@@ -8146,6 +9845,19 @@
|
|
|
8146
9845
|
$companyKnowledgePromotion.hidden = !companyKnowledgePromotion;
|
|
8147
9846
|
if (companyKnowledgePromotion) {
|
|
8148
9847
|
$companyPromotionSource.textContent = companyKnowledgePromotion.filename;
|
|
9848
|
+
// #2491 R6.3 (spec §8.5, §14.1): say what is copied, that an email carries people's details, and what an older
|
|
9849
|
+
// FloLess on the same folder sees. Said, never refused: the person decides.
|
|
9850
|
+
const notes = document.getElementById('company-promotion-notes');
|
|
9851
|
+
if (notes) {
|
|
9852
|
+
const mime = companyKnowledgePromotion.mime || '';
|
|
9853
|
+
const lines = !KB_OFFICE_MIMES.has(mime) ? [] : [
|
|
9854
|
+
'FloLess copies the original file and the text it read from it.',
|
|
9855
|
+
...(kbIsEmail(mime) ? ['This email contains people’s names, email addresses and messages. Company knowledge is shared with everyone in your company. Share it only if that’s fine.'] : []),
|
|
9856
|
+
'Colleagues using an older FloLess will not see the company library until they update.',
|
|
9857
|
+
];
|
|
9858
|
+
notes.hidden = !lines.length;
|
|
9859
|
+
notes.innerHTML = lines.map((line, i) => `<p class="${i === 1 && kbIsEmail(mime) ? 'warn' : ''}">${escapeHtml(line)}</p>`).join('');
|
|
9860
|
+
}
|
|
8149
9861
|
const prior = $companyPromotionLineage.value;
|
|
8150
9862
|
const entries = available ? state.sources.filter((entry) => !entry.removedAt) : [];
|
|
8151
9863
|
$companyPromotionLineage.innerHTML = '<option value="">New company entry</option>' + entries.map((entry) =>
|
|
@@ -8164,7 +9876,7 @@
|
|
|
8164
9876
|
} else {
|
|
8165
9877
|
const entries = state.sources.filter((entry) => !entry.removedAt);
|
|
8166
9878
|
$companyKnowledgeList.innerHTML = entries.length
|
|
8167
|
-
?
|
|
9879
|
+
? companyListHtml(entries, state)
|
|
8168
9880
|
: '<div class="company-empty">No company references yet. Preview a project file and choose “Promote to company…”.</div>';
|
|
8169
9881
|
}
|
|
8170
9882
|
|
|
@@ -8259,25 +9971,28 @@
|
|
|
8259
9971
|
const entry = state.sources.find((row) => row.librarySourceId === companyKnowledgePending.librarySourceId && !row.removedAt);
|
|
8260
9972
|
const latest = entry && entry.versions[entry.versions.length - 1];
|
|
8261
9973
|
if (!entry || !latest) throw new Error('That company version is no longer available.');
|
|
8262
|
-
await api(`/api/company-knowledge/sources/${encodeURIComponent(entry.librarySourceId)}/versions/${encodeURIComponent(latest.versionId)}/accept`, {
|
|
9974
|
+
const res = await api(`/api/company-knowledge/sources/${encodeURIComponent(entry.librarySourceId)}/versions/${encodeURIComponent(latest.versionId)}/accept`, {
|
|
8263
9975
|
method: 'POST', body: JSON.stringify({ projectId: companyKnowledgeProjectId }),
|
|
8264
9976
|
});
|
|
8265
9977
|
companyKnowledgePending = null;
|
|
8266
|
-
|
|
9978
|
+
// #2491 R6.9: where it went in this project's categories, and why.
|
|
9979
|
+
const placed = res && res.placement;
|
|
9980
|
+
showToast(`Added ${entry.displayName} v${entry.versions.length} to this project${placed && placed.categoryId ? `, in ${placed.where}` : ''}.${placed && placed.note && !placed.categoryId ? ` ${placed.note}` : ''}`, placed && placed.note && !placed.categoryId ? 'warn' : 'ok');
|
|
8267
9981
|
} else if (companyKnowledgePending?.kind === 'remove') {
|
|
8268
9982
|
const entry = state.sources.find((row) => row.librarySourceId === companyKnowledgePending.librarySourceId);
|
|
8269
9983
|
await api(`/api/company-knowledge/sources/${encodeURIComponent(companyKnowledgePending.librarySourceId)}`, { method: 'DELETE' });
|
|
8270
9984
|
companyKnowledgePending = null;
|
|
8271
9985
|
showToast(`${entry ? entry.displayName : 'Company reference'} removed`, 'ok');
|
|
8272
9986
|
} else if (companyKnowledgePromotion) {
|
|
8273
|
-
await api('/api/company-knowledge/promote', {
|
|
9987
|
+
const promoted = await api('/api/company-knowledge/promote', {
|
|
8274
9988
|
method: 'POST', body: JSON.stringify({
|
|
8275
9989
|
projectId: companyKnowledgeProjectId,
|
|
8276
9990
|
sourceId: companyKnowledgePromotion.sourceId,
|
|
8277
9991
|
librarySourceId: $companyPromotionLineage.value || null,
|
|
8278
9992
|
}),
|
|
8279
9993
|
});
|
|
8280
|
-
|
|
9994
|
+
const placed = promoted && promoted.placement;
|
|
9995
|
+
showToast(`Company reference published${placed && placed.categoryId ? `, in ${placed.where}` : ''}.${placed && placed.note && !placed.categoryId ? ` ${placed.note}` : ''}`, placed && placed.note && !placed.categoryId ? 'warn' : 'ok');
|
|
8281
9996
|
companyKnowledgePromotion = null;
|
|
8282
9997
|
}
|
|
8283
9998
|
await loadCompanyKnowledge(companyKnowledgeProjectId);
|
|
@@ -8288,6 +10003,7 @@
|
|
|
8288
10003
|
|
|
8289
10004
|
if ($companyKnowledgeModal) {
|
|
8290
10005
|
$companyKnowledgeModal.addEventListener('click', (event) => {
|
|
10006
|
+
if (companyCatClick(event)) return;
|
|
8291
10007
|
const folder = event.target.closest('[data-company-folder-choose]');
|
|
8292
10008
|
if (folder) { chooseCompanyFolder(); return; }
|
|
8293
10009
|
const accept = event.target.closest('[data-company-stage-accept]');
|
|
@@ -8304,6 +10020,24 @@
|
|
|
8304
10020
|
onBackdropDismiss($companyKnowledgeModal, () => closeCompanyKnowledge());
|
|
8305
10021
|
document.addEventListener('keydown', (event) => {
|
|
8306
10022
|
if (!$companyKnowledgeModal.classList.contains('show')) return;
|
|
10023
|
+
// #2491 R6.9: the name box and the menus answer their own keys first; Escape closes them, not the dialog.
|
|
10024
|
+
if (event.target.classList && event.target.classList.contains('company-cat-input')) {
|
|
10025
|
+
if (event.key === 'Enter') { event.preventDefault(); companyCatSave(); return; }
|
|
10026
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); companyCatEdit = null; renderCompanyKnowledge(); return; }
|
|
10027
|
+
}
|
|
10028
|
+
const pop = $companyKnowledgeList.querySelector('.company-pop');
|
|
10029
|
+
if (pop && event.key === 'Escape') {
|
|
10030
|
+
event.preventDefault(); event.stopPropagation();
|
|
10031
|
+
const back = pop.dataset.back; pop.remove();
|
|
10032
|
+
const el = back && ($companyKnowledgeList.querySelector(`[data-company-cat-menu="${CSS.escape(back)}"]`) || $companyKnowledgeList.querySelector(`[data-company-move="${CSS.escape(back)}"]`));
|
|
10033
|
+
if (el) el.focus();
|
|
10034
|
+
return;
|
|
10035
|
+
}
|
|
10036
|
+
if (pop && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
|
10037
|
+
const items = [...pop.querySelectorAll('.kb-ds-mi, .hc-go')];
|
|
10038
|
+
const at = items.indexOf(document.activeElement);
|
|
10039
|
+
if (at >= 0) { event.preventDefault(); items[(at + (event.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length].focus(); return; }
|
|
10040
|
+
}
|
|
8307
10041
|
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeCompanyKnowledge(); return; }
|
|
8308
10042
|
if (event.key !== 'Tab') return;
|
|
8309
10043
|
const focusable = [...$companyKnowledgeModal.querySelectorAll('button:not([hidden]):not(:disabled), input:not([hidden]):not(:disabled), [tabindex="0"]')]
|
|
@@ -8316,7 +10050,7 @@
|
|
|
8316
10050
|
}
|
|
8317
10051
|
|
|
8318
10052
|
// ── Knowledge verbs (each captures `proj` — the user may switch projects mid-await) ──
|
|
8319
|
-
async function kbUpload(fileList) {
|
|
10053
|
+
async function kbUpload(fileList, categoryId) {
|
|
8320
10054
|
const proj = current;
|
|
8321
10055
|
const files = Array.from(fileList || []);
|
|
8322
10056
|
if (!proj || !files.length) return;
|
|
@@ -8332,17 +10066,101 @@
|
|
|
8332
10066
|
catch { showToast('Could not read the selected files', 'warn'); return; }
|
|
8333
10067
|
if (current !== proj) return; // switched projects mid-read — never upload against the wrong KB
|
|
8334
10068
|
try {
|
|
8335
|
-
|
|
10069
|
+
// The project these files were picked for, by its incarnation: a project recreated under the same id is not it.
|
|
10070
|
+
// Per file (#2491): one file FloLess cannot take (an old .doc, an unsupported type) never sinks the rest of the
|
|
10071
|
+
// drop, and it is named with the reason in the server's plain words.
|
|
10072
|
+
const res = await api(kbUrl(proj.id, '/sources'), { method: 'POST',
|
|
10073
|
+
body: JSON.stringify({ files: uploads, partial: true, ...(proj.uuid ? { expectedProjectUuid: proj.uuid } : {}),
|
|
10074
|
+
...(categoryId !== undefined ? { categoryId } : {}) }) });
|
|
8336
10075
|
if (current !== proj) return;
|
|
8337
10076
|
const n = (res.sources || []).length;
|
|
8338
|
-
|
|
10077
|
+
// #2491 R6.9: dropped on a category — say where they went, and why when it was not that category.
|
|
10078
|
+
if (categoryId !== undefined && n) {
|
|
10079
|
+
const where = categoryId ? kbcLabel(kbCats(knowledgeState), categoryId) : 'Uncategorized';
|
|
10080
|
+
if (res.placement === 'placed' || categoryId === null) kbAnnounce(`Added ${n} reference${n === 1 ? '' : 's'} to ${where}.`);
|
|
10081
|
+
else showToast(`Added ${n} reference${n === 1 ? '' : 's'}, in Uncategorized: ${res.placement === 'unknown-category' ? 'that category is no longer there' : res.placement === 'unavailable' ? 'your categories could not be read' : 'only you can file references into a category'}.`, 'warn');
|
|
10082
|
+
}
|
|
10083
|
+
const missed = (res.results || []).filter((r) => r && r.outcome !== 'added');
|
|
10084
|
+
if (!missed.length) showToast(`Added ${n} reference${n === 1 ? '' : 's'}`, 'ok');
|
|
10085
|
+
else {
|
|
10086
|
+
const first = missed[0];
|
|
10087
|
+
const more = missed.length > 1 ? ` (and ${missed.length - 1} more not added)` : '';
|
|
10088
|
+
showToast(`${n ? `Added ${n} reference${n === 1 ? '' : 's'}. ` : ''}“${first.name}” wasn’t added: ${first.reason || 'FloLess could not take it.'}${more}`, 'warn');
|
|
10089
|
+
}
|
|
10090
|
+
// #2399 slice 0c: files uploaded from an open Add issue panel arrive ticked in it.
|
|
10091
|
+
if (kbDsPanel && kbDsPanel.kind === 'add') {
|
|
10092
|
+
if (kbDsPanel.chosen) for (const row of res.sources || []) kbDsPanel.chosen.add(row.sourceId);
|
|
10093
|
+
kbDsForceNext = true;
|
|
10094
|
+
kbDsFocus = { control: '.kb-ds-panel [data-kb-ds-add-go], .kb-ds-panel [data-kb-ds-upload]' };
|
|
10095
|
+
}
|
|
8339
10096
|
track('kb_sources_added', { app: proj.app, n });
|
|
8340
|
-
} catch {
|
|
8341
|
-
showToast(
|
|
10097
|
+
} catch (err) {
|
|
10098
|
+
showToast(err && err.body && err.body.code === 'project-changed'
|
|
10099
|
+
? 'This project was replaced while the files were being read, so nothing was added. Choose the files again.'
|
|
10100
|
+
// #2491: a file FloLess cannot take (an old .doc, an unsupported type) says why, in the server's plain words.
|
|
10101
|
+
: err && err.body && err.body.reason ? `Nothing was added. ${err.body.reason}`
|
|
10102
|
+
: 'Couldn’t add these references. Check the files and try again.', 'warn');
|
|
8342
10103
|
}
|
|
8343
10104
|
if (current === proj) renderKnowledge();
|
|
8344
10105
|
}
|
|
8345
10106
|
|
|
10107
|
+
/** Choose (or with null, clear) the design set. The revision on screen goes with it, so a design set changed
|
|
10108
|
+
* meanwhile (by a chat card or another window) is never overwritten by a screen that had not seen it. */
|
|
10109
|
+
async function kbDesignSetRegister(sourceId, seen) {
|
|
10110
|
+
const proj = current;
|
|
10111
|
+
if (!proj) return;
|
|
10112
|
+
kbCloseConfirm();
|
|
10113
|
+
// The repaint destroys the control that was pressed; the one that shows the result takes focus (paintKnowledge).
|
|
10114
|
+
kbFocusDesignSet = { sourceId };
|
|
10115
|
+
try {
|
|
10116
|
+
// What the person saw when they pressed it: the revision drawn into that control, this project's incarnation, and
|
|
10117
|
+
// for a choice the bytes of the row. Any of them having moved is a 409, never a write over something unseen.
|
|
10118
|
+
const expected = { [KEY_DESIGN_SET]: seen.revision, [KEY_DS_PROJECT]: proj.uuid || '(none)',
|
|
10119
|
+
...(sourceId ? { [KEY_DS_REFERENCE]: seen.blob || '(missing)' } : {}) };
|
|
10120
|
+
await api(`/api/projects/${encodeURIComponent(proj.id)}/design-set`, { method: 'POST', body: JSON.stringify({ sourceId, expected }) });
|
|
10121
|
+
showToast(sourceId ? 'Design set chosen' : 'Design set cleared', 'ok');
|
|
10122
|
+
track(sourceId ? 'kb_design_set_chosen' : 'kb_design_set_cleared', { app: proj.app });
|
|
10123
|
+
} catch (err) {
|
|
10124
|
+
kbFocusDesignSet = null;
|
|
10125
|
+
const code = err && err.body && err.body.code;
|
|
10126
|
+
showToast(code === 'design-set-changed'
|
|
10127
|
+
? 'The design set changed while this was open. Check it and choose again.'
|
|
10128
|
+
// The server's own sentence says what to do (busy, file not in the project, an index it cannot take).
|
|
10129
|
+
: (err && err.body && typeof err.body.error === 'string' && err.body.error) || 'Couldn’t change the design set. Try again.', 'warn');
|
|
10130
|
+
}
|
|
10131
|
+
if (current !== proj) return;
|
|
10132
|
+
kbInvalidateRefs();
|
|
10133
|
+
renderKnowledge();
|
|
10134
|
+
}
|
|
10135
|
+
function kbDesignSetAsk() {
|
|
10136
|
+
const proj = current;
|
|
10137
|
+
const d = knowledgeState && kbActiveDesignSet(knowledgeState);
|
|
10138
|
+
if (!proj || !d) return;
|
|
10139
|
+
const chat = window.flolessChat;
|
|
10140
|
+
if (!chat || typeof chat.fillMessageBox !== 'function' || chat.scopeProjectId?.() !== proj.id) {
|
|
10141
|
+
showToast('Open this project’s AI chat first, then ask again.', 'warn'); return;
|
|
10142
|
+
}
|
|
10143
|
+
chat.fillMessageBox(`Please read the design set “${d.filename}” in this project’s knowledge and record its sheet index: each sheet’s number, title and page.`);
|
|
10144
|
+
}
|
|
10145
|
+
function kbShowDesignSetClearConfirm(btn) {
|
|
10146
|
+
kbCloseConfirm();
|
|
10147
|
+
const box = btn.closest('.kb-refs-body');
|
|
10148
|
+
if (!box) return;
|
|
10149
|
+
const pop = document.createElement('div');
|
|
10150
|
+
pop.className = 'hist-confirm';
|
|
10151
|
+
pop.innerHTML = '<div class="hc-title">Clear the design set?</div>' +
|
|
10152
|
+
'<div class="hc-body">The file stays in your references. Its sheet index is forgotten.</div>' +
|
|
10153
|
+
'<div class="hc-act"><button type="button" class="hc-cancel">Keep</button>' +
|
|
10154
|
+
`<button type="button" class="hc-go danger" data-kb-ds-clear-go data-kb-ds-rev="${escapeAttr(btn.dataset.kbDsRev || '(unreadable)')}">Clear</button></div>`;
|
|
10155
|
+
box.appendChild(pop);
|
|
10156
|
+
const cr = box.getBoundingClientRect();
|
|
10157
|
+
const br = btn.getBoundingClientRect();
|
|
10158
|
+
pop.style.top = `${br.bottom - cr.top + box.scrollTop + 6}px`;
|
|
10159
|
+
pop.style.left = `${Math.max(8, Math.min(br.right - cr.left - pop.offsetWidth, box.clientWidth - pop.offsetWidth - 8))}px`;
|
|
10160
|
+
document.addEventListener('mousedown', kbOnDocDown, true);
|
|
10161
|
+
const keep = pop.querySelector('.hc-cancel'); if (keep) keep.focus();
|
|
10162
|
+
}
|
|
10163
|
+
|
|
8346
10164
|
async function kbToggle(sourceId, next) {
|
|
8347
10165
|
const proj = current;
|
|
8348
10166
|
if (!proj) return;
|
|
@@ -8351,13 +10169,13 @@
|
|
|
8351
10169
|
if (current === proj) renderKnowledge(); // re-render reconciles the optimistic flip either way
|
|
8352
10170
|
}
|
|
8353
10171
|
|
|
8354
|
-
async function kbRemove(sourceId) {
|
|
10172
|
+
async function kbRemove(sourceId, okMsg) {
|
|
8355
10173
|
const proj = current;
|
|
8356
10174
|
if (!proj) return;
|
|
8357
10175
|
kbCloseConfirm();
|
|
8358
10176
|
try {
|
|
8359
10177
|
await api(kbUrl(proj.id, `/sources/${encodeURIComponent(sourceId)}`), { method: 'DELETE' });
|
|
8360
|
-
showToast('Reference removed', 'ok');
|
|
10178
|
+
showToast(okMsg || 'Reference removed', 'ok');
|
|
8361
10179
|
} catch { showToast('Couldn’t remove this reference. Try again.', 'warn'); }
|
|
8362
10180
|
if (current === proj) renderKnowledge();
|
|
8363
10181
|
}
|
|
@@ -8477,7 +10295,7 @@
|
|
|
8477
10295
|
document.removeEventListener('mousedown', kbOnDocDown, true);
|
|
8478
10296
|
}
|
|
8479
10297
|
function kbOnDocDown(e) {
|
|
8480
|
-
if (!e.target.closest('.hist-confirm') && !e.target.closest('[data-kb-remove]')) kbCloseConfirm();
|
|
10298
|
+
if (!e.target.closest('.hist-confirm') && !e.target.closest('[data-kb-remove]') && !e.target.closest('[data-kb-ds-clear]')) kbCloseConfirm();
|
|
8481
10299
|
}
|
|
8482
10300
|
// Anchored to the SCROLL container (.kb-refs-body, position:relative) — .kb-col is overflow:hidden
|
|
8483
10301
|
// and would clip the popover. Same anchoring as .ws-history's rollback confirm.
|
|
@@ -8503,19 +10321,402 @@
|
|
|
8503
10321
|
document.addEventListener('mousedown', kbOnDocDown, true);
|
|
8504
10322
|
}
|
|
8505
10323
|
|
|
10324
|
+
// ── Design set issues: what the controls do (#2399 slice 0c) ──────────────────────────────────────
|
|
10325
|
+
// Every change carries the design-set revision drawn into the control that was pressed and this project's incarnation,
|
|
10326
|
+
// so a design set changed meanwhile (by a chat card or another window) is never written over by a screen that had not
|
|
10327
|
+
// seen it. An open panel's typed values live in `kbDsPanel`, so a repaint never loses them.
|
|
10328
|
+
let kbDsForceNext = false;
|
|
10329
|
+
/** A poll must not repaint under a panel the person is typing in or ticking; a repaint this code asks for still runs. */
|
|
10330
|
+
function kbDsPanelBusy() {
|
|
10331
|
+
if (kbDsForceNext) { kbDsForceNext = false; return false; }
|
|
10332
|
+
const panel = kbDsPanel && $wsKnowledge.querySelector('.kb-ds-panel');
|
|
10333
|
+
return !!panel && panel.contains(document.activeElement);
|
|
10334
|
+
}
|
|
10335
|
+
function kbDsRepaint() {
|
|
10336
|
+
kbInvalidateRefs();
|
|
10337
|
+
kbDsForceNext = true;
|
|
10338
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
10339
|
+
kbDsForceNext = false;
|
|
10340
|
+
}
|
|
10341
|
+
/** After a repaint the control that was pressed is gone: focus its successor, or the issue, or the section. */
|
|
10342
|
+
function kbDsRestoreFocus(host) {
|
|
10343
|
+
const want = kbDsFocus;
|
|
10344
|
+
if (!want) return;
|
|
10345
|
+
kbDsFocus = null;
|
|
10346
|
+
const issue = want.issueId ? host.querySelector(`[data-kb-ds-issue-id="${CSS.escape(want.issueId)}"]`) : null;
|
|
10347
|
+
const scope = issue || host.querySelector('.kb-ds');
|
|
10348
|
+
const target = (want.control && scope && scope.querySelector(want.control))
|
|
10349
|
+
|| (issue && issue.querySelector('.kb-ds-sum')) || host.querySelector('.kb-ds .kb-ds-add, .kb-ds .kb-ds-sum');
|
|
10350
|
+
if (target) target.focus({ preventScroll: false });
|
|
10351
|
+
if (want.select && target && typeof target.select === 'function') target.select();
|
|
10352
|
+
}
|
|
10353
|
+
const kbDsExpected = (proj, rev) => ({ [KEY_DESIGN_SET]: rev || '(unreadable)', [KEY_DS_PROJECT]: proj.uuid || '(none)' });
|
|
10354
|
+
const kbDsBase = (proj) => `/api/projects/${encodeURIComponent(proj.id)}/design-set`;
|
|
10355
|
+
function kbDsErrorText(err, fallback) {
|
|
10356
|
+
const code = err && err.body && err.body.code;
|
|
10357
|
+
if (code === 'design-set-changed') return 'The design set changed while this was open. Check it and try again.';
|
|
10358
|
+
return (err && err.body && typeof err.body.error === 'string' && err.body.error) || fallback;
|
|
10359
|
+
}
|
|
10360
|
+
function kbDsOpenPanel(panel, focus) {
|
|
10361
|
+
kbCloseConfirm();
|
|
10362
|
+
// The revision the person is editing against, kept with the panel: a repaint while it is open (another window renamed
|
|
10363
|
+
// the issue) must not quietly give Save the newer revision and let it overwrite that change.
|
|
10364
|
+
kbDsPanel = { ...panel, rev: kbDsRev(knowledgeState) };
|
|
10365
|
+
if (panel.issueId) { kbDsIsOpen({ issueId: panel.issueId }, knowledgeState); kbDsOpen.ids.add(panel.issueId); }
|
|
10366
|
+
kbDsFocus = focus;
|
|
10367
|
+
kbDsRepaint();
|
|
10368
|
+
}
|
|
10369
|
+
function kbDsClosePanel(focus) {
|
|
10370
|
+
kbDsPanel = null;
|
|
10371
|
+
kbDsFocus = focus || null;
|
|
10372
|
+
kbDsRepaint();
|
|
10373
|
+
}
|
|
10374
|
+
/** One write to the design set, then a fresh read of it. The server's own sentence says what went wrong. */
|
|
10375
|
+
async function kbDsWrite(method, path, body, okMsg, focus) {
|
|
10376
|
+
const proj = current;
|
|
10377
|
+
if (!proj) return false;
|
|
10378
|
+
let ok = true;
|
|
10379
|
+
try {
|
|
10380
|
+
await api(`${kbDsBase(proj)}${path}`, { method, body: JSON.stringify(body) });
|
|
10381
|
+
if (okMsg) showToast(okMsg, 'ok');
|
|
10382
|
+
} catch (err) {
|
|
10383
|
+
ok = false;
|
|
10384
|
+
const text = kbDsErrorText(err, 'Couldn’t change the design set. Try again.');
|
|
10385
|
+
if (kbDsPanel) kbDsPanel.error = text; else showToast(text, 'warn');
|
|
10386
|
+
}
|
|
10387
|
+
if (current !== proj) return ok;
|
|
10388
|
+
if (ok && kbDsPanel && kbDsPanel.kind !== 'read') kbDsPanel = null;
|
|
10389
|
+
kbDsFocus = focus || null;
|
|
10390
|
+
kbInvalidateRefs();
|
|
10391
|
+
kbDsForceNext = true;
|
|
10392
|
+
await renderKnowledge();
|
|
10393
|
+
kbDsForceNext = false;
|
|
10394
|
+
return ok;
|
|
10395
|
+
}
|
|
10396
|
+
const kbDsIssueById = (id) => ((knowledgeState && knowledgeState.designSet && knowledgeState.designSet.issues) || []).find((i) => i.issueId === id) || null;
|
|
10397
|
+
|
|
10398
|
+
/** The More menu: rename, index, withdraw or restore an issue — anchored like every other popover in this column. */
|
|
10399
|
+
function kbDsShowMenu(btn) {
|
|
10400
|
+
kbCloseConfirm();
|
|
10401
|
+
const issue = kbDsIssueById(btn.dataset.kbDsMore);
|
|
10402
|
+
const box = btn.closest('.kb-refs-body');
|
|
10403
|
+
if (!issue || !box) return;
|
|
10404
|
+
const pop = document.createElement('div');
|
|
10405
|
+
pop.className = 'hist-confirm kb-ds-menu';
|
|
10406
|
+
pop.setAttribute('role', 'menu');
|
|
10407
|
+
pop.setAttribute('aria-label', `More for ${issue.label}`);
|
|
10408
|
+
const id = escapeAttr(issue.issueId);
|
|
10409
|
+
const rev = escapeAttr(btn.dataset.kbDsRev || '(unreadable)');
|
|
10410
|
+
const live = issue.files.some((f) => !f.withdrawn && f.presence === 'present');
|
|
10411
|
+
pop.innerHTML =
|
|
10412
|
+
`<button type="button" role="menuitem" class="kb-ds-mi" data-kb-ds-rename="${id}" data-command-id="shell.kb-design-issue-rename">Rename or date…</button>` +
|
|
10413
|
+
(live ? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-ds-ask="${id}" data-command-id="shell.kb-design-set-ask">Ask AI to build the sheet index</button>` : '') +
|
|
10414
|
+
(issue.withdrawnAt
|
|
10415
|
+
? `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-ds-irestore="${id}" data-kb-ds-rev="${rev}" data-command-id="shell.kb-design-issue-restore">Restore issue</button>`
|
|
10416
|
+
: `<button type="button" role="menuitem" class="kb-ds-mi" data-kb-ds-iwithdraw="${id}" data-kb-ds-rev="${rev}" data-command-id="shell.kb-design-issue-withdraw">Withdraw issue</button>`);
|
|
10417
|
+
box.appendChild(pop);
|
|
10418
|
+
const cr = box.getBoundingClientRect();
|
|
10419
|
+
const br = btn.getBoundingClientRect();
|
|
10420
|
+
pop.style.top = `${br.bottom - cr.top + box.scrollTop + 6}px`;
|
|
10421
|
+
pop.style.left = `${Math.max(8, Math.min(br.left - cr.left, box.clientWidth - pop.offsetWidth - 8))}px`;
|
|
10422
|
+
document.addEventListener('mousedown', kbOnDocDown, true);
|
|
10423
|
+
const first = pop.querySelector('.kb-ds-mi'); if (first) first.focus();
|
|
10424
|
+
}
|
|
10425
|
+
|
|
10426
|
+
/** ✕ on a file of an issue: withdraw it (the default, it stays in the issue's history) or remove its reference. */
|
|
10427
|
+
function kbDsShowFileChoice(btn) {
|
|
10428
|
+
kbCloseConfirm();
|
|
10429
|
+
const issue = kbDsIssueById(btn.dataset.kbDsIssue);
|
|
10430
|
+
const f = issue && issue.files.find((x) => x.index === Number(btn.dataset.kbDsFx));
|
|
10431
|
+
const box = btn.closest('.kb-refs-body');
|
|
10432
|
+
if (!f || !box) return;
|
|
10433
|
+
const versions = Array.isArray(f.usedBy) ? f.usedBy.filter((u) => u.version).map((u) => `v${u.version}`) : [];
|
|
10434
|
+
const open = Array.isArray(f.usedBy) && f.usedBy.some((u) => !u.version);
|
|
10435
|
+
const use = f.usedBy === 'unknown' ? 'FloLess could not check which reads used it. '
|
|
10436
|
+
: versions.length || open ? `${[...versions, ...(open ? ['a read still open'] : [])].join(', ')} ${versions.length + (open ? 1 : 0) === 1 ? 'was' : 'were'} read from it and keep${versions.length + (open ? 1 : 0) === 1 ? 's' : ''} its own copy. ` : '';
|
|
10437
|
+
const row = btn.dataset.kbDsRow;
|
|
10438
|
+
const pop = document.createElement('div');
|
|
10439
|
+
pop.className = 'hist-confirm';
|
|
10440
|
+
pop.setAttribute('role', 'dialog');
|
|
10441
|
+
pop.setAttribute('aria-label', `Withdraw ${f.filename}`);
|
|
10442
|
+
if (btn.hasAttribute('data-kb-ds-fwd')) {
|
|
10443
|
+
pop.innerHTML = `<div class="hc-title">Remove “${escapeHtml(f.filename)}” from your references?</div>` +
|
|
10444
|
+
`<div class="hc-body">${escapeHtml(use)}It is withdrawn from ${escapeHtml(issue.label)} already. The design set keeps its copy.</div>` +
|
|
10445
|
+
'<div class="hc-act"><button type="button" class="hc-cancel" data-command-id="shell.kb-design-panel-cancel">Cancel</button>' +
|
|
10446
|
+
`<button type="button" class="hc-go" data-kb-ds-fremove="${escapeAttr(row || '')}" data-kb-ds-issue="${escapeAttr(issue.issueId)}" data-command-id="shell.kb-design-file-remove-go">Remove reference</button></div>`;
|
|
10447
|
+
} else
|
|
10448
|
+
pop.innerHTML = `<div class="hc-title">Withdraw “${escapeHtml(f.filename)}” from ${escapeHtml(issue.label)}?</div>` +
|
|
10449
|
+
`<div class="hc-body">${escapeHtml(use)}It stays in this issue’s history and nothing is thrown away. You can restore it.` +
|
|
10450
|
+
(row ? ' Or remove it from your references; the design set still keeps its copy.' : '') + '</div>' +
|
|
10451
|
+
'<div class="hc-act"><button type="button" class="hc-cancel" data-command-id="shell.kb-design-panel-cancel">Cancel</button>' +
|
|
10452
|
+
(row ? `<button type="button" class="hc-alt" data-kb-ds-fremove="${escapeAttr(row)}" data-kb-ds-issue="${escapeAttr(issue.issueId)}" data-command-id="shell.kb-design-file-remove-go">Remove reference</button>` : '') +
|
|
10453
|
+
`<button type="button" class="hc-go" data-kb-ds-fwithdraw="${f.index}" data-kb-ds-issue="${escapeAttr(issue.issueId)}" data-kb-ds-rev="${escapeAttr(btn.dataset.kbDsRev || '(unreadable)')}" data-command-id="shell.kb-design-file-withdraw">Withdraw</button></div>`;
|
|
10454
|
+
box.appendChild(pop);
|
|
10455
|
+
const cr = box.getBoundingClientRect();
|
|
10456
|
+
const br = btn.getBoundingClientRect();
|
|
10457
|
+
pop.style.top = `${br.bottom - cr.top + box.scrollTop + 6}px`;
|
|
10458
|
+
pop.style.left = `${Math.max(8, Math.min(br.right - cr.left - pop.offsetWidth, box.clientWidth - pop.offsetWidth - 8))}px`;
|
|
10459
|
+
document.addEventListener('mousedown', kbOnDocDown, true);
|
|
10460
|
+
// The safe choice has focus: Withdraw when it is offered, never the removal that happens to come first in the row.
|
|
10461
|
+
const safe = pop.querySelector('[data-kb-ds-fwithdraw]') || pop.querySelector('[data-kb-ds-fremove]'); if (safe) safe.focus();
|
|
10462
|
+
}
|
|
10463
|
+
|
|
10464
|
+
async function kbDsOpenRead(issueId) {
|
|
10465
|
+
const proj = current;
|
|
10466
|
+
if (!proj) return;
|
|
10467
|
+
kbDsOpenPanel({ kind: 'read', issueId, plan: null }, { issueId, control: '.kb-ds-panel' });
|
|
10468
|
+
let plan;
|
|
10469
|
+
try { plan = await api(`${kbDsBase(proj)}/issues/${encodeURIComponent(issueId)}/read-plan`); }
|
|
10470
|
+
catch (err) {
|
|
10471
|
+
if (current !== proj || !kbDsPanel || kbDsPanel.issueId !== issueId) return;
|
|
10472
|
+
kbDsPanel = null;
|
|
10473
|
+
showToast(kbDsErrorText(err, 'Couldn’t check the files of this issue. Try again.'), 'warn');
|
|
10474
|
+
kbDsRepaint();
|
|
10475
|
+
return;
|
|
10476
|
+
}
|
|
10477
|
+
if (current !== proj || !kbDsPanel || kbDsPanel.kind !== 'read' || kbDsPanel.issueId !== issueId) return;
|
|
10478
|
+
kbDsPanel.plan = plan;
|
|
10479
|
+
kbDsPanel.chosen = new Set(plan.included.map((f) => f.index));
|
|
10480
|
+
kbDsFocus = { issueId, control: '.kb-ds-panel input[type="checkbox"], .kb-ds-panel .btn-mini' };
|
|
10481
|
+
kbDsRepaint();
|
|
10482
|
+
}
|
|
10483
|
+
|
|
10484
|
+
async function kbDsReadGo(issueId, returnFocus) {
|
|
10485
|
+
const proj = current;
|
|
10486
|
+
const panel = kbDsPanel;
|
|
10487
|
+
if (!proj || !panel || panel.kind !== 'read' || !panel.plan) return;
|
|
10488
|
+
const chosen = [...panel.chosen].sort((a, b) => a - b);
|
|
10489
|
+
const asPlanned = panel.plan.chosenByDefault && chosen.length === panel.plan.included.length
|
|
10490
|
+
&& chosen.every((n, i) => n === panel.plan.included[i].index);
|
|
10491
|
+
try {
|
|
10492
|
+
// A changed choice gets its own plan key first: the read takes exactly what this panel shows.
|
|
10493
|
+
const plan = asPlanned ? panel.plan
|
|
10494
|
+
: await api(`${kbDsBase(proj)}/issues/${encodeURIComponent(issueId)}/read-plan?files=${chosen.join(',')}`);
|
|
10495
|
+
// The panel promised the ticked files (40 at most). If the server would take a different set — a copy changed
|
|
10496
|
+
// meanwhile — show its plan instead of starting a read the person did not see.
|
|
10497
|
+
const promised = chosen.slice(0, 40).join(',');
|
|
10498
|
+
if (!asPlanned && plan.included.map((f) => f.index).join(',') !== promised) {
|
|
10499
|
+
if (current !== proj || !kbDsPanel) return;
|
|
10500
|
+
kbDsPanel.plan = { ...plan, chosenByDefault: false };
|
|
10501
|
+
kbDsPanel.chosen = new Set(plan.included.map((f) => f.index));
|
|
10502
|
+
kbDsPanel.error = 'Some of the files you ticked cannot be read just now; the list below says why. Check it, then read again.';
|
|
10503
|
+
kbDsFocus = { issueId, control: '.kb-ds-err, [data-kb-ds-read-go]' };
|
|
10504
|
+
kbDsRepaint();
|
|
10505
|
+
return;
|
|
10506
|
+
}
|
|
10507
|
+
const res = await api(`/api/projects/${encodeURIComponent(proj.id)}/revision-requests`, { method: 'POST',
|
|
10508
|
+
body: JSON.stringify({ appId: proj.app, designIssue: { issueId, ...(asPlanned ? {} : { files: chosen }), planKey: plan.planKey } }) });
|
|
10509
|
+
if (current !== proj) return;
|
|
10510
|
+
const n = plan.included.length;
|
|
10511
|
+
const issue = kbDsIssueById(issueId);
|
|
10512
|
+
showToast(`Read queued — ${n} file${n === 1 ? '' : 's'} of “${(issue && issue.label) || 'the issue'}” for your terminal AI`, 'ok');
|
|
10513
|
+
track('kb_design_issue_read', { app: proj.app, n });
|
|
10514
|
+
if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
|
|
10515
|
+
kbDsClosePanel({ issueId, control: '[data-kb-ds-read]' });
|
|
10516
|
+
if (res && res.request && bridge.showRequestQueuedModal) bridge.showRequestQueuedModal(res.request, { copied: false, fileCount: n, returnFocus });
|
|
10517
|
+
} catch (err) {
|
|
10518
|
+
if (current !== proj || !kbDsPanel) return;
|
|
10519
|
+
const code = err && err.body && err.body.code;
|
|
10520
|
+
kbDsPanel.error = kbDsErrorText(err, 'Couldn’t queue the read. Try again.');
|
|
10521
|
+
kbDsPanel.openRequests = ['revision-read-active', 'multiple-failed-reads', 'recovery-pending'].includes(code);
|
|
10522
|
+
kbDsFocus = { issueId, control: '.kb-ds-err .kb-link, [data-kb-ds-read-go]' };
|
|
10523
|
+
kbDsRepaint();
|
|
10524
|
+
}
|
|
10525
|
+
}
|
|
10526
|
+
|
|
10527
|
+
/** The issue date as the server checks it: empty, or a real calendar date written YYYY-MM-DD. */
|
|
10528
|
+
const KB_DS_DATE_ERROR = 'The issue date must be a calendar date written as YYYY-MM-DD, or empty.';
|
|
10529
|
+
function kbDsDateOk(raw) {
|
|
10530
|
+
if (!raw) return true;
|
|
10531
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(raw)) return false;
|
|
10532
|
+
const at = new Date(`${raw}T00:00:00Z`);
|
|
10533
|
+
return Number.isFinite(at.getTime()) && at.toISOString().slice(0, 10) === raw;
|
|
10534
|
+
}
|
|
10535
|
+
async function kbDsAddGo(rev) {
|
|
10536
|
+
const proj = current;
|
|
10537
|
+
const st = knowledgeState;
|
|
10538
|
+
if (!proj || !st || !kbDsPanel || kbDsPanel.kind !== 'add') return;
|
|
10539
|
+
const drawings = kbDsAddable(st);
|
|
10540
|
+
const chosen = kbDsPanel.chosen ? drawings.filter((s) => kbDsPanel.chosen.has(s.sourceId)) : drawings.filter((s) => !kbInDesignSet(s, st));
|
|
10541
|
+
const label = ($wsKnowledge.querySelector('#kb-ds-label')?.value || '').trim();
|
|
10542
|
+
const issuedOn = ($wsKnowledge.querySelector('#kb-ds-date')?.value || '').trim();
|
|
10543
|
+
kbDsPanel.label = label; kbDsPanel.date = issuedOn;
|
|
10544
|
+
if (!kbDsDateOk(issuedOn)) { kbDsPanel.error = KB_DS_DATE_ERROR; kbDsFocus = { control: '#kb-ds-date' }; kbDsRepaint(); return; }
|
|
10545
|
+
if (!chosen.length) { kbDsPanel.error = 'Tick at least one drawing, or upload new files.'; kbDsFocus = { control: '.kb-ds-panel input[type="checkbox"]' }; kbDsRepaint(); return; }
|
|
10546
|
+
if (chosen.length > 50) { kbDsPanel.error = `Only 50 files fit in one issue; ${chosen.length} are ticked. Untick some and add them as another issue.`; kbDsFocus = { control: '.kb-ds-panel input[type="checkbox"]' }; kbDsRepaint(); return; }
|
|
10547
|
+
const before = new Set(((st.designSet && st.designSet.issues) || []).map((i) => i.issueId));
|
|
10548
|
+
const ok = await kbDsWrite('POST', '/issues', { sourceIds: chosen.map((s) => s.sourceId), ...(label ? { label } : {}), ...(issuedOn ? { issuedOn } : {}),
|
|
10549
|
+
expected: kbDsExpected(proj, rev) }, `Added ${label ? `“${label}”` : 'an issue'} to the design set`, { control: '.kb-ds-add' });
|
|
10550
|
+
if (ok && knowledgeState) {
|
|
10551
|
+
const added = ((knowledgeState.designSet && knowledgeState.designSet.issues) || []).find((i) => !before.has(i.issueId));
|
|
10552
|
+
if (added) { kbDsIsOpen(added, knowledgeState); kbDsOpen.ids.add(added.issueId); kbDsFocus = { issueId: added.issueId }; kbDsRepaint(); }
|
|
10553
|
+
}
|
|
10554
|
+
}
|
|
10555
|
+
|
|
10556
|
+
/** Clicks inside the Design set. Returns true when it handled the click. */
|
|
10557
|
+
function kbDsClick(e) {
|
|
10558
|
+
const proj = current;
|
|
10559
|
+
if (!proj) return false;
|
|
10560
|
+
const t = (sel) => e.target.closest(sel);
|
|
10561
|
+
let b;
|
|
10562
|
+
if ((b = t('[data-kb-ds-add]'))) { kbDsOpenPanel({ kind: 'add' }, { control: '.kb-ds-panel input[type="checkbox"], .kb-ds-panel [data-kb-ds-upload]' }); return true; }
|
|
10563
|
+
if ((b = t('[data-kb-ds-upload]'))) { $wsKnowledgeFile.click(); return true; }
|
|
10564
|
+
if ((b = t('[data-kb-ds-cancel]'))) {
|
|
10565
|
+
const issueId = kbDsPanel && kbDsPanel.issueId;
|
|
10566
|
+
kbDsClosePanel(issueId ? { issueId, control: kbDsPanel && kbDsPanel.kind === 'read' ? '[data-kb-ds-read]' : '[data-kb-ds-more]' } : { control: '.kb-ds-add' });
|
|
10567
|
+
return true;
|
|
10568
|
+
}
|
|
10569
|
+
if ((b = t('[data-kb-ds-add-go]'))) { kbDsAddGo(b.dataset.kbDsRev); return true; }
|
|
10570
|
+
if ((b = t('[data-kb-ds-current]'))) {
|
|
10571
|
+
const id = b.dataset.kbDsCurrent;
|
|
10572
|
+
kbDsWrite('PATCH', `/issues/${encodeURIComponent(id)}`, { makeCurrent: true, expected: kbDsExpected(proj, b.dataset.kbDsRev) },
|
|
10573
|
+
'This issue is now the current one', { issueId: id, control: '.kb-ds-sum' });
|
|
10574
|
+
return true;
|
|
10575
|
+
}
|
|
10576
|
+
if ((b = t('[data-kb-ds-more]'))) { kbDsShowMenu(b); return true; }
|
|
10577
|
+
if ((b = t('[data-kb-ds-rename]'))) {
|
|
10578
|
+
const issue = kbDsIssueById(b.dataset.kbDsRename);
|
|
10579
|
+
if (issue) kbDsOpenPanel({ kind: 'rename', issueId: issue.issueId }, { issueId: issue.issueId, control: '#kb-ds-label', select: true });
|
|
10580
|
+
return true;
|
|
10581
|
+
}
|
|
10582
|
+
if ((b = t('[data-kb-ds-rename-go]'))) {
|
|
10583
|
+
const id = b.dataset.kbDsRenameGo;
|
|
10584
|
+
const label = ($wsKnowledge.querySelector('#kb-ds-label')?.value || '').trim();
|
|
10585
|
+
const date = ($wsKnowledge.querySelector('#kb-ds-date')?.value || '').trim();
|
|
10586
|
+
if (kbDsPanel) { kbDsPanel.label = label; kbDsPanel.date = date; }
|
|
10587
|
+
if (!kbDsDateOk(date) && kbDsPanel) { kbDsPanel.error = KB_DS_DATE_ERROR; kbDsFocus = { issueId: id, control: '#kb-ds-date' }; kbDsRepaint(); return true; }
|
|
10588
|
+
kbDsWrite('PATCH', `/issues/${encodeURIComponent(id)}`, { ...(label ? { label } : {}), issuedOn: date || null, expected: kbDsExpected(proj, b.dataset.kbDsRev) },
|
|
10589
|
+
'Issue renamed', { issueId: id, control: '[data-kb-ds-more]' });
|
|
10590
|
+
return true;
|
|
10591
|
+
}
|
|
10592
|
+
if ((b = t('[data-kb-ds-ask]')) && b.dataset.kbDsAsk) {
|
|
10593
|
+
kbCloseConfirm();
|
|
10594
|
+
const issue = kbDsIssueById(b.dataset.kbDsAsk);
|
|
10595
|
+
const chat = window.flolessChat;
|
|
10596
|
+
if (!issue) return true;
|
|
10597
|
+
if (!chat || typeof chat.fillMessageBox !== 'function' || chat.scopeProjectId?.() !== proj.id) {
|
|
10598
|
+
showToast('Open this project’s AI chat first, then ask again.', 'warn'); return true;
|
|
10599
|
+
}
|
|
10600
|
+
chat.fillMessageBox(`Please read the design-set issue “${issue.label}” in this project’s knowledge and record its sheet index: each sheet’s number, title and page, and which file it is in.`);
|
|
10601
|
+
return true;
|
|
10602
|
+
}
|
|
10603
|
+
if ((b = t('[data-kb-ds-iwithdraw]'))) {
|
|
10604
|
+
const id = b.dataset.kbDsIwithdraw;
|
|
10605
|
+
kbCloseConfirm();
|
|
10606
|
+
kbDsWrite('POST', `/issues/${encodeURIComponent(id)}/withdraw`, { expected: kbDsExpected(proj, b.dataset.kbDsRev) },
|
|
10607
|
+
'Issue withdrawn. Nothing was thrown away; you can restore it.', { issueId: id, control: '[data-kb-ds-more]' });
|
|
10608
|
+
return true;
|
|
10609
|
+
}
|
|
10610
|
+
if ((b = t('[data-kb-ds-irestore]'))) {
|
|
10611
|
+
const id = b.dataset.kbDsIrestore;
|
|
10612
|
+
kbCloseConfirm();
|
|
10613
|
+
kbDsWrite('POST', `/issues/${encodeURIComponent(id)}/restore`, { expected: kbDsExpected(proj, b.dataset.kbDsRev) }, 'Issue restored', { issueId: id, control: '[data-kb-ds-more]' });
|
|
10614
|
+
return true;
|
|
10615
|
+
}
|
|
10616
|
+
if ((b = t('[data-kb-ds-fx]'))) { kbDsShowFileChoice(b); return true; }
|
|
10617
|
+
if ((b = t('[data-kb-ds-fwithdraw]'))) {
|
|
10618
|
+
const id = b.dataset.kbDsIssue;
|
|
10619
|
+
kbCloseConfirm();
|
|
10620
|
+
kbDsWrite('POST', `/issues/${encodeURIComponent(id)}/withdraw`, { file: Number(b.dataset.kbDsFwithdraw), expected: kbDsExpected(proj, b.dataset.kbDsRev) },
|
|
10621
|
+
'File withdrawn. You can restore it.', { issueId: id, control: `[data-kb-ds-frestore="${CSS.escape(b.dataset.kbDsFwithdraw)}"]` });
|
|
10622
|
+
return true;
|
|
10623
|
+
}
|
|
10624
|
+
if ((b = t('[data-kb-ds-fremove]'))) {
|
|
10625
|
+
const id = b.dataset.kbDsIssue;
|
|
10626
|
+
kbDsFocus = { issueId: id };
|
|
10627
|
+
kbRemove(b.dataset.kbDsFremove, 'Reference removed. The design set kept its copy.');
|
|
10628
|
+
return true;
|
|
10629
|
+
}
|
|
10630
|
+
if ((b = t('[data-kb-ds-frestore]'))) {
|
|
10631
|
+
const id = b.dataset.kbDsIssue;
|
|
10632
|
+
kbDsWrite('POST', `/issues/${encodeURIComponent(id)}/restore`, { file: Number(b.dataset.kbDsFrestore), expected: kbDsExpected(proj, b.dataset.kbDsRev) },
|
|
10633
|
+
'File restored', { issueId: id, control: `[data-kb-ds-fx="${CSS.escape(b.dataset.kbDsFrestore)}"]` });
|
|
10634
|
+
return true;
|
|
10635
|
+
}
|
|
10636
|
+
if ((b = t('[data-kb-ds-all]'))) { kbDsShowAll.add(b.dataset.kbDsAll); kbDsFocus = { issueId: b.dataset.kbDsAll, control: `.kb-ds-file:nth-child(${KB_DS_FILES_SHOWN + 1}) .kb-fname` }; kbDsRepaint(); return true; }
|
|
10637
|
+
if ((b = t('[data-kb-ds-read]'))) { kbDsOpenRead(b.dataset.kbDsRead); return true; }
|
|
10638
|
+
if ((b = t('[data-kb-ds-read-go]'))) { kbDsReadGo(b.dataset.kbDsReadGo, b.closest('.kb-ds-issue')?.querySelector('[data-kb-ds-read]')); return true; }
|
|
10639
|
+
if ((b = t('[data-kb-ds-requests]'))) { if (bridge.openRequest) bridge.openRequest(null); return true; }
|
|
10640
|
+
if ((b = t('[data-kb-ds-jump]'))) {
|
|
10641
|
+
const sec = $wsKnowledge.querySelector('.kb-ds');
|
|
10642
|
+
// The first issue, not the first control in the page order (Add issue comes before it in the header).
|
|
10643
|
+
if (sec) { sec.scrollIntoView({ block: 'start' }); const first = sec.querySelector('.kb-ds-sum') || sec.querySelector('.kb-ds-add'); if (first) first.focus({ preventScroll: true }); }
|
|
10644
|
+
return true;
|
|
10645
|
+
}
|
|
10646
|
+
return false;
|
|
10647
|
+
}
|
|
10648
|
+
// Ticks and typing in a panel are kept in its state, so a repaint redraws them as they were.
|
|
10649
|
+
$wsKnowledge.addEventListener('change', (e) => {
|
|
10650
|
+
const pick = e.target.closest('[data-kb-ds-pick], [data-kb-ds-add-pick]');
|
|
10651
|
+
if (!pick || !kbDsPanel) return;
|
|
10652
|
+
if (kbDsPanel.kind === 'read' && pick.dataset.kbDsPick !== undefined) {
|
|
10653
|
+
const n = Number(pick.dataset.kbDsPick);
|
|
10654
|
+
if (pick.checked) kbDsPanel.chosen.add(n); else kbDsPanel.chosen.delete(n);
|
|
10655
|
+
kbDsFocus = { issueId: kbDsPanel.issueId, control: `[data-kb-ds-pick="${n}"]` };
|
|
10656
|
+
} else if (kbDsPanel.kind === 'add' && pick.dataset.kbDsAddPick !== undefined) {
|
|
10657
|
+
const st = knowledgeState;
|
|
10658
|
+
if (!kbDsPanel.chosen) kbDsPanel.chosen = new Set(kbDsAddable(st).filter((s) => !kbInDesignSet(s, st)).map((s) => s.sourceId));
|
|
10659
|
+
if (pick.checked) kbDsPanel.chosen.add(pick.dataset.kbDsAddPick); else kbDsPanel.chosen.delete(pick.dataset.kbDsAddPick);
|
|
10660
|
+
kbDsFocus = { control: `[data-kb-ds-add-pick="${CSS.escape(pick.dataset.kbDsAddPick)}"]` };
|
|
10661
|
+
}
|
|
10662
|
+
kbDsPanel.error = null;
|
|
10663
|
+
const label = $wsKnowledge.querySelector('#kb-ds-label'); const date = $wsKnowledge.querySelector('#kb-ds-date');
|
|
10664
|
+
if (label) kbDsPanel.label = label.value; if (date) kbDsPanel.date = date.value;
|
|
10665
|
+
kbDsRepaint();
|
|
10666
|
+
});
|
|
10667
|
+
$wsKnowledge.addEventListener('input', (e) => {
|
|
10668
|
+
if (!kbDsPanel) return;
|
|
10669
|
+
if (e.target.id === 'kb-ds-label') kbDsPanel.label = e.target.value;
|
|
10670
|
+
if (e.target.id === 'kb-ds-date') kbDsPanel.date = e.target.value;
|
|
10671
|
+
});
|
|
10672
|
+
$wsKnowledge.addEventListener('keydown', (e) => {
|
|
10673
|
+
if (e.key !== 'Escape') return;
|
|
10674
|
+
if (e.target.closest('.kb-ds-menu')) { kbCloseConfirm(); return; }
|
|
10675
|
+
if (kbDsPanel && e.target.closest('.kb-ds-panel')) {
|
|
10676
|
+
e.preventDefault();
|
|
10677
|
+
const issueId = kbDsPanel.issueId;
|
|
10678
|
+
kbDsClosePanel(issueId ? { issueId, control: kbDsPanel && kbDsPanel.kind === 'read' ? '[data-kb-ds-read]' : '[data-kb-ds-more]' } : { control: '.kb-ds-add' });
|
|
10679
|
+
}
|
|
10680
|
+
});
|
|
10681
|
+
// Which issues are open is the person's choice and survives repaints. `toggle` does not bubble, so this listens in capture.
|
|
10682
|
+
$wsKnowledge.addEventListener('toggle', (e) => {
|
|
10683
|
+
const d = e.target;
|
|
10684
|
+
if (!d || !d.classList || !d.classList.contains('kb-ds-issue')) return;
|
|
10685
|
+
const issue = kbDsIssueById(d.dataset.kbDsIssueId);
|
|
10686
|
+
if (!issue) return;
|
|
10687
|
+
kbDsIsOpen(issue, knowledgeState);
|
|
10688
|
+
kbDsOpen.touched = true;
|
|
10689
|
+
if (d.open) kbDsOpen.ids.add(issue.issueId); else kbDsOpen.ids.delete(issue.issueId);
|
|
10690
|
+
kbInvalidateRefs();
|
|
10691
|
+
}, true);
|
|
10692
|
+
|
|
8506
10693
|
// One delegated listener for the whole pane — the column is re-rendered wholesale on every state
|
|
8507
10694
|
// change, so per-render wiring would leak handlers.
|
|
8508
10695
|
$wsKnowledge.addEventListener('click', (e) => {
|
|
10696
|
+
// #2491 R6.9: categories, selection and Move to… first — their menus share the design set's menu look.
|
|
10697
|
+
const rowAct = e.target.closest('[data-kb-row-act]');
|
|
10698
|
+
if (rowAct) { kbRowAct(rowAct); return; }
|
|
10699
|
+
if (kbCatClick(e)) return;
|
|
10700
|
+
if (e.target.closest('.kb-ds') || e.target.closest('.kb-ds-menu') || e.target.closest('[data-kb-ds-jump]') || e.target.closest('[data-kb-ds-fremove], [data-kb-ds-fwithdraw]')) {
|
|
10701
|
+
if (kbDsClick(e)) return;
|
|
10702
|
+
}
|
|
8509
10703
|
const promote = e.target.closest('[data-company-promote]');
|
|
8510
10704
|
if (promote) {
|
|
8511
10705
|
const row = knowledgeState && knowledgeState.sources.find((source) => source.sourceId === promote.dataset.companyPromote);
|
|
8512
|
-
if (row) openCompanyKnowledge({ sourceId: row.sourceId, filename: row.filename || 'untitled' }, promote);
|
|
10706
|
+
if (row) openCompanyKnowledge({ sourceId: row.sourceId, filename: row.filename || 'untitled', mime: row.mime }, promote);
|
|
8513
10707
|
return;
|
|
8514
10708
|
}
|
|
8515
10709
|
const company = e.target.closest('[data-company-open]');
|
|
8516
10710
|
if (company) { openCompanyKnowledge(null, company); return; }
|
|
8517
10711
|
const go = e.target.closest('[data-kb-remove-go]');
|
|
8518
10712
|
if (go) { kbRemove(go.dataset.kbRemoveGo); return; }
|
|
10713
|
+
const dsClearGo = e.target.closest('[data-kb-ds-clear-go]');
|
|
10714
|
+
if (dsClearGo) { kbDesignSetRegister(null, { revision: dsClearGo.dataset.kbDsRev || '(unreadable)' }); return; }
|
|
10715
|
+
const dsUse = e.target.closest('[data-kb-ds-use]');
|
|
10716
|
+
if (dsUse) { kbDesignSetRegister(dsUse.dataset.kbDsUse, { revision: dsUse.dataset.kbDsRev || '(unreadable)', blob: dsUse.dataset.kbDsBlob || '' }); return; }
|
|
10717
|
+
if (e.target.closest('[data-kb-ds-ask]')) { kbDesignSetAsk(); return; }
|
|
10718
|
+
const dsClear = e.target.closest('[data-kb-ds-clear]');
|
|
10719
|
+
if (dsClear) { kbShowDesignSetClearConfirm(dsClear); return; }
|
|
8519
10720
|
if (e.target.closest('.hc-cancel')) { kbCloseConfirm(); return; }
|
|
8520
10721
|
const rm = e.target.closest('[data-kb-remove]');
|
|
8521
10722
|
if (rm) {
|
|
@@ -8526,14 +10727,33 @@
|
|
|
8526
10727
|
}
|
|
8527
10728
|
const tog = e.target.closest('[data-kb-toggle]');
|
|
8528
10729
|
if (tog) {
|
|
8529
|
-
const row = tog.closest('.kb-src');
|
|
10730
|
+
const row = tog.dataset.kbToggleId ? null : tog.closest('.kb-src');
|
|
8530
10731
|
const next = tog.getAttribute('aria-checked') !== 'true';
|
|
8531
10732
|
tog.setAttribute('aria-checked', String(next)); // optimistic — reconciled by the re-render
|
|
8532
|
-
row.classList.toggle('off', !next);
|
|
10733
|
+
if (row) row.classList.toggle('off', !next);
|
|
8533
10734
|
// The DOM now disagrees with the model. If the PATCH fails, the re-rendered HTML would EQUAL the
|
|
8534
10735
|
// cache and the repaint would be skipped, stranding the wrong optimistic state on screen.
|
|
8535
10736
|
kbInvalidateRefs();
|
|
8536
|
-
kbToggle(row.dataset.sourceId, next);
|
|
10737
|
+
kbToggle(tog.dataset.kbToggleId || row.dataset.sourceId, next);
|
|
10738
|
+
return;
|
|
10739
|
+
}
|
|
10740
|
+
// #2491 R6.3: the text viewer's choices.
|
|
10741
|
+
const replace = e.target.closest('[data-kb-text-replace]');
|
|
10742
|
+
if (replace) {
|
|
10743
|
+
const row = knowledgeState && knowledgeState.sources.find((s) => s.sourceId === replace.dataset.kbTextReplace);
|
|
10744
|
+
const input = document.getElementById('ws-knowledge-replace');
|
|
10745
|
+
if (row && input) { kbReplaceTarget = { sourceId: row.sourceId, filename: row.filename || 'untitled' }; input.value = ''; input.click(); }
|
|
10746
|
+
return;
|
|
10747
|
+
}
|
|
10748
|
+
const paste = e.target.closest('[data-kb-text-paste]');
|
|
10749
|
+
if (paste) { kbOpenPasteNote(paste.dataset.kbTextPaste); return; }
|
|
10750
|
+
const pasteGo = e.target.closest('[data-kb-paste-go]');
|
|
10751
|
+
if (pasteGo) { kbPasteNote(pasteGo.dataset.kbPasteGo); return; }
|
|
10752
|
+
if (e.target.closest('[data-kb-paste-cancel]')) {
|
|
10753
|
+
const host = kbViewHost() && kbViewHost().querySelector('.kb-paste-host');
|
|
10754
|
+
if (host) host.innerHTML = '';
|
|
10755
|
+
const back = kbViewHost() && kbViewHost().querySelector('[data-kb-text-paste]');
|
|
10756
|
+
if (back) back.focus({ preventScroll: true });
|
|
8537
10757
|
return;
|
|
8538
10758
|
}
|
|
8539
10759
|
// Preview a source: the filename button. Re-clicking the open one is a no-op, not a reload.
|
|
@@ -8547,6 +10767,8 @@
|
|
|
8547
10767
|
return;
|
|
8548
10768
|
}
|
|
8549
10769
|
if (e.target.closest('[data-kb-fit]')) { const svg = kbGraphSvgEl(); if (svg) kbFitGraph(svg); return; }
|
|
10770
|
+
// The notes line (Stop, Load the rest) also shows above the first layout's spinner, outside .kb-graph.
|
|
10771
|
+
if (e.target.closest('.kb-graph, .kb-gnotes') && kbGraphClick(e)) return;
|
|
8550
10772
|
// Open a graph node's page.
|
|
8551
10773
|
const nodeEl = e.target.closest('[data-kb-node]');
|
|
8552
10774
|
if (nodeEl) { setViewer({ mode: 'page', slug: nodeEl.getAttribute('data-kb-node') }); if (knowledgeState) paintKnowledge(knowledgeState); return; }
|
|
@@ -8637,6 +10859,7 @@
|
|
|
8637
10859
|
// Graph nodes are keyboard-focusable (tabindex="0" role="button") but SVG <g> elements have no
|
|
8638
10860
|
// native activation behaviour, so Enter/Space must be wired explicitly.
|
|
8639
10861
|
$wsKnowledge.addEventListener('keydown', (e) => {
|
|
10862
|
+
if (kbCatKeydown(e)) return;
|
|
8640
10863
|
// Home zooms the graph back to fit — but not while typing in the Adjust box (Home = line start there).
|
|
8641
10864
|
if (e.key === 'Home' && !e.target.closest('input, textarea') && !e.target.isContentEditable) {
|
|
8642
10865
|
const svg = kbGraphSvgEl();
|
|
@@ -8649,12 +10872,31 @@
|
|
|
8649
10872
|
if (btn && btn.getAttribute('aria-disabled') !== 'true') kbAdjustSubmit();
|
|
8650
10873
|
return;
|
|
8651
10874
|
}
|
|
10875
|
+
const gnode = e.target.closest && e.target.closest('.kb-g-node[data-kb-gid]');
|
|
10876
|
+
if (gnode && kbGm && kbGm.view && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
|
10877
|
+
e.preventDefault();
|
|
10878
|
+
const to = kbgNearest(kbGm.pos, gnode.dataset.kbGid, e.key, kbGm.view.nodes.map((x) => x.id));
|
|
10879
|
+
if (to) $wsKnowledge.querySelector(`.kb-g-node[data-kb-gid="${CSS.escape(to)}"]`)?.focus();
|
|
10880
|
+
return;
|
|
10881
|
+
}
|
|
10882
|
+
if (gnode && gnode.hasAttribute('data-kb-doc') && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); gnode.dispatchEvent(new MouseEvent('click', { bubbles: true })); return; }
|
|
8652
10883
|
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
8653
10884
|
const n = e.target.closest('[data-kb-node]');
|
|
8654
10885
|
if (n) { e.preventDefault(); setViewer({ mode: 'page', slug: n.getAttribute('data-kb-node') }); if (knowledgeState) paintKnowledge(knowledgeState); }
|
|
8655
10886
|
});
|
|
8656
10887
|
// Live-enable the Adjust submit as the user types (the draft is DOM-owned; see kbSyncAdjustSubmit).
|
|
8657
10888
|
$wsKnowledge.addEventListener('input', (e) => { if (e.target && e.target.id === 'kb-adjust-input') kbSyncAdjustSubmit(); });
|
|
10889
|
+
// #2491 R6.9: the map's search highlights matches (it hides nothing); hover and focus light a node's neighbours.
|
|
10890
|
+
$wsKnowledge.addEventListener('input', (e) => { if (e.target && e.target.classList && e.target.classList.contains('kb-gsearch')) { kbGo.search = e.target.value; kbGraphRender(true); } });
|
|
10891
|
+
$wsKnowledge.addEventListener('mouseover', (e) => { const n = e.target.closest && e.target.closest('.kb-g-node[data-kb-gid]'); if (n) kbGraphHighlight(n.dataset.kbGid); });
|
|
10892
|
+
$wsKnowledge.addEventListener('mouseout', (e) => { if (e.target.closest && e.target.closest('.kb-g-node') && !(e.relatedTarget && e.relatedTarget.closest && e.relatedTarget.closest('.kb-g-node'))) kbGraphHighlight(null); });
|
|
10893
|
+
$wsKnowledge.addEventListener('focusin', (e) => { const n = e.target.closest && e.target.closest('.kb-g-node[data-kb-gid]'); if (n) kbGraphHighlight(n.dataset.kbGid); });
|
|
10894
|
+
// #2491 R6.3: Replace file… picks exactly one file.
|
|
10895
|
+
const $wsKnowledgeReplace = document.getElementById('ws-knowledge-replace');
|
|
10896
|
+
if ($wsKnowledgeReplace) $wsKnowledgeReplace.addEventListener('change', () => {
|
|
10897
|
+
const file = $wsKnowledgeReplace.files && $wsKnowledgeReplace.files[0];
|
|
10898
|
+
if (file) kbReplaceWith(file); else kbReplaceTarget = null;
|
|
10899
|
+
});
|
|
8658
10900
|
$wsKnowledgeFile.addEventListener('change', () => {
|
|
8659
10901
|
kbUpload($wsKnowledgeFile.files);
|
|
8660
10902
|
$wsKnowledgeFile.value = ''; // let the same file be picked twice in a row
|
|
@@ -8666,18 +10908,81 @@
|
|
|
8666
10908
|
const cur = $wsKnowledge.querySelector('.kb-drop.drag-over');
|
|
8667
10909
|
if (cur) { cur.classList.remove('drag-over'); kbInvalidateRefs(); }
|
|
8668
10910
|
};
|
|
8669
|
-
|
|
10911
|
+
// #2491 R6.9: dragging references (the selection, or one row) onto a category.
|
|
10912
|
+
$wsKnowledge.addEventListener('dragstart', (e) => {
|
|
10913
|
+
const row = e.target.closest && e.target.closest('.kb-src[data-source-id]');
|
|
10914
|
+
if (!row || !e.dataTransfer || !kbCats(knowledgeState).categories.length || !kbCatUsable(knowledgeState)) { if (row && e.dataTransfer) e.preventDefault(); return; }
|
|
10915
|
+
const id = row.dataset.sourceId;
|
|
10916
|
+
const sel = kbSelFor(current, knowledgeState).selected;
|
|
10917
|
+
kbDragIds = sel.has(id) ? kbVisibleRows().filter((x) => sel.has(x)) : [id];
|
|
10918
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
10919
|
+
e.dataTransfer.setData(KB_REFS_MIME, JSON.stringify(kbDragIds));
|
|
10920
|
+
const name = row.querySelector('.kb-fname')?.childNodes[0]?.textContent || 'reference';
|
|
10921
|
+
try { e.dataTransfer.setDragImage(kbDragChip(kbDragIds.length, name), 12, 12); } catch { /* the browser's own image */ }
|
|
10922
|
+
// No cache invalidation here: a repaint during the drag would destroy this row and the browser would cancel the drop.
|
|
10923
|
+
// The paint guard holds repaints while a drag is in flight; the end of the drag catches the column up.
|
|
10924
|
+
row.classList.add('dragging');
|
|
10925
|
+
});
|
|
10926
|
+
$wsKnowledge.addEventListener('dragend', () => {
|
|
10927
|
+
kbDragIds = null;
|
|
10928
|
+
kbClearDropHover();
|
|
10929
|
+
$wsKnowledge.querySelectorAll('.kb-src.dragging').forEach((el) => el.classList.remove('dragging'));
|
|
10930
|
+
kbInvalidateRefs();
|
|
10931
|
+
if (knowledgeState) paintKnowledge(knowledgeState);
|
|
10932
|
+
});
|
|
10933
|
+
// dragenter and dragover both answer: a drop target must accept the drag on entering it, not only while over it.
|
|
10934
|
+
const kbOnDragOver = (e) => {
|
|
8670
10935
|
e.preventDefault();
|
|
10936
|
+
const cat = kbDropTargetOf(e);
|
|
10937
|
+
const types = e.dataTransfer ? [...e.dataTransfer.types] : [];
|
|
10938
|
+
const refs = types.includes(KB_REFS_MIME) && kbDragIds;
|
|
10939
|
+
const files = types.includes('Files');
|
|
10940
|
+
if (cat && (refs || files)) {
|
|
10941
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = refs ? 'move' : 'copy';
|
|
10942
|
+
if (!kbDragHover || kbDragHover.el !== cat) {
|
|
10943
|
+
kbClearDropHover();
|
|
10944
|
+
cat.classList.add('drop-target');
|
|
10945
|
+
const id = cat.dataset.kbDropCat;
|
|
10946
|
+
const label = id === 'uncategorized' ? 'Uncategorized' : kbcLabel(kbCats(knowledgeState), id);
|
|
10947
|
+
const n = refs ? kbDragIds.length : (e.dataTransfer.items ? e.dataTransfer.items.length : 0);
|
|
10948
|
+
cat.setAttribute('data-drop-label', refs ? `Move ${n === 1 ? 'here' : `${n} here`}` : `Add ${n || ''} file${n === 1 ? '' : 's'} to ${label}`.replace(' ', ' '));
|
|
10949
|
+
// A folded category opens when held over it.
|
|
10950
|
+
const timer = setTimeout(() => {
|
|
10951
|
+
// Opening the folded category is the one repaint allowed mid-drag: it changes only that category's children,
|
|
10952
|
+
// never the dragged row.
|
|
10953
|
+
if (id !== 'uncategorized' && kbCatCollapsedFor(current).has(id)) { kbCatCollapsed.delete(id); kbCatSaveCollapsed(); kbCatExpandInPlace(id); }
|
|
10954
|
+
}, 600);
|
|
10955
|
+
kbDragHover = { el: cat, timer };
|
|
10956
|
+
}
|
|
10957
|
+
return;
|
|
10958
|
+
}
|
|
10959
|
+
if (kbDragHover && !cat) kbClearDropHover();
|
|
10960
|
+
if (refs && e.dataTransfer) e.dataTransfer.dropEffect = 'none';
|
|
8671
10961
|
const dz = e.target.closest('#kb-drop');
|
|
8672
10962
|
const cur = $wsKnowledge.querySelector('.kb-drop.drag-over');
|
|
8673
10963
|
if (cur && cur !== dz) cur.classList.remove('drag-over');
|
|
8674
10964
|
if (dz && !dz.classList.contains('drag-over')) { dz.classList.add('drag-over'); kbInvalidateRefs(); }
|
|
8675
|
-
}
|
|
10965
|
+
};
|
|
10966
|
+
$wsKnowledge.addEventListener('dragenter', kbOnDragOver);
|
|
10967
|
+
$wsKnowledge.addEventListener('dragover', kbOnDragOver);
|
|
8676
10968
|
$wsKnowledge.addEventListener('dragleave', (e) => { if (!$wsKnowledge.contains(e.relatedTarget)) kbClearDrag(); });
|
|
8677
10969
|
$wsKnowledge.addEventListener('drop', (e) => {
|
|
8678
10970
|
e.preventDefault();
|
|
8679
10971
|
kbClearDrag();
|
|
8680
|
-
|
|
10972
|
+
const cat = kbDropTargetOf(e);
|
|
10973
|
+
kbClearDropHover();
|
|
10974
|
+
const to = cat ? (cat.dataset.kbDropCat === 'uncategorized' ? null : cat.dataset.kbDropCat) : undefined;
|
|
10975
|
+
const raw = e.dataTransfer ? e.dataTransfer.getData(KB_REFS_MIME) : '';
|
|
10976
|
+
kbInvalidateRefs();
|
|
10977
|
+
if (raw) {
|
|
10978
|
+
kbDragIds = null;
|
|
10979
|
+
if (to === undefined) return; // dropped beside a category: nothing moves
|
|
10980
|
+
let ids = [];
|
|
10981
|
+
try { ids = JSON.parse(raw); } catch { ids = []; }
|
|
10982
|
+
if (Array.isArray(ids) && ids.length) kbPlace(ids.filter((x) => typeof x === 'string'), to);
|
|
10983
|
+
return;
|
|
10984
|
+
}
|
|
10985
|
+
if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length) kbUpload(e.dataTransfer.files, to === undefined ? undefined : to);
|
|
8681
10986
|
});
|
|
8682
10987
|
|
|
8683
10988
|
// ── Exports step ──────────────────────────────────────────────────────────────
|
|
@@ -10294,7 +12599,9 @@
|
|
|
10294
12599
|
function exportSourceOptions(data) {
|
|
10295
12600
|
if (!data) return [];
|
|
10296
12601
|
const out = [];
|
|
10297
|
-
|
|
12602
|
+
// #2449: each approved source carries its own frozen connection-assumptions label from the server, bound to it.
|
|
12603
|
+
const frozen = (row) => (row && row.connectionAssumptions && typeof row.connectionAssumptions.note === 'string' ? row.connectionAssumptions : null);
|
|
12604
|
+
if (data.default) out.push({ selector: { kind: 'latest-approved' }, label: `Latest approved · v${data.default.version}`, group: 'Recommended', version: data.default.version, assumptions: frozen(data.default) });
|
|
10298
12605
|
if (data.working) out.push({
|
|
10299
12606
|
selector: {
|
|
10300
12607
|
kind: 'working', expectedEtag: data.working.etag,
|
|
@@ -10304,7 +12611,7 @@
|
|
|
10304
12611
|
});
|
|
10305
12612
|
for (const saved of data.checkpoints || []) out.push({ selector: { kind: 'checkpoint', checkpointId: saved.checkpointId, expectedHash: saved.hash }, label: `Checkpoint ${String(saved.checkpointId).slice(0, 8)} · DRAFT`, group: 'Drafts', sub: saved.baseVersion ? `Pending work from v${saved.baseVersion}` : 'No approved baseline' });
|
|
10306
12613
|
for (const row of data.defaultUnavailable?.reason === 'refused' ? [] : (data.approved || [])) {
|
|
10307
|
-
if (!data.default || Number(row.version) !== Number(data.default.version)) out.push({ selector: { kind: 'approved', version: row.version }, label: `Older approved · v${row.version}`, group: 'Approved history' });
|
|
12614
|
+
if (!data.default || Number(row.version) !== Number(data.default.version)) out.push({ selector: { kind: 'approved', version: row.version }, label: `Older approved · v${row.version}`, group: 'Approved history', version: row.version, assumptions: frozen(row) });
|
|
10308
12615
|
}
|
|
10309
12616
|
return out;
|
|
10310
12617
|
}
|
|
@@ -10354,6 +12661,57 @@
|
|
|
10354
12661
|
return `<div class="export-source"><label id="export-source-label">Export source</label><div class="export-source-combo"><button type="button" class="wf-trigger export-source-trigger" aria-haspopup="listbox" aria-expanded="${String(exportSourcesState.open)}" aria-labelledby="export-source-label export-source-value"><span id="export-source-value">${escapeHtml(selected ? selected.label : 'Choose export source')}</span><span class="wf-caret" aria-hidden="true">▾</span></button><div class="wf-popover export-source-popover" role="listbox" aria-label="Export source"${exportSourcesState.open ? '' : ' hidden'}>${grouped}</div></div>${raw}${warning}</div>`;
|
|
10355
12662
|
}
|
|
10356
12663
|
|
|
12664
|
+
/**
|
|
12665
|
+
* #2449: the connection assumptions the SELECTED export source rests on, from that source's own frozen approval record,
|
|
12666
|
+
* said once above the cards. Only the bill of materials report carries the note inside its file; the other formats do
|
|
12667
|
+
* not, and the sentence says so, so a shared file is not taken as resting on nothing. A draft or checkpoint is not an
|
|
12668
|
+
* approved version: it says so instead of borrowing its base version's list.
|
|
12669
|
+
*/
|
|
12670
|
+
function exportsAssumptionsHtml() {
|
|
12671
|
+
const source = currentExportSourceOption();
|
|
12672
|
+
if (!source) return '';
|
|
12673
|
+
return selectedSourceAssumptionsHtml(source) + exportedFilesAssumptionsHtml(source);
|
|
12674
|
+
}
|
|
12675
|
+
|
|
12676
|
+
/**
|
|
12677
|
+
* The files already listed on the cards were exported from the LATEST approved version (the listing only returns
|
|
12678
|
+
* receipts for it). While another source is selected the note above describes that source, so the written files
|
|
12679
|
+
* keep their own line here: a CSV, Excel, IFC or SVG file carries no note inside it (PR #2507 review).
|
|
12680
|
+
*/
|
|
12681
|
+
function exportedFilesAssumptionsHtml(source) {
|
|
12682
|
+
const latest = exportSourceOptions(exportSourcesState.data).find((o) => o.selector.kind === 'latest-approved');
|
|
12683
|
+
const a = latest && latest.assumptions;
|
|
12684
|
+
if (!a || !exportState || !Object.values(exportState).some((e) => e && e.exportedAt)) return '';
|
|
12685
|
+
// Only when the listing that returned these files names the SAME approved version and contract as the source
|
|
12686
|
+
// listing: the two are separate requests, and an approval in another tab between them must not relabel v4's files
|
|
12687
|
+
// with v5's assumptions. A mismatch says nothing until the next refresh brings them back in step.
|
|
12688
|
+
const from = exportStateFrom;
|
|
12689
|
+
const latestHash = exportSourcesState.data && exportSourcesState.data.default && exportSourcesState.data.default.hash;
|
|
12690
|
+
if (!from || Number(from.version) !== Number(latest.version) || from.hash !== latestHash) return '';
|
|
12691
|
+
const sel = source.selector;
|
|
12692
|
+
if (sel.kind === 'latest-approved' || (sel.kind === 'approved' && Number(sel.version) === Number(latest.version))) return '';
|
|
12693
|
+
return `<div class="hist-change-caution hist-assumptions ws-exports-files-assumptions" role="note"><strong>The files already exported below come from approved version v${escapeHtml(String(latest.version))}: ${escapeHtml(a.note)}</strong>` +
|
|
12694
|
+
`<div class="hist-assumption-about">Choose Latest approved · v${escapeHtml(String(latest.version))} as the source to see the statements.</div></div>`;
|
|
12695
|
+
}
|
|
12696
|
+
|
|
12697
|
+
function selectedSourceAssumptionsHtml(source) {
|
|
12698
|
+
const kind = source.selector && source.selector.kind;
|
|
12699
|
+
if (kind === 'working' || kind === 'checkpoint') {
|
|
12700
|
+
// Said for every steel draft (only steel records connection assumptions), never only when some approved
|
|
12701
|
+
// version happens to rest on one: a draft made before the first approval needs it just as much.
|
|
12702
|
+
const steel = !!(current && (current.templateId || current.app) === 'steel-model');
|
|
12703
|
+
return steel ? '<div class="hist-change-caution hist-assumptions ws-exports-assumptions" role="note"><strong>A draft is not an approved version, so FloLess has no record of the connection assumptions it rests on.</strong>' +
|
|
12704
|
+
'<div class="hist-assumption-about">The AI Chat readiness review lists the ones on the current model.</div></div>' : '';
|
|
12705
|
+
}
|
|
12706
|
+
const a = source.assumptions;
|
|
12707
|
+
if (!a) return '';
|
|
12708
|
+
const entries = a.state === 'recorded' && Array.isArray(a.entries) ? a.entries : [];
|
|
12709
|
+
const items = entries.slice(0, 5).map((e) => `<li>“${escapeHtml(String(e.statement || ''))}” <span class="hist-assumption-about">About ${escapeHtml(String(e.readingText || ''))} (${escapeHtml(String(e.jointId || ''))})</span></li>`).join('');
|
|
12710
|
+
const more = entries.length > 5 ? `<li>${escapeHtml(String(entries.length - 5))} more are listed on version v${escapeHtml(String(source.version))} in History.</li>` : '';
|
|
12711
|
+
return `<div class="hist-change-caution hist-assumptions ws-exports-assumptions" role="note"><strong>Approved version v${escapeHtml(String(source.version))}: ${escapeHtml(a.note)}</strong>` +
|
|
12712
|
+
`${items || more ? `<ul>${items}${more}</ul>` : ''}<div class="hist-assumption-about">The bill of materials report (HTML) says this inside the file. The CSV, Excel, IFC and SVG files do not, so mention it when you share them.</div></div>`;
|
|
12713
|
+
}
|
|
12714
|
+
|
|
10357
12715
|
function paintExports(approvedAt, requestedRestoreKind) {
|
|
10358
12716
|
const hasModel = exportsHasModel;
|
|
10359
12717
|
// An explicit kind says "put them back on the button they pressed" — but only if they are still
|
|
@@ -10410,6 +12768,7 @@
|
|
|
10410
12768
|
// caption. The note's job — per the comment above — is to justify the exports-FOLDER button
|
|
10411
12769
|
// staying enabled, not to claim the export actions work unapproved. "Polishing is optional" was
|
|
10412
12770
|
// the true and useful half, and it survives; only the opening clause overreached.
|
|
12771
|
+
html += exportsAssumptionsHtml();
|
|
10413
12772
|
html += `<div class="exports-note"><b>Any saved source can be exported</b> — approved is the safe default, while DRAFT and older versions stay explicit. Polishing further ` +
|
|
10414
12773
|
`is optional. Each writes to this project’s <button type="button" class="exports-note-link" data-open-exports-folder ` +
|
|
10415
12774
|
`aria-label="Open the exports folder" data-tip="Open this project’s exports folder">▤ exports</button> folder.</div>`;
|
|
@@ -10657,6 +13016,7 @@
|
|
|
10657
13016
|
if (exportsHasModel !== paintedWith) paintExports(current.approvedAt, restoreKind);
|
|
10658
13017
|
let state = null;
|
|
10659
13018
|
let units = null; // the server's answer, applied below the staleness guard with the others
|
|
13019
|
+
let filesFrom = null; // #2449: the approved version the listed files came from, same rule
|
|
10660
13020
|
// SAYS THE THING THE GUARD MEANS. `if (units)` was correct only because the ternary above can
|
|
10661
13021
|
// never produce a falsy value — so a later, entirely reasonable "report what the server actually
|
|
10662
13022
|
// said, stop coercing" change to `units = r.units` would silently re-enable the resurrected-
|
|
@@ -10744,6 +13104,7 @@
|
|
|
10744
13104
|
// there for why.
|
|
10745
13105
|
answered = true;
|
|
10746
13106
|
approvedAt = r.approvedAt || undefined;
|
|
13107
|
+
filesFrom = r.receiptsFrom && Number.isInteger(r.receiptsFrom.version) && typeof r.receiptsFrom.hash === 'string' ? r.receiptsFrom : null;
|
|
10747
13108
|
units = r.units === 'mm' ? 'mm' : 'ft-in';
|
|
10748
13109
|
} else {
|
|
10749
13110
|
// Surface the load failure — don't let it read as "nothing exported yet" (a lie).
|
|
@@ -10772,6 +13133,7 @@
|
|
|
10772
13133
|
// on failure; moving this line below the guard dropped its `if` by accident. (Review round 3.)
|
|
10773
13134
|
if (answered) current.approvedAt = approvedAt;
|
|
10774
13135
|
exportState = state;
|
|
13136
|
+
exportStateFrom = answered ? filesFrom : null;
|
|
10775
13137
|
syncWorkspaceGuide(); // fresh approve/export state → tick the Export (and re-sync Approve) guide rows
|
|
10776
13138
|
paintExports(approvedAt, restoreKind);
|
|
10777
13139
|
}
|
|
@@ -11446,6 +13808,7 @@
|
|
|
11446
13808
|
async function attachRevision(files) {
|
|
11447
13809
|
const proj = current; // capture — the user may switch projects during the async file reads / POST
|
|
11448
13810
|
if (!proj || !files.length) return;
|
|
13811
|
+
if (!validateSteelDrawingFiles(wsDescOf(proj) === WORKSPACE_APPS['steel-model'] ? 'steel-model' : '', files)) return;
|
|
11449
13812
|
const projectGeneration = revisionOwnerGen;
|
|
11450
13813
|
const attachGeneration = ++revisionAttachGen;
|
|
11451
13814
|
const ownsAttach = () => current === proj
|
|
@@ -11461,7 +13824,7 @@
|
|
|
11461
13824
|
res = await api(`/api/projects/${encodeURIComponent(proj.id)}/revision-requests`, {
|
|
11462
13825
|
method: 'POST', body: JSON.stringify({ appId: proj.app, snapshots }),
|
|
11463
13826
|
});
|
|
11464
|
-
} catch (err) { if (ownsAttach()) showToast('We couldn’t attach that file because FloLess could not save it. Try again.', 'warn'); return; }
|
|
13827
|
+
} catch (err) { if (ownsAttach()) showToast(err?.body?.code === 'steel-pdf-required' ? err.body.error : 'We couldn’t attach that file because FloLess could not save it. Try again.', 'warn'); return; }
|
|
11465
13828
|
const req = res && res.request;
|
|
11466
13829
|
if (!ownsAttach()) {
|
|
11467
13830
|
if (bridge.loadRequests) bridge.loadRequests().catch(() => {});
|
|
@@ -11478,6 +13841,23 @@
|
|
|
11478
13841
|
revBaseVersion = (req && typeof req.baseVersion === 'number') ? req.baseVersion : 0;
|
|
11479
13842
|
revBaseProject = proj.id; // the baseline belongs to THIS project — see resetRevisionState
|
|
11480
13843
|
showToast(`${revBaseVersion <= 0 ? 'Initial' : 'Revised'} set queued — ${files.length} file${files.length > 1 ? 's' : ''} for your terminal AI`, 'ok');
|
|
13844
|
+
// #2399 slice 0c: the drawings also land in the project's design set as an issue. Said either way, never silent.
|
|
13845
|
+
const landed = res && res.designSet;
|
|
13846
|
+
if (landed && landed.landed && landed.created) {
|
|
13847
|
+
const left = Array.isArray(landed.omitted) ? landed.omitted.length : 0;
|
|
13848
|
+
showToast(`Added to the design set as “${landed.label || 'a new issue'}”${left ? `, without ${left} file${left === 1 ? '' : 's'} Knowledge could not store` : ''}`, left ? 'warn' : 'ok', { action: { label: 'View', commandId: 'shell.kb-design-set-view',
|
|
13849
|
+
onClick: () => { if (current === proj) setStep('knowledge'); } } });
|
|
13850
|
+
} else if (landed && !landed.landed) {
|
|
13851
|
+
showToast('These drawings are not in the design set yet. The read goes ahead.', 'warn', { action: { label: 'Add them', commandId: 'shell.kb-design-set-land',
|
|
13852
|
+
onClick: async () => {
|
|
13853
|
+
try {
|
|
13854
|
+
const out = await api(`/api/projects/${encodeURIComponent(proj.id)}/design-set/issues/from-read`, { method: 'POST', body: JSON.stringify({ requestId: req.id }) });
|
|
13855
|
+
const skipped = Array.isArray(out && out.omitted) ? out.omitted.length : 0;
|
|
13856
|
+
showToast(`Added to the design set${out && out.label ? ` as “${out.label}”` : ''}${skipped ? `, without ${skipped} file${skipped === 1 ? '' : 's'} it could not store` : ''}`, skipped ? 'warn' : 'ok');
|
|
13857
|
+
if (current === proj) { kbInvalidateRefs(); renderKnowledge(); }
|
|
13858
|
+
} catch (err) { showToast((err && err.body && err.body.error) || 'Couldn’t add them to the design set. Add them from Knowledge.', 'warn'); }
|
|
13859
|
+
} } });
|
|
13860
|
+
}
|
|
11481
13861
|
lastRevState = 'pending';
|
|
11482
13862
|
startRevisionPoll();
|
|
11483
13863
|
renderRevisionCard();
|
|
@@ -11487,7 +13867,7 @@
|
|
|
11487
13867
|
}
|
|
11488
13868
|
|
|
11489
13869
|
document.getElementById('ws-attach-revision').addEventListener('click', async () => {
|
|
11490
|
-
const files = await pickDrawingFiles($revisionFile);
|
|
13870
|
+
const files = await pickDrawingFiles($revisionFile, wsDescOf(current) === WORKSPACE_APPS['steel-model'] ? 'steel-model' : '');
|
|
11491
13871
|
if (files.length) attachRevision(files);
|
|
11492
13872
|
});
|
|
11493
13873
|
|
|
@@ -11771,7 +14151,7 @@
|
|
|
11771
14151
|
// Bounded (#1604): the poll skips its ticks while this is out, so a read that never answered
|
|
11772
14152
|
// would stop the card for good. 90 s, like the Requests window: the route's own lock waits
|
|
11773
14153
|
// give up after 60 s.
|
|
11774
|
-
const b = await api('/api/requests', {
|
|
14154
|
+
const b = await api('/api/requests', { timeoutMs: 90_000 });
|
|
11775
14155
|
reqs = Array.isArray(b) ? b : (b.requests || []);
|
|
11776
14156
|
// Every owned success is fresh evidence of server contact, even if a later-started poll is in
|
|
11777
14157
|
// flight or has failed. The route can legitimately outlast the 3-second polling interval.
|
|
@@ -12213,7 +14593,10 @@
|
|
|
12213
14593
|
const isAnsweredZ = (z) => !!z && typeof z === 'object' && !!z.answered && typeof z.answered === 'object' && typeof z.known === 'number';
|
|
12214
14594
|
const endpointHeightText = (z) => {
|
|
12215
14595
|
if (!z || typeof z.known !== 'number') return 'no height';
|
|
12216
|
-
|
|
14596
|
+
// #2521: a height the AI chose in a Quick model build is said as such, never shown as a plain drawn height.
|
|
14597
|
+
const tail = z.assumed === true ? ' (placed, not from the drawings)'
|
|
14598
|
+
: z.decided && typeof z.decided === 'object' ? ' (chosen by the AI in the Quick model, not from the drawings)' : '';
|
|
14599
|
+
return `${reviewElevation(z.known)}${tail}`;
|
|
12217
14600
|
};
|
|
12218
14601
|
const endWordOf = (key) => (key === 'from' ? 'Start' : 'End');
|
|
12219
14602
|
function plainLine(key, before, after) {
|
|
@@ -12944,7 +15327,7 @@
|
|
|
12944
15327
|
if (!props.length && !binds.length) {
|
|
12945
15328
|
// No disabled control standing in for an empty state — the group simply is not rendered.
|
|
12946
15329
|
body.appendChild(revEl('div', 'hd-empty', issues.length
|
|
12947
|
-
? '
|
|
15330
|
+
? 'This read found changes needing attention. The affected values were kept; review the details below.'
|
|
12948
15331
|
: leftOut.length
|
|
12949
15332
|
? 'Nothing needs your decision. What this read found is listed below with what was left out and why.'
|
|
12950
15333
|
: 'This read found no changes to make — the revised set matches what is already in the model.'));
|
|
@@ -12982,11 +15365,12 @@
|
|
|
12982
15365
|
const sum = document.createElement('summary');
|
|
12983
15366
|
sum.className = 'ws-archived-summary';
|
|
12984
15367
|
sum.appendChild(revEl('span', 'ws-archived-caret', '›'));
|
|
12985
|
-
sum.appendChild(document.createTextNode('
|
|
15368
|
+
sum.appendChild(document.createTextNode('Changes needing attention '));
|
|
12986
15369
|
sum.appendChild(revEl('span', 'ws-archived-count', String(issues.length)));
|
|
12987
15370
|
det.appendChild(sum);
|
|
15371
|
+
det.appendChild(revEl('div', 'rev-issue', 'The changes listed here were not applied. The existing values for these items were kept. You can continue with those values, ask the terminal AI to correct the read, or ask it to raise an RFI.'));
|
|
12988
15372
|
for (const it of issues) {
|
|
12989
|
-
const row = revEl('div', 'rev-issue', it.message || it.code || '
|
|
15373
|
+
const row = revEl('div', 'rev-issue', it.message || it.code || 'This item needs attention.');
|
|
12990
15374
|
row.appendChild(revEl('span', 'rev-issue-path', it.path || ''));
|
|
12991
15375
|
det.appendChild(row);
|
|
12992
15376
|
}
|
|
@@ -13782,7 +16166,7 @@
|
|
|
13782
16166
|
'data-tip="Show the complete member-by-member comparison">' +
|
|
13783
16167
|
'<span class="hd-caret">▸</span><span class="hd-toggle-label">View detailed changes</span></button>'
|
|
13784
16168
|
: '';
|
|
13785
|
-
const detailWarning = `${acceptedImportFindingsHtml(v)}${readinessHtml(v)}${detailReconciliationWarningHtml(v)}${shellAuthoredNoteHtml(v)}`;
|
|
16169
|
+
const detailWarning = `${acceptedImportFindingsHtml(v)}${connectionAssumptionsHtml(v)}${readinessHtml(v)}${detailReconciliationWarningHtml(v)}${shellAuthoredNoteHtml(v)}${designIssueNoteHtml(v)}`;
|
|
13786
16170
|
if (!s || !Array.isArray(s.bullets)) {
|
|
13787
16171
|
return `<div class="hist-event">${escapeHtml(v.message)}</div>${detailWarning}${toggle}`;
|
|
13788
16172
|
}
|
|
@@ -13797,6 +16181,29 @@
|
|
|
13797
16181
|
`<ul class="hist-change-list">${bullets}</ul>${cautions}${detailWarning}${toggle}`;
|
|
13798
16182
|
}
|
|
13799
16183
|
|
|
16184
|
+
/**
|
|
16185
|
+
* #2399 slice 0c (plan R4, R17): a version a drawing read made says which design-set issue it read and what it left
|
|
16186
|
+
* out — kept on the version, so it holds after the read's request is gone. A read whose drawings are in no issue offers
|
|
16187
|
+
* to add them; the server answers with the existing issue if they are already there.
|
|
16188
|
+
*/
|
|
16189
|
+
function designIssueNoteHtml(v) {
|
|
16190
|
+
if (!v || v.kind !== 'revision-read' || !v.source || !Array.isArray(v.source.files) || !v.source.files.length) return '';
|
|
16191
|
+
const d = v.source.designIssue;
|
|
16192
|
+
const n = escapeAttr(String(v.n));
|
|
16193
|
+
if (!d || typeof d.issueId !== 'string') {
|
|
16194
|
+
return '<div class="hist-ds-line"><button type="button" class="btn-mini" ' +
|
|
16195
|
+
`data-hist-ds-land="${n}" data-command-id="shell.history-design-set-land#v${escapeAttr(String(v.n))}" data-tip="Add the drawings this read was given to the project's design set, as an issue">Add these drawings to the design set</button></div>`;
|
|
16196
|
+
}
|
|
16197
|
+
const omitted = Array.isArray(d.omitted) ? d.omitted.filter((o) => o && typeof o.filename === 'string') : [];
|
|
16198
|
+
const covered = Array.isArray(d.included) ? d.included.length : null;
|
|
16199
|
+
if (!omitted.length) {
|
|
16200
|
+
return `<div class="hist-change-note" role="note">${escapeHtml(`Read from a design-set issue${covered !== null ? `: ${covered} file${covered === 1 ? '' : 's'}` : ''}.`)}</div>`;
|
|
16201
|
+
}
|
|
16202
|
+
const names = omitted.slice(0, 5).map((o) => `“${o.filename}”`).join(', ') + (omitted.length > 5 ? ` and ${omitted.length - 5} more` : '');
|
|
16203
|
+
return '<div class="hist-change-caution" role="note"><strong>Read from part of a design-set issue.</strong> ' +
|
|
16204
|
+
escapeHtml(`${covered !== null ? `${covered} of its files were read; ` : ''}${omitted.length} ${omitted.length === 1 ? 'was' : 'were'} left out: ${names}.`) + '</div>';
|
|
16205
|
+
}
|
|
16206
|
+
|
|
13800
16207
|
/**
|
|
13801
16208
|
* #1840: an approval that accepted open Tekla import findings carries the server's own sentence on
|
|
13802
16209
|
* its History row (one source for every approved surface), in the caution register the readiness
|
|
@@ -13808,6 +16215,20 @@
|
|
|
13808
16215
|
return `<div class="hist-change-caution" role="note"><strong>${escapeHtml(note)}</strong> FloLess could not fully check these when it read the model; the Audit tab lists each one.</div>`;
|
|
13809
16216
|
}
|
|
13810
16217
|
|
|
16218
|
+
/**
|
|
16219
|
+
* #2449: the connection assumptions this approved version rests on, frozen when it was approved. Each one's own words,
|
|
16220
|
+
* what it is about, and who confirmed it; a later record or withdraw never changes what an earlier version says here.
|
|
16221
|
+
*/
|
|
16222
|
+
function connectionAssumptionsHtml(v) {
|
|
16223
|
+
const a = v && v.kind === 'approve' && v.connectionAssumptions && typeof v.connectionAssumptions.note === 'string' ? v.connectionAssumptions : null;
|
|
16224
|
+
if (!a) return '';
|
|
16225
|
+
const entries = a.state === 'recorded' && Array.isArray(a.entries) ? a.entries : [];
|
|
16226
|
+
// Every one, never "N more" pointing elsewhere: nothing else shows this version's frozen list (the readiness review
|
|
16227
|
+
// shows the current model's), and the list is bounded by the store (ten per connection).
|
|
16228
|
+
const items = entries.map((e) => `<li>“${escapeHtml(String(e.statement || ''))}” <span class="hist-assumption-about">About ${escapeHtml(String(e.readingText || ''))} (${escapeHtml(String(e.jointId || ''))})</span></li>`).join('');
|
|
16229
|
+
return `<div class="hist-change-caution hist-assumptions" role="note"><strong>${escapeHtml(a.note)}</strong>${items ? `<ul>${items}</ul>` : ''}</div>`;
|
|
16230
|
+
}
|
|
16231
|
+
|
|
13811
16232
|
function readinessHtml(v) {
|
|
13812
16233
|
const ready = v && v.readiness;
|
|
13813
16234
|
if (!ready || typeof ready.state !== 'string') return '';
|
|
@@ -14695,6 +17116,24 @@
|
|
|
14695
17116
|
}
|
|
14696
17117
|
|
|
14697
17118
|
$wsHistory.addEventListener('click', (e) => {
|
|
17119
|
+
// #2399 slice 0c: add the drawings a read was given to the design set, after the fact (plan R4).
|
|
17120
|
+
const dsLand = e.target.closest('[data-hist-ds-land]');
|
|
17121
|
+
if (dsLand) {
|
|
17122
|
+
const proj = current;
|
|
17123
|
+
if (!proj) return;
|
|
17124
|
+
dsLand.setAttribute('aria-busy', 'true');
|
|
17125
|
+
api(`/api/projects/${encodeURIComponent(proj.id)}/design-set/issues/from-read`, { method: 'POST', body: JSON.stringify({ version: Number(dsLand.dataset.histDsLand) }) })
|
|
17126
|
+
.then((out) => {
|
|
17127
|
+
const skipped = Array.isArray(out && out.omitted) ? out.omitted.length : 0;
|
|
17128
|
+
showToast(out && out.created === false
|
|
17129
|
+
? `These drawings are already in the design set${out.label ? ` as “${out.label}”` : ''}`
|
|
17130
|
+
: `Added to the design set${out && out.label ? ` as “${out.label}”` : ''}${skipped ? `, without ${skipped} file${skipped === 1 ? '' : 's'} it could not store` : ''}`, skipped ? 'warn' : 'ok');
|
|
17131
|
+
if (current === proj) kbInvalidateRefs();
|
|
17132
|
+
})
|
|
17133
|
+
.catch((err) => showToast((err && err.body && typeof err.body.error === 'string' && err.body.error) || 'Couldn’t add these drawings to the design set. Try again.', 'warn'))
|
|
17134
|
+
.finally(() => dsLand.removeAttribute('aria-busy'));
|
|
17135
|
+
return;
|
|
17136
|
+
}
|
|
14698
17137
|
const note = e.target.closest('[data-revision-note]');
|
|
14699
17138
|
if (note) { editRevisionNote(Number(note.dataset.revisionNote)); return; }
|
|
14700
17139
|
const retryNote = e.target.closest('[data-revision-note-retry]');
|
|
@@ -15439,6 +17878,164 @@
|
|
|
15439
17878
|
if (current?.id !== projectId) throw new Error('That project could not be opened. Open it from Workspaces.');
|
|
15440
17879
|
}
|
|
15441
17880
|
|
|
17881
|
+
/**
|
|
17882
|
+
* Show one connection in a project's model editor, selected and framed (#2450 — the readiness card's
|
|
17883
|
+
* "Open in the model"). The editor does the selecting (`flolessEditorFocus`, steel-editor.html); this
|
|
17884
|
+
* only gets the person to the right editor and hands the request over.
|
|
17885
|
+
*
|
|
17886
|
+
* ONE SLOT, the latest request. A new call takes it, and the request it replaces is withdrawn from the
|
|
17887
|
+
* editor it was handed to BY ITS ID, so a withdrawal can never cancel the request that replaced it.
|
|
17888
|
+
* No call ever waits on another call: an earlier call's project change still in progress gives way
|
|
17889
|
+
* (`openProject`'s `stillWanted`) before it changes anything.
|
|
17890
|
+
*
|
|
17891
|
+
* The project already open stays open: `openProject` resets the frames, which would reload the editor
|
|
17892
|
+
* and could cost edits not yet saved, so the same project only switches to its Model step. Another
|
|
17893
|
+
* project goes through `openProject`, and its leave guard. Then it waits for the editor page of THIS
|
|
17894
|
+
* project to exist and hands the request over; the editor holds it until its model is ready.
|
|
17895
|
+
*
|
|
17896
|
+
* Every wait is watched. Getting there ends on a later click; the project open also has a generous
|
|
17897
|
+
* bound and gives way once this call has ended. The mode switch has no bound: it waits only while the
|
|
17898
|
+
* person answers a question, and cannot be called back. Then,
|
|
17899
|
+
* before and after the hand-over: a later call, leaving Workspaces, another project, the Model step
|
|
17900
|
+
* closed and not about to open, a reload of the frame (its document changes; its window does not), or
|
|
17901
|
+
* the editor's deadline. Whenever this stops waiting without the editor's answer, the request is withdrawn from
|
|
17902
|
+
* the editor, so it never selects anything after the person was told it was not shown.
|
|
17903
|
+
*
|
|
17904
|
+
* Resolves the editor's own outcome — `{ok:true}`, `{ok:true,fallback,said}` when it landed on the
|
|
17905
|
+
* main member instead, `{ok:false,said?}` — or `{superseded:true}` when a later call took over. What
|
|
17906
|
+
* cannot be done is thrown as a sentence written for the person (`plain`).
|
|
17907
|
+
*/
|
|
17908
|
+
const CONNECTION_FRAME_WAIT_MS = 60000;
|
|
17909
|
+
// Getting to the project can include the person answering a "leave unsaved changes?" question, so it
|
|
17910
|
+
// is bounded generously; a later click frees it at once either way.
|
|
17911
|
+
const CONNECTION_NAVIGATION_WAIT_MS = 300000;
|
|
17912
|
+
let connectionRequestSeq = 0;
|
|
17913
|
+
/** The latest request: `{ id, page }`, `page` being the editor window it was handed to, once it was. */
|
|
17914
|
+
let connectionRequest = null;
|
|
17915
|
+
// Every sentence this throws is written for the person; `plain` tells the caller it may show it as is.
|
|
17916
|
+
const connectionError = (sentence) => Object.assign(new Error(sentence), { plain: true });
|
|
17917
|
+
/** Withdraw a request from the editor it was handed to, by its id. Harmless when that editor has moved on. */
|
|
17918
|
+
const withdrawConnectionRequest = (request) => {
|
|
17919
|
+
try { request?.page?.flolessEditorFocusCancel?.(request.id); } catch { /* that page is gone */ }
|
|
17920
|
+
};
|
|
17921
|
+
async function openConnection(target) {
|
|
17922
|
+
const validId = (id) => typeof id === 'string' && !!id && id.length <= 200;
|
|
17923
|
+
// #2471: or one member an AI Chat answer cited, with the project identity it was cited in (checked at handover).
|
|
17924
|
+
const member = !!target && !validId(target.jointId) && validId(target.memberId);
|
|
17925
|
+
const thing = member ? 'member' : 'connection';
|
|
17926
|
+
const again = member ? 'Show in the model' : 'Open in the model';
|
|
17927
|
+
if (!target || !validId(target.projectId) || !(validId(target.jointId) || member)) throw connectionError(`That ${thing} could not be opened. Open its project from Workspaces.`);
|
|
17928
|
+
const mine = { id: `connection-${++connectionRequestSeq}`, page: null };
|
|
17929
|
+
withdrawConnectionRequest(connectionRequest);
|
|
17930
|
+
connectionRequest = mine;
|
|
17931
|
+
const superseded = () => connectionRequest !== mine;
|
|
17932
|
+
// Once this call has ended, for any reason, a project change it started gives way before it lands.
|
|
17933
|
+
let ended = false;
|
|
17934
|
+
const stillWanted = () => !ended && !superseded();
|
|
17935
|
+
const stayedOutside = () => connectionError(`You stayed where you were, so the ${thing} was not shown. Open the project from Workspaces, then press ${again} again.`);
|
|
17936
|
+
const leftWorkspaces = () => connectionError(`You left Workspaces, so the ${thing} was not shown. Open the project from Workspaces, then press ${again} again.`);
|
|
17937
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, 100));
|
|
17938
|
+
/**
|
|
17939
|
+
* Wait for a step of getting there, watched: a later click ends it at once. `bounded` adds the deadline,
|
|
17940
|
+
* for a step whose late arrival can be refused (`openProject` gives way through `stillWanted`). The mode
|
|
17941
|
+
* switch is never bounded: it only waits while the person answers a question (an Agent's unsaved
|
|
17942
|
+
* changes), and it cannot be called back, so a deadline there would say "not shown" and then switch.
|
|
17943
|
+
*/
|
|
17944
|
+
const navigating = async (work, bounded) => {
|
|
17945
|
+
const bound = bounded ? Date.now() + CONNECTION_NAVIGATION_WAIT_MS : Infinity;
|
|
17946
|
+
let done = null;
|
|
17947
|
+
const finished = work.then((value) => { done = { value }; }, (error) => { done = { error }; });
|
|
17948
|
+
for (;;) {
|
|
17949
|
+
// Back the moment the step finishes, or on the next check, whichever comes first.
|
|
17950
|
+
await Promise.race([finished, pause()]);
|
|
17951
|
+
if (done) { if (done.error) throw done.error; return done.value; }
|
|
17952
|
+
if (superseded()) return { superseded: true };
|
|
17953
|
+
if (Date.now() >= bound) throw connectionError(`The project did not open in time, so the ${thing} was not shown. Open it from Workspaces, then press ${again} again.`);
|
|
17954
|
+
}
|
|
17955
|
+
};
|
|
17956
|
+
// A project removed and made again under the same id is not the one the answer cited.
|
|
17957
|
+
const citedElsewhere = () => validId(target.projectUuid) && String(current?.uuid || '').toLowerCase() !== target.projectUuid.toLowerCase();
|
|
17958
|
+
const citedGone = () => connectionError(`This project is no longer the one the answer cited, so the ${thing} was not shown.`);
|
|
17959
|
+
let until = Infinity;
|
|
17960
|
+
// Everything that ends this call's wait without the editor's answer.
|
|
17961
|
+
const interrupted = () => {
|
|
17962
|
+
if (superseded()) return { superseded: true };
|
|
17963
|
+
if (mode !== 'workspaces') throw leftWorkspaces();
|
|
17964
|
+
if (current?.id !== target.projectId) throw connectionError(`You moved to another project, so the ${thing} was not shown.`);
|
|
17965
|
+
// The project's stages kept the Model step locked, or the person went to another step: the step's
|
|
17966
|
+
// own message says why, and there is nothing to wait for.
|
|
17967
|
+
if (currentStep !== 'model' && !(pendingPresenceStep && pendingPresenceStep.step === 'model')) {
|
|
17968
|
+
throw connectionError(`The Model step is not open, so the ${thing} was not shown. Open the Model step, then press ${again} again.`);
|
|
17969
|
+
}
|
|
17970
|
+
if (Date.now() >= until) throw connectionError(`The model did not open in time, so the ${thing} was not shown. Open the Model step, then press ${again} again.`);
|
|
17971
|
+
return null;
|
|
17972
|
+
};
|
|
17973
|
+
try {
|
|
17974
|
+
if ((await navigating(Promise.resolve(setMode('workspaces'))))?.superseded || superseded()) return { superseded: true };
|
|
17975
|
+
// setMode leaves the person where they were when they chose to stay (an Agent with unsaved changes).
|
|
17976
|
+
if (mode !== 'workspaces') throw stayedOutside();
|
|
17977
|
+
if (current?.id !== target.projectId) {
|
|
17978
|
+
const opened = await navigating(openProject(target.projectId, 'model', { stillWanted }), true);
|
|
17979
|
+
if (opened?.superseded || superseded()) return { superseded: true };
|
|
17980
|
+
// openProject answers "stayed" for several causes (the person chose to stay, the project's folder is
|
|
17981
|
+
// not available and its dialog is open, another navigation took over): say only what is certain.
|
|
17982
|
+
if (opened === STAYED_IN_PROJECT) throw connectionError(`That project did not open, so the ${thing} was not shown. Open it from Workspaces to see why, then press ${again} again.`);
|
|
17983
|
+
if (current?.id !== target.projectId) throw connectionError('That project could not be opened. Open it from Workspaces.');
|
|
17984
|
+
} else if (currentStep !== 'model') {
|
|
17985
|
+
setStep('model');
|
|
17986
|
+
}
|
|
17987
|
+
if (!frames.model.dataset.want) throw connectionError(`This project has no model editor to show the ${thing} in.`);
|
|
17988
|
+
// The editor's deadline starts once the person is in the project.
|
|
17989
|
+
until = Date.now() + CONNECTION_FRAME_WAIT_MS;
|
|
17990
|
+
let answer = null, settled = null, page = null, doc = null;
|
|
17991
|
+
const notTaken = `The model could not take the request. Press ${again} again.`;
|
|
17992
|
+
for (;;) {
|
|
17993
|
+
// An answer already in is the editor's account of what it did: once it has selected the connection,
|
|
17994
|
+
// leaving the step or the deadline passing does not make that untrue. Only a later click, another
|
|
17995
|
+
// project or a reload (a different page) stand between it and the person.
|
|
17996
|
+
if (settled) {
|
|
17997
|
+
if (superseded()) return { superseded: true };
|
|
17998
|
+
// The Model step may have been left after the selection, but not Workspaces: hidden, it shows nothing.
|
|
17999
|
+
if (mode !== 'workspaces') throw leftWorkspaces();
|
|
18000
|
+
if (current?.id !== target.projectId) throw connectionError(`You moved to another project, so the ${thing} was not shown.`);
|
|
18001
|
+
if (frames.model.contentWindow !== page || page.document !== doc) throw connectionError(`The model reloaded, so the ${thing} was not shown. Press ${again} again.`);
|
|
18002
|
+
const outcome = settled.outcome;
|
|
18003
|
+
return outcome && typeof outcome === 'object' ? { ...outcome } : { ok: false, said: notTaken };
|
|
18004
|
+
}
|
|
18005
|
+
const stop = interrupted();
|
|
18006
|
+
if (stop) return stop;
|
|
18007
|
+
const child = frames.model.contentWindow;
|
|
18008
|
+
if (!answer) {
|
|
18009
|
+
const state = child && child.flolessEditorState;
|
|
18010
|
+
if (state && state.project === target.projectId && typeof child.flolessEditorFocus === 'function') {
|
|
18011
|
+
if (citedElsewhere()) throw citedGone();
|
|
18012
|
+
// The frame's window survives a reload; its DOCUMENT does not. That is what tells a reload apart.
|
|
18013
|
+
page = child; doc = child.document;
|
|
18014
|
+
answer = child.flolessEditorFocus(member ? { memberId: target.memberId, requestId: mine.id } : { jointId: target.jointId, requestId: mine.id,
|
|
18015
|
+
// #2450: the readiness card's "Raise an RFI" also opens the editor's review dialog for it.
|
|
18016
|
+
...(target.raiseRfi === true ? { raiseRfi: true } : {}), ...(validId(target.checkId) ? { checkId: target.checkId } : {}) });
|
|
18017
|
+
if (!answer || typeof answer.then !== 'function') return { ok: false, said: notTaken };
|
|
18018
|
+
mine.page = page;
|
|
18019
|
+
answer.then((outcome) => { settled = { outcome }; }, (error) => {
|
|
18020
|
+
console.error('[workspaces] the model editor could not answer for the connection', error);
|
|
18021
|
+
settled = { outcome: { ok: false, said: notTaken } };
|
|
18022
|
+
});
|
|
18023
|
+
}
|
|
18024
|
+
} else if (child !== page || child.document !== doc) {
|
|
18025
|
+
throw connectionError(`The model reloaded, so the ${thing} was not shown. Press ${again} again.`);
|
|
18026
|
+
}
|
|
18027
|
+
await pause();
|
|
18028
|
+
}
|
|
18029
|
+
} catch (error) {
|
|
18030
|
+
// This call ended without the editor's answer: whatever it handed over is withdrawn.
|
|
18031
|
+
if (!superseded()) withdrawConnectionRequest(mine);
|
|
18032
|
+
throw error;
|
|
18033
|
+
} finally {
|
|
18034
|
+
ended = true;
|
|
18035
|
+
if (connectionRequest === mine) connectionRequest = null;
|
|
18036
|
+
}
|
|
18037
|
+
}
|
|
18038
|
+
|
|
15442
18039
|
// A cross-project object pin still belongs to its original conversation, wherever its model is shown.
|
|
15443
18040
|
async function openChatOwner(owner) {
|
|
15444
18041
|
const validId = (id) => typeof id === 'string' && !!id && id.length <= 200;
|
|
@@ -15499,10 +18096,150 @@
|
|
|
15499
18096
|
flashCard(project.id, { scroll: true });
|
|
15500
18097
|
if (current?.id === project.id) reconcileNow();
|
|
15501
18098
|
}
|
|
18099
|
+
/** The drop zone asks for the one click the browser needs, until it is used or left. Painted imperatively, so the
|
|
18100
|
+
* column's HTML cache is dropped on the way out and the next paint restores the zone's own words. */
|
|
18101
|
+
function kbDropAttention(drop) {
|
|
18102
|
+
drop.classList.add('attention');
|
|
18103
|
+
const dt = drop.querySelector('.dt'); if (dt) dt.textContent = 'Choose files';
|
|
18104
|
+
const ds = drop.querySelector('.ds'); if (ds) ds.textContent = 'Click here to pick the files to add';
|
|
18105
|
+
kbInvalidateRefs();
|
|
18106
|
+
const live = $wsKnowledge.querySelector('#kb-drop-live');
|
|
18107
|
+
if (live) live.textContent = 'Choose files is ready. Press it to pick the files to add.';
|
|
18108
|
+
drop.scrollIntoView({ block: 'nearest' });
|
|
18109
|
+
drop.focus();
|
|
18110
|
+
// Not on blur: the chat card that asked repaints right after and takes focus back. The zone keeps asking until the
|
|
18111
|
+
// person picks, or for a minute; a poll repaint in between restores its own words too (the cache was dropped).
|
|
18112
|
+
let timer = null;
|
|
18113
|
+
const done = () => {
|
|
18114
|
+
clearTimeout(timer); $wsKnowledgeFile.removeEventListener('change', done);
|
|
18115
|
+
if (live) live.textContent = '';
|
|
18116
|
+
if (knowledgeState && drop.isConnected) { kbInvalidateRefs(); paintKnowledge(knowledgeState); }
|
|
18117
|
+
};
|
|
18118
|
+
timer = setTimeout(done, 60_000);
|
|
18119
|
+
$wsKnowledgeFile.addEventListener('change', done);
|
|
18120
|
+
}
|
|
18121
|
+
|
|
18122
|
+
/**
|
|
18123
|
+
* #2399 slice 0b: a confirmed chat card to pick files. This window opens the project's Knowledge step and presses its own
|
|
18124
|
+
* drop zone, so the file dialog and the upload are the window's. The browser opens a file dialog only on a click of the
|
|
18125
|
+
* person's: when the confirm click is too long ago by now, the drop zone is left focused in front of them instead.
|
|
18126
|
+
* Resolves '' when the dialog was opened, or one plain sentence: why not, or what the person does next.
|
|
18127
|
+
*/
|
|
18128
|
+
async function knowledgePickStep(step) {
|
|
18129
|
+
const { projectId, projectUuid } = step || {};
|
|
18130
|
+
if (typeof projectId !== 'string' || !projectId) return 'FloLess could not tell which project this is for. Open it from Workspaces.';
|
|
18131
|
+
await setMode('workspaces');
|
|
18132
|
+
// Already in that project: switch step as a press on its Knowledge tab does. Re-opening a project that is open
|
|
18133
|
+
// left the step tabs showing the step it was on.
|
|
18134
|
+
if (current?.id === projectId) setStep('knowledge');
|
|
18135
|
+
else {
|
|
18136
|
+
const opened = await openProject(projectId, 'knowledge');
|
|
18137
|
+
if (opened === STAYED_IN_PROJECT) return 'You stayed in the project you were in, so the other one was not opened.';
|
|
18138
|
+
}
|
|
18139
|
+
if (current?.id !== projectId) return 'That project could not be opened. Open it from Workspaces.';
|
|
18140
|
+
// The card names the project's incarnation, or "(none)" for an older project that has none. A different one is a
|
|
18141
|
+
// replaced project; with none on either side FloLess cannot tell, so the person picks from the step they can see.
|
|
18142
|
+
const cardUuid = typeof projectUuid === 'string' && projectUuid ? projectUuid : '(none)';
|
|
18143
|
+
const hereUuid = current.uuid || '(none)';
|
|
18144
|
+
if (cardUuid !== hereUuid) return 'This project was replaced since the card was made, so nothing was opened. Ask again for the project as it is now.';
|
|
18145
|
+
const unverified = cardUuid === '(none)';
|
|
18146
|
+
// The step paints its column on its own; wait briefly for the drop zone it draws.
|
|
18147
|
+
let drop = null;
|
|
18148
|
+
for (let i = 0; i < 40 && !(drop = $wsKnowledge.querySelector('#kb-drop')); i += 1) await new Promise((r) => setTimeout(r, 50));
|
|
18149
|
+
if (!drop || current?.id !== projectId) return 'The project’s Knowledge step did not open. Open the project and use Drop references there.';
|
|
18150
|
+
if (unverified || (navigator.userActivation && !navigator.userActivation.isActive)) {
|
|
18151
|
+
kbDropAttention(drop);
|
|
18152
|
+
// #2427: nothing failed — the last click is the person's, so the card waits for them instead of reading red.
|
|
18153
|
+
return { handedOver: 'Choose files is ready in this project’s Knowledge step. Press it to pick the files.', focus: drop };
|
|
18154
|
+
}
|
|
18155
|
+
$wsKnowledgeFile.click();
|
|
18156
|
+
return '';
|
|
18157
|
+
}
|
|
18158
|
+
|
|
18159
|
+
/**
|
|
18160
|
+
* #2363: a confirmed chat card for a model source. This window opens the project and presses the Source step's own
|
|
18161
|
+
* Replace, Try again or Cancel control, so the real call (and the file picker) are the window's, with its editor session.
|
|
18162
|
+
* Resolves '' when it pressed the control, or one plain sentence: why it could not, or what the person does next.
|
|
18163
|
+
*/
|
|
18164
|
+
async function modelSourceStep(step) {
|
|
18165
|
+
const { verb, importer, projectId, operationId } = step || {};
|
|
18166
|
+
if (typeof projectId !== 'string' || !projectId || !['replace', 'retry', 'cancel'].includes(verb)) return 'FloLess could not tell which project this is for. Open it from Workspaces.';
|
|
18167
|
+
await setMode('workspaces');
|
|
18168
|
+
// The Source step is where the controls are; the project's default step is the Model tab, which hides them.
|
|
18169
|
+
const opened = await openProject(projectId, 'drawings');
|
|
18170
|
+
if (opened === STAYED_IN_PROJECT) return 'You stayed in the project you were in, so the other one was not opened.';
|
|
18171
|
+
if (current?.id !== projectId) return 'That project could not be opened. Open it from Workspaces.';
|
|
18172
|
+
if (!isModelSourceProject(current)) return 'This project does not read a Revit or Tekla model, so it has no model source to change.';
|
|
18173
|
+
const tekla = isTeklaParserProject(current);
|
|
18174
|
+
if (tekla !== (importer === 'tekla')) return `This project reads a ${tekla ? 'Tekla' : 'Revit'} model, not a ${importer === 'tekla' ? 'Tekla' : 'Revit'} one, so nothing was done. Ask again for the right project.`;
|
|
18175
|
+
// A state that could not be read says nothing about the project: never press a control on what an earlier project left.
|
|
18176
|
+
const source = await refreshRevitSourceState(projectId);
|
|
18177
|
+
if (current?.id !== projectId) return 'That project could not be opened. Open it from Workspaces.';
|
|
18178
|
+
if (!source) return 'FloLess could not read this project’s model source just now, so it did nothing. Check the project’s Source step.';
|
|
18179
|
+
const running = revitActiveOperation && !['ready', 'failed', 'cancelled'].includes(revitActiveOperation.state);
|
|
18180
|
+
// A Tekla folder or ZIP still being copied has no import yet; its own Cancel read stops the copy.
|
|
18181
|
+
const copying = tekla && !!teklaUploadAbort && teklaUploadProjectId === projectId;
|
|
18182
|
+
if (verb === 'replace') {
|
|
18183
|
+
if (running || copying) return 'An import is still running for this project, so its source cannot be replaced yet. Wait for it, or cancel it first.';
|
|
18184
|
+
if (!source.canReplace || $revitReplace.hidden) return 'This project’s model source cannot be replaced from here right now. Its Source step says why.';
|
|
18185
|
+
// A Revit file is chosen in the browser's own picker, which opens only on a click of the person's.
|
|
18186
|
+
// The confirm click may be too long ago by now; the Replace control is then left in front for them.
|
|
18187
|
+
if (!tekla && navigator.userActivation && !navigator.userActivation.isActive) {
|
|
18188
|
+
$revitReplace.scrollIntoView({ block: 'center' }); $revitReplace.focus();
|
|
18189
|
+
return { handedOver: `${$revitReplace.textContent || 'Replace RVT…'} is ready on this project. Press it to choose the file.`, focus: $revitReplace };
|
|
18190
|
+
}
|
|
18191
|
+
$revitReplace.click();
|
|
18192
|
+
return '';
|
|
18193
|
+
}
|
|
18194
|
+
if (copying && verb === 'cancel') return 'The Tekla source is still being copied, which this card cannot cancel. Press Cancel read on the project’s Source step.';
|
|
18195
|
+
const here = revitActiveOperation?.operationId;
|
|
18196
|
+
if (typeof operationId === 'string' && operationId && here !== operationId) {
|
|
18197
|
+
return verb === 'cancel'
|
|
18198
|
+
? 'That import has already finished or been replaced by a newer one, so nothing was cancelled. The project shows where it stands.'
|
|
18199
|
+
: 'That import is no longer the project’s latest, so nothing was retried. The project shows where it stands.';
|
|
18200
|
+
}
|
|
18201
|
+
// The controls answer by toast and repaint, not by a result: wait for the route's own answer to THIS press, for this project
|
|
18202
|
+
// and this import. Moving to another project, or the import ending some other way, is not a confirmation.
|
|
18203
|
+
const answered = async (verb, id) => {
|
|
18204
|
+
const end = Date.now() + 8000;
|
|
18205
|
+
while (Date.now() < end) {
|
|
18206
|
+
const o = sourceControlOutcome;
|
|
18207
|
+
if (o && o.verb === verb && o.projectId === projectId && o.operationId === id) return o.ok;
|
|
18208
|
+
if (current?.id !== projectId) return null;
|
|
18209
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
18210
|
+
}
|
|
18211
|
+
return null;
|
|
18212
|
+
};
|
|
18213
|
+
if (verb === 'cancel') {
|
|
18214
|
+
if (!running || $revitCancel.hidden) return 'Nothing is running to cancel any more. The project shows where it stands.';
|
|
18215
|
+
sourceControlOutcome = null;
|
|
18216
|
+
$revitCancel.click();
|
|
18217
|
+
const ok = await answered('cancel', here);
|
|
18218
|
+
return ok === true ? '' : ok === false ? 'The import was not cancelled: it may already be finishing. The project shows where it stands.'
|
|
18219
|
+
: 'Cancelling was asked for, but FloLess has not confirmed it yet. The project shows where it stands.';
|
|
18220
|
+
}
|
|
18221
|
+
if (tekla) return 'A Tekla read cannot be retried. Choose the Tekla source again from the project.';
|
|
18222
|
+
if (revitActiveOperation?.state !== 'failed' || $revitRetry.hidden) return 'This import did not fail, or it cannot be retried. The project shows where it stands.';
|
|
18223
|
+
sourceControlOutcome = null;
|
|
18224
|
+
$revitRetry.click();
|
|
18225
|
+
const ok = await answered('retry', here);
|
|
18226
|
+
return ok === true ? '' : ok === false ? 'The import was not started again. The project shows what went wrong.'
|
|
18227
|
+
: 'Trying again was asked for, but FloLess has not confirmed it yet. The project shows where it stands.';
|
|
18228
|
+
}
|
|
18229
|
+
|
|
15502
18230
|
window.flolessWorkspaces = {
|
|
18231
|
+
modelSourceStep,
|
|
18232
|
+
knowledgePickStep,
|
|
18233
|
+
// #2399 slice 0b: the open Knowledge step re-reads its project when something else changed it.
|
|
18234
|
+
knowledgeChanged: (projectId) => {
|
|
18235
|
+
if (current && current.id === projectId && !$wsKnowledge.hidden) renderKnowledge();
|
|
18236
|
+
tellModelFrame({ type: 'knowledge-changed', projectId });
|
|
18237
|
+
},
|
|
15503
18238
|
setMode, refresh: loadProjects, findActive: wsFindActive, find: wsFind, clearFind: wsClearFind,
|
|
15504
|
-
openHistory: wsOpenHistory, openKnowledgePage, openKnowledgeStep, openDrawingsStep, drawingFilterCheckpointSaved,
|
|
18239
|
+
openHistory: wsOpenHistory, openKnowledgePage, openKnowledgeStep, openDrawingsStep, openConnection, drawingFilterCheckpointSaved,
|
|
15505
18240
|
syncWorkspaceReporter, openChatOwner, openPagesHome, folderDecisionCompleted,
|
|
18241
|
+
// Project access (project-access.js loads after this file): the project open now, or null.
|
|
18242
|
+
currentProject: () => ($app.classList.contains('mode-workspaces') && current ? current : null),
|
|
15506
18243
|
};
|
|
15507
18244
|
applyMode(); // restore persisted mode immediately (matches panels.js applyView timing)
|
|
15508
18245
|
})();
|