@json-layout/core 1.10.10 → 1.10.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-layout/core",
3
- "version": "1.10.10",
3
+ "version": "1.10.11",
4
4
  "description": "Compilation and state management utilities for JSON Layout.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -187,7 +187,7 @@ const produceCompositeChildrenOptions = produce((draft, section) => {
187
187
  * @param {string | null} parentDataPath
188
188
  * @returns {boolean}
189
189
  */
190
- const matchError = (error, skeleton, dataPath, parentDataPath) => {
190
+ const matchLocalError = (error, skeleton, dataPath, parentDataPath) => {
191
191
  const originalError = error.params?.errors?.[0] ?? error
192
192
  if (parentDataPath === originalError.instancePath && originalError.params?.missingProperty === skeleton.key) {
193
193
  return true
@@ -204,22 +204,51 @@ const matchError = (error, skeleton, dataPath, parentDataPath) => {
204
204
 
205
205
  /**
206
206
  * should match if an error belongs to a child of the current node but the child was not displayed
207
+ * @param {import('../index.js').CompiledLayout} compiledLayout
207
208
  * @param {import('ajv').ErrorObject} error
208
209
  * @param {import('../index.js').SkeletonNode} skeleton
209
210
  * @param {string} dataPath
210
211
  * @param {string | null} parentDataPath
211
212
  * @returns {boolean}
212
213
  */
213
- const matchChildError = (error, skeleton, dataPath, parentDataPath) => {
214
+ const matchChildError = (compiledLayout, error, skeleton, dataPath, parentDataPath) => {
214
215
  const originalError = error.params?.errors?.[0] ?? error
215
- if (!(
216
- originalError.schemaPath === skeleton.pointer ||
217
- originalError.schemaPath.startsWith(skeleton.pointer + '/')
218
- ) && !(
219
- originalError.schemaPath === skeleton.refPointer ||
220
- originalError.schemaPath.startsWith(skeleton.refPointer + '/')
221
- )) return false
222
- if (originalError.instancePath.startsWith(dataPath)) return true
216
+ if (!originalError.instancePath.startsWith(dataPath)) return false
217
+ if (originalError.schemaPath === skeleton.pointer || originalError.schemaPath.startsWith(skeleton.pointer + '/') || originalError.schemaPath === skeleton.refPointer || originalError.schemaPath.startsWith(skeleton.refPointer + '/')) return true
218
+ if (skeleton.children) {
219
+ for (const c of skeleton.children) {
220
+ const childSkeleton = compiledLayout.skeletonNodes[c]
221
+ if (!childSkeleton) continue
222
+ if (matchPointerError(error, childSkeleton.pointer, childSkeleton.refPointer, dataPath, parentDataPath)) return true
223
+ }
224
+ }
225
+ if (skeleton.childrenTrees) {
226
+ for (const c of skeleton.childrenTrees) {
227
+ const childTree = compiledLayout.skeletonTrees[c]
228
+ if (!childTree) continue
229
+ if (matchPointerError(error, childTree.root, childTree.refPointer, dataPath, parentDataPath)) return true
230
+ }
231
+ }
232
+ return false
233
+ }
234
+
235
+ /**
236
+ * should match if an error belongs to a child of the current node but the child was not displayed
237
+ * @param {import('ajv').ErrorObject} error
238
+ * @param {string} pointer1
239
+ * @param {string} pointer2
240
+ * @param {string} dataPath
241
+ * @param {string | null} parentDataPath
242
+ * @returns {boolean}
243
+ */
244
+ const matchPointerError = (error, pointer1, pointer2, dataPath, parentDataPath) => {
245
+ const originalError = error.params?.errors?.[0] ?? error
246
+ if (!originalError.instancePath.startsWith(dataPath)) return false
247
+ if (originalError.schemaPath === pointer1 ||
248
+ originalError.schemaPath.startsWith(pointer2 + '/') ||
249
+ originalError.schemaPath === pointer2 ||
250
+ originalError.schemaPath.startsWith(pointer2 + '/')
251
+ ) return true
223
252
  return false
224
253
  }
225
254
 
@@ -445,29 +474,33 @@ export function createStateNode (
445
474
  const validChildTreeIndex = skeleton.childrenTrees?.findIndex((childTree) => compiledLayout.validates[compiledLayout.skeletonTrees[childTree].refPointer](data))
446
475
  const activeChildTreeIndex = /** @type {number} */(fullKey in context.activatedItems ? context.activatedItems[fullKey] : validChildTreeIndex)
447
476
  if (activeChildTreeIndex !== -1) {
477
+ const activeChildTree = compiledLayout.skeletonTrees[skeleton.childrenTrees[activeChildTreeIndex]]
478
+ const activeChildNode = compiledLayout.skeletonNodes[activeChildTree.root]
448
479
  if (!(fullKey in context.activatedItems)) context.autoActivatedItems[fullKey] = activeChildTreeIndex
449
480
  context.errors = context.errors?.filter(error => {
450
- const originalError = error.params?.errors?.[0] ?? error
451
481
  // if an item was selected, remove the oneOf error
452
- if (matchError(error, skeleton, dataPath, parentDataPath)) return false
482
+ if (matchLocalError(error, skeleton, dataPath, parentDataPath)) {
483
+ return false
484
+ }
453
485
  // also remove the errors from other children of the oneOf
454
- if (matchChildError(error, skeleton, dataPath, parentDataPath)) {
455
- if (originalError.schemaPath.startsWith(skeleton.pointer) && !originalError.schemaPath.startsWith(skeleton.pointer + '/' + activeChildTreeIndex)) return false
456
- if (originalError.schemaPath.startsWith(skeleton.refPointer) && !originalError.schemaPath.startsWith(skeleton.refPointer + '/' + activeChildTreeIndex)) return false
486
+ if (matchChildError(compiledLayout, error, skeleton, dataPath, parentDataPath) && !matchPointerError(error, activeChildNode.pointer, activeChildNode.refPointer, dataPath, parentDataPath)) {
487
+ return false
457
488
  }
458
489
  return true
459
490
  })
460
- if (context.additionalPropertiesErrors && validChildTreeIndex === -1) {
491
+ if (context.additionalPropertiesErrors) {
461
492
  // remove additional properties errors if the oneOf has no valid children
462
493
  context.additionalPropertiesErrors = context.additionalPropertiesErrors?.filter(error => {
463
- const originalError = error.params?.errors?.[0] ?? error
464
- if (originalError.instancePath === parentDataPath) return false
494
+ // also remove the additional errors from other children of the oneOf
495
+ if (matchChildError(compiledLayout, error, skeleton, dataPath, parentDataPath) && !matchPointerError(error, activeChildNode.pointer, activeChildNode.refPointer, dataPath, parentDataPath)) {
496
+ return false
497
+ }
465
498
  return true
466
499
  })
467
500
  }
468
501
  const activeChildKey = `${fullKey}/${activeChildTreeIndex}`
469
502
  if (context.autofocusTarget === fullKey) context.autofocusTarget = activeChildKey
470
- const activeChildTree = compiledLayout.skeletonTrees[skeleton.childrenTrees[activeChildTreeIndex]]
503
+
471
504
  children = [
472
505
  createStateNode(
473
506
  context,
@@ -478,7 +511,7 @@ export function createStateNode (
478
511
  fullKey,
479
512
  dataPath,
480
513
  dataPath,
481
- compiledLayout.skeletonNodes[activeChildTree.root],
514
+ activeChildNode,
482
515
  null,
483
516
  display,
484
517
  data,
@@ -569,14 +602,14 @@ export function createStateNode (
569
602
  }
570
603
  }
571
604
 
572
- let error = context.errors?.find(e => matchError(e, skeleton, dataPath, parentDataPath))
605
+ let error = context.errors?.find(e => matchLocalError(e, skeleton, dataPath, parentDataPath))
573
606
 
574
607
  // findLast in following lines is important because we want to keep the error of the highest child (deepest errors are listed first)
575
608
  if (!error && !isCompositeLayout(layout, compiledLayout.components) && layout.comp !== 'slot') {
576
- error = context.errors?.findLast(e => matchChildError(e, skeleton, dataPath, parentDataPath))
609
+ error = context.errors?.findLast(e => matchChildError(compiledLayout, e, skeleton, dataPath, parentDataPath))
577
610
  }
578
611
  if (!error && context.rehydrate && context.rehydrateErrors) {
579
- error = context.rehydrateErrors?.findLast(e => matchChildError(e, skeleton, dataPath, parentDataPath))
612
+ error = context.rehydrateErrors?.findLast(e => matchChildError(compiledLayout, e, skeleton, dataPath, parentDataPath))
580
613
  }
581
614
 
582
615
  // capture errors so that they are not repeated in parent nodes
@@ -585,10 +618,10 @@ export function createStateNode (
585
618
  logValidation(`${fullKey} capture validation error on node`, error)
586
619
  context.errors = context.errors?.filter(e => error !== e)
587
620
  if (!isCompositeLayout(layout, compiledLayout.components) && layout.comp !== 'slot') {
588
- context.errors = context.errors?.filter(e => !matchChildError(e, skeleton, dataPath, parentDataPath))
621
+ context.errors = context.errors?.filter(e => !matchChildError(compiledLayout, e, skeleton, dataPath, parentDataPath))
589
622
  }
590
623
  if (context.rehydrate && context.rehydrateErrors) {
591
- context.rehydrateErrors = context.rehydrateErrors?.filter(e => !matchChildError(e, skeleton, dataPath, parentDataPath))
624
+ context.rehydrateErrors = context.rehydrateErrors?.filter(e => !matchChildError(compiledLayout, e, skeleton, dataPath, parentDataPath))
592
625
  }
593
626
  }
594
627
  }
@@ -1 +1 @@
1
- {"version":3,"file":"state-node.d.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