@tsed/schema-formio 8.0.1 → 8.0.3

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.
Files changed (77) hide show
  1. package/package.json +11 -10
  2. package/src/components/anyToComponent.ts +28 -0
  3. package/src/components/arrayToComponent.ts +43 -0
  4. package/src/components/booleanToComponent.ts +15 -0
  5. package/src/components/dateToComponent.ts +66 -0
  6. package/src/components/defaultToComponent.ts +17 -0
  7. package/src/components/enumToComponent.ts +33 -0
  8. package/src/components/mapToComponent.ts +17 -0
  9. package/src/components/nestedToComponent.ts +23 -0
  10. package/src/components/numberToComponent.ts +20 -0
  11. package/src/components/objectToEditGrid.ts +13 -0
  12. package/src/components/panelToComponent.ts +13 -0
  13. package/src/components/propertiesToComponents.ts +106 -0
  14. package/src/components/stringToComponent.ts +44 -0
  15. package/src/decorators/component.ts +34 -0
  16. package/src/decorators/conditional.spec.ts +73 -0
  17. package/src/decorators/conditional.ts +49 -0
  18. package/src/decorators/currency.spec.ts +40 -0
  19. package/src/decorators/currency.ts +19 -0
  20. package/src/decorators/customClass.spec.ts +35 -0
  21. package/src/decorators/customClass.ts +14 -0
  22. package/src/decorators/customConditional.spec.ts +95 -0
  23. package/src/decorators/customConditional.ts +85 -0
  24. package/src/decorators/dataSourceJson.spec.ts +88 -0
  25. package/src/decorators/dataSourceJson.ts +26 -0
  26. package/src/decorators/dataSourceUrl.spec.ts +111 -0
  27. package/src/decorators/dataSourceUrl.ts +19 -0
  28. package/src/decorators/errorLabel.spec.ts +35 -0
  29. package/src/decorators/errorLabel.ts +14 -0
  30. package/src/decorators/errorMessage.spec.ts +35 -0
  31. package/src/decorators/errorMessage.ts +13 -0
  32. package/src/decorators/form.ts +25 -0
  33. package/src/decorators/hidden.spec.ts +35 -0
  34. package/src/decorators/hidden.ts +18 -0
  35. package/src/decorators/inputTags.spec.ts +36 -0
  36. package/src/decorators/inputTags.ts +22 -0
  37. package/src/decorators/label.spec.ts +34 -0
  38. package/src/decorators/label.ts +21 -0
  39. package/src/decorators/mask.spec.ts +105 -0
  40. package/src/decorators/mask.ts +46 -0
  41. package/src/decorators/maxWords.spec.ts +35 -0
  42. package/src/decorators/maxWords.ts +13 -0
  43. package/src/decorators/minWords.spec.ts +35 -0
  44. package/src/decorators/minWords.ts +13 -0
  45. package/src/decorators/modalEdit.spec.ts +35 -0
  46. package/src/decorators/modalEdit.ts +14 -0
  47. package/src/decorators/multiple.spec.ts +35 -0
  48. package/src/decorators/multiple.ts +14 -0
  49. package/src/decorators/openWhenEmpty.ts +14 -0
  50. package/src/decorators/password.spec.ts +35 -0
  51. package/src/decorators/password.ts +20 -0
  52. package/src/decorators/placeholder.spec.ts +35 -0
  53. package/src/decorators/placeholder.ts +15 -0
  54. package/src/decorators/prefix.spec.ts +35 -0
  55. package/src/decorators/prefix.ts +14 -0
  56. package/src/decorators/select.spec.ts +82 -0
  57. package/src/decorators/select.ts +25 -0
  58. package/src/decorators/suffix.spec.ts +35 -0
  59. package/src/decorators/suffix.ts +14 -0
  60. package/src/decorators/tableView.spec.ts +35 -0
  61. package/src/decorators/tableView.ts +15 -0
  62. package/src/decorators/tabs.ts +18 -0
  63. package/src/decorators/textCase.spec.ts +35 -0
  64. package/src/decorators/textCase.ts +15 -0
  65. package/src/decorators/textarea.spec.ts +35 -0
  66. package/src/decorators/textarea.ts +21 -0
  67. package/src/decorators/tooltip.spec.ts +35 -0
  68. package/src/decorators/tooltip.ts +15 -0
  69. package/src/decorators/validate.ts +18 -0
  70. package/src/domain/FormioDataResolver.ts +5 -0
  71. package/src/index.ts +52 -0
  72. package/src/registries/FormioMappersContainer.ts +21 -0
  73. package/src/registries/FormsContainer.ts +4 -0
  74. package/src/utils/getFormioProps.ts +12 -0
  75. package/src/utils/getFormioSchema.spec.ts +84 -0
  76. package/src/utils/getFormioSchema.ts +62 -0
  77. package/src/utils/getRef.ts +8 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/schema-formio",
