Skip to content

Commit

Permalink
Start journal entry pagination at 1 (#12298)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Dec 18, 2023
1 parent 4dc49e7 commit 8afc580
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/module/journal-entry/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ class JournalSheetPF2e<TJournalEntry extends JournalEntry> extends JournalSheet<
/** Use the system-themed styling only if the setting is enabled (on by default) */
static override get defaultOptions(): DocumentSheetOptions {
const options = super.defaultOptions;
options.sheetConfig &&=
Object.values(CONFIG.JournalEntry.sheetClasses).filter((c) => c.canConfigure).length > 1;

const { theme } = this;
if (theme) {
options.classes.push(theme);
}
return options;
}

/** Start pagination at 1 🤫 */
override async getData(options?: Partial<DocumentSheetOptions>): Promise<JournalSheetData<TJournalEntry>> {
const sheetData = await super.getData(options);
for (const entry of sheetData.toc) {
entry.number += 1;
}
return sheetData;
}
}

class JournalTextTinyMCESheetPF2e<
Expand Down
23 changes: 20 additions & 3 deletions types/foundry/client/apps/forms/journal-sheet.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {};
import type { JournalEntryPageSource } from "../../../common/documents/journal-entry-page.d.ts";

declare global {
/**
Expand Down Expand Up @@ -56,7 +56,9 @@ declare global {

protected override _getHeaderButtons(): ApplicationHeaderButton[];

override getData(options?: Partial<DocumentSheetOptions>): DocumentSheetData<TJournalEntry>;
override getData(
options?: Partial<DocumentSheetOptions>,
): JournalSheetData<TJournalEntry> | Promise<JournalSheetData<TJournalEntry>>;

override get template(): string;

Expand Down Expand Up @@ -199,7 +201,7 @@ declare global {
* Handle opening the context menu.
* @param target The element the context menu has been triggered for.
*/
_onContextMenuOpen(target: HTMLElement): void;
protected _onContextMenuOpen(target: HTMLElement): void;

/**
* Handle closing the context menu.
Expand Down Expand Up @@ -244,4 +246,19 @@ declare global {
pageId?: string;
pageIndex?: number;
}

interface JournalSheetData<TDocument extends JournalEntry> extends DocumentSheetData<TDocument> {
collapseMode: {
label: string;
icon: string;
};
searchIcon: string;
searchTooltip: string;
toc: JournalSheetPageData[];
}

interface JournalSheetPageData extends JournalEntryPageSource {
number: 0;
ownershipCls: string;
}
}
14 changes: 14 additions & 0 deletions types/foundry/client/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ declare global {
Anchor: string;
[key: string]: string;
};
sheetClasses: Record<
string,
Record<
string,
{
id: string;
cls: typeof JournalSheet;
default: boolean;
label: string;
canConfigure: boolean;
canBeDefault: boolean;
}
>
>;
sidebarIcon: string;
};

Expand Down
2 changes: 2 additions & 0 deletions types/foundry/common/documents/journal-entry-page.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ type JournalEntryPageSchema<
_stats: fields.DocumentStatsField;
};

export type JournalEntryPageSource = SourceFromSchema<JournalEntryPageSchema>;

export type CorePageType = "image" | "pdf" | "text" | "video";

0 comments on commit 8afc580

Please sign in to comment.