mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Upgrade mcschema core
This commit is contained in:
@@ -3,12 +3,6 @@ import { getFilterKey } from './getFilterKey'
|
||||
|
||||
export const canFlatten: Hook<[], boolean> = {
|
||||
base: () => false,
|
||||
boolean: () => false,
|
||||
choice: () => false,
|
||||
list: () => false,
|
||||
map: () => false,
|
||||
number: () => false,
|
||||
string: () => false,
|
||||
object({ node, getActiveFields }, path) {
|
||||
const filterKey = path.modelArr.length === 0 ? null : node.hook(getFilterKey, path, path)
|
||||
const visibleEntries = Object.entries(getActiveFields(path))
|
||||
|
||||
@@ -6,12 +6,6 @@ import { walk } from './walk'
|
||||
export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
|
||||
base() {},
|
||||
|
||||
boolean() {},
|
||||
|
||||
choice() {},
|
||||
|
||||
list() {},
|
||||
|
||||
map({ config }, path, value) {
|
||||
if (config.validation?.validator === 'block_state_map') {
|
||||
const block = relativePath(path, config.validation.params.id).get()
|
||||
@@ -31,8 +25,6 @@ export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
|
||||
}
|
||||
},
|
||||
|
||||
number() {},
|
||||
|
||||
object({ node, getActiveFields }, path, value) {
|
||||
let activeFields = getActiveFields(path)
|
||||
const filterKey = path.modelArr.length === 0 ? null : node.hook(getFilterKey, path, path)
|
||||
@@ -44,7 +36,5 @@ export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
|
||||
path.push(visibleKeys[0]).set(undefined)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
string() {}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,12 +2,6 @@ import { Hook, ModelPath, relativePath } from '@mcschema/core'
|
||||
|
||||
export const getFilterKey: Hook<[ModelPath, number?], string | null> = {
|
||||
base: () => null,
|
||||
boolean: () => null,
|
||||
choice: () => null,
|
||||
list: () => null,
|
||||
map: () => null,
|
||||
number: () => null,
|
||||
string: () => null,
|
||||
object({ filter, getActiveFields }, path, origin, depth = 0) {
|
||||
if (depth > 2) return null
|
||||
if (filter) {
|
||||
|
||||
@@ -9,10 +9,6 @@ import { Tracker } from '../Tracker'
|
||||
|
||||
export const suffixInjector: Hook<[Mounter], string | void> = {
|
||||
base() {},
|
||||
boolean() {},
|
||||
list() {},
|
||||
map() {},
|
||||
number() {},
|
||||
|
||||
choice({ switchNode }, path, mounter) {
|
||||
return switchNode.hook(this, path, mounter)
|
||||
|
||||
@@ -5,10 +5,6 @@ export const transformOutput: Hook<[any], any> = {
|
||||
return value
|
||||
},
|
||||
|
||||
boolean({}, _, value) {
|
||||
return value
|
||||
},
|
||||
|
||||
choice({ switchNode }, path, value) {
|
||||
return switchNode.hook(this, path, value)
|
||||
},
|
||||
@@ -29,10 +25,6 @@ export const transformOutput: Hook<[any], any> = {
|
||||
return res;
|
||||
},
|
||||
|
||||
number({}, _, value) {
|
||||
return value
|
||||
},
|
||||
|
||||
object({ getActiveFields }, path, value) {
|
||||
if (value === undefined || value === null || typeof value !== 'object') {
|
||||
return value
|
||||
@@ -45,9 +37,5 @@ export const transformOutput: Hook<[any], any> = {
|
||||
res[f] = activeFields[f].hook(this, path.push(f), value[f])
|
||||
})
|
||||
return res
|
||||
},
|
||||
|
||||
string({}, _, value) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
|
||||
...hook,
|
||||
|
||||
choice(params, path, value, ...args) {
|
||||
hook.choice(params, path, value, ...args)
|
||||
(hook.choice ?? hook.base)(params, path, value, ...args)
|
||||
params.switchNode.hook(this, path, value, ...args)
|
||||
},
|
||||
|
||||
list(params, path, value, ...args) {
|
||||
hook.list(params, path, value, ...args)
|
||||
(hook.list ?? hook.base)(params, path, value, ...args)
|
||||
if (!Array.isArray(value)) return
|
||||
value.forEach((e, i) =>
|
||||
params.children.hook(this, path.push(i), e, ...args)
|
||||
@@ -19,7 +19,7 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
|
||||
},
|
||||
|
||||
map(params, path, value, ...args) {
|
||||
hook.map(params, path, value, ...args)
|
||||
(hook.map ?? hook.base)(params, path, value, ...args)
|
||||
if (typeof value !== 'object') return
|
||||
Object.keys(value).forEach(f =>
|
||||
params.children.hook(this, path.push(f), value[f], ...args)
|
||||
@@ -27,7 +27,7 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
|
||||
},
|
||||
|
||||
object(params, path, value, ...args) {
|
||||
hook.object(params, path, value, ...args)
|
||||
(hook.object ?? hook.base)(params, path, value, ...args)
|
||||
if (value === null || typeof value !== 'object') return
|
||||
const activeFields = params.getActiveFields(path)
|
||||
Object.keys(activeFields)
|
||||
|
||||
Reference in New Issue
Block a user