Adding Prettier

* Added prettier with automatic useage on pre-commit to avoid style breakage
* Ran Prettier on the project
This commit is contained in:
WBHarry 2025-05-23 18:57:50 +02:00 committed by GitHub
parent 820c2df1f4
commit b24cdcc9ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
136 changed files with 13929 additions and 12206 deletions

View file

@ -1,7 +1,7 @@
import { getWidthOfText } from "./utils.mjs";
import { getWidthOfText } from './utils.mjs';
export default class RegisterHandlebarsHelpers {
static registerHelpers(){
static registerHelpers() {
Handlebars.registerHelper({
looseEq: this.looseEq,
times: this.times,
@ -11,60 +11,62 @@ export default class RegisterHandlebarsHelpers {
objectSelector: this.objectSelector,
includes: this.includes,
simpleEditor: this.simpleEditor,
debug: this.debug,
debug: this.debug
});
};
}
static looseEq(a, b){
static looseEq(a, b) {
return a == b;
}
static times(nr, block){
static times(nr, block) {
var accum = '';
for(var i = 0; i < nr; ++i)
accum += block.fn(i);
for (var i = 0; i < nr; ++i) accum += block.fn(i);
return accum;
}
static join(...options){
return options.slice(0, options.length-1);
static join(...options) {
return options.slice(0, options.length - 1);
}
static add(a, b){
static add(a, b) {
const aNum = Number.parseInt(a);
const bNum = Number.parseInt(b);
return (Number.isNaN(aNum) ? 0 : aNum) + (Number.isNaN(bNum) ? 0 : bNum);
}
static subtract(a, b){
static subtract(a, b) {
const aNum = Number.parseInt(a);
const bNum = Number.parseInt(b);
return (Number.isNaN(aNum) ? 0 : aNum) - (Number.isNaN(bNum) ? 0 : bNum);
}
static objectSelector(options){
static objectSelector(options) {
let { title, values, titleFontSize, ids, style } = options.hash;
const titleLength = getWidthOfText(title, titleFontSize, true, true);
const margins = 12;
const buttons = options.fn();
const nrButtons = Math.max($(buttons).length-1, 1);
const nrButtons = Math.max($(buttons).length - 1, 1);
const iconWidth = 26;
const texts = values.reduce((acc, x, index) => {
if(x){
acc.push(`<span class="object-select-item" data-action="viewObject" data-value="${ids[index]}">${x}</span>`);
}
const texts = values
.reduce((acc, x, index) => {
if (x) {
acc.push(
`<span class="object-select-item" data-action="viewObject" data-value="${ids[index]}">${x}</span>`
);
}
return acc;
}, []).join(' ');
return acc;
}, [])
.join(' ');
const html =
`<div ${style ? 'style="'+style+'"' : ''}">
const html = `<div ${style ? 'style="' + style + '"' : ''}">
<div class="object-select-display iconbar">
<span class="object-select-title">${title}</span>
<div class="object-select-text" style="padding-left: ${titleLength+margins}px; padding-right: ${nrButtons*iconWidth}px;">
<div class="object-select-text" style="padding-left: ${titleLength + margins}px; padding-right: ${nrButtons * iconWidth}px;">
${texts}
</div>
${buttons}
@ -76,25 +78,31 @@ export default class RegisterHandlebarsHelpers {
}
static rangePicker(options) {
let {name, value, min, max, step} = options.hash;
name = name || "range";
value = value ?? "";
if ( Number.isNaN(value) ) value = "";
const html =
`<input type="range" name="${name}" value="${value}" min="${min}" max="${max}" step="${step}"/>
let { name, value, min, max, step } = options.hash;
name = name || 'range';
value = value ?? '';
if (Number.isNaN(value)) value = '';
const html = `<input type="range" name="${name}" value="${value}" min="${min}" max="${max}" step="${step}"/>
<span class="range-value">${value}</span>`;
return new Handlebars.SafeString(html);
}
static includes(list, item){
static includes(list, item) {
return list.includes(item);
}
static simpleEditor(content, options) {
const { target, editable=true, button, engine="tinymce", collaborate=false, class: cssClass } = options.hash;
const config = {name: target, value: content, button, collaborate, editable, engine};
const {
target,
editable = true,
button,
engine = 'tinymce',
collaborate = false,
class: cssClass
} = options.hash;
const config = { name: target, value: content, button, collaborate, editable, engine };
const element = foundry.applications.fields.createEditorInput(config);
if ( cssClass ) element.querySelector(".editor-content").classList.add(cssClass);
if (cssClass) element.querySelector('.editor-content').classList.add(cssClass);
return new Handlebars.SafeString(element.outerHTML);
}
@ -102,4 +110,4 @@ export default class RegisterHandlebarsHelpers {
console.log(JSON.stringify(a));
return a;
}
}
}

View file

@ -1,4 +1,4 @@
export function handleSocketEvent({action=null, data={}}={}) {
export function handleSocketEvent({ action = null, data = {} } = {}) {
switch (action) {
case socketEvent.GMUpdate:
Hooks.callAll(socketEvent.GMUpdate, data.action, data.uuid, data.update);
@ -8,13 +8,13 @@ export function handleSocketEvent({action=null, data={}}={}) {
break;
}
}
export const socketEvent = {
GMUpdate: "DhpGMUpdate",
DhpFearUpdate: "DhpFearUpdate",
GMUpdate: 'DhpGMUpdate',
DhpFearUpdate: 'DhpFearUpdate'
};
export const GMUpdateEvent = {
UpdateDocument: "DhpGMUpdateDocument",
UpdateFear: "DhpUpdateFear"
};
UpdateDocument: 'DhpGMUpdateDocument',
UpdateFear: 'DhpUpdateFear'
};

View file

@ -1,7 +1,7 @@
export const loadCompendiumOptions = async (compendiums) => {
export const loadCompendiumOptions = async compendiums => {
const compendiumValues = [];
for(var compendium of compendiums){
for (var compendium of compendiums) {
const values = await getCompendiumOptions(compendium);
compendiumValues.push(values);
}
@ -9,11 +9,11 @@ export const loadCompendiumOptions = async (compendiums) => {
return compendiumValues;
};
const getCompendiumOptions = async (compendium) => {
const getCompendiumOptions = async compendium => {
const compendiumPack = await game.packs.get(compendium);
const values = [];
for(var value of compendiumPack.index){
for (var value of compendiumPack.index) {
const document = await compendiumPack.getDocument(value._id);
values.push(document);
}
@ -34,24 +34,23 @@ export const getWidthOfText = (txt, fontsize, allCaps, bold) => {
// getWidthOfText.e.innerText = txt;
// return getWidthOfText.e.offsetWidth;
const text = allCaps ? txt.toUpperCase() : txt;
if(getWidthOfText.c === undefined){
getWidthOfText.c=document.createElement('canvas');
getWidthOfText.ctx=getWidthOfText.c.getContext('2d');
if (getWidthOfText.c === undefined) {
getWidthOfText.c = document.createElement('canvas');
getWidthOfText.ctx = getWidthOfText.c.getContext('2d');
}
var fontspec = `${bold ? 'bold': ''} ${fontsize}px` + ' ' + 'Signika, sans-serif';
if(getWidthOfText.ctx.font !== fontspec)
getWidthOfText.ctx.font = fontspec;
var fontspec = `${bold ? 'bold' : ''} ${fontsize}px` + ' ' + 'Signika, sans-serif';
if (getWidthOfText.ctx.font !== fontspec) getWidthOfText.ctx.font = fontspec;
return getWidthOfText.ctx.measureText(text).width;
}
};
export const padArray = (arr, len, fill) => {
return arr.concat(Array(len).fill(fill)).slice(0,len);
}
return arr.concat(Array(len).fill(fill)).slice(0, len);
};
export const getTier = (level, asNr) => {
switch(Math.floor((level+1)/3)){
case 1:
switch (Math.floor((level + 1) / 3)) {
case 1:
return asNr ? 1 : 'tier1';
case 2:
return asNr ? 2 : 'tier2';
@ -60,23 +59,26 @@ export const getTier = (level, asNr) => {
default:
return asNr ? 0 : 'tier0';
}
}
};
export const capitalize = (string) => {
export const capitalize = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
}
};
export const getPathValue = (path, entity, numeric) => {
const pathValue = foundry.utils.getProperty(entity, path);
if(pathValue) return numeric ? Number.parseInt(pathValue) : pathValue;
if (pathValue) return numeric ? Number.parseInt(pathValue) : pathValue;
return numeric ? Number.parseInt(path) : path;
};
export const generateId = (title, length) => {
const id = title.split(" ").map((w, i) => {
const p = w.slugify({replacement: "", strict: true});
return i ? p.titleCase() : p;
}).join("");
return Number.isNumeric(length) ? id.slice(0, length).padEnd(length, "0") : id;
}
const id = title
.split(' ')
.map((w, i) => {
const p = w.slugify({ replacement: '', strict: true });
return i ? p.titleCase() : p;
})
.join('');
return Number.isNumeric(length) ? id.slice(0, length).padEnd(length, '0') : id;
};