@json-layout/core
Advanced tools
Comparing version 0.28.1 to 0.28.2
{ | ||
"name": "@json-layout/core", | ||
"version": "0.28.1", | ||
"version": "0.28.2", | ||
"description": "Compilation and state management utilities for JSON Layout.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -150,2 +150,6 @@ // import Debug from 'debug' | ||
if (schema.oneOf) { | ||
rawSchema.errorMessage.oneOf = options.messages.errorOneOf | ||
} | ||
if (type === 'object') { | ||
@@ -301,4 +305,2 @@ if (schema.properties) { | ||
node.children.push(oneOfPointer) | ||
rawSchema.errorMessage.oneOf = options.messages.errorOneOf | ||
} | ||
@@ -305,0 +307,0 @@ if (schema.if) { |
@@ -267,2 +267,7 @@ // eslint-disable-next-line import/no-named-default | ||
} | ||
if (!this._stateTree.valid && !this._stateTree.root.error && !this._stateTree.root.childError) { | ||
console.error('JSON layout failed to assign validation error to a node', this._lastCreateStateTreeContext.allErrors) | ||
} | ||
logDataBinding('emit update event', this._data, this._stateTree) | ||
@@ -269,0 +274,0 @@ this.options.onUpdate(this) |
import { isSwitchStruct, childIsCompObject, isCompositeLayout, isFocusableLayout, isItemsLayout, isGetItemsExpression, isGetItemsFetch } from '@json-layout/vocabulary' | ||
import { produce } from 'immer' | ||
import debug from 'debug' | ||
import { getChildDisplay } from './utils/display.js' | ||
import { shallowEqualArray, shallowProduceArray, shallowProduceObject } from './utils/immutable.js' | ||
const logStateNode = debug('jl:state-node') | ||
/** | ||
@@ -268,2 +271,4 @@ * @param {unknown} data | ||
) { | ||
logStateNode('createStateNode', fullKey) | ||
/** @type {import('./types.js').StateNodeCacheKey | null} */ | ||
@@ -278,2 +283,3 @@ let cacheKey = null | ||
if (reusedNode && context.cacheKeys[fullKey] && shallowEqualArray(context.cacheKeys[fullKey], cacheKey)) { | ||
logStateNode('createStateNode cache hit', fullKey) | ||
// @ts-ignore | ||
@@ -283,2 +289,3 @@ if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['hit']) | ||
} else { | ||
logStateNode('createStateNode cache miss', fullKey) | ||
// @ts-ignore | ||
@@ -288,2 +295,3 @@ if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['miss']) | ||
} else { | ||
logStateNode('createStateNode cache skip', fullKey) | ||
// @ts-ignore | ||
@@ -367,6 +375,8 @@ if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['skip']) | ||
// if an item was selected, remove the oneOf error | ||
if ((originalError.schemaPath === skeleton.pointer || originalError.schemaPath === skeleton.refPointer) && originalError.keyword === 'oneOf') return false | ||
if (matchError(error, skeleton, dataPath, parentDataPath)) return false | ||
// also remove the errors from other children of the oneOf | ||
if (originalError.schemaPath.startsWith(skeleton.pointer) && !originalError.schemaPath.startsWith(skeleton.pointer + '/' + activeChildTreeIndex)) return false | ||
if (originalError.schemaPath.startsWith(skeleton.refPointer) && !originalError.schemaPath.startsWith(skeleton.refPointer + '/' + activeChildTreeIndex)) return false | ||
if (matchChildError(error, skeleton, dataPath, parentDataPath)) { | ||
if (originalError.schemaPath.startsWith(skeleton.pointer) && !originalError.schemaPath.startsWith(skeleton.pointer + '/' + activeChildTreeIndex)) return false | ||
if (originalError.schemaPath.startsWith(skeleton.refPointer) && !originalError.schemaPath.startsWith(skeleton.refPointer + '/' + activeChildTreeIndex)) return false | ||
} | ||
return true | ||
@@ -434,3 +444,4 @@ }) | ||
if (!error) { | ||
error = context.errors?.find(error => matchChildError(error, skeleton, dataPath, parentDataPath)) | ||
// findLast here is important because we want to keep the error of the highest child (deepest errors are listed first) | ||
error = context.errors?.findLast(error => matchChildError(error, skeleton, dataPath, parentDataPath)) | ||
} | ||
@@ -437,0 +448,0 @@ |
@@ -54,3 +54,3 @@ import { produce } from 'immer' | ||
} | ||
context.errors = validate.errors | ||
context.errors = context.allErrors = validate.errors | ||
if (context.errors.length) { | ||
@@ -57,0 +57,0 @@ for (const error of context.errors) { |
@@ -63,2 +63,3 @@ import { type ErrorObject } from 'ajv/dist/2019.js' | ||
export interface CreateStateTreeContext { | ||
allErrors?: ErrorObject[] | ||
errors?: ErrorObject[] | ||
@@ -65,0 +66,0 @@ additionalPropertiesErrors?: ErrorObject[] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159370
65
3605