fix: extra column examples

fix: register example in onStartup
This commit is contained in:
windingwind 2024-05-04 00:32:24 +08:00
parent 7dc303e189
commit ff478a7dff
2 changed files with 36 additions and 46 deletions

View File

@ -32,6 +32,14 @@ async function onStartup() {
KeyExampleFactory.registerShortcuts();
await UIExampleFactory.registerExtraColumn();
await UIExampleFactory.registerExtraColumnWithCustomCell();
UIExampleFactory.registerItemPaneSection();
UIExampleFactory.registerReaderItemPaneSection();
await onMainWindowLoad(window);
}
@ -67,16 +75,8 @@ async function onMainWindowLoad(win: Window): Promise<void> {
UIExampleFactory.registerWindowMenuWithSeparator();
await UIExampleFactory.registerExtraColumn();
await UIExampleFactory.registerExtraColumnWithCustomCell();
await UIExampleFactory.registerCustomItemBoxRow();
UIExampleFactory.registerLibraryTabPanel();
UIExampleFactory.registerReaderTabPanel();
PromptExampleFactory.registerNormalCommandExample();
PromptExampleFactory.registerAnonymousCommandExample();

View File

@ -192,50 +192,40 @@ export class UIExampleFactory {
@example
static async registerExtraColumn() {
await ztoolkit.ItemTree.register(
"test1",
"text column",
(
field: string,
unformatted: boolean,
includeBaseMapped: boolean,
item: Zotero.Item,
) => {
const field = "test1";
await Zotero.ItemTreeManager.registerColumns({
pluginID: config.addonID,
dataKey: field,
label: "text column",
dataProvider: (item: Zotero.Item, dataKey: string) => {
return field + String(item.id);
},
{
iconPath: "chrome://zotero/skin/cross.png",
},
);
iconPath: "chrome://zotero/skin/cross.png",
});
}
@example
static async registerExtraColumnWithCustomCell() {
await ztoolkit.ItemTree.register(
"test2",
"custom column",
(
field: string,
unformatted: boolean,
includeBaseMapped: boolean,
item: Zotero.Item,
) => {
return String(item.id);
const field = "test2";
await Zotero.ItemTreeManager.registerColumns({
pluginID: config.addonID,
dataKey: field,
label: "custom column",
dataProvider: (item: Zotero.Item, dataKey: string) => {
return field + String(item.id);
},
{
renderCell(index, data, column) {
ztoolkit.log("Custom column cell is rendered!");
const span = document.createElementNS(
"http://www.w3.org/1999/xhtml",
"span",
);
span.className = `cell ${column.className}`;
span.style.background = "#0dd068";
span.innerText = "⭐" + data;
return span;
},
renderCell(index, data, column) {
ztoolkit.log("Custom column cell is rendered!");
const span = document.createElementNS(
"http://www.w3.org/1999/xhtml",
"span",
);
span.className = `cell ${column.className}`;
span.style.background = "#0dd068";
span.innerText = "⭐" + data;
return span;
},
);
});
}
@example
@ -279,7 +269,7 @@ export class UIExampleFactory {
}
@example
static registerLibraryTabPanel() {
static registerItemPaneSection() {
Zotero.ItemPaneManager.registerSection({
paneID: "example",
pluginID: config.addonID,
@ -302,7 +292,7 @@ export class UIExampleFactory {
}
@example
static async registerReaderTabPanel() {
static async registerReaderItemPaneSection() {
Zotero.ItemPaneManager.registerSection({
paneID: "reader-example",
pluginID: config.addonID,