@astroapps/forms-core 1.2.3 → 2.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/TODO.txt +6 -1
- package/jest.config.js +8 -0
- package/lib/controlBuilder.d.ts +60 -0
- package/lib/controlDefinition.d.ts +32 -8
- package/lib/evalExpression.d.ts +3 -2
- package/lib/formNode.d.ts +0 -7
- package/lib/formStateNode.d.ts +134 -0
- package/lib/index.cjs +1022 -324
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +852 -283
- package/lib/index.js.map +1 -1
- package/lib/overrideProxy.d.ts +7 -0
- package/lib/resolveChildren.d.ts +19 -0
- package/lib/schemaDataNode.d.ts +3 -0
- package/lib/schemaNode.d.ts +8 -1
- package/lib/schemaValidator.d.ts +3 -0
- package/lib/validators.d.ts +4 -5
- package/package.json +5 -5
- package/src/controlBuilder.ts +218 -0
- package/src/controlDefinition.ts +38 -8
- package/src/defaultSchemaInterface.ts +4 -3
- package/src/evalExpression.ts +38 -8
- package/src/formNode.ts +14 -54
- package/src/formStateNode.ts +807 -0
- package/src/index.ts +5 -1
- package/src/overrideProxy.ts +40 -0
- package/src/resolveChildren.ts +141 -0
- package/src/schemaBuilder.ts +3 -0
- package/src/schemaDataNode.ts +12 -0
- package/src/schemaNode.ts +59 -1
- package/src/schemaValidator.ts +19 -0
- package/src/validators.ts +20 -26
- package/tsconfig.test.json +21 -0
- package/lib/formState.d.ts +0 -48
- package/src/formState.ts +0 -529
package/src/formNode.ts
CHANGED
|
@@ -115,21 +115,26 @@ class FormTreeImpl extends FormTree {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export function legacyFormNode(definition: ControlDefinition) {
|
|
118
|
-
return createFormTree([definition]).rootNode
|
|
118
|
+
return createFormTree([definition]).rootNode;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export function createFormTree(
|
|
122
122
|
controls: ControlDefinition[],
|
|
123
123
|
getForm: FormTreeLookup = { getForm: () => undefined },
|
|
124
124
|
): FormTree {
|
|
125
|
-
return new FormTreeImpl(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
return new FormTreeImpl(
|
|
126
|
+
getForm,
|
|
127
|
+
controls.length === 1
|
|
128
|
+
? controls[0]
|
|
129
|
+
: ({
|
|
130
|
+
type: ControlDefinitionType.Group,
|
|
131
|
+
children: controls,
|
|
132
|
+
groupOptions: {
|
|
133
|
+
type: GroupRenderType.Standard,
|
|
134
|
+
hideTitle: true,
|
|
135
|
+
},
|
|
136
|
+
} as GroupedControlsDefinition),
|
|
137
|
+
);
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
export function createFormLookup<A extends Record<string, ControlDefinition[]>>(
|
|
@@ -247,48 +252,3 @@ export function visitFormDataInContext<A>(
|
|
|
247
252
|
const dataNode = lookupDataNode(node.definition, parentContext);
|
|
248
253
|
return visitFormData(node, dataNode ?? parentContext, cb, !dataNode);
|
|
249
254
|
}
|
|
250
|
-
|
|
251
|
-
export interface FormDataNode {
|
|
252
|
-
parent?: FormDataNode;
|
|
253
|
-
formNode: FormNode;
|
|
254
|
-
parentData: SchemaDataNode;
|
|
255
|
-
childIndex?: number;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function visitFormDataNode<A>(
|
|
259
|
-
node: FormDataNode,
|
|
260
|
-
visitFn: (node: FormDataNode, data?: SchemaDataNode) => A | undefined,
|
|
261
|
-
): A | undefined {
|
|
262
|
-
const dataNode = lookupDataNode(node.formNode.definition, node.parentData);
|
|
263
|
-
const v = visitFn(node, dataNode);
|
|
264
|
-
if (v !== undefined) return v;
|
|
265
|
-
|
|
266
|
-
const parentData = dataNode ?? node.parentData;
|
|
267
|
-
if (parentData.schema.field.collection && parentData.elementIndex == null) {
|
|
268
|
-
const elemCount = parentData.control.elements.length;
|
|
269
|
-
for (let i = 0; i < elemCount; i++) {
|
|
270
|
-
const v = visitChildren(parentData.getChildElement(i));
|
|
271
|
-
if (v !== undefined) return v;
|
|
272
|
-
}
|
|
273
|
-
return undefined;
|
|
274
|
-
} else {
|
|
275
|
-
return visitChildren(parentData);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function visitChildren(parentData: SchemaDataNode) {
|
|
279
|
-
const children = node.formNode.getChildNodes();
|
|
280
|
-
for (let i = 0; i < children.length; i++) {
|
|
281
|
-
const child = children[i];
|
|
282
|
-
const res = visitFormDataNode(
|
|
283
|
-
{
|
|
284
|
-
formNode: child,
|
|
285
|
-
parent: node,
|
|
286
|
-
parentData,
|
|
287
|
-
childIndex: i,
|
|
288
|
-
},
|
|
289
|
-
visitFn,
|
|
290
|
-
);
|
|
291
|
-
if (res !== undefined) return res;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|