@json-layout/core 0.11.0 → 0.13.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 +2 -2
- package/src/state/index.js +46 -4
- package/src/state/state-node.js +4 -1
- package/src/utils/doc-options.js +5 -0
- package/types/state/index.d.ts +13 -0
- package/types/state/index.d.ts.map +1 -1
- package/types/state/state-node.d.ts.map +1 -1
- package/types/utils/doc-options.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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": "^0.13.0",
|
|
63
63
|
"@types/markdown-it": "^13.0.1",
|
|
64
64
|
"ajv": "^8.12.0",
|
|
65
65
|
"ajv-errors": "^3.0.0",
|
package/src/state/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { produce } from 'immer'
|
|
|
5
5
|
import { evalExpression, producePatchedData } from './state-node.js'
|
|
6
6
|
import { createStateTree } from './state-tree.js'
|
|
7
7
|
import { Display } from './utils/display.js'
|
|
8
|
-
import { isFileLayout, isGetItemsExpression, isGetItemsFetch, isItemsLayout } from '@json-layout/vocabulary'
|
|
8
|
+
import { isFileLayout, isGetItemsExpression, isGetItemsFetch, isItemsLayout, editableCompNames } from '@json-layout/vocabulary'
|
|
9
9
|
import { shallowProduceArray } from './utils/immutable.js'
|
|
10
10
|
|
|
11
11
|
export { Display } from './utils/display.js'
|
|
@@ -74,6 +74,7 @@ function fillOptions (partialOptions, compiledLayout) {
|
|
|
74
74
|
removeAdditional: 'error',
|
|
75
75
|
autofocus: false,
|
|
76
76
|
readOnlyPropertiesMode: 'show',
|
|
77
|
+
debounceInputMs: 300,
|
|
77
78
|
...partialOptions,
|
|
78
79
|
messages
|
|
79
80
|
}
|
|
@@ -342,11 +343,12 @@ export class StatefulLayout {
|
|
|
342
343
|
}
|
|
343
344
|
|
|
344
345
|
/**
|
|
346
|
+
* @private
|
|
345
347
|
* @param {StateNode} node
|
|
346
348
|
* @param {unknown} data
|
|
347
349
|
* @param {number} [activateKey]
|
|
348
350
|
*/
|
|
349
|
-
|
|
351
|
+
applyInput (node, data, activateKey) {
|
|
350
352
|
logDataBinding('received input event from node', node, data)
|
|
351
353
|
|
|
352
354
|
const transformedData = node.layout.transformData && this.evalNodeExpression(node, node.layout.transformData, data)
|
|
@@ -370,7 +372,10 @@ export class StatefulLayout {
|
|
|
370
372
|
data = transformedData
|
|
371
373
|
}
|
|
372
374
|
|
|
373
|
-
if (
|
|
375
|
+
if (
|
|
376
|
+
(node.options.validateOn === 'input' || (node.options.validateOne === 'blur' && !editableCompNames.includes(node.layout.comp))) &&
|
|
377
|
+
!this.validationState.validatedChildren.includes(node.fullKey)
|
|
378
|
+
) {
|
|
374
379
|
this.validationState = { validatedChildren: this.validationState.validatedChildren.concat([node.fullKey]) }
|
|
375
380
|
}
|
|
376
381
|
if (activateKey !== undefined) {
|
|
@@ -385,17 +390,54 @@ export class StatefulLayout {
|
|
|
385
390
|
const parentNode = this._lastCreateStateTreeContext.nodes.find(p => p.fullKey === node.parentFullKey)
|
|
386
391
|
if (!parentNode) throw new Error(`parent with key "${node.parentFullKey}" not found`)
|
|
387
392
|
const newParentValue = producePatchedData(parentNode.data ?? (typeof node.key === 'number' ? [] : {}), node, data)
|
|
388
|
-
this.
|
|
393
|
+
this.applyInput(parentNode, newParentValue)
|
|
389
394
|
|
|
390
395
|
if (activateKey !== undefined) {
|
|
391
396
|
this.handleAutofocus()
|
|
392
397
|
}
|
|
393
398
|
}
|
|
394
399
|
|
|
400
|
+
/**
|
|
401
|
+
* @private
|
|
402
|
+
* @type {null | [StateNode, unknown, number | undefined, ReturnType<typeof setTimeout>]}
|
|
403
|
+
*/
|
|
404
|
+
debouncedInput = null
|
|
405
|
+
|
|
406
|
+
applyDebouncedInput () {
|
|
407
|
+
if (this.debouncedInput) {
|
|
408
|
+
clearTimeout(this.debouncedInput[3])
|
|
409
|
+
this.applyInput(this.debouncedInput[0], this.debouncedInput[1], this.debouncedInput[2])
|
|
410
|
+
this.debouncedInput = null
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @param {StateNode} node
|
|
416
|
+
* @param {unknown} data
|
|
417
|
+
* @param {number} [activateKey]
|
|
418
|
+
*/
|
|
419
|
+
input (node, data, activateKey) {
|
|
420
|
+
// debounced data from the same node is cancelled if a new input is received
|
|
421
|
+
// debounced data from another node is applied immediately
|
|
422
|
+
if (this.debouncedInput) {
|
|
423
|
+
if (this.debouncedInput[0] === node) clearTimeout(this.debouncedInput[3])
|
|
424
|
+
else this.applyDebouncedInput()
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (editableCompNames.includes(node.layout.comp) && node.options.debounceInputMs) {
|
|
428
|
+
this.debouncedInput = [node, data, activateKey, setTimeout(() => this.applyDebouncedInput(), node.options.debounceInputMs)]
|
|
429
|
+
} else {
|
|
430
|
+
this.applyInput(node, data, activateKey)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
395
434
|
/**
|
|
396
435
|
* @param {StateNode} node
|
|
397
436
|
*/
|
|
398
437
|
blur (node) {
|
|
438
|
+
// debounced data is applied immediately on blur
|
|
439
|
+
this.applyDebouncedInput()
|
|
440
|
+
|
|
399
441
|
logDataBinding('received blur event from node', node)
|
|
400
442
|
if (
|
|
401
443
|
(node.options.validateOn === 'input' || node.options.validateOn === 'blur') &&
|
package/src/state/state-node.js
CHANGED
|
@@ -247,7 +247,10 @@ export function createStateNode (
|
|
|
247
247
|
) {
|
|
248
248
|
/** @type {import('./types.js').StateNodeCacheKey | null} */
|
|
249
249
|
let cacheKey = null
|
|
250
|
-
|
|
250
|
+
|
|
251
|
+
// NOTE we have to exclude nodes with errors from the cache, because context.errors is unpurely modified
|
|
252
|
+
// TODO: implement a cleaner way to filter context.errors while being able to reuse nodes with errors
|
|
253
|
+
if (skeleton.pure && reusedNode && !reusedNode.error && !reusedNode.childError) {
|
|
251
254
|
cacheKey = [parentOptions, compiledLayout, fullKey, skeleton, childDefinition, parentDisplay.width, validationState, context.activeItems, context.initial, data]
|
|
252
255
|
if (context.cacheKeys[fullKey] && shallowEqualArray(context.cacheKeys[fullKey], cacheKey)) return reusedNode
|
|
253
256
|
}
|
package/src/utils/doc-options.js
CHANGED
|
@@ -123,5 +123,10 @@ export const runtimeOptions = [
|
|
|
123
123
|
hide: 'Hide the readOnly properties but keep them in the data.',
|
|
124
124
|
show: 'Show the readOnly properties.'
|
|
125
125
|
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
key: 'debounceInputMs',
|
|
129
|
+
description: 'The debounce time for the input event of editable fields.',
|
|
130
|
+
default: 300
|
|
126
131
|
}
|
|
127
132
|
]
|
package/types/state/index.d.ts
CHANGED
|
@@ -167,6 +167,19 @@ export class StatefulLayout {
|
|
|
167
167
|
* @returns {any}
|
|
168
168
|
*/
|
|
169
169
|
private evalNodeExpression;
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
* @param {StateNode} node
|
|
173
|
+
* @param {unknown} data
|
|
174
|
+
* @param {number} [activateKey]
|
|
175
|
+
*/
|
|
176
|
+
private applyInput;
|
|
177
|
+
/**
|
|
178
|
+
* @private
|
|
179
|
+
* @type {null | [StateNode, unknown, number | undefined, ReturnType<typeof setTimeout>]}
|
|
180
|
+
*/
|
|
181
|
+
private debouncedInput;
|
|
182
|
+
applyDebouncedInput(): void;
|
|
170
183
|
/**
|
|
171
184
|
* @param {StateNode} node
|
|
172
185
|
* @param {unknown} data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.js"],"names":[],"mappings":";AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,mEAAmE;AACnE,+BADkB,SAAS,GAAG,SAAS,8CACoC;AAE3E,oGAAoG;AACpG,iCADkB,SAAS,GAAG,SAAS,yHACkC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state/index.js"],"names":[],"mappings":";AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,mEAAmE;AACnE,+BADkB,SAAS,GAAG,SAAS,8CACoC;AAE3E,oGAAoG;AACpG,iCADkB,SAAS,GAAG,SAAS,yHACkC;AAmCzE;IAoHE;;;;;OAKG;IACH,4BALW,OAAO,aAAa,EAAE,cAAc,gBACpC,OAAO,aAAa,EAAE,YAAY,WAClC,QAAQ,qBAAqB,CAAC,SAC9B,OAAO,EAejB;IAtID;;;OAGG;IACH,iBAFU,OAAO,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAEhD;IAEN;;;;OAIG;IACH,iCAAe;IACf,mEAAqD;IAErD;;;OAGG;IAEH,mBAAU;IACV,gDAA2C;IAE3C;;;OAGG;IACH,uBAFU,OAAO,aAAa,EAAE,YAAY,CAEhC;IAEZ;;;OAGG;IAEH,iBAAQ;IACR,uBAAuC;IAEvC;;;OAGG;IAEH,yBAAgB;IAQhB;;;OAGG;IACH,+DAOC;IAlBD;;OAEG;IACH,4DAEC;IAeD;;;OAGG;IAEH,iBAAQ;IAKR;;OAEG;IACH,6DAGC;IAVD;;OAEG;IACH,0DAAuC;IASvC;;;OAGG;IACH,cAAK;IAEL,uBAIC;IALD,oBAAiC;IAOjC;;;OAGG;IAEH,oCAA2B;IAE3B;;;OAGG;IACH,yBAAgB;IAChB;;;OAGG;IACH,iCAAwB;IAExB;;OAEG;IACH,OAFU,OAAO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AE,eAAe;6BACpC,OAAO,YAAY,EAAE,cAAc;iCACnC,OAAO,YAAY,EAAE,kBAAkB;6BACvC,OAAO,YAAY,EAAE,cAAc;kCACnC,OAAO,YAAY,EAAE,mBAAmB;uBACxC,OAAO,YAAY,EAAE,QAAQ;+BAC7B,OAAO,YAAY,EAAE,gBAAgB;0BACrC,OAAO,YAAY,EAAE,WAAW;8BAChC,OAAO,YAAY,EAAE,eAAe;uBACpC,OAAO,YAAY,EAAE,QAAQ;4BAC7B,OAAO,YAAY,EAAE,aAAa;2BAClC,OAAO,YAAY,EAAE,YAAY;sBACjC,OAAO,YAAY,EAAE,OAAO;wBAlCjB,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-node.d.ts","sourceRoot":"","sources":["../../src/state/state-node.js"],"names":[],"mappings":"AAqKA;;;;;;;;;;GAUG;AACH,4CAVW,OAAO,aAAa,EAAE,kBAAkB,EAAE,cAC1C,OAAO,yBAAyB,EAAE,UAAU,QAC5C,GAAG,WACH,OAAO,YAAY,EAAE,gBAAgB,WACrC,OAAO,oBAAoB,EAAE,OAAO,UACpC,OAAO,yBAAyB,EAAE,UAAU,YAC5C,OAAO,cACP,OAAO,GACL,GAAG,CAMf;AA+BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,yCAjBW,OAAO,YAAY,EAAE,sBAAsB,iBAC3C,OAAO,YAAY,EAAE,gBAAgB,kBACrC,OAAO,aAAa,EAAE,cAAc,OACpC,MAAM,GAAG,MAAM,WACf,MAAM,iBACN,MAAM,GAAG,IAAI,YACb,MAAM,kBACN,MAAM,GAAG,IAAI,YACb,OAAO,aAAa,EAAE,YAAY,mBAClC,OAAO,yBAAyB,EAAE,KAAK,GAAG,IAAI,iBAC9C,OAAO,oBAAoB,EAAE,OAAO,QACpC,OAAO,cACP,OAAO,mBACP,OAAO,YAAY,EAAE,eAAe,4DAElC,OAAO,YAAY,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"state-node.d.ts","sourceRoot":"","sources":["../../src/state/state-node.js"],"names":[],"mappings":"AAqKA;;;;;;;;;;GAUG;AACH,4CAVW,OAAO,aAAa,EAAE,kBAAkB,EAAE,cAC1C,OAAO,yBAAyB,EAAE,UAAU,QAC5C,GAAG,WACH,OAAO,YAAY,EAAE,gBAAgB,WACrC,OAAO,oBAAoB,EAAE,OAAO,UACpC,OAAO,yBAAyB,EAAE,UAAU,YAC5C,OAAO,cACP,OAAO,GACL,GAAG,CAMf;AA+BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,yCAjBW,OAAO,YAAY,EAAE,sBAAsB,iBAC3C,OAAO,YAAY,EAAE,gBAAgB,kBACrC,OAAO,aAAa,EAAE,cAAc,OACpC,MAAM,GAAG,MAAM,WACf,MAAM,iBACN,MAAM,GAAG,IAAI,YACb,MAAM,kBACN,MAAM,GAAG,IAAI,YACb,OAAO,aAAa,EAAE,YAAY,mBAClC,OAAO,yBAAyB,EAAE,KAAK,GAAG,IAAI,iBAC9C,OAAO,oBAAoB,EAAE,OAAO,QACpC,OAAO,cACP,OAAO,mBACP,OAAO,YAAY,EAAE,eAAe,4DAElC,OAAO,YAAY,EAAE,SAAS,CA0O1C;AAED,uFAAuF;AACvF,yCADmB,GAAG,QAAQ,OAAO,YAAY,EAAE,SAAS,QAAQ,OAAO,KAAK,GAAG,CAOjF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-options.d.ts","sourceRoot":"","sources":["../../src/utils/doc-options.js"],"names":[],"mappings":"AAEA;;GAEG;AAEH,yBAAyB;AACzB,wCA8BC;AAED,yBAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"doc-options.d.ts","sourceRoot":"","sources":["../../src/utils/doc-options.js"],"names":[],"mappings":"AAEA;;GAEG;AAEH,yBAAyB;AACzB,wCA8BC;AAED,yBAAyB;AACzB,wCA2FC;yBAhIY;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAAC,EAAE"}
|