@json-layout/core 0.35.0 → 1.0.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.35.0",
3
+ "version": "1.0.1",
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.23.2",
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' }
@@ -467,14 +467,16 @@ export class StatefulLayout {
467
467
  * @param {StateNode} node
468
468
  */
469
469
  blur (node) {
470
- // debounced data is applied immediately on blur
471
- this.applyDebouncedInput()
472
-
473
470
  if (this._currentInput === node.fullKey) this._currentInput = null
474
471
 
475
- // re-apply once now that _currentInput was emptied to add default data
476
- if (node.layout.getDefaultData && useDefaultData(node.data, node.layout, node.options)) {
477
- this.applyInput(node, node.data, true)
472
+ // debounced data is applied immediately on blur
473
+ if (this.debouncedInput) {
474
+ this.applyDebouncedInput()
475
+ } else {
476
+ // re-apply once now that _currentInput was emptied to add default data
477
+ if (node.layout.getDefaultData && useDefaultData(node.data, node.layout, node.options)) {
478
+ this.applyInput(node, node.data, true)
479
+ }
478
480
  }
479
481
 
480
482
  logDataBinding('received blur event from node', node)
@@ -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.if) {
262
- if (evalExpression(compiledLayout.expressions, normalizedLayout.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) {
263
- return normalizedLayout
264
- }
265
- } else {
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
@@ -1 +1 @@
1
- {"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,4CAlBW,GAAG,kBACH,MAAM,WACN,OAAO,YAAY,EAAE,cAAc,yBACxB,MAAM,OAAO,MAAM,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,iBACxD,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,iBACjD,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,oBACjD,MAAM,EAAE,oBACR,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,qBACxB,OAAO,MAAM,EAAE,OAAO,yBAAyB,EAAE,gBAAgB,CAAC,eAClE,OAAO,yBAAyB,EAAE,UAAU,EAAE,OAC9C,MAAM,GAAG,MAAM,WACf,MAAM,YACN,OAAO,oGAIL,OAAO,YAAY,EAAE,YAAY,CAse7C"}
1
+ {"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,4CAlBW,GAAG,kBACH,MAAM,WACN,OAAO,YAAY,EAAE,cAAc,yBACxB,MAAM,OAAO,MAAM,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,iBACxD,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,iBACjD,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,YAAY,CAAC,oBACjD,MAAM,EAAE,oBACR,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,qBACxB,OAAO,MAAM,EAAE,OAAO,yBAAyB,EAAE,gBAAgB,CAAC,eAClE,OAAO,yBAAyB,EAAE,UAAU,EAAE,OAC9C,MAAM,GAAG,MAAM,WACf,MAAM,YACN,OAAO,oGAIL,OAAO,YAAY,EAAE,YAAY,CAof7C"}
@@ -1 +1 @@
1
- {"version":3,"file":"state-node.d.ts","sourceRoot":"","sources":["../../src/state/state-node.js"],"names":[],"mappings":"AAgNA;;;;;;;;;;;GAWG;AACH,4CAXW,OAAO,aAAa,EAAE,kBAAkB,EAAE,cAC1C,OAAO,yBAAyB,EAAE,UAAU,QAC5C,GAAG,WACH,OAAO,YAAY,EAAE,gBAAgB,WACrC,OAAO,oBAAoB,EAAE,OAAO,UACpC,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