@json-layout/core
Advanced tools
Comparing version 1.2.2 to 1.3.0
{ | ||
"name": "@json-layout/core", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Compilation and state management utilities for JSON Layout.", | ||
@@ -62,3 +62,3 @@ "type": "module", | ||
"dependencies": { | ||
"@json-layout/vocabulary": "~1.2.1", | ||
"@json-layout/vocabulary": "~1.3.0", | ||
"ajv": "^8.12.0", | ||
@@ -65,0 +65,0 @@ "ajv-errors": "^3.0.0", |
// import Debug from 'debug' | ||
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout, childIsCompObject } from '@json-layout/vocabulary' | ||
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout, childIsCompositeCompObject } from '@json-layout/vocabulary' | ||
import { makeSkeletonTree } from './skeleton-tree.js' | ||
@@ -101,3 +101,3 @@ import { partialResolveRefs } from './utils/resolve-refs.js' | ||
if (child.if) pushExpression(expressions, child.if) | ||
if (childIsCompObject(child)) { | ||
if (childIsCompositeCompObject(child)) { | ||
for (const grandChild of child.children) prepareLayoutChild(grandChild) | ||
@@ -104,0 +104,0 @@ } |
@@ -233,3 +233,7 @@ // eslint-disable-next-line import/no-named-default | ||
let nbIter = 0 | ||
while (this._data !== (this._stateTree.root.data ?? null) || this._autofocusTarget !== this._lastCreateStateTreeContext.autofocusTarget) { | ||
while ( | ||
this._data !== (this._stateTree.root.data ?? null) || | ||
this._autofocusTarget !== this._lastCreateStateTreeContext.autofocusTarget || | ||
(nbIter === 0 && this._lastCreateStateTreeContext.errors?.length) | ||
) { | ||
nbIter += 1 | ||
@@ -284,3 +288,4 @@ if (nbIter > 100) { | ||
files: [], | ||
nodes: [] | ||
nodes: [], | ||
rehydrateErrors: this._lastCreateStateTreeContext?.errors | ||
} | ||
@@ -287,0 +292,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { isSwitchStruct, childIsCompObject, isCompositeLayout, isFocusableLayout, isItemsLayout, isGetItemsExpression, isGetItemsFetch, isListLayout } from '@json-layout/vocabulary' | ||
import { isSwitchStruct, childIsCompositeCompObject, childIsSlotCompObject, isCompositeLayout, isFocusableLayout, isItemsLayout, isGetItemsExpression, isGetItemsFetch, isListLayout } from '@json-layout/vocabulary' | ||
import { produce } from 'immer' | ||
@@ -35,4 +35,4 @@ import debug from 'debug' | ||
// use Immer for efficient updating with immutability and no-op detection | ||
/** @type {(draft: import('./types.js').StateNode, key: string | number, fullKey: string, parentFullKey: string | null, dataPath: string, parentDataPath: string | null, skeleton: import('../index.js').SkeletonNode, layout: import('@json-layout/vocabulary').BaseCompObject, width: number, cols: number, data: unknown, error: string | undefined, validated: boolean, options: import('./types.js').StateNodeOptions, autofocus: boolean, props: import('@json-layout/vocabulary').StateNodePropsLib, itemsCacheKey: any, children: import('../index.js').StateNode[] | undefined) => import('../index.js').StateNode} */ | ||
const produceStateNode = produce((draft, key, fullKey, parentFullKey, dataPath, parentDataPath, skeleton, layout, width, cols, data, error, validated, options, autofocus, props, itemsCacheKey, children) => { | ||
/** @type {(draft: import('./types.js').StateNode, key: string | number, fullKey: string, parentFullKey: string | null, dataPath: string, parentDataPath: string | null, skeleton: import('../index.js').SkeletonNode, layout: import('@json-layout/vocabulary').BaseCompObject, width: number, cols: number, data: unknown, error: string | undefined, validated: boolean, options: import('./types.js').StateNodeOptions, autofocus: boolean, props: import('@json-layout/vocabulary').StateNodePropsLib, slots: import('@json-layout/vocabulary').Slots | undefined, itemsCacheKey: any, children: import('../index.js').StateNode[] | undefined) => import('../index.js').StateNode} */ | ||
const produceStateNode = produce((draft, key, fullKey, parentFullKey, dataPath, parentDataPath, skeleton, layout, width, cols, data, error, validated, options, autofocus, props, slots, itemsCacheKey, children) => { | ||
draft.messages = layout.messages ? produceStateNodeMessages(draft.messages || {}, layout.messages, options) : options.messages | ||
@@ -65,3 +65,3 @@ | ||
draft.props = props | ||
draft.slots = slots | ||
draft.children = children | ||
@@ -186,4 +186,12 @@ }) | ||
const originalError = error.params?.errors?.[0] ?? error | ||
if (parentDataPath === originalError.instancePath && originalError.params?.missingProperty === skeleton.key) return true | ||
if (originalError.instancePath === dataPath && (originalError.schemaPath === skeleton.pointer || originalError.schemaPath === skeleton.refPointer)) return true | ||
if (parentDataPath === originalError.instancePath && originalError.params?.missingProperty === skeleton.key) { | ||
return true | ||
} | ||
if ( | ||
originalError.instancePath === dataPath && | ||
(originalError.schemaPath === skeleton.pointer || originalError.schemaPath === skeleton.refPointer) && | ||
!originalError.params?.missingProperty | ||
) { | ||
return true | ||
} | ||
return false | ||
@@ -247,2 +255,3 @@ } | ||
const noneComp = { comp: 'none' } | ||
/** | ||
@@ -268,10 +277,10 @@ * @param {import('@json-layout/vocabulary').NormalizedLayout} normalizedLayout | ||
if (childDefinition?.if && !evalExpression(compiledLayout.expressions, childDefinition.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) { | ||
return { comp: 'none' } | ||
return noneComp | ||
} | ||
if (normalizedLayout.if && !evalExpression(compiledLayout.expressions, normalizedLayout.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) { | ||
return { comp: 'none' } | ||
return noneComp | ||
} | ||
return normalizedLayout | ||
} | ||
return { comp: 'none' } | ||
return noneComp | ||
} | ||
@@ -354,3 +363,3 @@ | ||
const normalizedLayout = childDefinition && childIsCompObject(childDefinition) | ||
const normalizedLayout = childDefinition && (childIsCompositeCompObject(childDefinition) || childIsSlotCompObject(childDefinition)) | ||
? childDefinition | ||
@@ -360,2 +369,3 @@ : compiledLayout.normalizedLayouts[skeleton.pointer] | ||
const [display, cols] = getChildDisplay(parentDisplay, childDefinition?.cols ?? layout.cols) | ||
const slots = childDefinition?.slots ?? layout.slots | ||
@@ -554,5 +564,5 @@ const options = layout.getOptions | ||
let error = context.errors?.find(error => matchError(error, skeleton, dataPath, parentDataPath)) | ||
if (!error) { | ||
if (!error && context.rehydrate && context.rehydrateErrors) { | ||
// 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)) | ||
error = context.rehydrateErrors?.findLast(e => matchChildError(e, skeleton, dataPath, parentDataPath)) | ||
} | ||
@@ -564,5 +574,6 @@ | ||
logValidation(`${fullKey} capture validation error on node`, error) | ||
context.errors = context.errors?.filter(error => { | ||
return !matchError(error, skeleton, dataPath, parentDataPath) && !matchChildError(error, skeleton, dataPath, parentDataPath) | ||
}) | ||
context.errors = context.errors?.filter(e => error !== e) | ||
if (context.rehydrate && context.rehydrateErrors) { | ||
context.rehydrateErrors = context.rehydrateErrors?.filter(e => !matchChildError(e, skeleton, dataPath, parentDataPath)) | ||
} | ||
} | ||
@@ -693,2 +704,3 @@ } | ||
props, | ||
slots, | ||
itemsCacheKey, | ||
@@ -695,0 +707,0 @@ children && shallowProduceArray(reusedNode?.children, children) |
@@ -73,2 +73,5 @@ import { produce } from 'immer' | ||
} | ||
if (context.rehydrate && context.rehydrateErrors?.length) { | ||
logValidation(`${skeleton.root} some validation errors were not captured by a leaf property, try to capture on a parent`, context.rehydrateErrors) | ||
} | ||
const root = createStateNode( | ||
@@ -75,0 +78,0 @@ context, |
@@ -29,3 +29,4 @@ import { type ErrorObject } from 'ajv/dist/2019.js' | ||
type Child, | ||
type StateNodePropsLib | ||
type StateNodePropsLib, | ||
type Slots | ||
} from '@json-layout/vocabulary' | ||
@@ -54,2 +55,3 @@ import { type SkeletonTree, type SkeletonNode, type StatefulLayout, type CompiledLayout } from '../index.js' | ||
props?: StateNodePropsLib | ||
slots?: Slots | ||
itemsCacheKey: any | ||
@@ -67,2 +69,3 @@ children?: StateNode[] | ||
errors?: ErrorObject[] | ||
rehydrateErrors?: ErrorObject[] | ||
additionalPropertiesErrors?: ErrorObject[] | ||
@@ -69,0 +72,0 @@ files: FileRef[] |
import { type ErrorObject } from 'ajv/dist/2019.js'; | ||
import { type BaseCompObject, type Cols, type StateNodeOptionsBase, type TextField, type Textarea, type NumberField, type Slider, type Checkbox, type Switch, type DatePicker, type DateTimePicker, type TimePicker, type ColorPicker, type Section, type OneOfSelect, type Select, type Autocomplete, type Tabs, type VerticalTabs, type ExpansionPanels, type Stepper, type List, type Combobox, type FileInput, type Card, type Child, type StateNodePropsLib } from '@json-layout/vocabulary'; | ||
import { type BaseCompObject, type Cols, type StateNodeOptionsBase, type TextField, type Textarea, type NumberField, type Slider, type Checkbox, type Switch, type DatePicker, type DateTimePicker, type TimePicker, type ColorPicker, type Section, type OneOfSelect, type Select, type Autocomplete, type Tabs, type VerticalTabs, type ExpansionPanels, type Stepper, type List, type Combobox, type FileInput, type Card, type Child, type StateNodePropsLib, type Slots } from '@json-layout/vocabulary'; | ||
import { type SkeletonTree, type SkeletonNode, type StatefulLayout, type CompiledLayout } from '../index.js'; | ||
@@ -24,2 +24,3 @@ import { type LocaleMessages } from '../i18n/types.js'; | ||
props?: StateNodePropsLib; | ||
slots?: Slots; | ||
itemsCacheKey: any; | ||
@@ -35,2 +36,3 @@ children?: StateNode[]; | ||
errors?: ErrorObject[]; | ||
rehydrateErrors?: ErrorObject[]; | ||
additionalPropertiesErrors?: ErrorObject[]; | ||
@@ -37,0 +39,0 @@ files: FileRef[]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
181224
4059
+ Added@json-layout/vocabulary@1.3.0(transitive)
- Removed@json-layout/vocabulary@1.2.1(transitive)