diff --git a/src/app/components/generator/Tree.tsx b/src/app/components/generator/Tree.tsx index fd357a47..06f4b555 100644 --- a/src/app/components/generator/Tree.tsx +++ b/src/app/components/generator/Tree.tsx @@ -11,7 +11,7 @@ type TreePanelProps = { blockStates: BlockStateRegistry | null, onError: (message: string) => unknown, } -export function Tree({ lang, model, blockStates, onError }: TreePanelProps) { +export function Tree({ lang, version, model, blockStates, onError }: TreePanelProps) { if (!model || !blockStates || lang === 'none') return <> const [error] = useErrorBoundary(e => { @@ -26,6 +26,6 @@ export function Tree({ lang, model, blockStates, onError }: TreePanelProps) { }) return
- +
} diff --git a/src/app/schema/renderHtml.tsx b/src/app/schema/renderHtml.tsx index 850d3717..cf1f5168 100644 --- a/src/app/schema/renderHtml.tsx +++ b/src/app/schema/renderHtml.tsx @@ -7,7 +7,7 @@ import config from '../../config.json' import { Btn, Octicon } from '../components' import { useFocus } from '../hooks' import { locale } from '../Locales' -import type { BlockStateRegistry } from '../services' +import type { BlockStateRegistry, VersionId } from '../services' import { CachedDecorator, CachedFeature } from '../services' import { deepClone, deepEqual, hexId, isObject, newSeed } from '../Utils' import { ModelWrapper } from './ModelWrapper' @@ -33,20 +33,21 @@ const keysModel = new DataModel(MapNode( ), { historyMax: 0 }) type JSXTriple = [JSX.Element | null, JSX.Element | null, JSX.Element | null] -type RenderHook = Hook<[any, string, BlockStateRegistry, Record], JSXTriple> +type RenderHook = Hook<[any, string, VersionId, BlockStateRegistry, Record], JSXTriple> type NodeProps = T & { node: INode, path: ModelPath, value: any, lang: string, + version: VersionId, states: BlockStateRegistry, ctx: Record, } -export function FullNode({ model, lang, blockStates }: { model: DataModel, lang: string, blockStates: BlockStateRegistry }) { +export function FullNode({ model, lang, version, blockStates }: { model: DataModel, lang: string, version: VersionId, blockStates: BlockStateRegistry }) { const path = new ModelPath(model) - const [prefix, suffix, body] = model.schema.hook(renderHtml, path, deepClone(model.data), lang, blockStates, {}) + const [prefix, suffix, body] = model.schema.hook(renderHtml, path, deepClone(model.data), lang, version, blockStates, {}) return suffix?.props?.children.some((c: any) => c) ?
{prefix}{suffix}
{body}
@@ -58,14 +59,14 @@ const renderHtml: RenderHook = { return [null, null, null] }, - boolean(params, path, value, lang, states, ctx) { - return [null, , null] + boolean(params, path, value, lang, version, states, ctx) { + return [null, , null] }, - choice({ choices, config, switchNode }, path, value, lang, states, ctx) { + choice({ choices, config, switchNode }, path, value, lang, version, states, ctx) { const choice = switchNode.activeCase(path, true) as typeof choices[number] const contextPath = (config?.context) ? new ModelPath(path.getModel(), new Path(path.getArray(), [config.context])) : path - const [prefix, suffix, body] = choice.node.hook(this, contextPath, value, lang, states, ctx) + const [prefix, suffix, body] = choice.node.hook(this, contextPath, value, lang, version, states, ctx) if (choices.length === 1) { return [prefix, suffix, body] } @@ -86,7 +87,7 @@ const renderHtml: RenderHook = { return [prefix, <>{inject}{suffix}, body] }, - list({ children, config }, path, value, lang, states, ctx) { + list({ children, config }, path, value, lang, version, states, ctx) { const { expand, collapse, isToggled } = useToggles() const [maxShown, setMaxShown] = useState(50) @@ -98,7 +99,7 @@ const renderHtml: RenderHook = {
const suffix = <>{[...Array(config.maxLength)].map((_, i) => { - const child = children.hook(this, path.modelPush(i), value?.[i]?.node, lang, states, ctx) + const child = children.hook(this, path.modelPush(i), value?.[i]?.node, lang, version, states, ctx) return child[1] })} return [prefix, suffix, null] @@ -162,7 +163,7 @@ const renderHtml: RenderHook = { }, }, ] - return + return {canToggle && } {value.length > 1 &&
@@ -178,7 +179,7 @@ const renderHtml: RenderHook = { return [null, suffix, body] }, - map({ children, keys, config }, path, value, lang, states, ctx) { + map({ children, keys, config }, path, value, lang, version, states, ctx) { const { expand, collapse, isToggled } = useToggles() const keyPath = new ModelPath(keysModel, new Path([hashString(path.toString())])) @@ -201,10 +202,10 @@ const renderHtml: RenderHook = { path.model.errors.add(path.push(key), 'error.invalid_enum_option', value[key]) } }) - return ObjectNode(Object.fromEntries(properties)).hook(this, path, value, lang, states, ctx) + return ObjectNode(Object.fromEntries(properties)).hook(this, path, value, lang, version, states, ctx) } const suffix = <> - {keysSchema.hook(this, keyPath, keyPath.get() ?? '', lang, states, ctx)[1]} + {keysSchema.hook(this, keyPath, keyPath.get() ?? '', lang, version, states, ctx)[1]} const body = <> @@ -229,7 +230,7 @@ const renderHtml: RenderHook = { path.model.errors.add(cPath, 'error.invalid_enum_option', cValue) } const onRemove = () => cPath.set(undefined) - return + return {canToggle && } @@ -238,11 +239,11 @@ const renderHtml: RenderHook = { return [null, suffix, body] }, - number(params, path, value, lang, states, ctx) { - return [null, , null] + number(params, path, value, lang, version, states, ctx) { + return [null, , null] }, - object({ node, config, getActiveFields, getChildModelPath }, path, value, lang, states, ctx) { + object({ node, config, getActiveFields, getChildModelPath }, path, value, lang, version, states, ctx) { const { expand, collapse, isToggled } = useToggles() if (path.getArray().length == 0 && isDecorated(config.context, value)) { @@ -284,7 +285,7 @@ const renderHtml: RenderHook = { const cPath = getChildModelPath(path, key) const context = cPath.getContext().join('.') if (hiddenFields.includes(context)) return null - const [cPrefix, cSuffix, cBody] = child.hook(this, cPath, value[key], lang, states, newCtx) + const [cPrefix, cSuffix, cBody] = child.hook(this, cPath, value[key], lang, version, states, newCtx) if (!cPrefix && !cSuffix && !((cBody?.props?.children?.length ?? 0) > 0)) return null const isFlattened = child.type(cPath) === 'object' && flattenedFields.includes(context) const isInlined = inlineFields.includes(context) @@ -293,15 +294,15 @@ const renderHtml: RenderHook = { suffix = <>{suffix}{cSuffix} return isFlattened ? cBody : null } - return + return }) } return [prefix, suffix, body] }, - string(params, path, value, lang, states, ctx) { - return [null, , null] + string(params, path, value, lang, version, states, ctx) { + return [null, , null] }, } @@ -379,7 +380,7 @@ function NumberSuffix({ path, config, integer, value, lang }: NodeProps } -function StringSuffix({ path, getValues, config, node, value, lang, states }: NodeProps) { +function StringSuffix({ path, getValues, config, node, value, lang, version, states }: NodeProps) { const onChange = (evt: Event) => { evt.stopPropagation() const newValue = (evt.target as HTMLSelectElement).value @@ -424,7 +425,7 @@ function StringSuffix({ path, getValues, config, node, value, lang, states }: No {values.map(v =>