mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 16:16:50 +00:00
Switch to vite and preact
This commit is contained in:
41
src/app/schema/transformOutput.ts
Normal file
41
src/app/schema/transformOutput.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Hook } from '@mcschema/core'
|
||||
|
||||
export const transformOutput: Hook<[any], any> = {
|
||||
base({}, _, value) {
|
||||
return value
|
||||
},
|
||||
|
||||
choice({ switchNode }, path, value) {
|
||||
return switchNode.hook(this, path, value)
|
||||
},
|
||||
|
||||
list({ children }, path, value) {
|
||||
if (!Array.isArray(value)) return value
|
||||
return value.map((obj, index) =>
|
||||
children.hook(this, path.push(index), obj)
|
||||
)
|
||||
},
|
||||
|
||||
map({ children }, path, value) {
|
||||
if (value === undefined) return undefined
|
||||
const res: any = {}
|
||||
Object.keys(value).forEach(f =>
|
||||
res[f] = children.hook(this, path.push(f), value[f])
|
||||
)
|
||||
return res
|
||||
},
|
||||
|
||||
object({ getActiveFields }, path, value) {
|
||||
if (value === undefined || value === null || typeof value !== 'object') {
|
||||
return value
|
||||
}
|
||||
const res: any = {}
|
||||
const activeFields = getActiveFields(path)
|
||||
Object.keys(activeFields)
|
||||
.filter(k => activeFields[k].enabled(path))
|
||||
.forEach(f => {
|
||||
res[f] = activeFields[f].hook(this, path.push(f), value[f])
|
||||
})
|
||||
return res
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user