@formspec/constraints 0.1.0-alpha.10 → 0.1.0-alpha.11
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/dist/browser.cjs +458 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.js +413 -61
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +526 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +481 -45
- package/dist/index.js.map +1 -1
- package/package.json +10 -7
- package/dist/__tests__/loader.test.js +0 -133
- package/dist/__tests__/loader.test.js.map +0 -1
- package/dist/__tests__/validators.test.js +0 -404
- package/dist/__tests__/validators.test.js.map +0 -1
- package/dist/defaults.js +0 -106
- package/dist/defaults.js.map +0 -1
- package/dist/loader.js +0 -140
- package/dist/loader.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/validators/field-options.js +0 -79
- package/dist/validators/field-options.js.map +0 -1
- package/dist/validators/field-types.js +0 -93
- package/dist/validators/field-types.js.map +0 -1
- package/dist/validators/formspec.js +0 -152
- package/dist/validators/formspec.js.map +0 -1
- package/dist/validators/index.js +0 -5
- package/dist/validators/index.js.map +0 -1
- package/dist/validators/layout.js +0 -107
- package/dist/validators/layout.js.map +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates a layout element against constraints.
|
|
3
|
-
*
|
|
4
|
-
* @param context - Information about the layout element
|
|
5
|
-
* @param constraints - Layout constraints
|
|
6
|
-
* @returns Array of validation issues (empty if valid)
|
|
7
|
-
*/
|
|
8
|
-
export function validateLayout(context, constraints) {
|
|
9
|
-
const issues = [];
|
|
10
|
-
// Check if groups are allowed
|
|
11
|
-
if (context.layoutType === "group") {
|
|
12
|
-
const groupSeverity = constraints.group;
|
|
13
|
-
if (groupSeverity && groupSeverity !== "off") {
|
|
14
|
-
issues.push(createGroupIssue(context, groupSeverity));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
// Check if conditionals are allowed
|
|
18
|
-
if (context.layoutType === "conditional") {
|
|
19
|
-
const conditionalSeverity = constraints.conditionals;
|
|
20
|
-
if (conditionalSeverity && conditionalSeverity !== "off") {
|
|
21
|
-
issues.push(createConditionalIssue(context, conditionalSeverity));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// Check nesting depth (applies to both groups and fields within nested structures)
|
|
25
|
-
const maxDepth = constraints.maxNestingDepth;
|
|
26
|
-
if (maxDepth !== undefined && context.depth > maxDepth) {
|
|
27
|
-
issues.push(createNestingDepthIssue(context, maxDepth));
|
|
28
|
-
}
|
|
29
|
-
return issues;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a validation issue for a disallowed group.
|
|
33
|
-
*/
|
|
34
|
-
function createGroupIssue(context, severity) {
|
|
35
|
-
const labelInfo = context.label ? ` "${context.label}"` : "";
|
|
36
|
-
const issue = {
|
|
37
|
-
code: "DISALLOWED_GROUP",
|
|
38
|
-
message: `Group${labelInfo} is not allowed - visual grouping is not supported in this project`,
|
|
39
|
-
severity: severity === "error" ? "error" : "warning",
|
|
40
|
-
category: "layout",
|
|
41
|
-
};
|
|
42
|
-
if (context.path !== undefined) {
|
|
43
|
-
issue.path = context.path;
|
|
44
|
-
}
|
|
45
|
-
return issue;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Creates a validation issue for a disallowed conditional.
|
|
49
|
-
*/
|
|
50
|
-
function createConditionalIssue(context, severity) {
|
|
51
|
-
const issue = {
|
|
52
|
-
code: "DISALLOWED_CONDITIONAL",
|
|
53
|
-
message: `Conditional visibility (when/is) is not allowed in this project`,
|
|
54
|
-
severity: severity === "error" ? "error" : "warning",
|
|
55
|
-
category: "layout",
|
|
56
|
-
};
|
|
57
|
-
if (context.path !== undefined) {
|
|
58
|
-
issue.path = context.path;
|
|
59
|
-
}
|
|
60
|
-
return issue;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Creates a validation issue for exceeding nesting depth.
|
|
64
|
-
*/
|
|
65
|
-
function createNestingDepthIssue(context, maxDepth) {
|
|
66
|
-
const issue = {
|
|
67
|
-
code: "EXCEEDED_NESTING_DEPTH",
|
|
68
|
-
message: `Nesting depth ${String(context.depth)} exceeds maximum allowed depth of ${String(maxDepth)}`,
|
|
69
|
-
severity: "error",
|
|
70
|
-
category: "layout",
|
|
71
|
-
};
|
|
72
|
-
if (context.path !== undefined) {
|
|
73
|
-
issue.path = context.path;
|
|
74
|
-
}
|
|
75
|
-
return issue;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Checks if a layout type is allowed by the constraints.
|
|
79
|
-
*
|
|
80
|
-
* @param layoutType - The type of layout element
|
|
81
|
-
* @param constraints - Layout constraints
|
|
82
|
-
* @returns true if allowed, false if disallowed
|
|
83
|
-
*/
|
|
84
|
-
export function isLayoutTypeAllowed(layoutType, constraints) {
|
|
85
|
-
if (layoutType === "group") {
|
|
86
|
-
const severity = constraints.group;
|
|
87
|
-
return !severity || severity === "off";
|
|
88
|
-
}
|
|
89
|
-
// layoutType === "conditional"
|
|
90
|
-
const severity = constraints.conditionals;
|
|
91
|
-
return !severity || severity === "off";
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Checks if a nesting depth is allowed.
|
|
95
|
-
*
|
|
96
|
-
* @param depth - Current nesting depth
|
|
97
|
-
* @param constraints - Layout constraints
|
|
98
|
-
* @returns true if allowed, false if exceeds limit
|
|
99
|
-
*/
|
|
100
|
-
export function isNestingDepthAllowed(depth, constraints) {
|
|
101
|
-
const maxDepth = constraints.maxNestingDepth;
|
|
102
|
-
if (maxDepth === undefined) {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
return depth <= maxDepth;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=layout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/validators/layout.ts"],"names":[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