simpler-forms 0.1.0-alpha.1 → 0.1.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/README.md +221 -76
- package/dist/src/casing.d.ts +43 -0
- package/dist/src/casing.js +146 -0
- package/dist/src/casing.js.map +1 -0
- package/dist/src/decorators/index.d.ts +1 -0
- package/dist/src/decorators/index.js +1 -0
- package/dist/src/decorators/index.js.map +1 -1
- package/dist/src/decorators/mapping.d.ts +11 -0
- package/dist/src/decorators/mapping.js +22 -0
- package/dist/src/decorators/mapping.js.map +1 -0
- package/dist/src/decorators/meta.d.ts +13 -3
- package/dist/src/decorators/meta.js +31 -4
- package/dist/src/decorators/meta.js.map +1 -1
- package/dist/src/decorators/ui.d.ts +14 -12
- package/dist/src/decorators/ui.js +20 -43
- package/dist/src/decorators/ui.js.map +1 -1
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.js +48 -13
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/emitters/block-ui.d.ts +14 -3
- package/dist/src/emitters/block-ui.js +81 -119
- package/dist/src/emitters/block-ui.js.map +1 -1
- package/dist/src/emitters/layout-ui.d.ts +12 -0
- package/dist/src/emitters/layout-ui.js +225 -0
- package/dist/src/emitters/layout-ui.js.map +1 -0
- package/dist/src/emitters/overlay.d.ts +3 -6
- package/dist/src/emitters/overlay.js +3 -86
- package/dist/src/emitters/overlay.js.map +1 -1
- package/dist/src/forms.d.ts +23 -0
- package/dist/src/forms.js +54 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +15 -6
- package/dist/src/index.js +12 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/layout.d.ts +50 -0
- package/dist/src/layout.js +397 -0
- package/dist/src/layout.js.map +1 -0
- package/dist/src/lib.d.ts +485 -39
- package/dist/src/lib.js +215 -15
- package/dist/src/lib.js.map +1 -1
- package/dist/src/linter.js +2 -41
- package/dist/src/linter.js.map +1 -1
- package/dist/src/mapping-from.d.ts +20 -0
- package/dist/src/mapping-from.js +149 -0
- package/dist/src/mapping-from.js.map +1 -0
- package/dist/src/mapping.d.ts +58 -0
- package/dist/src/mapping.js +209 -0
- package/dist/src/mapping.js.map +1 -0
- package/dist/src/model.d.ts +69 -17
- package/dist/src/model.js +65 -19
- package/dist/src/model.js.map +1 -1
- package/dist/src/public.d.ts +20 -4
- package/dist/src/public.js +28 -4
- package/dist/src/public.js.map +1 -1
- package/dist/src/validate.d.ts +2 -1
- package/dist/src/validate.js +180 -58
- package/dist/src/validate.js.map +1 -1
- package/lib/main.tsp +1 -0
- package/lib/mapping.tsp +71 -0
- package/lib/meta.tsp +23 -4
- package/lib/types.tsp +13 -65
- package/lib/ui.tsp +34 -17
- package/package.json +7 -1
- package/src/casing.ts +172 -0
- package/src/decorators/index.ts +1 -0
- package/src/decorators/mapping.ts +57 -0
- package/src/decorators/meta.ts +50 -11
- package/src/decorators/ui.ts +43 -59
- package/src/emitter.ts +59 -13
- package/src/emitters/block-ui.ts +83 -135
- package/src/emitters/layout-ui.ts +280 -0
- package/src/emitters/overlay.ts +3 -103
- package/src/forms.ts +82 -0
- package/src/index.ts +12 -3
- package/src/layout.ts +592 -0
- package/src/lib.ts +221 -15
- package/src/linter.ts +1 -42
- package/src/mapping-from.ts +193 -0
- package/src/mapping.ts +351 -0
- package/src/model.ts +170 -37
- package/src/public.ts +50 -6
- package/src/validate.ts +188 -59
- package/dist/src/emitters/override-condition.d.ts +0 -12
- package/dist/src/emitters/override-condition.js +0 -25
- package/dist/src/emitters/override-condition.js.map +0 -1
- package/src/emitters/override-condition.ts +0 -37
package/src/public.ts
CHANGED
|
@@ -24,6 +24,20 @@ export {
|
|
|
24
24
|
type Block,
|
|
25
25
|
} from "./model.js";
|
|
26
26
|
|
|
27
|
+
// --- forms ----------------------------------------------------------------
|
|
28
|
+
// Each `@Meta.form` is published as `forms/<id>/`, and a target emitter writing a form's
|
|
29
|
+
// artifacts beside the others writes them there.
|
|
30
|
+
export {
|
|
31
|
+
/** Every publishable `@Meta.form`, with the layout that presents it, if any. */
|
|
32
|
+
resolveForms,
|
|
33
|
+
type PublishedForm,
|
|
34
|
+
} from "./forms.js";
|
|
35
|
+
export {
|
|
36
|
+
type FormMeta,
|
|
37
|
+
/** Every `@UI.layout` model, with the model it presents. */
|
|
38
|
+
allLayouts,
|
|
39
|
+
} from "./model.js";
|
|
40
|
+
|
|
27
41
|
// --- conditions -----------------------------------------------------------
|
|
28
42
|
export {
|
|
29
43
|
/** The model a `countAtLeast` condition's source property belongs to. */
|
|
@@ -37,14 +51,10 @@ export {
|
|
|
37
51
|
type PresentCondition,
|
|
38
52
|
} from "./model.js";
|
|
39
53
|
|
|
40
|
-
/** An `enabledWhen` from `@UI.overrides`, normalized to the same shape as the decorator. */
|
|
41
|
-
export { normalizedOverrideEnabledWhen } from "./emitters/override-condition.js";
|
|
42
|
-
|
|
43
54
|
// --- model-level state ----------------------------------------------------
|
|
44
55
|
export {
|
|
45
56
|
modelLabel,
|
|
46
57
|
modelOrder,
|
|
47
|
-
modelOverrides,
|
|
48
58
|
modelAtLeastOneOf,
|
|
49
59
|
/** Own and inherited properties in declaration order, derived declaration winning. */
|
|
50
60
|
modelProperties,
|
|
@@ -63,10 +73,8 @@ export {
|
|
|
63
73
|
propHelpText,
|
|
64
74
|
propWidget,
|
|
65
75
|
propEncodedCheckboxGroup,
|
|
66
|
-
propSection,
|
|
67
76
|
propOmit,
|
|
68
77
|
propReadOnly,
|
|
69
|
-
propOverrides,
|
|
70
78
|
propResponseRole,
|
|
71
79
|
propVisibleWhen,
|
|
72
80
|
propEnabledWhen,
|
|
@@ -93,3 +101,39 @@ export {
|
|
|
93
101
|
cardinalityRequiredPathWhenPositiveDecimalString,
|
|
94
102
|
cardinalityPositiveDecimalStringWhenPathPresent,
|
|
95
103
|
} from "./model.js";
|
|
104
|
+
|
|
105
|
+
// --- mapping --------------------------------------------------------------
|
|
106
|
+
// A mapping emitter takes the members it emits as an option, checks them against
|
|
107
|
+
// `mappingTargets`, and resolves each form it emits once per member.
|
|
108
|
+
export {
|
|
109
|
+
/** Every member of every enum declared with `@Mapping.targets`. */
|
|
110
|
+
mappingTargets,
|
|
111
|
+
modelMappedTo,
|
|
112
|
+
propMappedTo,
|
|
113
|
+
modelMappingPaths,
|
|
114
|
+
propMappedFrom,
|
|
115
|
+
type MappingLink,
|
|
116
|
+
type MappingPathLink,
|
|
117
|
+
type MappingFromLink,
|
|
118
|
+
} from "./model.js";
|
|
119
|
+
export {
|
|
120
|
+
/** A model's mapping in one target, resolved through every model it composes. */
|
|
121
|
+
resolveMapping,
|
|
122
|
+
type ResolvedMapping,
|
|
123
|
+
type MappingNode,
|
|
124
|
+
type MappingNodeKind,
|
|
125
|
+
} from "./mapping.js";
|
|
126
|
+
export {
|
|
127
|
+
/** A form's mapping read from the `@Mapping.from` links on its target: the same tree. */
|
|
128
|
+
resolveMappingFrom,
|
|
129
|
+
mappedFromRoot,
|
|
130
|
+
} from "./mapping-from.js";
|
|
131
|
+
|
|
132
|
+
// --- property casing ------------------------------------------------------
|
|
133
|
+
// A target emitter writing its own artifacts uses these to name properties as this one does.
|
|
134
|
+
export {
|
|
135
|
+
/** The name a property is emitted under, honoring `@encodedName("application/json")`. */
|
|
136
|
+
jsonPropertyName,
|
|
137
|
+
snakeCase,
|
|
138
|
+
type PropertyCasing,
|
|
139
|
+
} from "./casing.js";
|
package/src/validate.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Enum,
|
|
3
|
+
EnumMember,
|
|
3
4
|
Model,
|
|
4
5
|
ModelProperty,
|
|
5
6
|
Namespace,
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
cardinalityRequiredWhen,
|
|
20
21
|
childBlock,
|
|
21
22
|
conditionSourceModel,
|
|
22
|
-
orderedProps,
|
|
23
23
|
propCalculationMaterialization,
|
|
24
24
|
propComputed,
|
|
25
25
|
readBlock,
|
|
@@ -28,14 +28,28 @@ import {
|
|
|
28
28
|
modelProperties,
|
|
29
29
|
propEnabledWhen,
|
|
30
30
|
propNotBefore,
|
|
31
|
-
propOmit,
|
|
32
31
|
propReadOnlyWhen,
|
|
33
32
|
propRequiredWhen,
|
|
34
|
-
propSection,
|
|
35
33
|
propVisibleWhen,
|
|
36
34
|
propValidationConstraintsWhen,
|
|
37
35
|
scalarType,
|
|
36
|
+
declaredWidgetSets,
|
|
37
|
+
widgetMembers,
|
|
38
|
+
declaredTagSets,
|
|
39
|
+
tagMembers,
|
|
40
|
+
declaredEntitySets,
|
|
41
|
+
entityMembers,
|
|
42
|
+
allMappingLinks,
|
|
43
|
+
allMappingPathLinks,
|
|
44
|
+
declaredMappingSets,
|
|
45
|
+
allLayouts,
|
|
46
|
+
allMappingFromLinks,
|
|
38
47
|
} from "./model.js";
|
|
48
|
+
import { resolveMappingWithProblems } from "./mapping.js";
|
|
49
|
+
import { resolveMappingFrom } from "./mapping-from.js";
|
|
50
|
+
import { resolveForms } from "./forms.js";
|
|
51
|
+
import { resolveLayout } from "./layout.js";
|
|
52
|
+
import { emitLayoutUi } from "./emitters/layout-ui.js";
|
|
39
53
|
|
|
40
54
|
/**
|
|
41
55
|
* Whole-program checks whose failure means the emitted artifacts would be wrong.
|
|
@@ -44,18 +58,19 @@ import {
|
|
|
44
58
|
* one exists because the defect it catches is currently invisible: a question named after a
|
|
45
59
|
* form, two blocks colliding on one output path, a condition comparing against a value the
|
|
46
60
|
* source enum does not have, a calculation that depends on itself, a field that is required
|
|
47
|
-
* but can be hidden,
|
|
61
|
+
* but can be hidden, a widget no renderer was declared to provide, a form that cannot be
|
|
62
|
+
* published, and a layout that misplaces a field.
|
|
48
63
|
*/
|
|
49
64
|
export function $onValidate(program: Program): void {
|
|
50
65
|
const blocks = allBlocks(program);
|
|
51
66
|
|
|
52
67
|
checkQuestionIds(program, blocks);
|
|
53
68
|
checkDuplicateIds(program, blocks);
|
|
69
|
+
program.reportDiagnostics(resolveForms(program).problems);
|
|
70
|
+
checkLayouts(program);
|
|
54
71
|
|
|
55
72
|
for (const block of blocks) {
|
|
56
73
|
if (block.model.kind !== "Model") continue;
|
|
57
|
-
checkSections(program, block);
|
|
58
|
-
checkOverridePaths(program, block);
|
|
59
74
|
for (const prop of block.model.properties.values()) {
|
|
60
75
|
checkConditions(program, prop);
|
|
61
76
|
checkRequiredButHidden(program, prop);
|
|
@@ -63,6 +78,9 @@ export function $onValidate(program: Program): void {
|
|
|
63
78
|
}
|
|
64
79
|
}
|
|
65
80
|
|
|
81
|
+
checkWidgets(program);
|
|
82
|
+
checkCatalogue(program);
|
|
83
|
+
checkMappings(program);
|
|
66
84
|
checkDateOrders(program);
|
|
67
85
|
checkCardinalityPaths(program);
|
|
68
86
|
checkCalculationCycles(program, blocks);
|
|
@@ -284,6 +302,154 @@ function checkDateOrders(program: Program): void {
|
|
|
284
302
|
visit(program.getGlobalNamespaceType());
|
|
285
303
|
}
|
|
286
304
|
|
|
305
|
+
/**
|
|
306
|
+
* A widget is a contract with the program's renderers, which this library knows nothing about,
|
|
307
|
+
* so the program declares the set it provides with `@UI.widgets`. A member of any other enum
|
|
308
|
+
* would be emitted under a name no renderer has promised to handle.
|
|
309
|
+
*/
|
|
310
|
+
function checkWidgets(program: Program): void {
|
|
311
|
+
const declared = declaredWidgetSets(program);
|
|
312
|
+
for (const [prop, member] of widgetMembers(program)) {
|
|
313
|
+
if (declared.has(member.enum)) continue;
|
|
314
|
+
reportDiagnostic(program, {
|
|
315
|
+
code: "widget-not-declared",
|
|
316
|
+
target: prop,
|
|
317
|
+
format: {
|
|
318
|
+
name: prop.name,
|
|
319
|
+
widget: member.name,
|
|
320
|
+
enumName: member.enum.name,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Tags and entities are the program's catalogue vocabulary, declared with `@Meta.tags` and
|
|
328
|
+
* `@Meta.entities` as widgets are with `@UI.widgets`. A member of any other enum would be
|
|
329
|
+
* catalogued under a heading the program never named.
|
|
330
|
+
*/
|
|
331
|
+
function checkCatalogue(program: Program): void {
|
|
332
|
+
const tagSets = declaredTagSets(program);
|
|
333
|
+
for (const [type, members] of tagMembers(program)) {
|
|
334
|
+
for (const member of members) {
|
|
335
|
+
if (tagSets.has(member.enum)) continue;
|
|
336
|
+
reportDiagnostic(program, {
|
|
337
|
+
code: "tag-not-declared",
|
|
338
|
+
target: type,
|
|
339
|
+
format: {
|
|
340
|
+
name: type.name,
|
|
341
|
+
tag: member.name,
|
|
342
|
+
enumName: member.enum.name,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const entitySets = declaredEntitySets(program);
|
|
348
|
+
for (const [type, member] of entityMembers(program)) {
|
|
349
|
+
if (entitySets.has(member.enum)) continue;
|
|
350
|
+
reportDiagnostic(program, {
|
|
351
|
+
code: "entity-not-declared",
|
|
352
|
+
target: type,
|
|
353
|
+
format: {
|
|
354
|
+
name: type.name,
|
|
355
|
+
entity: member.name,
|
|
356
|
+
enumName: member.enum.name,
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* A mapping is a contract with one of the program's emitters, declared with
|
|
364
|
+
* `@Mapping.targets` as a widget is with `@UI.widgets`. Each model linked in a mapping is
|
|
365
|
+
* resolved through everything it composes, and every link that does not hold there is
|
|
366
|
+
* reported once, however many forms compose the model it is declared on.
|
|
367
|
+
*/
|
|
368
|
+
function checkMappings(program: Program): void {
|
|
369
|
+
const declared = declaredMappingSets(program);
|
|
370
|
+
const links = allMappingLinks(program);
|
|
371
|
+
const undeclared = (target: Model | ModelProperty, mapping: EnumMember) => {
|
|
372
|
+
if (declared.has(mapping.enum)) return;
|
|
373
|
+
reportDiagnostic(program, {
|
|
374
|
+
code: "mapping-target-undeclared",
|
|
375
|
+
target,
|
|
376
|
+
format: {
|
|
377
|
+
name: target.name || "an anonymous model",
|
|
378
|
+
mapping: mapping.name,
|
|
379
|
+
enumName: mapping.enum.name,
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
for (const [model, paths] of allMappingPathLinks(program))
|
|
384
|
+
for (const { mapping } of paths) undeclared(model, mapping);
|
|
385
|
+
|
|
386
|
+
const roots: [Model, EnumMember][] = [];
|
|
387
|
+
for (const [target, list] of links) {
|
|
388
|
+
const seen = new Set<EnumMember>();
|
|
389
|
+
for (const { mapping, mappedTo } of list) {
|
|
390
|
+
undeclared(target, mapping);
|
|
391
|
+
if (seen.has(mapping)) {
|
|
392
|
+
reportDiagnostic(program, {
|
|
393
|
+
code: "mapping-duplicate",
|
|
394
|
+
target,
|
|
395
|
+
format: {
|
|
396
|
+
name: target.name || "an anonymous model",
|
|
397
|
+
mapping: mapping.name,
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
seen.add(mapping);
|
|
403
|
+
if (mappedTo.kind !== target.kind) {
|
|
404
|
+
reportDiagnostic(program, {
|
|
405
|
+
code: "mapping-type-mismatch",
|
|
406
|
+
target,
|
|
407
|
+
format: {
|
|
408
|
+
mapping: mapping.name,
|
|
409
|
+
source: target.name || "an anonymous model",
|
|
410
|
+
target: mappedTo.name || "an anonymous model",
|
|
411
|
+
reason:
|
|
412
|
+
target.kind === "Model"
|
|
413
|
+
? "a model corresponds to a model, not a property"
|
|
414
|
+
: "a property corresponds to a property, not a model",
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (target.kind === "Model") roots.push([target, mapping]);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const reported = new Set<string>();
|
|
424
|
+
for (const [model, mapping] of roots) {
|
|
425
|
+
for (const problem of resolveMappingWithProblems(program, model, mapping)
|
|
426
|
+
?.problems ?? []) {
|
|
427
|
+
const key = JSON.stringify([problem.code, problem.format]);
|
|
428
|
+
if (reported.has(key)) continue;
|
|
429
|
+
reported.add(key);
|
|
430
|
+
reportDiagnostic(program, problem);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
for (const [target, links] of allMappingFromLinks(program)) {
|
|
435
|
+
for (const { mapping } of links) undeclared(target, mapping);
|
|
436
|
+
if (target.kind !== "Model") continue;
|
|
437
|
+
for (const { mapping, source } of links) {
|
|
438
|
+
if (source.kind !== "Model") continue;
|
|
439
|
+
for (const problem of resolveMappingFrom(program, source, mapping)
|
|
440
|
+
?.problems ?? []) {
|
|
441
|
+
// A wrapper element is a limit of what an emitter writes, not a broken link: the
|
|
442
|
+
// emitter whose output cannot hold one reports it.
|
|
443
|
+
if (problem.code === "simpler-forms/mapping-from-wrapper") continue;
|
|
444
|
+
const key = JSON.stringify([problem.code, problem.message]);
|
|
445
|
+
if (reported.has(key)) continue;
|
|
446
|
+
reported.add(key);
|
|
447
|
+
program.reportDiagnostic(problem);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
287
453
|
function checkEncodedCheckboxGroup(
|
|
288
454
|
program: Program,
|
|
289
455
|
prop: ModelProperty,
|
|
@@ -505,6 +671,21 @@ function checkComputedPaths(program: Program, blocks: Block[]): void {
|
|
|
505
671
|
}
|
|
506
672
|
}
|
|
507
673
|
|
|
674
|
+
// ---------------------------------------------------------------------------
|
|
675
|
+
// layouts
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Every layout is resolved and laid out here, published or not, so a preview-only layout
|
|
679
|
+
* is checked as strictly as a form's.
|
|
680
|
+
*/
|
|
681
|
+
function checkLayouts(program: Program): void {
|
|
682
|
+
for (const [layout, presented] of allLayouts(program)) {
|
|
683
|
+
const resolved = resolveLayout(program, layout, presented);
|
|
684
|
+
program.reportDiagnostics(resolved.diagnostics);
|
|
685
|
+
program.reportDiagnostics(emitLayoutUi(program, resolved).diagnostics);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
508
689
|
// ---------------------------------------------------------------------------
|
|
509
690
|
// identity
|
|
510
691
|
|
|
@@ -691,58 +872,7 @@ function checkRequiredButHidden(program: Program, prop: ModelProperty): void {
|
|
|
691
872
|
}
|
|
692
873
|
|
|
693
874
|
// ---------------------------------------------------------------------------
|
|
694
|
-
//
|
|
695
|
-
|
|
696
|
-
function checkSections(program: Program, block: Block): void {
|
|
697
|
-
if (block.kind !== "form" || !block.sections) return;
|
|
698
|
-
for (const prop of orderedProps(program, block)) {
|
|
699
|
-
if (propOmit(program, prop)) continue;
|
|
700
|
-
if (propSection(program, prop)) continue;
|
|
701
|
-
if (typeof block.overrides[prop.name]?.section === "string") continue;
|
|
702
|
-
reportDiagnostic(program, {
|
|
703
|
-
code: "section-orphan",
|
|
704
|
-
target: prop,
|
|
705
|
-
format: { name: prop.name },
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* An override addresses a field by the path an applicant's answer takes. A path that does
|
|
712
|
-
* not resolve is a silently ignored override -- the CommonGrants bank's stringly-typed
|
|
713
|
-
* override table, caught at compile time instead of at website build time.
|
|
714
|
-
*/
|
|
715
|
-
function checkOverridePaths(program: Program, block: Block): void {
|
|
716
|
-
const paths = Object.keys(block.overrides);
|
|
717
|
-
for (const [overridePath, override] of Object.entries(block.overrides)) {
|
|
718
|
-
if (override.visibleReadOnly === true && override.readOnly !== true) {
|
|
719
|
-
reportDiagnostic(program, {
|
|
720
|
-
code: "visible-read-only-without-read-only",
|
|
721
|
-
target: block.model,
|
|
722
|
-
format: { path: overridePath },
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
const condition = override.enabledWhen;
|
|
726
|
-
const enabledWhen = condition as Record<string, unknown> | undefined;
|
|
727
|
-
if (
|
|
728
|
-
enabledWhen &&
|
|
729
|
-
typeof enabledWhen === "object" &&
|
|
730
|
-
!Array.isArray(enabledWhen) &&
|
|
731
|
-
typeof enabledWhen.path === "string"
|
|
732
|
-
) {
|
|
733
|
-
paths.push(enabledWhen.path);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
for (const path of paths) {
|
|
737
|
-
const reason = resolvePath(program, block.model as Model, path.split("."));
|
|
738
|
-
if (!reason) continue;
|
|
739
|
-
reportDiagnostic(program, {
|
|
740
|
-
code: "override-path-unresolved",
|
|
741
|
-
target: block.model,
|
|
742
|
-
format: { path, reason },
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|
|
875
|
+
// paths
|
|
746
876
|
|
|
747
877
|
/** Undefined when the path resolves; otherwise why it did not. */
|
|
748
878
|
function resolvePath(
|
|
@@ -790,7 +920,6 @@ function objectBehind(
|
|
|
790
920
|
return type;
|
|
791
921
|
}
|
|
792
922
|
|
|
793
|
-
/** A widget declaration naming a section the form does not have would render nothing. */
|
|
794
923
|
// ---------------------------------------------------------------------------
|
|
795
924
|
// calculations
|
|
796
925
|
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** The bounded, target-neutral condition shape supported by @UI.overrides.enabledWhen. */
|
|
2
|
-
export type NormalizedOverrideCondition = {
|
|
3
|
-
sourcePath: string[];
|
|
4
|
-
operator: "equals";
|
|
5
|
-
value: string | number | boolean | null;
|
|
6
|
-
} | {
|
|
7
|
-
sourcePath: string[];
|
|
8
|
-
operator: "in";
|
|
9
|
-
values: (string | number | boolean | null)[];
|
|
10
|
-
};
|
|
11
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
12
|
-
export declare function normalizedOverrideEnabledWhen(override: Record<string, unknown>): NormalizedOverrideCondition | undefined;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const primitive = (value) => value === null ||
|
|
2
|
-
typeof value === "string" ||
|
|
3
|
-
typeof value === "number" ||
|
|
4
|
-
typeof value === "boolean";
|
|
5
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
6
|
-
export function normalizedOverrideEnabledWhen(override) {
|
|
7
|
-
const raw = override.enabledWhen;
|
|
8
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
9
|
-
return undefined;
|
|
10
|
-
const condition = raw;
|
|
11
|
-
const path = condition.path;
|
|
12
|
-
if (typeof path !== "string" || !path)
|
|
13
|
-
return undefined;
|
|
14
|
-
const sourcePath = path.split(".").filter(Boolean);
|
|
15
|
-
if (!sourcePath.length)
|
|
16
|
-
return undefined;
|
|
17
|
-
const values = condition.in;
|
|
18
|
-
if (Array.isArray(values) && values.length > 0 && values.every(primitive)) {
|
|
19
|
-
return { sourcePath, operator: "in", values };
|
|
20
|
-
}
|
|
21
|
-
if (!primitive(condition.equals))
|
|
22
|
-
return undefined;
|
|
23
|
-
return { sourcePath, operator: "equals", value: condition.equals };
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=override-condition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"override-condition.js","sourceRoot":"","sources":["../../../src/emitters/override-condition.ts"],"names":[],"mappings":"AAaA,MAAM,SAAS,GAAG,CAAC,KAAc,EAA6C,EAAE,CAC9E,KAAK,KAAK,IAAI;IACd,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,KAAK,SAAS,CAAC;AAE7B,wFAAwF;AACxF,MAAM,UAAU,6BAA6B,CAC3C,QAAiC;IAEjC,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC;IACjC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5E,MAAM,SAAS,GAAG,GAA8B,CAAC;IACjD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** The bounded, target-neutral condition shape supported by @UI.overrides.enabledWhen. */
|
|
2
|
-
export type NormalizedOverrideCondition =
|
|
3
|
-
| {
|
|
4
|
-
sourcePath: string[];
|
|
5
|
-
operator: "equals";
|
|
6
|
-
value: string | number | boolean | null;
|
|
7
|
-
}
|
|
8
|
-
| {
|
|
9
|
-
sourcePath: string[];
|
|
10
|
-
operator: "in";
|
|
11
|
-
values: (string | number | boolean | null)[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const primitive = (value: unknown): value is string | number | boolean | null =>
|
|
15
|
-
value === null ||
|
|
16
|
-
typeof value === "string" ||
|
|
17
|
-
typeof value === "number" ||
|
|
18
|
-
typeof value === "boolean";
|
|
19
|
-
|
|
20
|
-
/** Parse enabledWhen once so canonical and target-specific UI emitters cannot drift. */
|
|
21
|
-
export function normalizedOverrideEnabledWhen(
|
|
22
|
-
override: Record<string, unknown>,
|
|
23
|
-
): NormalizedOverrideCondition | undefined {
|
|
24
|
-
const raw = override.enabledWhen;
|
|
25
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
26
|
-
const condition = raw as Record<string, unknown>;
|
|
27
|
-
const path = condition.path;
|
|
28
|
-
if (typeof path !== "string" || !path) return undefined;
|
|
29
|
-
const sourcePath = path.split(".").filter(Boolean);
|
|
30
|
-
if (!sourcePath.length) return undefined;
|
|
31
|
-
const values = condition.in;
|
|
32
|
-
if (Array.isArray(values) && values.length > 0 && values.every(primitive)) {
|
|
33
|
-
return { sourcePath, operator: "in", values };
|
|
34
|
-
}
|
|
35
|
-
if (!primitive(condition.equals)) return undefined;
|
|
36
|
-
return { sourcePath, operator: "equals", value: condition.equals };
|
|
37
|
-
}
|