@tsed/schema-formio 8.0.0 → 8.0.2

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
@@ -0,0 +1,18 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Set hidden field.
5
+ *
6
+ * A hidden field is still a part of the form, but is hidden from view.
7
+ *
8
+ * @param bool
9
+ * @decorator
10
+ * @formio
11
+ * @property
12
+ * @schema
13
+ */
14
+ export function Hidden(bool: boolean = true): PropertyDecorator {
15
+ return Component({
16
+ hidden: bool
17
+ });
18
+ }
@@ -0,0 +1,36 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {InputTags} from "./inputTags.js";
3
+
4
+ describe("InputTags", () => {
5
+ it("should declare a model with Tags field", async () => {
6
+ class Model {
7
+ @InputTags()
8
+ test: string[];
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ components: [
13
+ {
14
+ key: "test",
15
+ type: "tags",
16
+ input: true,
17
+ label: "Test",
18
+ storeas: "array",
19
+ tableView: false,
20
+ disabled: false,
21
+ validate: {
22
+ required: false
23
+ }
24
+ }
25
+ ],
26
+ display: "form",
27
+ machineName: "model",
28
+ name: "model",
29
+ title: "Model",
30
+ type: "form",
31
+ submissionAccess: [],
32
+ access: [],
33
+ tags: []
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,22 @@
1
+ import {useDecorators} from "@tsed/core";
2
+ import {CollectionOf} from "@tsed/schema";
3
+
4
+ import {Component} from "./component.js";
5
+ /**
6
+ * Configure the property as Tags component.
7
+ * @decorator
8
+ * @formio
9
+ * @property
10
+ * @schema
11
+ */
12
+ export function InputTags(props: Record<string, any> = {}): PropertyDecorator {
13
+ return useDecorators(
14
+ CollectionOf(String),
15
+ Component({
16
+ ...props,
17
+ tableView: false,
18
+ storeas: "array",
19
+ type: "tags"
20
+ })
21
+ );
22
+ }
@@ -0,0 +1,34 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Label} from "./label.js";
3
+
4
+ describe("@Label", () => {
5
+ it("should add a tooltip on field", async () => {
6
+ class Model {
7
+ @Label("The label")
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: "The label",
19
+ type: "textfield",
20
+ validate: {
21
+ required: false
22
+ }
23
+ }
24
+ ],
25
+ display: "form",
26
+ machineName: "model",
27
+ name: "model",
28
+ submissionAccess: [],
29
+ tags: [],
30
+ title: "Model",
31
+ type: "form"
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,21 @@
1
+ import {CustomKey, JsonEntityFn} from "@tsed/schema";
2
+
3
+ import {Component} from "./component.js";
4
+
5
+ /**
6
+ * Change the label field
7
+ * @decorator
8
+ * @formio
9
+ * @property
10
+ * @schema
11
+ * @param label
12
+ */
13
+ export function Label(label: string) {
14
+ return JsonEntityFn((entity) => {
15
+ return entity.decoratorType === "property"
16
+ ? Component({
17
+ label
18
+ })
19
+ : CustomKey("x-formio-label", label);
20
+ });
21
+ }
@@ -0,0 +1,105 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Mask, Masks} from "./mask.js";
3
+
4
+ describe("@Mask", () => {
5
+ it("should add a mask on field (1)", async () => {
6
+ class Model {
7
+ @Mask("(99999)", "____")
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
+ inputMask: "(99999)",
21
+ inputMaskPlaceholderChar: "____",
22
+ validate: {
23
+ required: false
24
+ }
25
+ }
26
+ ],
27
+ display: "form",
28
+ machineName: "model",
29
+ name: "model",
30
+ submissionAccess: [],
31
+ tags: [],
32
+ title: "Model",
33
+ type: "form"
34
+ });
35
+ });
36
+ it("should add a mask on field (2)", async () => {
37
+ class Model {
38
+ @Mask("(99999)")
39
+ test: string;
40
+ }
41
+
42
+ expect(await getFormioSchema(Model)).toEqual({
43
+ access: [],
44
+ components: [
45
+ {
46
+ disabled: false,
47
+ input: true,
48
+ key: "test",
49
+ label: "Test",
50
+ type: "textfield",
51
+ inputMask: "(99999)",
52
+ inputMaskPlaceholderChar: "",
53
+ validate: {
54
+ required: false
55
+ }
56
+ }
57
+ ],
58
+ display: "form",
59
+ machineName: "model",
60
+ name: "model",
61
+ submissionAccess: [],
62
+ tags: [],
63
+ title: "Model",
64
+ type: "form"
65
+ });
66
+ });
67
+ });
68
+
69
+ describe("@Masks", () => {
70
+ it("should add masks on field", async () => {
71
+ class Model {
72
+ @Masks({label: "label", mask: "mask"})
73
+ test: string;
74
+ }
75
+
76
+ expect(await getFormioSchema(Model)).toEqual({
77
+ access: [],
78
+ components: [
79
+ {
80
+ disabled: false,
81
+ input: true,
82
+ key: "test",
83
+ label: "Test",
84
+ inputMasks: [
85
+ {
86
+ label: "label",
87
+ mask: "mask"
88
+ }
89
+ ],
90
+ type: "textfield",
91
+ validate: {
92
+ required: false
93
+ }
94
+ }
95
+ ],
96
+ display: "form",
97
+ machineName: "model",
98
+ name: "model",
99
+ submissionAccess: [],
100
+ tags: [],
101
+ title: "Model",
102
+ type: "form"
103
+ });
104
+ });
105
+ });
@@ -0,0 +1,46 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * An input mask helps the user with input by ensuring a predefined format.
5
+ *
6
+ * - 9: numeric
7
+ * - a: alphabetical
8
+ * - *: alphanumeric
9
+ *
10
+ * Example telephone mask: (999) 999-9999
11
+ *
12
+ * See the [jquery.inputmask](https://github.com/RobinHerbots/Inputmask) documentation for more information.
13
+ *
14
+ * @decorator
15
+ * @formio
16
+ * @property
17
+ * @schema
18
+ */
19
+ export function Mask(inputMask: string, inputMaskPlaceholderChar: string = "") {
20
+ return Component({
21
+ inputMask,
22
+ inputMaskPlaceholderChar
23
+ });
24
+ }
25
+
26
+ /**
27
+ * An input mask helps the user with input by ensuring a predefined format.
28
+ *
29
+ * - 9: numeric
30
+ * - a: alphabetical
31
+ * - *: alphanumeric
32
+ *
33
+ * Example telephone mask: (999) 999-9999
34
+ *
35
+ * See the [jquery.inputmask](https://github.com/RobinHerbots/Inputmask) documentation for more information.
36
+ *
37
+ * @decorator
38
+ * @formio
39
+ * @property
40
+ * @schema
41
+ */
42
+ export function Masks(...inputMasks: {label: string; mask: string}[]) {
43
+ return Component({
44
+ inputMasks
45
+ });
46
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {MaxWords} from "./maxWords.js";
3
+
4
+ describe("@MaxWords", () => {
5
+ it("should set the max words", async () => {
6
+ class Model {
7
+ @MaxWords(10)
8
+ test: string;
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ components: [
13
+ {
14
+ disabled: false,
15
+ input: true,
16
+ key: "test",
17
+ label: "Test",
18
+ type: "textfield",
19
+ validate: {
20
+ required: false,
21
+ maxWords: 10
22
+ }
23
+ }
24
+ ],
25
+ submissionAccess: [],
26
+ access: [],
27
+ tags: [],
28
+ display: "form",
29
+ machineName: "model",
30
+ name: "model",
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,13 @@
1
+ import {Validate} from "./validate.js";
2
+
3
+ /**
4
+ * Add the minimum amount of words that can be added to this field.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ * @param value
10
+ */
11
+ export function MaxWords(value: number) {
12
+ return Validate("maxWords", value);
13
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {MinWords} from "./minWords.js";
3
+
4
+ describe("@MinWords", () => {
5
+ it("should set the min words", async () => {
6
+ class Model {
7
+ @MinWords(10)
8
+ test: string;
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ components: [
13
+ {
14
+ disabled: false,
15
+ input: true,
16
+ key: "test",
17
+ label: "Test",
18
+ type: "textfield",
19
+ validate: {
20
+ required: false,
21
+ minWords: 10
22
+ }
23
+ }
24
+ ],
25
+ submissionAccess: [],
26
+ access: [],
27
+ tags: [],
28
+ display: "form",
29
+ machineName: "model",
30
+ name: "model",
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,13 @@
1
+ import {Validate} from "./validate.js";
2
+
3
+ /**
4
+ * Add the maximum amount of words that can be added to this field.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ * @param value
10
+ */
11
+ export function MinWords(value: number) {
12
+ return Validate("minWords", value);
13
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {ModalEdit} from "./modalEdit.js";
3
+
4
+ describe("@ModalEdit", () => {
5
+ it("should transform field to editable modal", async () => {
6
+ class Model {
7
+ @ModalEdit()
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
+ modalEdit: true,
20
+ type: "textfield",
21
+ validate: {
22
+ required: false
23
+ }
24
+ }
25
+ ],
26
+ display: "form",
27
+ machineName: "model",
28
+ name: "model",
29
+ submissionAccess: [],
30
+ tags: [],
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,14 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Opens up a modal to edit the value of this component.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ */
10
+ export function ModalEdit(modalEdit = true) {
11
+ return Component({
12
+ modalEdit
13
+ });
14
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Multiple} from "./multiple.js";
3
+
4
+ describe("Multiple", () => {
5
+ it("should declare a model with multiple field", async () => {
6
+ class Model {
7
+ @Multiple()
8
+ test: string;
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ components: [
13
+ {
14
+ disabled: false,
15
+ input: true,
16
+ key: "test",
17
+ label: "Test",
18
+ multiple: false,
19
+ type: "textfield",
20
+ validate: {
21
+ required: false
22
+ }
23
+ }
24
+ ],
25
+ display: "form",
26
+ machineName: "model",
27
+ submissionAccess: [],
28
+ access: [],
29
+ tags: [],
30
+ name: "model",
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,14 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Change the multiple value on the decorated property.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ */
10
+ export function Multiple(multiple = false): PropertyDecorator {
11
+ return Component({
12
+ multiple
13
+ });
14
+ }
@@ -0,0 +1,14 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Open automatically the editgrid when the list is empty.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ */
10
+ export function OpenWhenEmpty(openWhenEmpty = true): PropertyDecorator {
11
+ return Component({
12
+ openWhenEmpty
13
+ });
14
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Password} from "./password.js";
3
+
4
+ describe("Password", () => {
5
+ it("should declare a model with password field", async () => {
6
+ class Model {
7
+ @Password()
8
+ test: string;
9
+ }
10
+
11
+ expect(await getFormioSchema(Model)).toEqual({
12
+ components: [
13
+ {
14
+ disabled: false,
15
+ input: true,
16
+ key: "test",
17
+ label: "Test",
18
+ protected: true,
19
+ type: "password",
20
+ validate: {
21
+ required: false
22
+ }
23
+ }
24
+ ],
25
+ display: "form",
26
+ machineName: "model",
27
+ name: "model",
28
+ title: "Model",
29
+ type: "form",
30
+ submissionAccess: [],
31
+ access: [],
32
+ tags: []
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,20 @@
1
+ import {Component} from "./component.js";
2
+
3
+ export interface PasswordOpts extends Record<string, any> {
4
+ showCharCount?: boolean;
5
+ showWordCount?: boolean;
6
+ }
7
+ /**
8
+ * Configure the property as Password component.
9
+ * @decorator
10
+ * @formio
11
+ * @property
12
+ * @schema
13
+ */
14
+ export function Password(props: PasswordOpts = {}): PropertyDecorator {
15
+ return Component({
16
+ ...props,
17
+ type: "password",
18
+ protected: true
19
+ });
20
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Placeholder} from "./placeholder.js";
3
+
4
+ describe("@Placeholder", () => {
5
+ it("should add a placeholder on field", async () => {
6
+ class Model {
7
+ @Placeholder("The placeholder")
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
+ placeholder: "The placeholder",
20
+ type: "textfield",
21
+ validate: {
22
+ required: false
23
+ }
24
+ }
25
+ ],
26
+ display: "form",
27
+ machineName: "model",
28
+ name: "model",
29
+ submissionAccess: [],
30
+ tags: [],
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,15 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * The placeholder text that will appear when this field is empty.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ * @param placeholder
10
+ */
11
+ export function Placeholder(placeholder: string) {
12
+ return Component({
13
+ placeholder
14
+ });
15
+ }
@@ -0,0 +1,35 @@
1
+ import {getFormioSchema} from "../utils/getFormioSchema.js";
2
+ import {Prefix} from "./prefix.js";
3
+
4
+ describe("@Prefix", () => {
5
+ it("should add a prefix on field", async () => {
6
+ class Model {
7
+ @Prefix("The prefix")
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
+ prefix: "The prefix",
20
+ type: "textfield",
21
+ validate: {
22
+ required: false
23
+ }
24
+ }
25
+ ],
26
+ display: "form",
27
+ machineName: "model",
28
+ name: "model",
29
+ submissionAccess: [],
30
+ tags: [],
31
+ title: "Model",
32
+ type: "form"
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,14 @@
1
+ import {Component} from "./component.js";
2
+
3
+ /**
4
+ * Add prefix word on the decorated field.
5
+ * @decorator
6
+ * @formio
7
+ * @property
8
+ * @schema
9
+ */
10
+ export function Prefix(prefix: string) {
11
+ return Component({
12
+ prefix
13
+ });
14
+ }