mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 15:47:08 +00:00
Complete refactor (#123)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Hook, ModelPath, Path, StringHookParams, ValidationOption, EnumOption, INode, DataModel, MapNode, StringNode } from '@mcschema/core'
|
||||
import { locale, pathLocale, segmentedLocale } from '../locales'
|
||||
import { locale, segmentedLocale } from '../Locales'
|
||||
import { Mounter } from '../Mounter'
|
||||
import { hexId } from '../utils'
|
||||
import { hexId, htmlEncode } from '../Utils'
|
||||
|
||||
/**
|
||||
* Secondary model used to remember the keys of a map
|
||||
@@ -248,6 +248,12 @@ function hashString(str: string) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
function pathLocale(path: Path, params?: string[]): string {
|
||||
// return path.getContext().slice(-5).join('.')
|
||||
return segmentedLocale(path.getContext(), params)
|
||||
?? path.getContext()[path.getContext().length - 1] ?? ''
|
||||
}
|
||||
|
||||
function error(p: ModelPath, exact = true) {
|
||||
const errors = p.model.errors.get(p, exact)
|
||||
if (errors.length === 0) return ''
|
||||
@@ -259,8 +265,3 @@ function help(path: ModelPath) {
|
||||
if (message === undefined) return ''
|
||||
return `data-help="${htmlEncode(message)}"`
|
||||
}
|
||||
|
||||
function htmlEncode(str: string) {
|
||||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user