Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(viewer): preserve Reach selection through Export controls

HengYangb4937aa0e3e7
diff --git a/archify.zip b/archify.zip
index 59b52548..727b22ad 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/assets/template.html b/archify/assets/template.html
index 5e07671c..7e9305c8 100644
--- a/archify/assets/template.html
+++ b/archify/assets/template.html
@@ -9115,7 +9115,9 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var target = event.target;
if (chip.hidden || !target || typeof target.closest !== 'function' || chip.contains(target)) return;
if (container.getAttribute('data-just-panned') === 'true') return;
- if (target.closest('[data-node-id], [data-relationship-hit-key], .overview-map')) return;
+ // Export consumes the active semantic snapshot; its controls are not
+ // an outside selection. Genuine outside activation still clears it.
+ if (target.closest('[data-node-id], [data-relationship-hit-key], .overview-map, #btn-export, #export-menu')) return;
clear();
}, true);
window.addEventListener('scroll', requestLensPlacement, { passive: true });
diff --git a/scripts/browser-test-inventory.mjs b/scripts/browser-test-inventory.mjs
index 76836bfa..4e3fb26d 100644
--- a/scripts/browser-test-inventory.mjs
+++ b/scripts/browser-test-inventory.mjs
@@ -27,6 +27,7 @@ export const browserTestFiles = [
'crossover-state-browser.test.mjs',
'semantic-passport-move-browser.test.mjs',
'export-browser.test.mjs',
+ 'export-selection-browser.test.mjs',
'sequence-note-export-browser.test.mjs',
'viewer-identifiers-browser.test.mjs',
'repository-evidence-browser.test.mjs',
diff --git a/test/export-selection-browser.test.mjs b/test/export-selection-browser.test.mjs
new file mode 100644
index 00000000..22bd0d0e
--- /dev/null
+++ b/test/export-selection-browser.test.mjs
@@ -0,0 +1,60 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { execFileSync } from 'node:child_process';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+import { findChrome } from '../archify/bin/visual-check.mjs';
+import { desktopBrowser } from './helpers/desktop-browser.mjs';
+import { createViewerClick } from './helpers/viewer-click.mjs';
+
+const skillRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'archify');
+const chrome = process.env.ARCHIFY_CHROME ? findChrome() : null;
+
+test('Export menu preserves authored reach until genuine outside dismissal', {
+ skip: chrome ? false : 'Set ARCHIFY_CHROME to run real-browser Export selection checks.',
+}, async (t) => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-export-selection-'));
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
+ const file = path.join(root, 'architecture.html');
+ execFileSync(process.execPath, [
+ path.join(skillRoot, 'renderers/architecture/render-architecture.mjs'),
+ path.join(skillRoot, 'examples/web-app.architecture.json'),
+ file,
+ ]);
+ const browser = desktopBrowser(chrome);
+ t.after(() => browser.close());
+ const session = await browser.sessionPromise;
+ const send = (method, params = {}) => browser.cdp.send(method, params, session);
+ await send('Emulation.setFocusEmulationEnabled', { enabled: true });
+ async function run(expression) {
+ const result = await send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
+ assert.equal(result.exceptionDetails, undefined, result.exceptionDetails?.exception?.description);
+ return result.result?.value;
+ }
+ const click = await createViewerClick({ send, run, timeout: 5000 });
+ await send('Page.navigate', { url: pathToFileURL(file).href });
+ await run(`new Promise((resolve,reject)=>{const start=performance.now();function sample(){
+ if(window.Archify?.focus&&Archify.viewerChromeLayout?.whenStable)return resolve();
+ if(performance.now()-start>5000)return reject(new Error('Viewer did not initialize'));
+ requestAnimationFrame(sample);
+ }sample();})`);
+ assert.equal(await run(`Archify.focus.set('api') && Archify.focus.reach('downstream')`), true);
+ const before = await run('Archify.focus.reachabilitySnapshot()');
+ assert(before?.nodeIds.length > 1);
+ await click('#btn-export');
+ const opened = await run(`({snapshot:Archify.focus.reachabilitySnapshot(),
+ open:Archify.exportMenu.isOpen(),
+ enabled:!document.querySelector('[data-action="reach-share-card"]').disabled,
+ hidden:document.querySelector('[data-action="reach-share-card"]').hidden})`);
+ assert.deepEqual(opened.snapshot, before);
+ assert.equal(opened.open, true);
+ assert.equal(opened.enabled, true);
+ assert.equal(opened.hidden, false);
+ await click('#btn-export');
+ assert.deepEqual(await run('Archify.focus.reachabilitySnapshot()'), before);
+ await run(`document.querySelector('.header-row').click()`);
+ assert.equal(await run('Archify.focus.reachabilitySnapshot()'), null);
+ assert.equal(await run('Archify.focus.active()'), null);
+});
diff --git a/viewer/focus.js b/viewer/focus.js
index 5a86012c..788cb027 100644
--- a/viewer/focus.js
+++ b/viewer/focus.js
@@ -1544,7 +1544,9 @@
var target = event.target;
if (chip.hidden || !target || typeof target.closest !== 'function' || chip.contains(target)) return;
if (container.getAttribute('data-just-panned') === 'true') return;
- if (target.closest('[data-node-id], [data-relationship-hit-key], .overview-map')) return;
+ // Export consumes the active semantic snapshot; its controls are not
+ // an outside selection. Genuine outside activation still clears it.
+ if (target.closest('[data-node-id], [data-relationship-hit-key], .overview-map, #btn-export, #export-menu')) return;
clear();
}, true);
window.addEventListener('scroll', requestLensPlacement, { passive: true });