From 2c25156174ca2b5b1202fe643a167d66d1e87192 Mon Sep 17 00:00:00 2001 From: theluckystrike <51033404+theluckystrike@users.noreply.github.com> Date: Sat, 3 Oct 2026 13:23:56 +0700 Subject: [PATCH 1/2] fix(types): allow non-object src in OnCopyProps The enableClipboard callback receives the value of the copied entry, so src can be a string, number, boolean or null. It was typed as object, which made typeof narrowing on src resolve to never. Co-Authored-By: Claude Opus 5.5 --- index.d.ts | 4 ++-- test/tests/js/components/CopyToClipboard-test.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2f44856..6a36f14 100644 --- a/index.d.ts +++ b/index.d.ts @@ -175,9 +175,9 @@ export interface ReactJsonViewProps { export interface OnCopyProps { /** - * The JSON tree source object + * The value of the copied entry. */ - src: object + src: object | string | number | boolean | null /** * List of keys. */ diff --git a/test/tests/js/components/CopyToClipboard-test.js b/test/tests/js/components/CopyToClipboard-test.js index 2332fb1..534e0ad 100644 --- a/test/tests/js/components/CopyToClipboard-test.js +++ b/test/tests/js/components/CopyToClipboard-test.js @@ -4,7 +4,7 @@ import { expect } from 'chai' import CopyToClipboard from './../../../../src/js/components/CopyToClipboard' -function copyToClipboard (src) { +function copyToClipboard (src, clickCallback) { const copied = [] const { clipboard } = global.navigator @@ -20,6 +20,7 @@ function copyToClipboard (src) { src={src} namespace={['root']} theme='rjv-default' + clickCallback={clickCallback} hidden={false} /> ) @@ -96,4 +97,12 @@ describe('', function () { it('CopyToClipboard copies a regexp as source text', function () { expect(copyToClipboard(/pattern/g)).to.deep.equal(['/pattern/g']) }) + + it('CopyToClipboard passes a string value to clickCallback as src', function () { + const calls = [] + copyToClipboard('a string', copy => calls.push(copy)) + expect(calls).to.deep.equal([ + { src: 'a string', namespace: ['root'], name: 'root' } + ]) + }) }) From cc8e837080f282bce790b464f74b90544a303b6b Mon Sep 17 00:00:00 2001 From: theluckystrike <51033404+theluckystrike@users.noreply.github.com> Date: Sat, 3 Oct 2026 13:33:45 +0700 Subject: [PATCH 2/2] fix(types): include undefined in OnCopyProps src Entries whose value is undefined render a copy icon too. Co-Authored-By: Claude Opus 5.5 --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 6a36f14..82a0732 100644 --- a/index.d.ts +++ b/index.d.ts @@ -177,7 +177,7 @@ export interface OnCopyProps { /** * The value of the copied entry. */ - src: object | string | number | boolean | null + src: object | string | number | boolean | null | undefined /** * List of keys. */