Add the ArtBrowser open when using Foundry's editImage action

This commit is contained in:
Oliver 2026-02-01 16:28:29 -07:00
parent 516c0d0c5e
commit cf8c82784b
5 changed files with 47 additions and 1 deletions

View file

@ -22,6 +22,12 @@
}
}
},
"settings": {
"openForEditImage": {
"name": "Open Art Browser for Documents",
"hint": "Whether or not to open the custom Art Browser when picking an image using the edit image action within Foundry for all documents. Systems and Modules that use a different edit image action will not work with this setting."
}
},
"dialogs": {
"Link": {
"title": "Create/Edit Link",

View file

@ -0,0 +1,25 @@
import { ArtBrowser } from "../apps/ArtBrowser.mjs";
import { __ID__ } from "../consts.mjs";
Hooks.on(`getHeaderControlsDocumentSheetV2`, (sheet) => {
const original = sheet.options.actions.editImage;
sheet.options.actions.editImage = async (event, target) => {
if (!game.settings.get(__ID__, `openForEditImage`)) {
return original.call(sheet, event, target);
};
if (target.nodeName !== `IMG`) {
throw new Error(`The editImage action is available only for IMG elements.`);
};
const src = await ArtBrowser.select(1);
if (!src) { return };
target.src = src;
if (sheet.options.form.submitOnChange) {
const submit = new Event(`submit`, { cancelable: true });
sheet.form.dispatchEvent(submit);
};
};
});

View file

@ -2,12 +2,14 @@ import { api } from "../api.mjs";
import { ArtSidebar } from "../apps/ArtSidebar.mjs";
import { registerCustomComponents } from "../apps/elements/_index.mjs";
import helpers from "../handlebarsHelpers/_index.mjs";
import { registerUserSettings } from "../settings/user.mjs";
Hooks.on(`init`, () => {
globalThis.tb = api;
Handlebars.registerHelper(helpers);
registerUserSettings();
registerCustomComponents();
Handlebars.registerHelper(helpers);
// Art sidebar tab
CONFIG.ui.sidebar.TABS.art = {

View file

@ -1,3 +1,4 @@
import "./hooks/init.mjs";
import "./hooks/ready.mjs";
import "./hooks/renderTokenApplication.mjs";
import "./hooks/getHeaderControlsDocumentSheetV2.mjs";

12
module/settings/user.mjs Normal file
View file

@ -0,0 +1,12 @@
import { __ID__ } from "../consts.mjs";
export function registerUserSettings() {
game.settings.register(__ID__, `openForEditImage`, {
name: `IT.settings.openForEditImage.name`,
hint: `IT.settings.openForEditImage.hint`,
scope: `user`,
type: Boolean,
default: true,
config: true,
});
};