3
3
  "description": "Transform Ts.ED Schema & JsonSchema to a valid Formio schema",
4
4
  "type": "module",
5
- "version": "8.0.1",
5
+ "version": "8.0.3",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -10,6 +10,7 @@
10
10
  "browser": "./lib/browser/schema-formio.umd.min.js",
11
11
  "exports": {
12
12
  ".": {
13
+ "@tsed/source": "./src/index.ts",
13
14
  "types": "./lib/types/index.d.ts",
14
15
  "browser": "./lib/browser/schema-formio.umd.min.js",
15
16
  "import": "./lib/esm/index.js",
@@ -38,24 +39,24 @@
38
39
  "tsed"
39
40
  ],
40
41
  "dependencies": {
41
- "@tsed/formio-types": "8.0.1",
42
+ "@tsed/formio-types": "8.0.3",
42
43
  "change-case": "^5.4.4",
43
44
  "tslib": "2.7.0"
44
45
  },
45
46
  "devDependencies": {
46
- "@tsed/barrels": "8.0.1",
47
- "@tsed/core": "8.0.1",
48
- "@tsed/openspec": "8.0.1",
49
- "@tsed/schema": "8.0.1",
50
- "@tsed/typescript": "8.0.1",
47
+ "@tsed/barrels": "8.0.3",
48
+ "@tsed/core": "8.0.3",
49
+ "@tsed/openspec": "8.0.3",
50
+ "@tsed/schema": "8.0.3",
51
+ "@tsed/typescript": "8.0.3",
51
52
  "eslint": "9.12.0",
52
53
  "typescript": "5.4.5",
53
54
  "vitest": "2.1.2"
54
55
  },
55
56
  "peerDependencies": {
56
- "@tsed/core": "8.0.1",
57
- "@tsed/openspec": "8.0.1",
58
- "@tsed/schema": "8.0.1",
57
+ "@tsed/core": "8.0.3",
58
+ "@tsed/openspec": "8.0.3",
59
+ "@tsed/schema": "8.0.3",
59
60
  "formiojs": ">=4.0.0",
60
61
  "lodash": ">=4.0.0",
61
62
  "moment": ">=2.0.0"
@@ -0,0 +1,28 @@
1
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
2
+ import {getRef} from "../utils/getRef.js";
3
+
4
+ export function anyToComponent(schema: any, options: any) {
5
+ schema = getRef(schema, options);
6
+
7
+ switch (schema?.type) {
8
+ case "object":
9
+ if (!schema.properties && !schema.$ref) {
10
+ return execMapper("map", schema, options);
11
+ }
12
+
13
+ return execMapper("nested", schema, options);
14
+ case "array":
15
+ return execMapper("array", schema, options);
16
+ case "string":
17
+ return execMapper("string", schema, options);
18
+ case "boolean":
19
+ return execMapper("boolean", schema, options);
20
+ case "integer":
21
+ case "number":
22
+ return execMapper("number", schema, options);
23
+ }
24
+
25
+ return {};
26
+ }
27
+
28
+ registerFormioMapper("any", anyToComponent);
@@ -0,0 +1,43 @@
1
+ import {cleanObject} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+ import {getRef} from "../utils/getRef.js";
5
+
6
+ export function arrayToComponent(schema: any, options: any) {
7
+ const itemSchema = schema.items.$ref ? getRef(schema.items, options) : schema.items;
8
+
9
+ const {type} = itemSchema;
10
+
11
+ switch (type) {
12
+ case "object": // editgrid
13
+ return {
14
+ ...execMapper("default", schema, options),
15
+ ...execMapper("editgrid", itemSchema, options)
16
+ };
17
+ case "string": // tag or enum?
18
+ if (itemSchema.enum) {
19
+ const component = execMapper("enum", itemSchema, options);
20
+
21
+ return {
22
+ ...component,
23
+ inline: false,
24
+ type: "selectboxes"
25
+ };
26
+ }
27
+
28
+ const component = execMapper(type, itemSchema, options);
29
+
30
+ return cleanObject({
31
+ ...component,
32
+ multiple: component.type === "tags" ? undefined : true
33
+ });
34
+ default:
35
+ case "number":
36
+ return {
37
+ ...execMapper(type, itemSchema, options),
38
+ multiple: true
39
+ };
40
+ }
41
+ }
42
+
43
+ registerFormioMapper("array", arrayToComponent);
@@ -0,0 +1,15 @@
1
+ import {cleanObject} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ function booleanToComponent(schema: any, options: any) {
6
+ const component = execMapper("default", schema, options);
7
+
8
+ return cleanObject({
9
+ ...component,
10
+ input: true,
11
+ type: component.type || "checkbox"
12
+ });
13
+ }
14
+
15
+ registerFormioMapper("boolean", booleanToComponent);
@@ -0,0 +1,66 @@
1
+ import {getValue} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ function dateToComponent(schema: any, options: any) {
6
+ const component = execMapper("default", schema, options);
7
+
8
+ const base = {
9
+ enableMinDateInput: false,
10
+ enableMaxDateInput: false,
11
+ input: true,
12
+ ...component,
13
+ type: "datetime",
14
+ datePicker: {
15
+ disableWeekends: false,
16
+ disableWeekdays: false,
17
+ ...getValue(component, "datePicker")
18
+ },
19
+ widget: {
20
+ type: "calendar",
21
+ displayInTimezone: "viewer",
22
+ locale: "en",
23
+ useLocaleSettings: false,
24
+ allowInput: true,
25
+ mode: "single",
26
+ noCalendar: false,
27
+ hourIncrement: 1,
28
+ minuteIncrement: 1,
29
+ minDate: null,
30
+ disableWeekends: false,
31
+ disableWeekdays: false,
32
+ maxDate: null,
33
+ ...getValue(component, "widget")
34
+ }
35
+ };
36
+
37
+ if (schema.format === "date") {
38
+ return {
39
+ ...base,
40
+ format: "yyyy-MM-dd",
41
+ enableTime: false,
42
+ widget: {
43
+ ...base.widget,
44
+ enableTime: false,
45
+ format: "yyyy-MM-dd",
46
+ ...getValue(component, "widget")
47
+ }
48
+ };
49
+ }
50
+
51
+ return {
52
+ ...base,
53
+ timePicker: {
54
+ showMeridian: false,
55
+ ...getValue(component, "timePicker")
56
+ },
57
+ widget: {
58
+ ...base.widget,
59
+ enableTime: true,
60
+ time_24hr: true,
61
+ ...getValue(component, "widget")
62
+ }
63
+ };
64
+ }
65
+
66
+ registerFormioMapper("date", dateToComponent);
@@ -0,0 +1,17 @@
1
+ import {cleanObject} from "@tsed/core";
2
+
3
+ import {registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+ import {getFormioProps} from "../utils/getFormioProps.js";
5
+
6
+ export function defaultToComponent(schema: any, options: any): any {
7
+ const formioProps = getFormioProps(schema);
8
+
9
+ return cleanObject({
10
+ ...formioProps,
11
+ disabled: !!schema.readOnly,
12
+ description: schema.description,
13
+ defaultValue: schema.default
14
+ });
15
+ }
16
+
17
+ registerFormioMapper("default", defaultToComponent);
@@ -0,0 +1,33 @@
1
+ import {cleanObject} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ export function enumToComponent(schema: any, options: any) {
6
+ const component = execMapper("default", schema, options);
7
+ const values = schema.enum.map((value: any) => {
8
+ return {
9
+ label: value,
10
+ value
11
+ };
12
+ });
13
+
14
+ if (component.type === "select") {
15
+ return cleanObject({
16
+ ...component,
17
+ data: {
18
+ json: component.data?.json || JSON.stringify(values)
19
+ },
20
+ dataSrc: "json",
21
+ idPath: "value",
22
+ valueProperty: "value",
23
+ template: component.template || "<span>{{ item.label }}</span>"
24
+ });
25
+ }
26
+
27
+ return cleanObject({
28
+ ...component,
29
+ values: schema["x-values"] || values.map((value: any) => ({...value, shortcut: ""}))
30
+ });
31
+ }
32
+
33
+ registerFormioMapper("enum", enumToComponent);
@@ -0,0 +1,17 @@
1
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
2
+
3
+ export function mapToComponent(schema: any, options: any) {
4
+ return {
5
+ ...execMapper("default", schema, options),
6
+ type: "datamap",
7
+ tableView: false,
8
+ input: true,
9
+ valueComponent: {
10
+ ...(schema.additionalProperties ? execMapper("any", schema.additionalProperties, options) : {}),
11
+ hideLabel: true,
12
+ tableView: true
13
+ }
14
+ };
15
+ }
16
+
17
+ registerFormioMapper("map", mapToComponent);
@@ -0,0 +1,23 @@
1
+ import {sentenceCase} from "change-case";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ export function nestedToComponent(schema: any, options: any) {
6
+ return {
7
+ ...execMapper("default", schema, options),
8
+ label: false,
9
+ tableView: false,
10
+ type: "form",
11
+ display: "form",
12
+ input: true,
13
+ components: [
14
+ {
15
+ key: "panel",
16
+ label: options.parentKey && sentenceCase(options.parentKey),
17
+ ...execMapper("panel", schema, options)
18
+ }
19
+ ]
20
+ };
21
+ }
22
+
23
+ registerFormioMapper("nested", nestedToComponent);
@@ -0,0 +1,20 @@
1
+ import {cleanObject, getValue} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ export function numberToComponent(schema: any, options: any) {
6
+ const component = execMapper("default", schema, options);
7
+
8
+ return cleanObject({
9
+ ...component,
10
+ input: true,
11
+ delimiter: getValue(component, "delimiter", false),
12
+ inputFormat: getValue(component, "inputFormat", "plain"),
13
+ mask: getValue(component, "mask", false),
14
+ requireDecimal: false,
15
+ type: "number"
16
+ });
17
+ }
18
+
19
+ registerFormioMapper("number", numberToComponent);
20
+ registerFormioMapper("integer", numberToComponent);
@@ -0,0 +1,13 @@
1
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
2
+
3
+ export function objectToEditGrid(schema: any, options: any) {
4
+ return {
5
+ ...execMapper("default", schema, options),
6
+ rowDrafts: false,
7
+ type: "editgrid",
8
+ input: true,
9
+ components: execMapper("properties", schema, options)
10
+ };
11
+ }
12
+
13
+ registerFormioMapper("editgrid", objectToEditGrid);
@@ -0,0 +1,13 @@
1
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
2
+
3
+ export function panelToComponent(schema: any, options: any) {
4
+ return {
5
+ ...execMapper("default", schema, options),
6
+ collapsible: false,
7
+ input: false,
8
+ tableView: false,
9
+ components: execMapper("properties", schema, options)
10
+ };
11
+ }
12
+
13
+ registerFormioMapper("panel", panelToComponent);
@@ -0,0 +1,106 @@
1
+ import {cleanObject, isFunction} from "@tsed/core";
2
+ import {FormioComponent, FormioForm} from "@tsed/formio-types";
3
+ import {sentenceCase} from "change-case";
4
+
5
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
6
+
7
+ function bindResolvers(component: FormioComponent, options: any) {
8
+ if (component.data) {
9
+ const data = {...component.data};
10
+
11
+ Object.entries(data).forEach(([key, resolver]) => {
12
+ if (isFunction(resolver)) {
13
+ options.resolvers.push(async (form: FormioForm) => {
14
+ data[key] = await resolver({...options, component, form});
15
+ });
16
+ }
17
+ });
18
+
19
+ return {
20
+ ...component,
21
+ data
22
+ };
23
+ }
24
+
25
+ return component;
26
+ }
27
+
28
+ function mapValidation(key: string, base: FormioComponent, schema: any, propSchema: any) {
29
+ const required = (schema.required || []).includes(key);
30
+ const validate = {
31
+ ...(base.validate || {}),
32
+ required,
33
+ pattern: propSchema.pattern,
34
+ minLength: !required || (required && propSchema.minLength > 1) ? propSchema.minLength : undefined,
35
+ maxLength: propSchema.maxLength,
36
+ min: propSchema.minimum || propSchema.minItems,
37
+ max: propSchema.maximum || propSchema.maxItems
38
+ };
39
+
40
+ switch (propSchema.type) {
41
+ case "string":
42
+ if (propSchema.minLength === 0 && validate.required) {
43
+ validate.minLength = undefined;
44
+ validate.required = false;
45
+ }
46
+ break;
47
+ case "boolean":
48
+ validate.required = false;
49
+ break;
50
+ }
51
+
52
+ return cleanObject(validate);
53
+ }
54
+
55
+ export function propertiesToComponents(schema: any, options: any): any[] {
56
+ const tabs = {
57
+ label: "Tabs",
58
+ key: "tabs",
59
+ type: "tabs",
60
+ input: false,
61
+ tableView: false,
62
+ components: new Map<string, any>(),
63
+ pushed: false
64
+ };
65
+ const components: any[] = [];
66
+
67
+ Object.entries(schema.properties).forEach(([key, propSchema]: [string, any]) => {
68
+ const tabsOptions = propSchema["x-formiotabs"];
69
+ const base = execMapper("any", propSchema, {...options, parentKey: key});
70
+
71
+ let component = cleanObject({
72
+ key,
73
+ ...base,
74
+ label: base.label == false ? undefined : base.label || propSchema.title || sentenceCase(key),
75
+ validate: mapValidation(key, base, schema, propSchema)
76
+ });
77
+
78
+ component = bindResolvers(component, options);
79
+
80
+ if (tabsOptions) {
81
+ if (!tabs.pushed) {
82
+ components.push(tabs);
83
+ tabs.pushed = true;
84
+ }
85
+
86
+ if (!tabs.components.has(tabsOptions.key)) {
87
+ tabs.components.set(tabsOptions.key, {
88
+ ...tabsOptions,
89
+ components: []
90
+ });
91
+ }
92
+
93
+ tabs.components.get(tabsOptions.key).components.push(component);
94
+ } else {
95
+ components.push(component);
96
+ }
97
+ });
98
+
99
+ if (tabs.components.size) {
100
+ tabs.components = [...tabs.components.values()] as any;
101
+ }
102
+
103
+ return components;
104
+ }
105
+
106
+ registerFormioMapper("properties", propertiesToComponents);
@@ -0,0 +1,44 @@
1
+ import {cleanObject} from "@tsed/core";
2
+
3
+ import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer.js";
4
+
5
+ export function stringToComponent(schema: any, options: any) {
6
+ if (schema.format) {
7
+ const component = execMapper("default", schema, options);
8
+ switch (schema.format) {
9
+ case "date":
10
+ case "date-time":
11
+ return execMapper("date", schema, options);
12
+ case "uri":
13
+ return cleanObject({
14
+ input: true,
15
+ ...component,
16
+ type: component.type || "url"
17
+ });
18
+ default:
19
+ return cleanObject({
20
+ input: true,
21
+ ...component,
22
+ type: component.type || schema.format
23
+ });
24
+ }
25
+ }
26
+
27
+ if (schema.enum) {
28
+ const component = execMapper("enum", schema, options);
29
+
30
+ return {
31
+ ...component,
32
+ type: component.type || "radio"
33
+ };
34
+ }
35
+
36
+ const component = execMapper("default", schema, options);
37
+ return cleanObject({
38
+ input: true,
39
+ type: component.type || "textfield",
40
+ ...component
41
+ });
42
+ }
43
+
44
+ registerFormioMapper("string", stringToComponent);
@@ -0,0 +1,34 @@
1
+ import {JsonEntityFn, JsonEntityStore} from "@tsed/schema";
2
+
3
+ /**
4
+ * Declare a formio Component schema on the decorated propertyKey.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ */
10
+ export function Component(component: Record<string, any>): PropertyDecorator {
11
+ component = Object.entries(component).reduce((component: Record<string, any>, [key, value]) => {
12
+ if (key === "validate") {
13
+ component["x-formio-validate"] = {
14
+ ...(component["x-formio-validate"] || {}),
15
+ ...value
16
+ };
17
+ }
18
+
19
+ return {
20
+ ...component,
21
+ [`x-formio-${key}`]: value
22
+ };
23
+ }, {});
24
+
25
+ return JsonEntityFn((store: JsonEntityStore) => {
26
+ Object.entries(component).forEach(([key, value]) => {
27
+ store.itemSchema.customKey(key, value);
28
+
29
+ if (store.isCollection) {
30
+ store.schema.customKey(key, value);
31
+ }
32
+ });
33
+ });
34
+ }
@@ -0,0 +1,73 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {HideWhen, ShowWhen} from "./conditional.js";
3
+
4
+ describe("@Conditional", () => {
5
+ it("should add conditional rule on field (show)", async () => {
6
+ class Model {
7
+ @ShowWhen("test2", 1)
8
+ test: string;
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ access: [],
13
+ components: [
14
+ {
15
+ disabled: false,
16
+ input: true,
17
+ key: "test",
18
+ label: "Test",
19
+ type: "textfield",
20
+ conditional: {
21
+ eq: 1,
22
+ show: true,
23
+ when: "test2"
24
+ },
25
+ validate: {
26
+ required: false
27
+ }
28
+ }
29
+ ],
30
+ display: "form",
31
+ machineName: "model",
32
+ name: "model",
33
+ submissionAccess: [],
34
+ tags: [],
35
+ title: "Model",
36
+ type: "form"
37
+ });
38
+ });
39
+ it("should add conditional rule on field (hide)", async () => {
40
+ class Model {
41
+ @HideWhen("test2", 1)
42
+ test: string;
43
+ }
44
+
45
+ expect(await getFormioSchema(Model)).toEqual({
46
+ access: [],
47
+ components: [
48
+ {
49
+ disabled: false,
50
+ input: true,
51
+ key: "test",
52
+ label: "Test",
53
+ type: "textfield",
54
+ conditional: {
55
+ eq: 1,
56
+ show: false,
57
+ when: "test2"
58
+ },
59
+ validate: {
60
+ required: false
61
+ }
62
+ }
63
+ ],
64
+ display: "form",
65
+ machineName: "model",
66
+ name: "model",
67
+ submissionAccess: [],
68
+ tags: [],
69
+ title: "Model",
70
+ type: "form"
71
+ });
72
+ });
73
+ });
@@ -0,0 +1,49 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Adds a conditional display rule on the input form.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ * @param conditional
10
+ */
11
+ export function Conditional(conditional: {show: boolean; when: string; eq: any}) {
12
+ return Component({
13
+ conditional
14
+ });
15
+ }
16
+
17
+ /**
18
+ * Adds a conditional display rule on the input form.
19
+ * @decorator
20
+ * @formio
21
+ * @property
22
+ * @schema
23
+ * @param property
24
+ * @param eq
25
+ */
26
+ export function ShowWhen(property: string, eq: any) {
27
+ return Conditional({
28
+ show: true,
29
+ when: property,
30
+ eq
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Adds a conditional display rule on the input form.
36
+ * @decorator
37
+ * @formio
38
+ * @property
39
+ * @schema
40
+ * @param property
41
+ * @param eq
42
+ */
43
+ export function HideWhen(property: string, eq: any) {
44
+ return Conditional({
45
+ show: false,
46
+ when: property,
47
+ eq
48
+ });
49
+ }