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): explain rejected reading-address copies

HengYang38773e0a3a0c
diff --git a/archify/assets/template.html b/archify/assets/template.html
index bc896115..49d7086b 100644
--- a/archify/assets/template.html
+++ b/archify/assets/template.html
@@ -9004,8 +9004,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var value = readerLink(relationId
? 'relation=' + encodeURIComponent(relationId)
: 'focus=' + encodeURIComponent(activeIds[0]) + (reachabilityMode ? '&reach=' + reachabilityMode : ''));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
copyBtn.setAttribute('aria-label', copied
? viewerText(relationId ? 'viewer.passport.copy.pinned.success' : 'viewer.passport.copy.focused.success')
@@ -12938,8 +12937,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
function copyLink() {
if (mode !== 'result') return Promise.resolve(false);
var value = readerLink('route=' + encodeURIComponent(startId) + '~' + encodeURIComponent(endId));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
copyBtn.setAttribute('aria-label', viewerText(copied ? 'viewer.route.copy.success' : 'viewer.route.copy.failed'));
window.setTimeout(function () {
@@ -13594,10 +13592,13 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
function copyLink() {
if (!selectedKinds.length) return Promise.resolve(false);
var value = readerLink('lens=' + selectedKinds.map(encodeURIComponent).join('~'));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
- window.setTimeout(function () { copyBtn.textContent = viewerText('viewer.common.copyLink'); }, 1600);
+ copyBtn.setAttribute('aria-label', viewerText(copied ? 'viewer.lens.copy' : 'viewer.common.copyFailed'));
+ window.setTimeout(function () {
+ copyBtn.textContent = viewerText('viewer.common.copyLink');
+ copyBtn.setAttribute('aria-label', viewerText('viewer.lens.copy'));
+ }, 1600);
return copied;
});
}
diff --git a/test/reading-address-browser.test.mjs b/test/reading-address-browser.test.mjs
index aaa64ae0..6e4ace95 100644
--- a/test/reading-address-browser.test.mjs
+++ b/test/reading-address-browser.test.mjs
@@ -105,12 +105,24 @@ test('native copy links preserve a host page and opaque reader state without cha
}
for (const invalid of ['javascript:{state}', 'https://example.test/no-state',
'https://example.test/#{state}/{state}', 'https://user:[email protected]/#{state}']) {
- await run(`document.documentElement.setAttribute('data-reading-link-template', ${JSON.stringify(invalid)}); Archify.focus.set('source',{toggle:false,updateUrl:false})`);
- const result = await copy('Archify.focus.copyLink()');
- assert.equal(result.copied, false);
- assert.equal(result.text, null);
- assert.equal(result.clipboardCalls, 0);
- assert.equal(result.residual, 0);
+ await run(`document.documentElement.setAttribute('data-reading-link-template', ${JSON.stringify(invalid)})`);
+ for (const [setup, action] of states) {
+ assert.equal(await run(setup), true);
+ const result = await copy(action);
+ assert.equal(result.copied, false);
+ assert.equal(result.text, null);
+ assert.equal(result.clipboardCalls, 0);
+ assert.equal(result.residual, 0);
+ const button = action.startsWith('Archify.focus.') ? 'btn-focus-copy'
+ : action.startsWith('Archify.routeProbe.') ? 'route-probe-copy' : 'semantic-lens-copy';
+ const feedback = await run(`(() => {
+ const button = document.getElementById(${JSON.stringify(button)});
+ return { text: button.textContent, accessible: button.getAttribute('aria-label') };
+ })()`);
+ assert.match(feedback.text, /copy failed/i, `${action} must explain rejected addresses`);
+ assert.match(feedback.accessible, /(?:could not copy|copy failed)/i,
+ `${action} must announce rejected addresses`);
+ }
}
const host = 'https://example.test/publication#page=opaque&reader={state}';
const script = `<script>(async () => {
diff --git a/viewer/focus.js b/viewer/focus.js
index 72c1e187..e3af5cdf 100644
--- a/viewer/focus.js
+++ b/viewer/focus.js
@@ -1399,8 +1399,7 @@
var value = readerLink(relationId
? 'relation=' + encodeURIComponent(relationId)
: 'focus=' + encodeURIComponent(activeIds[0]) + (reachabilityMode ? '&reach=' + reachabilityMode : ''));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
copyBtn.setAttribute('aria-label', copied
? viewerText(relationId ? 'viewer.passport.copy.pinned.success' : 'viewer.passport.copy.focused.success')
diff --git a/viewer/route-probe.js b/viewer/route-probe.js
index 20f62d6d..05cd118d 100644
--- a/viewer/route-probe.js
+++ b/viewer/route-probe.js
@@ -888,8 +888,7 @@
function copyLink() {
if (mode !== 'result') return Promise.resolve(false);
var value = readerLink('route=' + encodeURIComponent(startId) + '~' + encodeURIComponent(endId));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
copyBtn.setAttribute('aria-label', viewerText(copied ? 'viewer.route.copy.success' : 'viewer.route.copy.failed'));
window.setTimeout(function () {
diff --git a/viewer/semantic-lens.js b/viewer/semantic-lens.js
index 2f7a5674..caa76f9e 100644
--- a/viewer/semantic-lens.js
+++ b/viewer/semantic-lens.js
@@ -522,10 +522,13 @@
function copyLink() {
if (!selectedKinds.length) return Promise.resolve(false);
var value = readerLink('lens=' + selectedKinds.map(encodeURIComponent).join('~'));
- if (value === null) return Promise.resolve(false);
- return copyReaderText(value).then(function (copied) {
+ return (value === null ? Promise.resolve(false) : copyReaderText(value)).then(function (copied) {
copyBtn.textContent = viewerText(copied ? 'viewer.common.copied' : 'viewer.common.copyFailed');
- window.setTimeout(function () { copyBtn.textContent = viewerText('viewer.common.copyLink'); }, 1600);
+ copyBtn.setAttribute('aria-label', viewerText(copied ? 'viewer.lens.copy' : 'viewer.common.copyFailed'));
+ window.setTimeout(function () {
+ copyBtn.textContent = viewerText('viewer.common.copyLink');
+ copyBtn.setAttribute('aria-label', viewerText('viewer.lens.copy'));
+ }, 1600);
return copied;
});
}