@scenid/react-formulator 0.5.3 → 0.5.5

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 (64) hide show
  1. package/dist/index.cjs.js +31 -35
  2. package/dist/index.esm.js +31 -35
  3. package/package.json +4 -1
  4. package/.babelrc +0 -30
  5. package/.eslintignore +0 -22
  6. package/.eslintrc +0 -70
  7. package/.firebaserc +0 -5
  8. package/.storybook/main.js +0 -12
  9. package/.storybook/preview.js +0 -9
  10. package/firebase.json +0 -22
  11. package/functions/.eslintignore +0 -1
  12. package/functions/.eslintrc.js +0 -29
  13. package/functions/index.js +0 -32
  14. package/functions/package-lock.json +0 -6810
  15. package/functions/package.json +0 -29
  16. package/rollup.config.js +0 -40
  17. package/src/Components/HiddenData.jsx +0 -24
  18. package/src/Components/SelectOrCreate.jsx +0 -156
  19. package/src/Editable/FormAutocomplete/FormAutocomplete.jsx +0 -155
  20. package/src/Editable/FormAutocomplete/useFetchOptions.js +0 -83
  21. package/src/Editable/FormBoolean.jsx +0 -46
  22. package/src/Editable/FormCatalogType.jsx +0 -29
  23. package/src/Editable/FormField.jsx +0 -231
  24. package/src/Editable/FormNumber.jsx +0 -36
  25. package/src/Editable/FormRepeater.jsx +0 -218
  26. package/src/Editable/FormSelect.jsx +0 -52
  27. package/src/Editable/FormText.jsx +0 -20
  28. package/src/FormGroupHeader.jsx +0 -85
  29. package/src/FormHelpers.js +0 -191
  30. package/src/FormSectionBlock.jsx +0 -71
  31. package/src/FormSectionCard.jsx +0 -62
  32. package/src/FormulatorForm.jsx +0 -539
  33. package/src/FormulatorFormSection.jsx +0 -456
  34. package/src/ReadOnly/FormReadOnlyBoolean.jsx +0 -36
  35. package/src/ReadOnly/FormReadOnlyField.jsx +0 -126
  36. package/src/ReadOnly/FormReadOnlyMarkdown.jsx +0 -20
  37. package/src/ReadOnly/FormReadOnlyNumber.jsx +0 -17
  38. package/src/ReadOnly/FormReadOnlyRepeater.jsx +0 -52
  39. package/src/ReadOnly/FormReadOnlySelect.jsx +0 -18
  40. package/src/ReadOnly/FormReadOnlyText.jsx +0 -45
  41. package/src/helpers.js +0 -13
  42. package/src/index.js +0 -20
  43. package/stories/CustomRenderField.jsx +0 -46
  44. package/stories/Forms.stories.jsx +0 -283
  45. package/stories/Introduction.stories.mdx +0 -206
  46. package/stories/StoryBase.jsx +0 -35
  47. package/stories/assets/code-brackets.svg +0 -1
  48. package/stories/assets/colors.svg +0 -1
  49. package/stories/assets/comments.svg +0 -1
  50. package/stories/assets/direction.svg +0 -1
  51. package/stories/assets/flow.svg +0 -1
  52. package/stories/assets/plugin.svg +0 -1
  53. package/stories/assets/repo.svg +0 -1
  54. package/stories/assets/stackalt.svg +0 -1
  55. package/stories/forms/login.render.schema.json +0 -23
  56. package/stories/forms/login.validation.schema.json +0 -29
  57. package/stories/forms/markdown.render.schema.json +0 -30
  58. package/stories/forms/markdown.validation.schema.json +0 -18
  59. package/stories/forms/register.render.schema.json +0 -32
  60. package/stories/forms/register.validation.schema.json +0 -34
  61. package/stories/forms/rlp.render.schema.json +0 -153
  62. package/stories/forms/rlp.translations.json +0 -883
  63. package/stories/forms/rlp.validation.schema.json +0 -1631
  64. package/stories/forms/types.schemas.js +0 -319
