@scenid/react-formulator 0.5.2 → 0.5.4

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 +34 -19
  2. package/dist/index.esm.js +34 -19
  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 -164
  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 -457
  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 -36
  39. package/src/ReadOnly/FormReadOnlySelect.jsx +0 -18
  40. package/src/ReadOnly/FormReadOnlyText.jsx +0 -41
  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 -267
  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,29 +0,0 @@
1
- {
2
- "name": "functions",
3
- "description": "Cloud Functions for Firebase",
4
- "scripts": {
5
- "lint": "eslint .",
6
- "serve": "firebase emulators:start --only functions",
7
- "shell": "firebase functions:shell",
8
- "start": "npm run shell",
9
- "deploy": "firebase deploy --only functions",
10
- "logs": "firebase functions:log"
11
- },
12
- "engines": {
13
- "node": "16"
14
- },
15
- "main": "index.js",
16
- "dependencies": {
17
- "cors": "^2.8.5",
18
- "eslint-config-standard": "^17.0.0",
19
- "express": "^4.18.0",
20
- "firebase-admin": "^10.0.2",
21
- "firebase-functions": "^3.18.0"
22
- },
23
- "devDependencies": {
24
- "eslint": "^8.9.0",
25
- "eslint-config-google": "^0.14.0",
26
- "firebase-functions-test": "^0.2.0"
27
- },
28
- "private": true
29
- }
package/rollup.config.js DELETED
@@ -1,40 +0,0 @@
1
- import babel from '@rollup/plugin-babel'
2
-
3
- import peerDepsExternal from 'rollup-plugin-peer-deps-external'
4
- import resolve from '@rollup/plugin-node-resolve'
5
- import commonjs from '@rollup/plugin-commonjs'
6
- import css from "rollup-plugin-import-css"
7
-
8
- import pkg from './package.json'
9
-
10
- export default {
11
- input: 'src/index.js',
12
- output: [
13
- { file: pkg.main, format: 'cjs' },
14
- { file: pkg.module, format: 'esm' }
15
- ],
16
- plugins: [
17
- peerDepsExternal(),
18
- babel({
19
- babelHelpers: 'runtime',
20
- exclude: 'node_modules/**',
21
- presets: [
22
- '@babel/preset-env',
23
- '@babel/preset-react'
24
- ],
25
- plugins: [
26
- '@babel/plugin-proposal-export-default-from',
27
- [
28
- '@babel/transform-runtime',
29
- { regenerator: true }
30
- ]
31
- ]
32
- }),
33
- resolve({
34
- extensions: ['.js', '.jsx'],
35
- preferBuiltins: true
36
- }),
37
- commonjs(),
38
- css()
39
- ]
40
- }
@@ -1,24 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import { Box, Typography } from '@material-ui/core'
5
- import { Alert } from '@material-ui/lab'
6
-
7
- const HiddenData = ({ subject, label }) => (
8
- <Box mb={2}>
9
- <Alert severity="warning">
10
- <Typography variant="body1">
11
- {subject ? `${subject} ` : ''}
12
- <span style={{ fontWeight: 'bold' }}>{label}</span>
13
- &nbsp;ist ausgeblendet.
14
- </Typography>
15
- </Alert>
16
- </Box>
17
- )
18
-
19
- HiddenData.propTypes = {
20
- subject: PropTypes.string,
21
- label: PropTypes.string.isRequired
22
- }
23
-
24
- export default HiddenData
@@ -1,156 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import { TextField, InputAdornment, CircularProgress } from '@material-ui/core'
5
-
6
- import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete'
7
-
8
- const filter = createFilterOptions()
9
-
10
- const renderInput = (
11
- {
12
- required,
13
- label,
14
- onInputChange,
15
- variant,
16
- loading
17
- },
18
- params
19
- ) => {
20
- let InputProps = params.InputProps || {}
21
-
22
- if (loading) {
23
- InputProps = {
24
- endAdornment: (
25
- <InputAdornment position="end">
26
- <CircularProgress
27
- size={20}
28
- thickness={4}
29
- />
30
- </InputAdornment>
31
- )
32
- }
33
- }
34
-
35
- return (
36
- <TextField
37
- // eslint-disable-next-line react/jsx-props-no-spreading
38
- {...params}
39
- required={required}
40
- label={label}
41
- variant={variant}
42
- onChange={onInputChange}
43
- InputProps={InputProps}
44
- />
45
- )
46
- }
47
-
48
- const SelectOrCreate = ({
49
- id,
50
- label,
51
- variant,
52
- loading,
53
- required,
54
- disabled,
55
- allowCreate,
56
- options,
57
- searchKey,
58
- renderOption,
59
- renderNewOption,
60
- value,
61
- onOpen,
62
- onClose,
63
- onChange,
64
- onInputChange
65
- }) => (
66
- <Autocomplete
67
- id={id}
68
- value={value}
69
- fullWidth
70
- disabled={disabled}
71
- onOpen={onOpen}
72
- onClose={onClose}
73
- onChange={(_, newValue) => {
74
- if (typeof newValue === 'string') {
75
- if (!allowCreate && Array.isArray(options) && !options.find(o => o.entry === newValue)) onChange(undefined)
76
- else onChange({ [searchKey]: newValue })
77
- } else if (allowCreate && newValue && newValue.inputValue) {
78
- // Create a new value from the user input
79
- onChange({ [searchKey]: newValue.inputValue })
80
- } else {
81
- onChange(newValue)
82
- }
83
- }}
84
- filterOptions={(allOptions, params) => {
85
- const filtered = filter(allOptions, params)
86
-
87
- // Suggest the creation of a new value
88
- if (allowCreate && params.inputValue !== '') {
89
- filtered.push({
90
- inputValue: params.inputValue,
91
- [searchKey]: renderNewOption(params.inputValue)
92
- })
93
- }
94
-
95
- return filtered
96
- }}
97
- selectOnFocus
98
- clearOnBlur
99
- handleHomeEndKeys
100
- options={options}
101
- getOptionLabel={option => {
102
- // Value selected with enter, right from the input
103
- if (typeof option === 'string') {
104
- if (!allowCreate && Array.isArray(options) && !options.find(o => o.entry === option)) return ''
105
- return option
106
- }
107
-
108
- // Add "xxx" option created dynamically
109
- if (option.inputValue) {
110
- return option.inputValue
111
- }
112
-
113
- // Regular option
114
- return option[searchKey]
115
- }}
116
- renderOption={renderOption}
117
- freeSolo
118
- renderInput={params => (
119
- renderInput(
120
- {
121
- required,
122
- disabled,
123
- label,
124
- onInputChange,
125
- variant,
126
- loading
127
- },
128
- params
129
- )
130
- )}
131
- />
132
- )
133
-
134
- SelectOrCreate.propTypes = {
135
- id: PropTypes.string,
136
- label: PropTypes.string.isRequired,
137
- variant: PropTypes.string,
138
- loading: PropTypes.bool,
139
- required: PropTypes.bool,
140
- disabled: PropTypes.bool,
141
- allowCreate: PropTypes.bool,
142
- options: PropTypes.array.isRequired,
143
- searchKey: PropTypes.string.isRequired,
144
- renderOption: PropTypes.func.isRequired,
145
- renderNewOption: PropTypes.func.isRequired,
146
- value: PropTypes.oneOfType([
147
- PropTypes.string,
148
- PropTypes.object
149
- ]).isRequired,
150
- onOpen: PropTypes.func,
151
- onClose: PropTypes.func,
152
- onChange: PropTypes.func.isRequired,
153
- onInputChange: PropTypes.func.isRequired
154
- }
155
-
156
- export default SelectOrCreate
@@ -1,164 +0,0 @@
1
- import React, { useEffect, useCallback } from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import {
5
- Box,
6
- Typography,
7
- FormControl,
8
- FormHelperText,
9
- TextField,
10
- InputAdornment,
11
- CircularProgress
12
- } from '@material-ui/core'
13
-
14
- import FormField from '../FormField'
15
- import FormReadOnlyText from '../../ReadOnly/FormReadOnlyText'
16
- import SelectOrCreate from '../../Components/SelectOrCreate'
17
-
18
- import useFetchOptions from './useFetchOptions'
19
-
20
- const FormAutocomplete = ({
21
- name,
22
- label,
23
- value,
24
- options: optionsArg,
25
- baererToken,
26
- allowCreate,
27
- dirty,
28
- hasErrors,
29
- errors,
30
- variant,
31
- required,
32
- disabled,
33
- readOnly,
34
- onChange
35
- }) => {
36
- const { loading, fetch, abort, options } = useFetchOptions(optionsArg, { token: baererToken })
37
-
38
- const changeValue = useCallback(newValue => { onChange({ target: { name, value: newValue?.entry || '' } }) }, [onChange])
39
-
40
- useEffect(() => {
41
- if (!readOnly) {
42
- fetch()
43
- }
44
- }, [])
45
-
46
- if (readOnly) {
47
- return (
48
- <FormField
49
- component={FormReadOnlyText}
50
- type="text"
51
- componentProps={{}}
52
- name={name}
53
- value={value}
54
- />
55
- )
56
- }
57
-
58
- if (!options) {
59
- return (
60
- <FormControl
61
- error={dirty && hasErrors}
62
- margin="dense"
63
- fullWidth
64
- required={required}
65
- >
66
- <TextField
67
- label={label}
68
- variant={variant}
69
- value={value}
70
- disabled
71
- InputProps={{
72
- endAdornment: (
73
- <InputAdornment position="end">
74
- <CircularProgress
75
- size={20}
76
- thickness={4}
77
- />
78
- </InputAdornment>
79
- )
80
- }}
81
- />
82
- </FormControl>
83
- )
84
- }
85
-
86
- return (
87
- <FormControl
88
- error={dirty && hasErrors}
89
- margin="dense"
90
- fullWidth
91
- required={required}
92
- >
93
- <SelectOrCreate
94
- loading={loading}
95
- label={label}
96
- variant={variant}
97
- allowCreate={allowCreate}
98
- options={options}
99
- searchKey="entry"
100
- required={required}
101
- disabled={disabled}
102
- renderOption={option => (
103
- <Box>
104
- <Typography variant="body1">
105
- {option.entry}
106
- </Typography>
107
- {
108
- (option.count !== undefined && option.count !== null)
109
- && (
110
- <Typography variant="caption">
111
- {`${option.count} Einträge`}
112
- </Typography>
113
- )
114
- }
115
- </Box>
116
- )}
117
- renderNewOption={newValue => (
118
- <Typography variant="body1">
119
- <strong>{`"${newValue}" `}</strong>
120
- erstellen
121
- </Typography>
122
- )}
123
- value={value}
124
- onOpen={() => {
125
- changeValue({ entry: value })
126
- fetch()
127
- }}
128
- onClose={abort}
129
- onChange={changeValue}
130
- />
131
- {
132
- (dirty && !disabled && hasErrors)
133
- && (
134
- <FormHelperText>
135
- {errors.map(e => e.message).join('. ')}
136
- </FormHelperText>
137
- )
138
- }
139
- </FormControl>
140
- )
141
- }
142
-
143
- FormAutocomplete.propTypes = {
144
- name: PropTypes.string,
145
- label: PropTypes.string,
146
- value: PropTypes.any,
147
- options: PropTypes.oneOfType([
148
- PropTypes.array,
149
- PropTypes.string,
150
- PropTypes.func
151
- ]).isRequired,
152
- baererToken: PropTypes.string,
153
- allowCreate: PropTypes.bool,
154
- variant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
155
- required: PropTypes.bool,
156
- disabled: PropTypes.bool,
157
- readOnly: PropTypes.bool,
158
- dirty: PropTypes.bool,
159
- hasErrors: PropTypes.bool,
160
- errors: PropTypes.array,
161
- onChange: PropTypes.func
162
- }
163
-
164
- export default FormAutocomplete
@@ -1,83 +0,0 @@
1
- import { useCallback, useRef, useState } from 'react'
2
-
3
- const abortableOAuthFetch = async (url, { token, signal }) => {
4
- let r, text, result
5
- try {
6
- const options = {
7
- method: 'GET'
8
- }
9
-
10
- if (token) {
11
- options.headers = {
12
- 'Content-Type': 'application/json',
13
- Authorization: `Bearer ${token}`
14
- }
15
- }
16
-
17
- if (signal) {
18
- options.signal = signal
19
- }
20
-
21
- r = await fetch(url, options)
22
-
23
- text = await r.text()
24
- result = JSON.parse(text)
25
- } catch (e) {
26
- throw new Error(text)
27
- }
28
-
29
- if (!r.ok) throw new Error(result.error)
30
-
31
- return result
32
- }
33
-
34
- const useFetchOptions = (arg, fetchOptions = {}) => {
35
- const controller = useRef()
36
-
37
- const [loading, setLoading] = useState(false)
38
- const [options, setOptions] = useState()
39
-
40
- const fetch = useCallback(async () => {
41
- if (Array.isArray(arg)) return setOptions(arg)
42
- if (typeof arg !== 'string' && typeof arg !== 'function') return setOptions([])
43
-
44
- let fetcher = arg
45
- if (typeof arg === 'string') {
46
- fetcher = signal => abortableOAuthFetch(arg, { token: fetchOptions.token, signal })
47
- }
48
-
49
- controller.current = new AbortController()
50
- setLoading(true)
51
-
52
- try {
53
- const r = await fetcher(controller.current.signal)
54
- controller.current = undefined
55
-
56
- if (!Array.isArray(r)) throw new Error('autocomplete fetcher returned a non array value')
57
-
58
- setOptions(r)
59
- } catch (e) {
60
- console.log(e)
61
- }
62
-
63
- setLoading(false)
64
- }, [arg, controller.current, setLoading, setOptions])
65
-
66
- const abort = useCallback(() => {
67
- if (loading) setLoading(false)
68
-
69
- if (controller.current) {
70
- controller.current.abort()
71
- controller.current = undefined
72
- }
73
- }, [loading, setLoading, controller.current])
74
-
75
- return {
76
- loading,
77
- fetch,
78
- abort,
79
- options
80
- }
81
- }
82
-
83
- export default useFetchOptions
@@ -1,46 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import { Checkbox, Switch } from '@material-ui/core'
5
-
6
- const isBoolean = val => val === false || val === true
7
- const isChecked = (value, defaultValue) => (isBoolean(value) ? value : (defaultValue || false))
8
-
9
- const FormBoolean = ({ variant, name, value, defaultValue, needsToBeTrue, onChange }) => {
10
- const handleChange = e => {
11
- let newValue = e.target.checked
12
- if (needsToBeTrue === true && newValue === false) newValue = undefined
13
- onChange({ target: { name, value: newValue } })
14
- }
15
-
16
- if (variant === 'checkbox') {
17
- return (
18
- <Checkbox
19
- color="primary"
20
- name={name}
21
- checked={isChecked(value, defaultValue)}
22
- onChange={handleChange}
23
- />
24
- )
25
- }
26
-
27
- return (
28
- <Switch
29
- color="primary"
30
- name={name}
31
- checked={isChecked(value, defaultValue)}
32
- onChange={handleChange}
33
- />
34
- )
35
- }
36
-
37
- FormBoolean.propTypes = {
38
- variant: PropTypes.string,
39
- name: PropTypes.string.isRequired,
40
- value: PropTypes.bool,
41
- defaultValue: PropTypes.bool,
42
- needsToBeTrue: PropTypes.bool,
43
- onChange: PropTypes.func.isRequired
44
- }
45
-
46
- export default FormBoolean
@@ -1,29 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- import FormAutocomplete from './FormAutocomplete/FormAutocomplete'
5
- import FormSelect from './FormSelect'
6
-
7
- const FormCatalogType = ({ type, options, autocomplete, ...props }) => {
8
- if (autocomplete === true) {
9
- return (
10
- <FormAutocomplete
11
- type="autocomplete"
12
- // eslint-disable-next-line react/jsx-props-no-spreading
13
- {...props}
14
- options={options.map(entry => ({ entry: entry.value }))}
15
- />
16
- )
17
- }
18
-
19
- // eslint-disable-next-line react/jsx-props-no-spreading
20
- return <FormSelect type={type} options={options} {...props} />
21
- }
22
-
23
- FormCatalogType.propTypes = {
24
- type: PropTypes.string.isRequired,
25
- options: PropTypes.array.isRequired,
26
- autocomplete: PropTypes.bool
27
- }
28
-
29
- export default FormCatalogType