Adding citekey to the item pane in Z7

1,380 views
Skip to first unread message

Emiliano Heyns

unread,
Jul 15, 2023, 4:08:24 PM7/15/23
to zotero-dev
In Z6 I used to add a read-only textbox to the item pane to show the citekey in a way that it was copy-pastable. In Z7 I've tried using addDynamicRow to add a read-only input field, and a label with user-select auto, but it keeps messing with focus of other fields in the item pane. Any tips on how best to approach this? 

XY Wong

unread,
Jul 18, 2023, 4:02:47 AM7/18/23
to zotero-dev
This might be helpful:  zotero-plugin-toolkit/src/managers/itemBox.ts at master · windingwind/zotero-plugin-toolkit (github.com)

I am working on providing some APIs for plugins, and support for custom rows in the item pane is planned but no guarantees.

Emiliano Heyns

unread,
Jul 18, 2023, 4:07:12 AM7/18/23
to zotero-dev
I'm using a version of that, but I need the row to remain clickable because I need the citekey to be select-copyable.

XY Wong

unread,
Jul 18, 2023, 10:45:22 AM7/18/23
to zotero-dev
The row can be clickable and actually even editable, and you can prevent it from updating source data if you don't want it to, which means it can be editable. However, in my implementation in ztoolkit, the editable row can cause a focusing bug so not recommended to make it editable.

A temporary workaround is to add a click listener to the row and when clicked, copy the citation key to the clipboard.

XY Wong

unread,
Jul 18, 2023, 10:47:28 AM7/18/23
to zotero-dev
*which means it can be editable > which means it can be select-copyable but not editable

Emiliano Heyns

unread,
Jul 18, 2023, 10:58:24 AM7/18/23
to zotero-dev
I'll first try the old way I had, which was to have the citekey outside the box of editable rows. I appreciate the insight, you have an impressively deep understanding of the zotero guts, but copy-on-click or have it editable with just not saving the edits (which is what you're saying right?) seems less intuitive than having it placed in a weird location. 

XY Wong

unread,
Jul 20, 2023, 10:49:18 AM7/20/23
to zotero-dev
yeah. hope the layout won't be changed too much because my pdf-preview plugin also wants to add things to that view (and i have to detect the bbt loading to decide how to add my component).

Emiliano Heyns

unread,
Jul 26, 2023, 10:49:08 PM7/26/23
to zotero-dev
I'm going to use addDynamicRow until something better becomes available. The user can type over the citekey but it's restored when the field blurs.

XY Wong

unread,
Jul 26, 2023, 10:54:46 PM7/26/23
to zotero-dev
We will soon have a new API for adding custom rows in the item box, you could turn to the official API when it's ready.

Emiliano Heyns

unread,
Jul 27, 2023, 5:17:02 AM7/27/23
to zotero-dev
It'd be helpful for me if this API allowed a read-only-but-selectable row. Right now, I have to choose to do it as an editable field (which allows the user to type over the read-only value) or as a display-only field like date-added (which can't be copy-pasted). 

XY Wong

unread,
Jul 27, 2023, 9:59:12 PM7/27/23
to zotero-dev
Yes, we plan to support that.

Emiliano Heyns

unread,
Jul 29, 2023, 10:06:48 PM7/29/23
to zotero-dev
I've settled on an editable citekey field for now. It's something I was going to have to deal with anyhow once Zotero gets a citation key field for all regular item types.

Emiliano Heyns

unread,
Aug 3, 2023, 6:36:47 AM8/3/23
to zotero-dev
When I create the field using this.createValueElement, the 3rd parameter is the tabindex, right? When I add the field, the tab always goes to the citekey field, regardless of which field the cursor was in.
Message has been deleted

Emiliano Heyns

unread,
Aug 3, 2023, 7:57:05 AM8/3/23
to zotero-dev
I've also tried to fool refresh into thinking citationKey is a native field, and it does add a row, but it's half-height, and doesn't display the value:

    $patch$(itemBoxInstance.__proto__, 'refresh', original => function() {
      const fieldOrder: string[] = this._fieldOrder
      if (!fieldOrder.length) {
        const fieldNames: string[] = []

        if (!this.showTypeMenu) {
          fieldNames.push('itemType')
        }
        fieldNames.push('citationKey')

        const fields = Zotero.ItemFields.getItemTypeFields(this.item.getField('itemTypeID'))

        for (const id of fields) {
          fieldNames.push(Zotero.ItemFields.getName(id))
        }

        if (this.item instanceof Zotero.FeedItem) {
          const row = Zotero.getActiveZoteroPane().getCollectionTreeRow()
          if (row && row.isFeeds()) {
            fieldNames.unshift('feed')
          }
        }
        else {
          fieldNames.push('dateAdded', 'dateModified')
        }
        this._fieldOrder = fieldNames
      }

      // eslint-disable-next-line prefer-rest-params
      original.apply(this, arguments)

      this._fieldOrder = fieldOrder
    })

