diff --git a/.eslintignore b/.eslintignore index fb7b0f0..972e6d7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,5 @@ # SPDX-License-Identifier: MIT dist +src/components/ +src/lib/ \ No newline at end of file diff --git a/src/module/applications/compendium-browser.js b/src/module/applications/compendium-browser.js index b26a1eb..672b1fd 100644 --- a/src/module/applications/compendium-browser.js +++ b/src/module/applications/compendium-browser.js @@ -2,7 +2,6 @@ import { createApp } from "../../lib/vue.esm-browser.js"; import { VueCompendiumBrowser } from "../../components/components.vue.es.js"; - /** * Application class for the Compendium Browser. * @@ -24,7 +23,7 @@ export class CompendiumBrowserVueApplication extends Application { this.vueRoot = null; this.vueListenersActive = false; this.vueComponents = { - 'compendium-browser': VueCompendiumBrowser + "compendium-browser": VueCompendiumBrowser }; } @@ -32,13 +31,13 @@ export class CompendiumBrowserVueApplication extends Application { static get defaultOptions() { return {...super.defaultOptions, classes: [ - 'form', - 'compendium-browser' + "form", + "compendium-browser" ], popOut: true, template: "modules/compendium-browser/templates/vue-compendium-browser.html", - id: 'compendium-browser', - title: game.i18n.localize('CMPBrowser.compendiumBrowser'), + id: "compendium-browser", + title: game.i18n.localize("CMPBrowser.compendiumBrowser"), width: 800, height: 730, resizable: true, @@ -51,7 +50,7 @@ export class CompendiumBrowserVueApplication extends Application { // is loaded in the create() method of their respective components. return { // @todo add more default options, like saved filters. - defaultTab: this.options.defaultTab ?? 'creatures', + defaultTab: this.options.defaultTab ?? "creatures", }; } @@ -72,7 +71,7 @@ export class CompendiumBrowserVueApplication extends Application { data() { return { context: context, - } + }; }, // Define our character sheet component. components: this.vueComponents, @@ -101,11 +100,11 @@ export class CompendiumBrowserVueApplication extends Application { // If we don't have an active vueRoot, run Foundry's render and then mount // the Vue application to the form. - await this._render(force, options).catch(err => { + await this._render(force, options).catch((err) => { err.message = `An error occurred while rendering ${this.constructor.name} ${this.appId}: ${err.message}`; console.error(err); this._state = Application.RENDER_STATES.ERROR; - }) + }); // Mount our rendered app. let $selector = $(`[data-appid="${this.appId}"] .compendium-browser-mount`); @@ -147,11 +146,11 @@ export class CompendiumBrowserVueApplication extends Application { */ activateVueListeners(html, repeat = false) { if (!this.options.editable) { - html.find('input,select,textarea').attr('disabled', true); + html.find("input,select,textarea").attr("disabled", true); return; } - if (html.find('.archmage-v2-vue').length > 0) { + if (html.find(".archmage-v2-vue").length > 0) { this.vueListenersActive = true; } @@ -160,10 +159,9 @@ export class CompendiumBrowserVueApplication extends Application { // Input listeners. let inputs = '.section input[type="text"], .section input[type="number"]'; - html.on('focus', inputs, (event) => this._onFocus(event)); + html.on("focus", inputs, (event) => this._onFocus(event)); } - /** * Handle focus events. * @@ -171,9 +169,9 @@ export class CompendiumBrowserVueApplication extends Application { */ _onFocus(event) { let target = event.currentTarget; - setTimeout(function() { + setTimeout(function () { if (target == document.activeElement) { - $(target).trigger('select'); + $(target).trigger("select"); } }, 100); } diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index 3efd81f..58a8959 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1,7 +1,7 @@ +import { CompendiumBrowserVueApplication } from "./applications/compendium-browser.js"; import { preloadTemplates } from "./preloadTemplates.js"; import { dnd5eProvider } from "./providers/dnd5e.js"; import { registerSettings } from "./settings.js"; -import { CompendiumBrowserVueApplication } from './applications/compendium-browser.js'; const STOP_SEARCH = "StopSearchException"; const COMPENDIUM_BROWSER = "compendium-browser"; @@ -1588,15 +1588,15 @@ Hooks.once("setup", async () => { /* ---------------------------------------------- */ -Hooks.once('ready', () => { +Hooks.once("ready", () => { // Handle click events for the compendium browser. document.addEventListener("click", (event) => { if (event?.target?.classList && event.target.classList.contains("open-compendium-browser")) { // Retrieve the existing compendium browser, if any. - let compendiumBrowser = Object.values(ui.windows).find(app => app.constructor.name == 'CompendiumBrowserVueApplication'); + let compendiumBrowser = Object.values(ui.windows).find((app) => app.constructor.name == "CompendiumBrowserVueApplication"); // Otherwise, build a new one. if (!compendiumBrowser) { - compendiumBrowser = new CompendiumBrowserVueApplication({ defaultTab: event.target.dataset.tab ?? 'creatures' }); + compendiumBrowser = new CompendiumBrowserVueApplication({ defaultTab: event.target.dataset.tab ?? "creatures" }); } // Render the browser. compendiumBrowser.render(true); @@ -1607,19 +1607,19 @@ Hooks.once('ready', () => { /* ---------------------------------------------- */ Hooks.on("renderDocumentDirectory", (app, html, options) => { - if (["actors", "items"].includes(options.tabName) && !options.cssId.toLowerCase().includes('compendium')) { + if (["actors", "items"].includes(options.tabName) && !options.cssId.toLowerCase().includes("compendium")) { const htmlElement = html[0]; - let compendiumButton = ''; + let compendiumButton = ""; if (options.tabName == "items") { compendiumButton = `
- - + +
`; } else { - compendiumButton = ``; + compendiumButton = ``; } // Append button. Click handler added in 'ready' hook. htmlElement.querySelector(".directory-footer").insertAdjacentHTML("beforeend", compendiumButton); diff --git a/src/vue/index.js b/src/vue/index.js index 86b23cd..472f4f9 100644 --- a/src/vue/index.js +++ b/src/vue/index.js @@ -1,2 +1,2 @@ // Main app. -export { default as VueCompendiumBrowser } from './CompendiumBrowser.vue'; +export { default as VueCompendiumBrowser } from "./CompendiumBrowser.vue"; diff --git a/src/vue/methods/Helpers.js b/src/vue/methods/Helpers.js index af1ff15..4607bf2 100644 --- a/src/vue/methods/Helpers.js +++ b/src/vue/methods/Helpers.js @@ -6,7 +6,7 @@ export function getSafeValue(property, defaultValue) { export function cssClass(string) { return encodeURIComponent( string.trim().toLowerCase() - ).replace(/%[0-9A-F]{2}/gi, '-'); + ).replace(/%[0-9A-F]{2}/gi, "-"); } export function numberFormat(value, dec = 0, sign = false) { @@ -18,7 +18,7 @@ export function numberFormat(value, dec = 0, sign = false) { export function concat(...args) { return args.reduce((acc, cur) => { return acc + cur; - }, ''); + }, ""); } export async function getActor(actorData) { @@ -40,7 +40,7 @@ export async function getActor(actorData) { */ export function getActorModuleArt(actor) { // UUID doesn't exactly match the format used in the map currently. - const actorMapId = actor.uuid.replace('.Actor', ''); + const actorMapId = actor.uuid.replace(".Actor", ""); // Retrieve the art from the map, or fallback to the actor image. const art = game.dnd5e.moduleArt.map.get(actorMapId); return art?.actor ?? actor.img; @@ -74,11 +74,11 @@ export async function getPackIndex(packNames = [], fields = []) { * @param {string} uuid Document UUID to open. * @param {string} type Document type to open. Defaults to 'Actor'. */ -export function openDocument(uuid, type = 'Actor') { +export function openDocument(uuid, type = "Actor") { getDocumentClass(type).fromDropData({ type: type, uuid: uuid - }).then(document => { + }).then((document) => { if (document?.sheet) { document.sheet.render(true); } @@ -94,8 +94,8 @@ export function openDocument(uuid, type = 'Actor') { * @param {Event} event Drag event. * @param {Object} entry Pack index entry object. */ -export function startDrag(event, entry, type = 'Actor') { - event.dataTransfer.setData('text/plain', JSON.stringify({ +export function startDrag(event, entry, type = "Actor") { + event.dataTransfer.setData("text/plain", JSON.stringify({ type: type, uuid: entry.uuid })); diff --git a/vite.config.mjs b/vite.config.mjs index 843fc89..1b65380 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -1,14 +1,14 @@ -import path from 'path' -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' +import path from "path"; +import { defineConfig } from "vite"; +import vue from "@vitejs/plugin-vue"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], resolve: { alias: { - '@/': `${path.resolve(__dirname, 'src/vue')}/`, - '@src/': `${path.resolve(__dirname, 'src')}/`, + "@/": `${path.resolve(__dirname, "src/vue")}/`, + "@src/": `${path.resolve(__dirname, "src")}/`, } }, css: { @@ -18,30 +18,29 @@ export default defineConfig({ }, build: { sourcemap: true, - outDir: './src/components', + outDir: "./src/components", lib: { - entry: path.resolve(__dirname, 'src/vue/index.js'), - name: 'v3ArchmageVueComponents', - formats: ['es'], // also supports 'umd' + entry: path.resolve(__dirname, "src/vue/index.js"), + name: "v3ArchmageVueComponents", + formats: ["es"], // also supports 'umd' fileName: (format) => `components.vue.${format}.js`, }, rollupOptions: { external: [ - 'vue', + "vue", ], output: { // Provide global variables to use in the UMD build // Add external deps here globals: { - vue: 'Vue', + vue: "Vue", }, // Map the external dependency to a local copy of Vue 3 esm. paths: { - vue: `../lib/vue.esm-browser.js` + vue: "../lib/vue.esm-browser.js" }, assetFileNames: (assetInfo) => { - if (assetInfo.name == 'style.css') - return `styles.vue.css`; + if (assetInfo.name == "style.css") return "styles.vue.css"; return assetInfo.name; } }, diff --git a/vite.config.prod.mjs b/vite.config.prod.mjs index 38761bf..23ee1c6 100644 --- a/vite.config.prod.mjs +++ b/vite.config.prod.mjs @@ -1,14 +1,14 @@ -import path from 'path' -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' +import path from "path"; +import { defineConfig } from "vite"; +import vue from "@vitejs/plugin-vue"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], resolve: { alias: { - '@/': `${path.resolve(__dirname, 'src/vue')}/`, - '@src/': `${path.resolve(__dirname, 'src')}/`, + "@/": `${path.resolve(__dirname, "src/vue")}/`, + "@src/": `${path.resolve(__dirname, "src")}/`, } }, // css: { @@ -20,30 +20,29 @@ export default defineConfig({ // }, build: { sourcemap: true, - outDir: './dist/vue', + outDir: "./dist/vue", lib: { - entry: path.resolve(__dirname, 'src/vue/index.js'), - name: 'CompendiumBrowserVue', - formats: ['es'], // also supports 'umd' + entry: path.resolve(__dirname, "src/vue/index.js"), + name: "CompendiumBrowserVue", + formats: ["es"], // also supports 'umd' fileName: (format) => `components.vue.${format}.js`, }, rollupOptions: { external: [ - 'vue', + "vue", ], output: { // Provide global variables to use in the UMD build // Add external deps here globals: { - vue: 'Vue', + vue: "Vue", }, // Map the external dependency to a local copy of Vue 3 esm. paths: { - vue: `../lib/vue.esm-browser.prod.js` + vue: "../lib/vue.esm-browser.prod.js" }, assetFileNames: (assetInfo) => { - if (assetInfo.name == 'style.css') - return `styles.vue.css`; + if (assetInfo.name == "style.css") return "styles.vue.css"; return assetInfo.name; } },