Studio: WIP

This commit is contained in:
Pieter Vander Vennet 2023-08-23 11:11:53 +02:00
parent 04ecdad1bb
commit 903e168a89
62 changed files with 19152 additions and 123399 deletions

View file

@ -0,0 +1,46 @@
import { Validator } from "../Validator"
import { Translation } from "../../i18n/Translation"
import licenses from "../../../assets/generated/license_info.json"
import { Utils } from "../../../Utils"
export default class IconValidator extends Validator {
private static allLicenses = new Set(licenses.map((l) => l.path))
private static allLicensesArr = Array.from(IconValidator.allLicenses)
public static readonly isMeta = true
constructor() {
super("icon", "Makes sure that a valid .svg-path is added")
}
getFeedback(s: string, getCountry, sloppy?: boolean): Translation | undefined {
if (!s.startsWith("http")) {
if (!IconValidator.allLicenses.has(s)) {
const close = sloppy
? []
: Utils.sortedByLevenshteinDistance(
s.substring(s.lastIndexOf("/")),
IconValidator.allLicensesArr,
(s) => s.substring(s.lastIndexOf("/"))
).slice(0, 5)
return new Translation(
[
`Unkown builtin icon ${s}, perhaps you meant one of: <ul>`,
...close.map(
(item) =>
`<li><span class="flex justify-start"> <img src='${item}' class="w-6 h-6"/>${item}</span></li>`
),
"</ul>",
].join("")
)
}
}
if (!s.endsWith(".svg")) {
return new Translation("An icon should end with `.svg`")
}
return undefined
}
isValid(key: string, getCountry?: () => string): boolean {
return this.getFeedback(key, getCountry, true) === undefined
}
}

View file

@ -3,6 +3,7 @@ import { Translation } from "../../i18n/Translation"
export default class ImageUrlValidator extends UrlValidator {
private static readonly allowedExtensions = ["jpg", "jpeg", "svg", "png"]
public readonly isMeta = true
constructor() {
super(

View file

@ -8,6 +8,8 @@ import TagKeyValidator from "./TagKeyValidator"
*/
export default class SimpleTagValidator extends Validator {
private static readonly KeyValidator = new TagKeyValidator()
public readonly isMeta = true
constructor() {
super(
"simple_tag",

View file

@ -3,6 +3,8 @@ import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
export default class TagKeyValidator extends Validator {
public readonly isMeta = true
constructor() {
super("key", "Validates a key, mostly that no weird characters are used")
}

View file

@ -0,0 +1,24 @@
import { Validator } from "../Validator"
import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
import TagKeyValidator from "./TagKeyValidator"
import SimpleTagValidator from "./SimpleTagValidator"
/**
* Checks that the input conforms a JSON-encoded tag expression or a simpleTag`key=value`,
*/
export default class TagValidator extends Validator {
public readonly isMeta = true
constructor() {
super("tag", "A simple tag of the format `key=value` OR a tagExpression")
}
getFeedback(tag: string, _): Translation | undefined {
return undefined
}
isValid(tag: string, _): boolean {
return this.getFeedback(tag, _) === undefined
}
}

View file

@ -1,6 +1,8 @@
import { Validator } from "../Validator"
export default class TranslationValidator extends Validator {
public readonly isMeta = true
constructor() {
super("translation", "Makes sure the the string is of format `Record<string, string>` ")
}