@json-layout/core 1.12.0 → 1.12.2
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.12.
|
|
3
|
+
"version": "1.12.2",
|
|
4
4
|
"description": "Compilation and state management utilities for JSON Layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"LICENSE"
|
|
54
54
|
],
|
|
55
55
|
"scripts": {
|
|
56
|
-
"test:only": "node --
|
|
57
|
-
"test": "mkdir -p tmp && node --
|
|
56
|
+
"test:only": "node --test --test-only test/*.spec.js",
|
|
57
|
+
"test": "mkdir -p tmp && node --test test/*.spec.js",
|
|
58
58
|
"build": "rm -rf ./types && tsc -p tsconfig.build.json",
|
|
59
59
|
"watch:build": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
60
|
-
"watch:test": "node --
|
|
60
|
+
"watch:test": "node --test --watch test/*.spec.js"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|
|
63
63
|
"type": "git",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"homepage": "https://github.com/json-layout/json-layout#readme",
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@json-layout/vocabulary": "^2.
|
|
79
|
+
"@json-layout/vocabulary": "^2.5.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"ajv": "^8.17.1",
|
package/src/state/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export const isItemsNode = (node, components) => !!node && isItemsLayout(node.la
|
|
|
51
51
|
|
|
52
52
|
const logDataBinding = debug('jl:data-binding')
|
|
53
53
|
const logSelectItems = debug('jl:select-items')
|
|
54
|
+
const logGetItems = debug('jl:get-items')
|
|
54
55
|
const logActivatedItems = debug('jl:activated-items')
|
|
55
56
|
|
|
56
57
|
export class StatefulLayout {
|
|
@@ -316,10 +317,13 @@ export class StatefulLayout {
|
|
|
316
317
|
this.activatedItems = produce(this.activatedItems, draft => { draft[activatedKey] = createStateTreeContext.autoActivatedItems[activatedKey] })
|
|
317
318
|
}
|
|
318
319
|
for (const node of createStateTreeContext.getItemsDataRequests) {
|
|
320
|
+
logGetItems(node.fullKey, 'automatic get items triggered')
|
|
319
321
|
this.getItems(node).then(items => {
|
|
322
|
+
logGetItems(node.fullKey, 'automatic get items, fetched results', items)
|
|
320
323
|
const rawData = /** @type {any[]} */(node.data ?? [])
|
|
321
324
|
const existingItems = rawData.map(item => this.prepareSelectItem(node, item))
|
|
322
325
|
const data = produceListData(rawData, existingItems, items)
|
|
326
|
+
logGetItems(node.fullKey, 'automatic get items, input produced data', data)
|
|
323
327
|
this.input(node, data)
|
|
324
328
|
}, err => console.error('error fetching items', node.fullKey, err))
|
|
325
329
|
}
|
|
@@ -417,7 +421,7 @@ export class StatefulLayout {
|
|
|
417
421
|
}
|
|
418
422
|
|
|
419
423
|
if (activateKey !== undefined) {
|
|
420
|
-
logActivatedItems('activated item on input',
|
|
424
|
+
logActivatedItems(node.fullKey, 'activated item on input', activateKey)
|
|
421
425
|
this.activatedItems = produce(this.activatedItems, draft => { draft[node.fullKey] = activateKey })
|
|
422
426
|
this._autofocusTarget = node.fullKey + '/' + activateKey
|
|
423
427
|
}
|
|
@@ -557,10 +561,10 @@ export class StatefulLayout {
|
|
|
557
561
|
let rawItems
|
|
558
562
|
if (node.layout.items || (node.layout.getItems && isGetItemsExpression(node.layout.getItems))) {
|
|
559
563
|
rawItems = node.itemsCacheKey
|
|
560
|
-
|
|
564
|
+
logGetItems(node.fullKey, 'raw items from context or schema or getItems expression', rawItems)
|
|
561
565
|
}
|
|
562
566
|
if (node.layout.getItems && isGetItemsFetch(node.layout.getItems)) {
|
|
563
|
-
|
|
567
|
+
logGetItems(node.fullKey, 'will fetch raw items from URL', node.itemsCacheKey)
|
|
564
568
|
const url = new URL(node.itemsCacheKey)
|
|
565
569
|
/** @type {Record<string, string> | null} */
|
|
566
570
|
let headers = null
|
|
@@ -578,7 +582,7 @@ export class StatefulLayout {
|
|
|
578
582
|
}
|
|
579
583
|
}
|
|
580
584
|
if (qSearchParam) {
|
|
581
|
-
|
|
585
|
+
logGetItems(node.fullKey, 'apply search params', qSearchParam)
|
|
582
586
|
appliedQ = true
|
|
583
587
|
if (q) url.searchParams.set(qSearchParam, q)
|
|
584
588
|
else url.searchParams.delete(qSearchParam)
|
|
@@ -586,7 +590,7 @@ export class StatefulLayout {
|
|
|
586
590
|
let fetchOptions = typeof node.options.fetchOptions === 'function' ? node.options.fetchOptions(url) : node.options.fetchOptions
|
|
587
591
|
if (headers) fetchOptions = { ...fetchOptions, headers }
|
|
588
592
|
rawItems = await node.options.fetch(url.href, fetchOptions)
|
|
589
|
-
|
|
593
|
+
logGetItems(node.fullKey, 'raw items fetched from URL', rawItems)
|
|
590
594
|
}
|
|
591
595
|
|
|
592
596
|
if (!rawItems) {
|
|
@@ -594,7 +598,7 @@ export class StatefulLayout {
|
|
|
594
598
|
}
|
|
595
599
|
if (node.layout.getItems?.itemsResults) {
|
|
596
600
|
rawItems = this.evalNodeExpression(node, node.layout.getItems.itemsResults, rawItems)
|
|
597
|
-
|
|
601
|
+
logGetItems(node.fullKey, 'items passed through the getItems.itemsResults expression', rawItems)
|
|
598
602
|
}
|
|
599
603
|
|
|
600
604
|
if (!Array.isArray(rawItems)) throw new Error(`getItems didn't return an array for node ${node.fullKey}, you can define itemsResults to extract the array`)
|
|
@@ -657,7 +661,7 @@ export class StatefulLayout {
|
|
|
657
661
|
}
|
|
658
662
|
if (layout.getItems?.itemIcon) item.icon = this.evalNodeExpression(node, layout.getItems?.itemIcon, rawItem)
|
|
659
663
|
|
|
660
|
-
logSelectItems(
|
|
664
|
+
logSelectItems('select item after applying itemValue/itemKey/itemTitle/itemIcon expressions', node.fullKey, item)
|
|
661
665
|
return /** @type {import('@json-layout/vocabulary').SelectItem} */(item)
|
|
662
666
|
}
|
|
663
667
|
|
|
@@ -671,7 +675,7 @@ export class StatefulLayout {
|
|
|
671
675
|
* @param {number} key
|
|
672
676
|
*/
|
|
673
677
|
activateItem (node, key) {
|
|
674
|
-
logActivatedItems('activate item explicitly',
|
|
678
|
+
logActivatedItems(node.fullKey, 'activate item explicitly', key)
|
|
675
679
|
this.activatedItems = produce(this.activatedItems, draft => { draft[node.fullKey] = key })
|
|
676
680
|
this._autofocusTarget = node.fullKey + '/' + key
|
|
677
681
|
if (node.key === '$oneOf') {
|
|
@@ -681,7 +685,7 @@ export class StatefulLayout {
|
|
|
681
685
|
if (!parentNode.data || typeof parentNode.data !== 'object') throw new Error(`parent with key "${node.parentFullKey}" is missing data object`)
|
|
682
686
|
/** @type {Record<string, any>} */
|
|
683
687
|
const newParentData = { ...parentNode.data }
|
|
684
|
-
logActivatedItems('remove properties of previous oneOf activated item', node.
|
|
688
|
+
logActivatedItems(node.fullKey, 'remove properties of previous oneOf activated item', node.children?.[0].fullKey)
|
|
685
689
|
for (const propertyKey of node.children?.[0].skeleton.propertyKeys) {
|
|
686
690
|
delete newParentData[propertyKey]
|
|
687
691
|
}
|
|
@@ -699,12 +703,12 @@ export class StatefulLayout {
|
|
|
699
703
|
* @param {StateNode} node
|
|
700
704
|
*/
|
|
701
705
|
deactivateItem (node) {
|
|
702
|
-
logActivatedItems('deactivate item explicitly'
|
|
706
|
+
logActivatedItems(node.fullKey, 'deactivate item explicitly')
|
|
703
707
|
// also deactivate children oneOf for example
|
|
704
708
|
this.activatedItems = produce(this.activatedItems, draft => {
|
|
705
709
|
for (const key in draft) {
|
|
706
710
|
if (key.startsWith(node.fullKey)) {
|
|
707
|
-
logActivatedItems('item deactivation deletes a key', key)
|
|
711
|
+
logActivatedItems(node.fullKey, 'item deactivation deletes a key', key)
|
|
708
712
|
delete draft[key]
|
|
709
713
|
}
|
|
710
714
|
}
|
package/src/state/state-node.js
CHANGED
|
@@ -8,6 +8,7 @@ import { pathURL } from './utils/urls.js'
|
|
|
8
8
|
|
|
9
9
|
const logStateNode = debug('jl:state-node')
|
|
10
10
|
const logValidation = debug('jl:validation')
|
|
11
|
+
const logGetItems = debug('jl:get-items')
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @param {unknown} data
|
|
@@ -381,6 +382,9 @@ export function createStateNode (
|
|
|
381
382
|
logStateNode('createStateNode cache hit', fullKey)
|
|
382
383
|
// @ts-ignore
|
|
383
384
|
if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['hit'])
|
|
385
|
+
if (reusedNode.layout.comp === 'list' && reusedNode.layout.getItems) {
|
|
386
|
+
logGetItems(fullKey, 'list component node is fully reused from cache, no fetch will be triggered')
|
|
387
|
+
}
|
|
384
388
|
return reusedNode
|
|
385
389
|
} else {
|
|
386
390
|
logStateNode('createStateNode cache miss', fullKey)
|
|
@@ -766,6 +770,11 @@ export function createStateNode (
|
|
|
766
770
|
|
|
767
771
|
const autofocus = isFocusableLayout(layout, compiledLayout.components) && !options.readOnly && !options.summary && context.autofocusTarget === fullKey
|
|
768
772
|
const shouldLoadData = layout.comp === 'list' && itemsCacheKey && reusedNode?.itemsCacheKey !== itemsCacheKey
|
|
773
|
+
if (shouldLoadData) {
|
|
774
|
+
logGetItems(fullKey, 'list component with getItems expression registered for fetch', itemsCacheKey)
|
|
775
|
+
} else if (layout.comp === 'list' && itemsCacheKey) {
|
|
776
|
+
logGetItems(fullKey, 'list component with unchanged getItems cache key, no fetch will be triggered', itemsCacheKey)
|
|
777
|
+
}
|
|
769
778
|
const node = produceStateNode(
|
|
770
779
|
reusedNode ?? /** @type {import('./types.js').StateNode} */({}),
|
|
771
780
|
key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.js"],"names":[],"mappings":";;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+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