@@ -1,191 +0,0 @@
1
- /* eslint-disable max-classes-per-file */
2
- import Ajv from 'ajv'
3
-
4
- import validator from 'validator'
5
- import formatStringByPattern from 'format-string-by-pattern'
6
-
7
- export class Normalizer {
8
- static IBAN(value) {
9
- if (!value || value === '') return ''
10
- const finalValue = value.replace(/[^A-Z0-9]+/g, '')
11
- return formatStringByPattern('DE99 9999 9999 9999 9999 9999 9999 9999', finalValue)
12
- }
13
-
14
- static Verwendungszweck(value) {
15
- if (!value || value === '') return ''
16
- const finalValue = value.replace(/ä/, 'ae').replace(/ö/, 'oe').replace(/ü/, 'ue')
17
- return finalValue
18
- }
19
-
20
- static PhoneNumber(value) {
21
- if (!value || value === '') return ''
22
- const finalValue = value.replace(/[^0-9]/g, '')
23
- return finalValue
24
- }
25
- }
26
-
27
- export class Validator {
28
- static normalize(value) {
29
- return `${value}`
30
- }
31
-
32
- static isURL(value) {
33
- const string = Validator.normalize(value)
34
- if (!value || value === '' || validator.isURL(string)) return undefined
35
- return 'Muss eine URL sein'
36
- }
37
-
38
- static hasDigits(value) {
39
- const string = Validator.normalize(value)
40
- const valid = new RegExp(/\d/)
41
- if (string.match(valid)) return 'Straße darf keine Hausnummer beinhalten'
42
- return undefined
43
- }
44
-
45
- static isLength(min, max) {
46
- return value => {
47
- const string = Validator.normalize(value)
48
- if (!value || value === '' || validator.isLength(string, { min, max })) return undefined
49
- return `Länge muss zwischen ${min} und ${max !== undefined ? max : '∞'} liegen`
50
- }
51
- }
52
-
53
- static notEmpty(value) {
54
- const string = Validator.normalize(value)
55
- if ((validator.isEmpty(string) || string === 'undefined' || string === '')) return 'Darf nicht leer sein'
56
- return undefined
57
- }
58
-
59
- static isInt(value) {
60
- const string = Validator.normalize(value)
61
- if (!value || value === '' || validator.isInt(string)) return undefined
62
- return 'Muss eine Zahl sein'
63
- }
64
-
65
- static isEmail(value) {
66
- const string = Validator.normalize(value)
67
- if (!value || value === '' || validator.isEmail(string)) return undefined
68
- return 'Muss eine Email-Adresse sein'
69
- }
70
-
71
- static hasNoSpecialCharacters(value) {
72
- const string = Validator.normalize(value)
73
- const valid = new RegExp(/.*[^a-zA-Z0-9/ ?:().,'+-]+.*/)
74
- if (string.match(valid)) return 'Verwendungszweck darf nur Buchstaben, Zahlen und /?:().,\'+- beinhalten'
75
- return undefined
76
- }
77
-
78
- static async isUniqueProperty(property, value, whitelistedId) {
79
- const TYPE = {
80
- OU: 'OU',
81
- PERSON: 'Person',
82
- ADDRESS: 'Address'
83
- }
84
-
85
- const searchTarget = {
86
- reporterId: TYPE.OU,
87
- iknr: TYPE.OU,
88
- bsnr: TYPE.OU,
89
- product: TYPE.OU,
90
- lanr: TYPE.PERSON
91
- }
92
-
93
- const writtenProperty = {
94
- reporterId: 'Melder ID',
95
- bsnr: 'BSNR',
96
- lanr: 'LANR',
97
- iknr: 'IKNR',
98
- product: 'Produkt'
99
- }
100
-
101
- try {
102
- if (!searchTarget[property]) {
103
- throw new Error(`isUniqueProperty received incorrect property type. Property must be one of: ${Object.keys(searchTarget)}`)
104
- }
105
-
106
- // eslint-disable-next-line no-unused-vars
107
- const body = {
108
- search: {
109
- OU: (searchTarget[property] === TYPE.OU) ? [{ propName: property, query: value }] : [],
110
- Person: (searchTarget[property] === TYPE.PERSON) ? [{ propName: property, query: value }] : []
111
- }
112
- }
113
-
114
- // const { payload } = await apiRequest(METHOD.POST, settings.get('crm'), '/list', body, accessToken)
115
- const payload = { meta: 'FAKE', graph: 'FAKE' }
116
- const { meta, graph } = payload
117
-
118
- if (meta.count === 0) return true
119
-
120
- if (searchTarget[property] === TYPE.OU) {
121
- // eslint-disable-next-line prefer-destructuring
122
- const resultId = graph[0].ou.properties.id
123
- if (resultId !== whitelistedId) {
124
- throw new Error(`${writtenProperty[property]} wurde bereits für "${graph[0].ou.properties.name}" vergeben.`)
125
- }
126
- }
127
-
128
- if (searchTarget[property] === TYPE.PERSON) {
129
- // eslint-disable-next-line prefer-destructuring
130
- const employees = graph[0].employees
131
- employees.forEach(employee => {
132
- if (employee.id !== whitelistedId) {
133
- throw new Error(`${writtenProperty[property]} wurde bereits für "${employee.firstName} ${employee.lastName}" vergeben.`)
134
- }
135
- })
136
- }
137
- } catch (e) {
138
- return e.message
139
- }
140
-
141
- return true
142
- }
143
-
144
- static isOneOfValue(list) {
145
- return value => {
146
- const string = Validator.normalize(value)
147
- if (!list.includes(string)) return 'Bitte eine der Optionen wählen.'
148
- return undefined
149
- }
150
- }
151
- }
152
-
153
- export const clearFormValues = values => Object.entries(values).filter(e => e[1] !== null && e[1] !== undefined).map(e => ({ [e[0]]: e[1] })).reduce((l, r) => ({ ...l, ...r }), {})
154
-
155
- export const minimizeFormValues = (values, schema) => {
156
- const minimizedValues = {}
157
- const { properties } = schema
158
- Object.keys(values).forEach(value => {
159
- if (Object.keys(properties).some(prop => prop === value)) {
160
- minimizedValues[value] = values[value]
161
- }
162
- })
163
- return minimizedValues
164
- }
165
-
166
- export const validateFormValues = (values, schema) => {
167
- const ajv = new Ajv({ useDefaults: true, coerceTypes: true })
168
- const data = clearFormValues(values)
169
- const valid = ajv.validate(schema, data)
170
- const cleanData = cleanFormValues(data, schema)
171
- return { valid, data: cleanData, errors: ajv.errors }
172
- }
173
-
174
- const cleanFormValues = (values, schema) => {
175
- const { properties } = schema
176
- const cleanValues = {}
177
- Object.keys(values).forEach(valueKey => {
178
- // eslint-disable-next-line array-callback-return
179
- Object.keys(properties).some(schemaKey => {
180
- if (valueKey === schemaKey) cleanValues[valueKey] = values[valueKey]
181
- })
182
- })
183
- return cleanValues
184
- }
185
-
186
- export const mapFormValuesToProps = (formValuesToMap) => (state, { form }) => {
187
- // const selector = formValueSelector(form)
188
- const selector = form
189
- const values = formValuesToMap.map(v => ({ [v]: selector(state, v) })).reduce((l, r) => ({ ...l, ...r }), {})
190
- return { formValues: values }
191
- }
@@ -1,71 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import { Box } from '@material-ui/core'
5
- import { makeStyles } from '@material-ui/core/styles'
6
-
7
- import FormGroupHeader from './FormGroupHeader'
8
-
9
- const useStyles = makeStyles(theme => ({
10
- formSectionBlock: {
11
- '&:not(:last-child)': {
12
- marginBottom: theme.spacing(3)
13
- }
14
- }
15
- }))
16
-
17
- const FormSectionBlock = ({ label, labelVariant, desc, descVariant, textAlign, children }) => {
18
- const styles = useStyles()
19
-
20
- return (
21
- <Box className={styles.formSectionBlock}>
22
- <FormGroupHeader
23
- label={label}
24
- labelVariant={labelVariant}
25
- desc={desc}
26
- descVariant={descVariant}
27
- textAlign={textAlign}
28
- />
29
- {children}
30
- </Box>
31
- )
32
- }
33
-
34
- FormSectionBlock.propTypes = {
35
- label: PropTypes.string,
36
- labelVariant: PropTypes.oneOf([
37
- 'h1',
38
- 'h2',
39
- 'h3',
40
- 'h4',
41
- 'h5',
42
- 'h6',
43
- 'subtitle1',
44
- 'subtitle2',
45
- 'body1',
46
- 'body2',
47
- 'button',
48
- 'caption',
49
- 'overline'
50
- ]),
51
- desc: PropTypes.string,
52
- descVariant: PropTypes.oneOf([
53
- 'h1',
54
- 'h2',
55
- 'h3',
56
- 'h4',
57
- 'h5',
58
- 'h6',
59
- 'subtitle1',
60
- 'subtitle2',
61
- 'body1',
62
- 'body2',
63
- 'button',
64
- 'caption',
65
- 'overline'
66
- ]),
67
- textAlign: PropTypes.oneOf(['left', 'center', 'right']),
68
- children: PropTypes.node
69
- }
70
-
71
- export default FormSectionBlock
@@ -1,62 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import { Box, Paper } from '@material-ui/core'
5
-
6
- import FormGroupHeader from './FormGroupHeader'
7
-
8
- const FormSectionCard = ({ label, labelVariant, desc, descVariant, textAlign, children }) => (
9
- <Box mb={2}>
10
- <Paper elevation={0}>
11
- <Box p={2}>
12
- <FormGroupHeader
13
- label={label}
14
- labelVariant={labelVariant}
15
- desc={desc}
16
- descVariant={descVariant}
17
- textAlign={textAlign}
18
- />
19
- {children}
20
- </Box>
21
- </Paper>
22
- </Box>
23
- )
24
-
25
- FormSectionCard.propTypes = {
26
- label: PropTypes.string,
27
- labelVariant: PropTypes.oneOf([
28
- 'h1',
29
- 'h2',
30
- 'h3',
31
- 'h4',
32
- 'h5',
33
- 'h6',
34
- 'subtitle1',
35
- 'subtitle2',
36
- 'body1',
37
- 'body2',
38
- 'button',
39
- 'caption',
40
- 'overline'
41
- ]),
42
- desc: PropTypes.string,
43
- descVariant: PropTypes.oneOf([
44
- 'h1',
45
- 'h2',
46
- 'h3',
47
- 'h4',
48
- 'h5',
49
- 'h6',
50
- 'subtitle1',
51
- 'subtitle2',
52
- 'body1',
53
- 'body2',
54
- 'button',
55
- 'caption',
56
- 'overline'
57
- ]),
58
- textAlign: PropTypes.oneOf(['left', 'center', 'right']),
59
- children: PropTypes.node
60
- }
61
-
62
- export default FormSectionCard