XY Wong

unread,
Aug 3, 2023, 9:08:22 AM8/3/23
to zotero-dev
Yes. that's the bug I mentioned that prevents me from using an editable item box row.

Emiliano Heyns

unread,
Aug 3, 2023, 9:37:50 AM8/3/23
to zotero-dev
Does that mean that your toolbox method has the same problem (because that's where I cribbed mine from)? 

I think I'm going to revert back to the method I had for Zotero 6, and will just not display the citekey in the item pane until a more robust method is available. 

XY Wong

unread,
Aug 3, 2023, 9:40:36 AM8/3/23
to zotero-dev
That's the problem with my toolkit method. I am working on the official API, so if you are not in a hurry, you could put this aside temporarily, use some workaround (like non-editable but click to copy) or revert to your z6 solution.

The API is on the way.

Emiliano Heyns

unread,
Aug 3, 2023, 4:43:05 PM8/3/23
to zotero-dev
I'll revert to the Z6 method for Z6, and await the API. My Z6 method doesn't work because itemBoxInstance doesn't have a .parentNode -- how is that possible?

Abe Jellinek

unread,
Aug 3, 2023, 4:47:16 PM8/3/23
to zoter...@googlegroups.com
You’re constructing it yourself: https://github.com/retorquere/zotero-better-bibtex/blob/542de6a0a2ddc6d5147a37bd5610ff92c02a0081/content/ZoteroItemPane.ts#L32C17-L32C17

You should be getting the <item-box> from the document just like you are in the else branch there.

-- 
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/71821da7-bee1-40d2-b1f8-45845449a6f2n%40googlegroups.com.

Emiliano Heyns

unread,
Aug 3, 2023, 4:56:29 PM8/3/23
to zotero-dev
I lifted that blindly from the windingwind toolkit :D so I should be testing for querySelector('item-box')? Not '#item-box'?

Emiliano Heyns

unread,
Aug 3, 2023, 5:12:06 PM8/3/23
to zotero-dev
Alas -- no errors when I do it by querySelector('item-box'), but also no citekey. I will await the API.

Emiliano Heyns

unread,
Sep 2, 2023, 10:10:37 AM9/2/23
to zotero-dev
Any news on the availability for this API?

XY Wong

unread,
Sep 2, 2023, 10:56:41 AM9/2/23
to zotero-dev
It's under code review. You can track all the issues/PRs related to plugin APIs here: https://github.com/zotero/zotero/issues?q=label%3APlugins

Leopold

unread,
Jan 30, 2024, 2:26:46 AMJan 30
to zotero-dev
Hey friends,

Just wanted to check the progress here.

Not sure if I've missed any relevant discussions elsewhere, but it seems that the PR has not been merged and hence the API is not yet available (see a discussion here: https://github.com/zotero/zotero/pull/3255#issuecomment-1855880780)

I'm guessing that the redesigned UI, which requires some new APIs, might be a blocker here - appreciate any clarification on this :)

Cheers,
Leo

Emiliano Heyns

unread,
Feb 17, 2024, 7:38:41 PMFeb 17
to zotero-dev
It seems that https://github.com/MuiseDestiny/zotero-style can add a field to the item pane, does this mean the api is available?

XY Wong

unread,
Feb 17, 2024, 8:26:53 PMFeb 17
to zotero-dev
No it's not - that plugin is using zotero-plugin-toolkit/docs/zotero-plugin-toolkit.itemboxmanager.md at master · windingwind/zotero-plugin-toolkit (github.com), which should be replaced by the api when it's ready

Emiliano Heyns

unread,
Feb 17, 2024, 9:13:51 PMFeb 17
to zotero-dev
Is there a rough timeline in availability? If it's likely to take long I might try to reconstruct what the plugin toolkit does. 

You received this message because you are subscribed to a topic in the Google Groups "zotero-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotero-dev/dzBI00ptxGw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/5f34559f-1cb8-44e2-8710-4c7278cfb280n%40googlegroups.com.

XY Wong

unread,
Feb 17, 2024, 9:44:10 PMFeb 17
to zotero-dev
No timeline, but won't be too far when we get the item pane implementation more stable. We already have a PR, just need to make it work (better) with the redesigned item pane.

I think we can expect it to arrive before the Zotero 7 stable release.

Emiliano Heyns

unread,
Feb 18, 2024, 3:07:37 AMFeb 18
to zotero-dev
Understood, but that can still be a way off. Any reason not to adapt what zotero-style did in the interim? I'll take any decent excuse to not do UI work :D. 

XY Wong

unread,
Feb 23, 2024, 7:54:45 AMFeb 23
to zotero-dev
> Any reason not to adapt what zotero-style did in the interim? I'll take any decent excuse to not do UI work :D. 

Well, I think the current third-party implementation is not perfect, like, it breaks the keyboard navigation.

Reply all
Reply to author
Forward
0 new messages