@json-layout/core 0.18.0 → 0.20.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 +3 -4
- package/src/compile/index.js +2 -2
- package/src/compile/serialize.js +6 -4
- package/src/compile/skeleton-node.js +103 -8
- package/src/compile/types.ts +5 -1
- package/src/state/index.js +6 -3
- package/src/state/state-node.js +15 -9
- package/types/compile/index.d.ts +0 -16
- package/types/compile/index.d.ts.map +0 -1
- package/types/compile/serialize.d.ts +0 -6
- package/types/compile/serialize.d.ts.map +0 -1
- package/types/compile/skeleton-node.d.ts +0 -15
- package/types/compile/skeleton-node.d.ts.map +0 -1
- package/types/compile/skeleton-tree.d.ts +0 -13
- package/types/compile/skeleton-tree.d.ts.map +0 -1
- package/types/compile/types.d.ts +0 -54
- package/types/compile/types.d.ts.map +0 -1
- package/types/compile/utils/resolve-refs.d.ts +0 -9
- package/types/compile/utils/resolve-refs.d.ts.map +0 -1
- package/types/i18n/en.d.ts +0 -3
- package/types/i18n/en.d.ts.map +0 -1
- package/types/i18n/fr.d.ts +0 -3
- package/types/i18n/fr.d.ts.map +0 -1
- package/types/i18n/index.d.ts +0 -3
- package/types/i18n/index.d.ts.map +0 -1
- package/types/i18n/types.d.ts +0 -35
- package/types/i18n/types.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- package/types/state/index.d.ts +0 -275
- package/types/state/index.d.ts.map +0 -1
- package/types/state/state-node.d.ts +0 -35
- package/types/state/state-node.d.ts.map +0 -1
- package/types/state/state-tree.d.ts +0 -13
- package/types/state/state-tree.d.ts.map +0 -1
- package/types/state/types.d.ts +0 -174
- package/types/state/types.d.ts.map +0 -1
- package/types/state/utils/display.d.ts +0 -51
- package/types/state/utils/display.d.ts.map +0 -1
- package/types/state/utils/immutable.d.ts +0 -21
- package/types/state/utils/immutable.d.ts.map +0 -1
- package/types/utils/build.d.ts +0 -5
- package/types/utils/build.d.ts.map +0 -1
- package/types/utils/clone.d.ts +0 -3
- package/types/utils/clone.d.ts.map +0 -1
- package/types/utils/doc-options.d.ts +0 -14
- package/types/utils/doc-options.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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.18.0",
|
|
63
63
|
"@types/markdown-it": "^13.0.1",
|
|
64
64
|
"ajv": "^8.12.0",
|
|
65
65
|
"ajv-errors": "^3.0.0",
|
|
@@ -69,8 +69,7 @@
|
|
|
69
69
|
"immer": "^10.0.3",
|
|
70
70
|
"magicast": "^0.3.3",
|
|
71
71
|
"markdown-it": "^13.0.2",
|
|
72
|
-
"mitt": "^3.0.1"
|
|
73
|
-
"recast": "^0.23.4"
|
|
72
|
+
"mitt": "^3.0.1"
|
|
74
73
|
},
|
|
75
74
|
"devDependencies": {
|
|
76
75
|
"@types/debug": "^4.1.7",
|
package/src/compile/index.js
CHANGED
|
@@ -142,8 +142,8 @@ export function compile (_schema, partialOptions = {}) {
|
|
|
142
142
|
|
|
143
143
|
for (const expression of expressionsDefinitions) {
|
|
144
144
|
const expressionsParams = expression.pure
|
|
145
|
-
? ['data', 'options', 'context', 'display', 'layout']
|
|
146
|
-
: ['data', 'options', 'context', 'display', 'layout', 'rootData', 'parent']
|
|
145
|
+
? ['data', 'options', 'context', 'display', 'layout', 'validates']
|
|
146
|
+
: ['data', 'options', 'context', 'display', 'layout', 'validates', 'rootData', 'parent']
|
|
147
147
|
/* if (expression.type === 'expr-eval') {
|
|
148
148
|
expressions.push(exprEvalParser.parse(expression.expr).toJSFunction(expressionsParams.join(',')))
|
|
149
149
|
} */
|
package/src/compile/serialize.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { ok } from 'assert/strict'
|
|
3
3
|
import standaloneCode from 'ajv/dist/standalone/index.js'
|
|
4
4
|
import { parseModule, generateCode, builders } from 'magicast'
|
|
5
|
-
import { parse, print } from 'recast'
|
|
6
5
|
import clone from '../utils/clone.js'
|
|
7
6
|
import { isSwitchStruct } from '@json-layout/vocabulary'
|
|
8
7
|
|
|
@@ -59,10 +58,13 @@ export const exportLocalizeErrors = localizeErrors;\n` + code
|
|
|
59
58
|
i = 0
|
|
60
59
|
const expressionsNodes = []
|
|
61
60
|
for (const expression of compiledLayout.expressions) {
|
|
61
|
+
const id = `expression${i++}`
|
|
62
|
+
code += expression.toString().replace('function anonymous', `function ${id}`)
|
|
63
|
+
/* Previous code based on recast/esprima, suffered syntax limitations
|
|
62
64
|
const fn = parse(expression.toString()).program.body[0]
|
|
63
|
-
fn.id =
|
|
64
|
-
code += `\n${print(fn)}\n`
|
|
65
|
-
expressionsNodes.push(builders.raw(
|
|
65
|
+
fn.id = id
|
|
66
|
+
code += `\n${print(fn)}\n` */
|
|
67
|
+
expressionsNodes.push(builders.raw(id))
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
/** @type {Record<string, Omit<import('@json-layout/vocabulary').ComponentInfo, 'schema'>>} */
|
|
@@ -13,6 +13,9 @@ import { makeSkeletonTree } from './skeleton-tree.js'
|
|
|
13
13
|
* @param {string} pointer
|
|
14
14
|
* @param {string | null} parentPointer
|
|
15
15
|
* @param {boolean} required
|
|
16
|
+
* @param {string} [condition]
|
|
17
|
+
* @param {boolean} [dependent]
|
|
18
|
+
* @param {string} [knownType]
|
|
16
19
|
* @returns {import('./types.js').SkeletonNode}
|
|
17
20
|
*/
|
|
18
21
|
export function makeSkeletonNode (
|
|
@@ -25,9 +28,12 @@ export function makeSkeletonNode (
|
|
|
25
28
|
key,
|
|
26
29
|
pointer,
|
|
27
30
|
parentPointer,
|
|
28
|
-
required
|
|
31
|
+
required,
|
|
32
|
+
condition,
|
|
33
|
+
dependent,
|
|
34
|
+
knownType
|
|
29
35
|
) {
|
|
30
|
-
const { type, nullable } = getSchemaFragmentType(schema)
|
|
36
|
+
const { type, nullable } = knownType ? { type: knownType, nullable: false } : getSchemaFragmentType(schema)
|
|
31
37
|
|
|
32
38
|
// improve on ajv error messages based on ajv-errors (https://ajv.js.org/packages/ajv-errors.html)
|
|
33
39
|
schema.errorMessage = schema.errorMessage ?? {}
|
|
@@ -37,7 +43,10 @@ export function makeSkeletonNode (
|
|
|
37
43
|
pointer,
|
|
38
44
|
options.components,
|
|
39
45
|
options.markdown,
|
|
40
|
-
options.optionsKeys
|
|
46
|
+
options.optionsKeys,
|
|
47
|
+
undefined,
|
|
48
|
+
type,
|
|
49
|
+
nullable
|
|
41
50
|
)
|
|
42
51
|
normalizedLayouts[pointer] = normalizationResult.layout
|
|
43
52
|
if (normalizationResult.errors.length) {
|
|
@@ -54,7 +63,7 @@ export function makeSkeletonNode (
|
|
|
54
63
|
else if (type === 'array') defaultData = []
|
|
55
64
|
}
|
|
56
65
|
|
|
57
|
-
let pure =
|
|
66
|
+
let pure = !dependent
|
|
58
67
|
/**
|
|
59
68
|
* @param {import('@json-layout/vocabulary').Expression[]} expressions
|
|
60
69
|
* @param {import('@json-layout/vocabulary').Expression} expression
|
|
@@ -103,13 +112,30 @@ export function makeSkeletonNode (
|
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
/** @type {import('./types.js').SkeletonNode} */
|
|
106
|
-
const node = {
|
|
115
|
+
const node = {
|
|
116
|
+
key: key ?? '',
|
|
117
|
+
pointer,
|
|
118
|
+
parentPointer,
|
|
119
|
+
pure,
|
|
120
|
+
propertyKeys: [],
|
|
121
|
+
roPropertyKeys: [],
|
|
122
|
+
nullable,
|
|
123
|
+
required: required && !nullable
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (condition) {
|
|
127
|
+
if (isSwitchStruct(normalizedLayout)) throw new Error('Switch struct not allowed in conditional schema')
|
|
128
|
+
node.condition = { type: 'js-eval', expr: condition, pure: true }
|
|
129
|
+
pushExpression(expressions, node.condition)
|
|
130
|
+
}
|
|
131
|
+
|
|
107
132
|
if (type === 'object') {
|
|
108
133
|
if (schema.properties) {
|
|
109
134
|
node.children = node.children ?? []
|
|
110
135
|
for (const propertyKey of Object.keys(schema.properties)) {
|
|
111
136
|
node.propertyKeys.push(propertyKey)
|
|
112
137
|
if (schema.properties[propertyKey].readOnly) node.roPropertyKeys.push(propertyKey)
|
|
138
|
+
const dependent = schema.dependentRequired && Object.values(schema.dependentRequired).some(dependentProperties => dependentProperties.includes(propertyKey))
|
|
113
139
|
node.children.push(makeSkeletonNode(
|
|
114
140
|
schema.properties[propertyKey],
|
|
115
141
|
options,
|
|
@@ -120,12 +146,37 @@ export function makeSkeletonNode (
|
|
|
120
146
|
propertyKey,
|
|
121
147
|
`${pointer}/properties/${propertyKey}`,
|
|
122
148
|
pointer,
|
|
123
|
-
schema.required?.includes(propertyKey)
|
|
149
|
+
schema.required?.includes(propertyKey),
|
|
150
|
+
undefined,
|
|
151
|
+
dependent
|
|
124
152
|
))
|
|
125
153
|
if (schema?.required?.includes(propertyKey)) {
|
|
126
154
|
schema.errorMessage.required = schema.errorMessage.required ?? {}
|
|
127
155
|
schema.errorMessage.required[propertyKey] = options.messages.errorRequired
|
|
128
156
|
}
|
|
157
|
+
if (schema.dependentRequired && Object.keys(schema.dependentRequired).includes(propertyKey)) {
|
|
158
|
+
schema.errorMessage.dependentRequired = options.messages.errorRequired
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (schema.dependentSchemas?.[propertyKey] || (schema.dependencies?.[propertyKey] && !Array.isArray(schema.dependencies[propertyKey]))) {
|
|
162
|
+
const dependentSchema = schema.dependentSchemas?.[propertyKey] ?? schema.dependencies[propertyKey]
|
|
163
|
+
const dependentPointer = schema.dependentSchemas?.[propertyKey] ? `${pointer}/dependentSchemas/${propertyKey}` : `${pointer}/dependencies/${propertyKey}`
|
|
164
|
+
node.children.push(makeSkeletonNode(
|
|
165
|
+
dependentSchema,
|
|
166
|
+
options,
|
|
167
|
+
validates,
|
|
168
|
+
validationErrors,
|
|
169
|
+
normalizedLayouts,
|
|
170
|
+
expressions,
|
|
171
|
+
`$deps-${propertyKey}`,
|
|
172
|
+
dependentPointer,
|
|
173
|
+
pointer,
|
|
174
|
+
false,
|
|
175
|
+
`"${propertyKey}" in data`,
|
|
176
|
+
undefined,
|
|
177
|
+
'object'
|
|
178
|
+
))
|
|
179
|
+
}
|
|
129
180
|
}
|
|
130
181
|
}
|
|
131
182
|
if (schema.allOf) {
|
|
@@ -141,7 +192,10 @@ export function makeSkeletonNode (
|
|
|
141
192
|
`$allOf-${i}`,
|
|
142
193
|
`${pointer}/allOf/${i}`,
|
|
143
194
|
pointer,
|
|
144
|
-
false
|
|
195
|
+
false,
|
|
196
|
+
undefined,
|
|
197
|
+
undefined,
|
|
198
|
+
'object'
|
|
145
199
|
)
|
|
146
200
|
node.propertyKeys = node.propertyKeys.concat(allOfNode.propertyKeys)
|
|
147
201
|
node.roPropertyKeys = node.roPropertyKeys.concat(allOfNode.roPropertyKeys)
|
|
@@ -157,7 +211,9 @@ export function makeSkeletonNode (
|
|
|
157
211
|
options.components,
|
|
158
212
|
options.markdown,
|
|
159
213
|
options.optionsKeys,
|
|
160
|
-
'oneOf'
|
|
214
|
+
'oneOf',
|
|
215
|
+
type,
|
|
216
|
+
nullable
|
|
161
217
|
)
|
|
162
218
|
normalizedLayouts[oneOfPointer] = normalizationResult.layout
|
|
163
219
|
if (normalizationResult.errors.length) {
|
|
@@ -195,6 +251,45 @@ export function makeSkeletonNode (
|
|
|
195
251
|
|
|
196
252
|
schema.errorMessage.oneOf = options.messages.errorOneOf
|
|
197
253
|
}
|
|
254
|
+
if (schema.if) {
|
|
255
|
+
validates.push(`${pointer}/if`)
|
|
256
|
+
if (schema.then) {
|
|
257
|
+
node.children = node.children ?? []
|
|
258
|
+
node.children.push(makeSkeletonNode(
|
|
259
|
+
schema.then,
|
|
260
|
+
options,
|
|
261
|
+
validates,
|
|
262
|
+
validationErrors,
|
|
263
|
+
normalizedLayouts,
|
|
264
|
+
expressions,
|
|
265
|
+
'$then',
|
|
266
|
+
`${pointer}/then`,
|
|
267
|
+
pointer,
|
|
268
|
+
false,
|
|
269
|
+
`validates["${pointer}/if"](data)`,
|
|
270
|
+
undefined,
|
|
271
|
+
'object'
|
|
272
|
+
))
|
|
273
|
+
}
|
|
274
|
+
if (schema.else) {
|
|
275
|
+
node.children = node.children ?? []
|
|
276
|
+
node.children.push(makeSkeletonNode(
|
|
277
|
+
schema.else,
|
|
278
|
+
options,
|
|
279
|
+
validates,
|
|
280
|
+
validationErrors,
|
|
281
|
+
normalizedLayouts,
|
|
282
|
+
expressions,
|
|
283
|
+
'$else',
|
|
284
|
+
`${pointer}/else`,
|
|
285
|
+
pointer,
|
|
286
|
+
false,
|
|
287
|
+
`!validates["${pointer}/if"](data)`,
|
|
288
|
+
undefined,
|
|
289
|
+
'object'
|
|
290
|
+
))
|
|
291
|
+
}
|
|
292
|
+
}
|
|
198
293
|
}
|
|
199
294
|
|
|
200
295
|
if (type === 'array' && schema.items) {
|
package/src/compile/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type ajvModule from 'ajv/dist/2019.js'
|
|
2
2
|
import type MarkdownIt from 'markdown-it'
|
|
3
|
-
import { type ComponentInfo, type BaseCompObject, type NormalizedLayout, type StateNodeOptionsBase } from '@json-layout/vocabulary'
|
|
3
|
+
import { type ComponentInfo, type BaseCompObject, type NormalizedLayout, type StateNodeOptionsBase, type Expression } from '@json-layout/vocabulary'
|
|
4
4
|
import { type ValidateFunction, type SchemaObject, type ErrorObject } from 'ajv/dist/2019.js'
|
|
5
5
|
import { type Display } from '../state/utils/display.js'
|
|
6
6
|
import { type LocaleMessages } from '../i18n/types.js'
|
|
@@ -16,6 +16,7 @@ export type CompiledExpression = (
|
|
|
16
16
|
context: object,
|
|
17
17
|
display: Display,
|
|
18
18
|
layout: BaseCompObject,
|
|
19
|
+
validates: Record<string, ValidateFunction>,
|
|
19
20
|
rootData?: unknown,
|
|
20
21
|
parent?: ParentContextExpression | null
|
|
21
22
|
) => any
|
|
@@ -67,6 +68,9 @@ export interface SkeletonNode {
|
|
|
67
68
|
pure: boolean
|
|
68
69
|
propertyKeys: string[]
|
|
69
70
|
roPropertyKeys: string[]
|
|
71
|
+
condition?: Expression
|
|
70
72
|
children?: SkeletonNode[] // optional children in the case of arrays and object nodes
|
|
71
73
|
childrenTrees?: SkeletonTree[] // other trees that can be instantiated with separate validation (for example in the case of new array items of oneOfs, etc)
|
|
74
|
+
required?: boolean
|
|
75
|
+
nullable?: boolean
|
|
72
76
|
}
|
package/src/state/index.js
CHANGED
|
@@ -371,14 +371,13 @@ export class StatefulLayout {
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
/**
|
|
374
|
-
* @private
|
|
375
374
|
* @param {StateNode} node
|
|
376
375
|
* @param {import('@json-layout/vocabulary').Expression} expression
|
|
377
376
|
* @param {any} data
|
|
378
377
|
* @returns {any}
|
|
379
378
|
*/
|
|
380
379
|
evalNodeExpression (node, expression, data) {
|
|
381
|
-
return evalExpression(this.compiledLayout.expressions, expression, data, node.options, new Display(node.width), node.layout, this._data, this.getParentContextExpression(node))
|
|
380
|
+
return evalExpression(this.compiledLayout.expressions, expression, data, node.options, new Display(node.width), node.layout, this.compiledLayout.validates, this._data, this.getParentContextExpression(node))
|
|
382
381
|
}
|
|
383
382
|
|
|
384
383
|
/**
|
|
@@ -427,7 +426,11 @@ export class StatefulLayout {
|
|
|
427
426
|
}
|
|
428
427
|
const parentNode = this._lastCreateStateTreeContext.nodes.find(p => p.fullKey === node.parentFullKey)
|
|
429
428
|
if (!parentNode) throw new Error(`parent with key "${node.parentFullKey}" not found`)
|
|
430
|
-
const newParentValue = producePatchedData(
|
|
429
|
+
const newParentValue = producePatchedData(
|
|
430
|
+
parentNode.data ?? (typeof node.key === 'number' ? [] : {}),
|
|
431
|
+
node,
|
|
432
|
+
(data === null || data === undefined) ? (node.skeleton.nullable ? null : undefined) : data
|
|
433
|
+
)
|
|
431
434
|
this.applyInput(parentNode, newParentValue, validated)
|
|
432
435
|
|
|
433
436
|
if (activateKey !== undefined) {
|
package/src/state/state-node.js
CHANGED
|
@@ -170,16 +170,17 @@ const matchChildError = (error, skeleton, dataPath, parentDataPath) => {
|
|
|
170
170
|
* @param {import('./types.js').StateNodeOptions} options
|
|
171
171
|
* @param {import('./utils/display.js').Display} display
|
|
172
172
|
* @param {import('@json-layout/vocabulary').BaseCompObject} layout
|
|
173
|
+
* @param {Record<string, import('ajv').ValidateFunction>} validates
|
|
173
174
|
* @param {unknown} rootData
|
|
174
175
|
* @param {import('../compile/types.js').ParentContextExpression | null} parentContext
|
|
175
176
|
* @returns {any}
|
|
176
177
|
*/
|
|
177
|
-
export function evalExpression (expressions, expression, data, options, display, layout, rootData, parentContext) {
|
|
178
|
+
export function evalExpression (expressions, expression, data, options, display, layout, validates, rootData, parentContext) {
|
|
178
179
|
if (expression.ref === undefined) throw new Error('expression was not compiled : ' + JSON.stringify(expression))
|
|
179
180
|
const compiledExpression = expressions[expression.ref]
|
|
180
181
|
return expression.pure
|
|
181
|
-
? compiledExpression(data, options, options.context, display, layout)
|
|
182
|
-
: compiledExpression(data, options, options.context, display, layout, rootData, parentContext)
|
|
182
|
+
? compiledExpression(data, options, options.context, display, layout, validates)
|
|
183
|
+
: compiledExpression(data, options, options.context, display, layout, validates, rootData, parentContext)
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
/**
|
|
@@ -195,13 +196,13 @@ export function evalExpression (expressions, expression, data, options, display,
|
|
|
195
196
|
const getCompObject = (normalizedLayout, options, compiledLayout, display, data, rootData, parentContext) => {
|
|
196
197
|
if (isSwitchStruct(normalizedLayout)) {
|
|
197
198
|
for (const compObject of normalizedLayout.switch) {
|
|
198
|
-
if (!compObject.if || !!evalExpression(compiledLayout.expressions, compObject.if, data, options, display, compObject, rootData, parentContext)) {
|
|
199
|
+
if (!compObject.if || !!evalExpression(compiledLayout.expressions, compObject.if, data, options, display, compObject, compiledLayout.validates, rootData, parentContext)) {
|
|
199
200
|
return compObject
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
} else {
|
|
203
204
|
if (normalizedLayout.if) {
|
|
204
|
-
if (evalExpression(compiledLayout.expressions, normalizedLayout.if, data, options, display, normalizedLayout, rootData, parentContext)) {
|
|
205
|
+
if (evalExpression(compiledLayout.expressions, normalizedLayout.if, data, options, display, normalizedLayout, compiledLayout.validates, rootData, parentContext)) {
|
|
205
206
|
return normalizedLayout
|
|
206
207
|
}
|
|
207
208
|
} else {
|
|
@@ -269,7 +270,7 @@ export function createStateNode (
|
|
|
269
270
|
? produceNodeOptions(
|
|
270
271
|
reusedNode?.options ?? /** @type {import('./types.js').StateNodeOptions} */({}),
|
|
271
272
|
parentOptions,
|
|
272
|
-
evalExpression(compiledLayout.expressions, layout.getOptions, data, parentOptions, display, layout, context.rootData, parentContext)
|
|
273
|
+
evalExpression(compiledLayout.expressions, layout.getOptions, data, parentOptions, display, layout, compiledLayout.validates, context.rootData, parentContext)
|
|
273
274
|
)
|
|
274
275
|
: parentOptions
|
|
275
276
|
|
|
@@ -292,6 +293,11 @@ export function createStateNode (
|
|
|
292
293
|
skeleton.roPropertyKeys?.includes(/** @type {string} */(childLayout.key))
|
|
293
294
|
) continue
|
|
294
295
|
const childSkeleton = skeleton.children?.find(c => c.key === childLayout.key) ?? skeleton
|
|
296
|
+
if (childSkeleton.condition) {
|
|
297
|
+
if (!evalExpression(compiledLayout.expressions, childSkeleton.condition, objectData, parentOptions, display, layout, compiledLayout.validates, context.rootData, parentContext)) {
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
}
|
|
295
301
|
const isSameData = typeof childLayout.key === 'string' && childLayout.key.startsWith('$')
|
|
296
302
|
const childFullKey = `${fullKey}/${childLayout.key}`
|
|
297
303
|
if (focusChild) context.autofocusTarget = childFullKey
|
|
@@ -427,12 +433,12 @@ export function createStateNode (
|
|
|
427
433
|
|
|
428
434
|
if (layout.getConstData) {
|
|
429
435
|
if (!context.rehydrate) {
|
|
430
|
-
nodeData = evalExpression(compiledLayout.expressions, layout.getConstData, nodeData, options, display, layout, context.rootData, parentContext)
|
|
436
|
+
nodeData = evalExpression(compiledLayout.expressions, layout.getConstData, nodeData, options, display, layout, compiledLayout.validates, context.rootData, parentContext)
|
|
431
437
|
}
|
|
432
438
|
} else {
|
|
433
439
|
if (layout.getDefaultData && useDefaultData(nodeData, layout, options)) {
|
|
434
440
|
if (!context.rehydrate) {
|
|
435
|
-
nodeData = evalExpression(compiledLayout.expressions, layout.getDefaultData, nodeData, options, display, layout, context.rootData, parentContext)
|
|
441
|
+
nodeData = evalExpression(compiledLayout.expressions, layout.getDefaultData, nodeData, options, display, layout, compiledLayout.validates, context.rootData, parentContext)
|
|
436
442
|
}
|
|
437
443
|
} else {
|
|
438
444
|
if (isDataEmpty(nodeData)) {
|
|
@@ -452,7 +458,7 @@ export function createStateNode (
|
|
|
452
458
|
|
|
453
459
|
let props
|
|
454
460
|
if (layout.getProps) {
|
|
455
|
-
props = evalExpression(compiledLayout.expressions, layout.getProps, nodeData, options, display, layout, context.rootData, parentContext)
|
|
461
|
+
props = evalExpression(compiledLayout.expressions, layout.getProps, nodeData, options, display, layout, compiledLayout.validates, context.rootData, parentContext)
|
|
456
462
|
}
|
|
457
463
|
|
|
458
464
|
const autofocus = isFocusableLayout(layout, compiledLayout.components) && !options.readOnly && !options.summary && context.autofocusTarget === fullKey
|
package/types/compile/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {object} _schema
|
|
3
|
-
* @param {PartialCompileOptions} [partialOptions]
|
|
4
|
-
* @returns {CompiledLayout}
|
|
5
|
-
*/
|
|
6
|
-
export function compile(_schema: object, partialOptions?: import("./types.js").PartialCompileOptions | undefined): CompiledLayout;
|
|
7
|
-
export { resolveRefs } from "./utils/resolve-refs.js";
|
|
8
|
-
/** @type {(draft: PartialCompileOptions, newOptions: PartialCompileOptions) => PartialCompileOptions} */
|
|
9
|
-
export const produceCompileOptions: (draft: PartialCompileOptions, newOptions: PartialCompileOptions) => PartialCompileOptions;
|
|
10
|
-
export type SkeletonTree = import('./types.js').SkeletonTree;
|
|
11
|
-
export type SkeletonNode = import('./types.js').SkeletonNode;
|
|
12
|
-
export type CompiledLayout = import('./types.js').CompiledLayout;
|
|
13
|
-
export type CompileOptions = import('./types.js').CompileOptions;
|
|
14
|
-
export type PartialCompileOptions = import('./types.js').PartialCompileOptions;
|
|
15
|
-
export type CompiledExpression = import('./types.js').CompiledExpression;
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.js"],"names":[],"mappings":"AAgGA;;;;GAIG;AACH,iCAJW,MAAM,4EAEJ,cAAc,CAkF1B;;AAnJD,yGAAyG;AACzG,4CADmB,qBAAqB,cAAc,qBAAqB,KAAK,qBAAqB,CAQnG;2BAxBW,OAAO,YAAY,EAAE,YAAY;2BACjC,OAAO,YAAY,EAAE,YAAY;6BACjC,OAAO,YAAY,EAAE,cAAc;6BACnC,OAAO,YAAY,EAAE,cAAc;oCACnC,OAAO,YAAY,EAAE,qBAAqB;iCAC1C,OAAO,YAAY,EAAE,kBAAkB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/compile/serialize.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,0CAHW,OAAO,YAAY,EAAE,cAAc,GACjC,MAAM,CA+ElB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {any} schema
|
|
3
|
-
* @param {import('./index.js').CompileOptions} options
|
|
4
|
-
* @param {string[]} validates
|
|
5
|
-
* @param {Record<string, string[]>} validationErrors
|
|
6
|
-
* @param {Record<string, import('@json-layout/vocabulary').NormalizedLayout>} normalizedLayouts
|
|
7
|
-
* @param {import('@json-layout/vocabulary').Expression[]} expressions
|
|
8
|
-
* @param {string | number} key
|
|
9
|
-
* @param {string} pointer
|
|
10
|
-
* @param {string | null} parentPointer
|
|
11
|
-
* @param {boolean} required
|
|
12
|
-
* @returns {import('./types.js').SkeletonNode}
|
|
13
|
-
*/
|
|
14
|
-
export function makeSkeletonNode(schema: any, options: import('./index.js').CompileOptions, validates: string[], validationErrors: Record<string, string[]>, normalizedLayouts: Record<string, import('@json-layout/vocabulary').NormalizedLayout>, expressions: import('@json-layout/vocabulary').Expression[], key: string | number, pointer: string, parentPointer: string | null, required: boolean): import('./types.js').SkeletonNode;
|
|
15
|
-
//# sourceMappingURL=skeleton-node.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skeleton-node.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-node.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,yCAZW,GAAG,WACH,OAAO,YAAY,EAAE,cAAc,aACnC,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,iBACN,MAAM,GAAG,IAAI,YACb,OAAO,GACL,OAAO,YAAY,EAAE,YAAY,CA4N7C"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {any} schema
|
|
3
|
-
* @param {import('./index.js').CompileOptions} options
|
|
4
|
-
* @param {string[]} validates
|
|
5
|
-
* @param {Record<string, string[]>} validationErrors
|
|
6
|
-
* @param {Record<string, import('@json-layout/vocabulary').NormalizedLayout>} normalizedLayouts
|
|
7
|
-
* @param {import('@json-layout/vocabulary').Expression[]} expressions
|
|
8
|
-
* @param {string} pointer
|
|
9
|
-
* @param {string} title
|
|
10
|
-
* @returns {import('./types.js').SkeletonTree}
|
|
11
|
-
*/
|
|
12
|
-
export function makeSkeletonTree(schema: any, options: import('./index.js').CompileOptions, validates: string[], validationErrors: Record<string, string[]>, normalizedLayouts: Record<string, import('@json-layout/vocabulary').NormalizedLayout>, expressions: import('@json-layout/vocabulary').Expression[], pointer: string, title: string): import('./types.js').SkeletonTree;
|
|
13
|
-
//# sourceMappingURL=skeleton-tree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skeleton-tree.d.ts","sourceRoot":"","sources":["../../src/compile/skeleton-tree.js"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,yCAVW,GAAG,WACH,OAAO,YAAY,EAAE,cAAc,aACnC,MAAM,EAAE,oBACR,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC,qBACxB,OAAO,MAAM,EAAE,OAAO,yBAAyB,EAAE,gBAAgB,CAAC,eAClE,OAAO,yBAAyB,EAAE,UAAU,EAAE,WAC9C,MAAM,SACN,MAAM,GACJ,OAAO,YAAY,EAAE,YAAY,CAe7C"}
|
package/types/compile/types.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type ajvModule from 'ajv/dist/2019.js';
|
|
2
|
-
import type MarkdownIt from 'markdown-it';
|
|
3
|
-
import { type ComponentInfo, type BaseCompObject, type NormalizedLayout, type StateNodeOptionsBase } from '@json-layout/vocabulary';
|
|
4
|
-
import { type ValidateFunction, type SchemaObject } from 'ajv/dist/2019.js';
|
|
5
|
-
import { type Display } from '../state/utils/display.js';
|
|
6
|
-
import { type LocaleMessages } from '../i18n/types.js';
|
|
7
|
-
export interface ParentContextExpression {
|
|
8
|
-
data: unknown;
|
|
9
|
-
parent: ParentContextExpression | undefined | null;
|
|
10
|
-
}
|
|
11
|
-
export type CompiledExpression = (data: any, options: StateNodeOptionsBase, context: object, display: Display, layout: BaseCompObject, rootData?: unknown, parent?: ParentContextExpression | null) => any;
|
|
12
|
-
export interface CompileOptions {
|
|
13
|
-
ajv: ajvModule.default;
|
|
14
|
-
ajvOptions?: ajvModule.Options;
|
|
15
|
-
code: boolean;
|
|
16
|
-
markdown: (text: string) => string;
|
|
17
|
-
markdownItOptions?: MarkdownIt.Options;
|
|
18
|
-
locale: string;
|
|
19
|
-
messages: LocaleMessages;
|
|
20
|
-
optionsKeys: string[];
|
|
21
|
-
components: Record<string, ComponentInfo>;
|
|
22
|
-
}
|
|
23
|
-
export type PartialCompileOptions = Partial<Omit<CompileOptions, 'messages'>> & {
|
|
24
|
-
messages?: Partial<LocaleMessages>;
|
|
25
|
-
components?: Record<string, Omit<ComponentInfo, 'name'>>;
|
|
26
|
-
};
|
|
27
|
-
export interface CompiledLayout {
|
|
28
|
-
options?: CompileOptions;
|
|
29
|
-
schema?: SchemaObject;
|
|
30
|
-
skeletonTree: SkeletonTree;
|
|
31
|
-
validates: Record<string, ValidateFunction>;
|
|
32
|
-
validationErrors: Record<string, string[]>;
|
|
33
|
-
normalizedLayouts: Record<string, NormalizedLayout>;
|
|
34
|
-
expressions: CompiledExpression[];
|
|
35
|
-
locale: string;
|
|
36
|
-
messages: LocaleMessages;
|
|
37
|
-
components: Record<string, Omit<ComponentInfo, 'schema'>>;
|
|
38
|
-
localizeErrors: (errors: ajvModule.ErrorObject[]) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface SkeletonTree {
|
|
41
|
-
title: string;
|
|
42
|
-
root: SkeletonNode;
|
|
43
|
-
}
|
|
44
|
-
export interface SkeletonNode {
|
|
45
|
-
key: string | number;
|
|
46
|
-
pointer: string;
|
|
47
|
-
parentPointer: string | null;
|
|
48
|
-
pure: boolean;
|
|
49
|
-
propertyKeys: string[];
|
|
50
|
-
roPropertyKeys: string[];
|
|
51
|
-
children?: SkeletonNode[];
|
|
52
|
-
childrenTrees?: SkeletonTree[];
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compile/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {import('ajv').SchemaObject} schema
|
|
3
|
-
* @param {ajvModule.default} ajv
|
|
4
|
-
* @param {string} locale
|
|
5
|
-
* @returns {import('ajv').SchemaObject}
|
|
6
|
-
*/
|
|
7
|
-
export function resolveRefs(schema: import('ajv').SchemaObject, ajv: ajvModule.default, locale?: string): import('ajv').SchemaObject;
|
|
8
|
-
import ajvModule from 'ajv/dist/2019.js';
|
|
9
|
-
//# sourceMappingURL=resolve-refs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-refs.d.ts","sourceRoot":"","sources":["../../../src/compile/utils/resolve-refs.js"],"names":[],"mappings":"AA2DA;;;;;GAKG;AACH,oCALW,OAAO,KAAK,EAAE,YAAY,OAC1B,UAAU,OAAO,WACjB,MAAM,GACJ,OAAO,KAAK,EAAE,YAAY,CAKtC;sBApEqB,kBAAkB"}
|
package/types/i18n/en.d.ts
DELETED
package/types/i18n/en.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/i18n/en.js"],"names":[],"mappings":"wBAAW,OAAO,YAAY,EAAE,cAAc"}
|
package/types/i18n/fr.d.ts
DELETED
package/types/i18n/fr.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fr.d.ts","sourceRoot":"","sources":["../../src/i18n/fr.js"],"names":[],"mappings":"wBAAW,OAAO,YAAY,EAAE,cAAc"}
|
package/types/i18n/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.js"],"names":[],"mappings":"wBAGW,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,cAAc,CAAC"}
|
package/types/i18n/types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export interface CompileOptionsMessages {
|
|
2
|
-
errorOneOf: string;
|
|
3
|
-
errorRequired: string;
|
|
4
|
-
}
|
|
5
|
-
export interface StateOptionsMessages {
|
|
6
|
-
addItem: string;
|
|
7
|
-
delete: string;
|
|
8
|
-
edit: string;
|
|
9
|
-
duplicate: string;
|
|
10
|
-
sort: string;
|
|
11
|
-
up: string;
|
|
12
|
-
down: string;
|
|
13
|
-
showHelp: string;
|
|
14
|
-
mdeLink1: string;
|
|
15
|
-
mdeLink2: string;
|
|
16
|
-
mdeImg1: string;
|
|
17
|
-
mdeImg2: string;
|
|
18
|
-
mdeTable1: string;
|
|
19
|
-
mdeTable2: string;
|
|
20
|
-
bold: string;
|
|
21
|
-
italic: string;
|
|
22
|
-
heading: string;
|
|
23
|
-
quote: string;
|
|
24
|
-
unorderedList: string;
|
|
25
|
-
orderedList: string;
|
|
26
|
-
createLink: string;
|
|
27
|
-
insertImage: string;
|
|
28
|
-
createTable: string;
|
|
29
|
-
preview: string;
|
|
30
|
-
mdeGuide: string;
|
|
31
|
-
undo: string;
|
|
32
|
-
redo: string;
|
|
33
|
-
}
|
|
34
|
-
export type LocaleMessages = CompileOptionsMessages & StateOptionsMessages;
|
|
35
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/i18n/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,oBAAoB,CAAA"}
|
package/types/index.d.ts
DELETED
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|