@json-layout/core 0.35.0 → 1.0.0
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.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Compilation and state management utilities for JSON Layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://github.com/json-layout/json-layout#readme",
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@json-layout/vocabulary": "^0.
|
|
62
|
+
"@json-layout/vocabulary": "^1.0.0",
|
|
63
63
|
"ajv": "^8.12.0",
|
|
64
64
|
"ajv-errors": "^3.0.0",
|
|
65
65
|
"ajv-formats": "^2.1.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import Debug from 'debug'
|
|
2
|
-
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout } from '@json-layout/vocabulary'
|
|
2
|
+
import { normalizeLayoutFragment, isSwitchStruct, isGetItemsExpression, isGetItemsFetch, isItemsLayout, getSchemaFragmentType, isCompositeLayout, childIsCompObject } from '@json-layout/vocabulary'
|
|
3
3
|
import { makeSkeletonTree } from './skeleton-tree.js'
|
|
4
4
|
import { partialResolveRefs } from './utils/resolve-refs.js'
|
|
5
5
|
|
|
@@ -92,9 +92,23 @@ export function makeSkeletonNode (
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @param {import('@json-layout/vocabulary').Child} child
|
|
97
|
+
*/
|
|
98
|
+
const prepareLayoutChild = (child) => {
|
|
99
|
+
if (child.if) pushExpression(expressions, child.if)
|
|
100
|
+
if (childIsCompObject(child)) {
|
|
101
|
+
for (const grandChild of child.children) prepareLayoutChild(grandChild)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
const compObjects = isSwitchStruct(normalizedLayout) ? normalizedLayout.switch : [normalizedLayout]
|
|
106
|
+
|
|
96
107
|
for (const compObject of compObjects) {
|
|
97
108
|
if (compObject.if) pushExpression(expressions, compObject.if)
|
|
109
|
+
if (isCompositeLayout(compObject, options.components)) {
|
|
110
|
+
for (const child of compObject.children) prepareLayoutChild(child)
|
|
111
|
+
}
|
|
98
112
|
|
|
99
113
|
if (schema.const !== undefined && compObject.constData === undefined) compObject.constData = schema.const
|
|
100
114
|
if (compObject.constData !== undefined && !compObject.getConstData) compObject.getConstData = { type: 'js-eval', expr: 'layout.constData', pure: true, dataAlias: 'value' }
|
package/src/state/state-node.js
CHANGED
|
@@ -242,6 +242,7 @@ export function evalExpression (expressions, expression, data, options, display,
|
|
|
242
242
|
|
|
243
243
|
/**
|
|
244
244
|
* @param {import('@json-layout/vocabulary').NormalizedLayout} normalizedLayout
|
|
245
|
+
* @param {import('@json-layout/vocabulary').Child | null} childDefinition
|
|
245
246
|
* @param {import('./types.js').StateNodeOptions} options
|
|
246
247
|
* @param {import('../index.js').CompiledLayout} compiledLayout
|
|
247
248
|
* @param {import('./utils/display.js').Display} display
|
|
@@ -250,7 +251,7 @@ export function evalExpression (expressions, expression, data, options, display,
|
|
|
250
251
|
* @param {import('../compile/types.js').ParentContextExpression | null} parentContext
|
|
251
252
|
* @returns {import('@json-layout/vocabulary').BaseCompObject}
|
|
252
253
|
*/
|
|
253
|
-
const getCompObject = (normalizedLayout, options, compiledLayout, display, data, rootData, parentContext) => {
|
|
254
|
+
const getCompObject = (normalizedLayout, childDefinition, options, compiledLayout, display, data, rootData, parentContext) => {
|
|
254
255
|
if (isSwitchStruct(normalizedLayout)) {
|
|
255
256
|
for (const compObject of normalizedLayout.switch) {
|
|
256
257
|
if (!compObject.if || !!evalExpression(compiledLayout.expressions, compObject.if, data, options, display, compObject, compiledLayout.validates, rootData, parentContext)) {
|
|
@@ -258,13 +259,13 @@ const getCompObject = (normalizedLayout, options, compiledLayout, display, data,
|
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
261
|
} else {
|
|
261
|
-
if (normalizedLayout.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return normalizedLayout
|
|
262
|
+
if (childDefinition?.if && !evalExpression(compiledLayout.expressions, childDefinition.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) {
|
|
263
|
+
return { comp: 'none' }
|
|
264
|
+
}
|
|
265
|
+
if (normalizedLayout.if && !evalExpression(compiledLayout.expressions, normalizedLayout.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) {
|
|
266
|
+
return { comp: 'none' }
|
|
267
267
|
}
|
|
268
|
+
return normalizedLayout
|
|
268
269
|
}
|
|
269
270
|
return { comp: 'none' }
|
|
270
271
|
}
|
|
@@ -347,7 +348,7 @@ export function createStateNode (
|
|
|
347
348
|
const normalizedLayout = childDefinition && childIsCompObject(childDefinition)
|
|
348
349
|
? childDefinition
|
|
349
350
|
: compiledLayout.normalizedLayouts[skeleton.pointer]
|
|
350
|
-
const layout = getCompObject(normalizedLayout, parentOptions, compiledLayout, parentDisplay, data, context.rootData, parentContext)
|
|
351
|
+
const layout = getCompObject(normalizedLayout, childDefinition, parentOptions, compiledLayout, parentDisplay, data, context.rootData, parentContext)
|
|
351
352
|
const [display, cols] = getChildDisplay(parentDisplay, childDefinition?.cols ?? layout.cols)
|
|
352
353
|
|
|
353
354
|
const options = layout.getOptions
|