@json-layout/core 0.30.0 → 0.30.1

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": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "Compilation and state management utilities for JSON Layout.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,5 +1,5 @@
1
1
  // import Debug from 'debug'
2
- import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType } from '@json-layout/vocabulary'
2
+ import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout } from '@json-layout/vocabulary'
3
3
  import { makeSkeletonTree } from './skeleton-tree.js'
4
4
  import { partialResolveRefs } from './utils/resolve-refs.js'
5
5
 
@@ -74,14 +74,6 @@ export function makeSkeletonNode (
74
74
  }
75
75
  const normalizedLayout = normalizedLayouts[pointer]
76
76
 
77
- let defaultData
78
- if ('default' in schema) defaultData = schema.default
79
- else if (required) {
80
- if (nullable) defaultData = null
81
- else if (type === 'object') defaultData = {}
82
- else if (type === 'array') defaultData = []
83
- }
84
-
85
77
  let pure = !dependent
86
78
  /**
87
79
  * @param {import('@json-layout/vocabulary').Expression[]} expressions
@@ -106,6 +98,13 @@ export function makeSkeletonNode (
106
98
  if (compObject.constData !== undefined && !compObject.getConstData) compObject.getConstData = { type: 'js-eval', expr: 'layout.constData', pure: true, dataAlias: 'value' }
107
99
  if (compObject.getConstData) pushExpression(expressions, compObject.getConstData)
108
100
 
101
+ let defaultData
102
+ if ('default' in schema) defaultData = schema.default
103
+ else if (required) {
104
+ if (nullable) defaultData = null
105
+ else if (type === 'object' && isCompositeLayout(compObject, options.components)) defaultData = {}
106
+ else if (type === 'array') defaultData = []
107
+ }
109
108
  if (defaultData !== undefined && compObject.defaultData === undefined) compObject.defaultData = defaultData
110
109
  if (compObject.defaultData !== undefined && !compObject.getDefaultData) compObject.getDefaultData = { type: 'js-eval', expr: 'layout.defaultData', pure: true, dataAlias: 'value' }
111
110
  if (compObject.getDefaultData) pushExpression(expressions, compObject.getDefaultData)