@kaspernj/api-maker 1.0.441 → 1.0.443
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/package.json +1 -1
- package/src/bootstrap/checkbox.jsx +16 -9
- package/src/bootstrap/checkboxes.jsx +108 -45
- package/src/inputs/attachment.jsx +10 -7
- package/src/inputs/auto-submit.mjs +1 -1
- package/src/inputs/checkbox.jsx +23 -14
- package/src/params.mjs +6 -6
- package/src/table/table.jsx +2 -4
- package/src/use-input.mjs +13 -18
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
2
|
+
import Checkbox from "../inputs/checkbox"
|
|
2
3
|
import classNames from "classnames"
|
|
3
4
|
import {digs} from "diggerize"
|
|
4
|
-
import inputWrapper from "../inputs/input-wrapper"
|
|
5
5
|
import InvalidFeedback from "./invalid-feedback"
|
|
6
|
+
import memo from "set-state-compare/src/memo"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
7
8
|
import React from "react"
|
|
9
|
+
import useInput from "../use-input"
|
|
8
10
|
|
|
9
|
-
class ApiMakerBootstrapCheckbox extends
|
|
11
|
+
export default memo(shapeComponent(class ApiMakerBootstrapCheckbox extends ShapeComponent {
|
|
10
12
|
static defaultProps = {
|
|
11
13
|
defaultValue: 1,
|
|
12
14
|
zeroInput: true
|
|
@@ -28,8 +30,15 @@ class ApiMakerBootstrapCheckbox extends React.PureComponent {
|
|
|
28
30
|
zeroInput: PropTypes.bool
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
setup() {
|
|
34
|
+
const {inputProps, restProps: useInputRestProps, wrapperOpts} = useInput({props: this.props, wrapperOptions: {type: "checkbox"}})
|
|
35
|
+
|
|
36
|
+
this.setInstance({inputProps, useInputRestProps, wrapperOpts})
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
render () {
|
|
32
|
-
const {
|
|
40
|
+
const {inputProps, useInputRestProps, wrapperOpts} = this.tt
|
|
41
|
+
const {className, hint, id, inputRef, label, labelClassName, wrapperClassName, ...restProps} = useInputRestProps
|
|
33
42
|
const {errors} = digs(wrapperOpts, "errors")
|
|
34
43
|
|
|
35
44
|
return (
|
|
@@ -37,8 +46,8 @@ class ApiMakerBootstrapCheckbox extends React.PureComponent {
|
|
|
37
46
|
<div className="form-check">
|
|
38
47
|
<Checkbox
|
|
39
48
|
className={classNames("form-check-input", className, {"is-invalid": errors.length > 0})}
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
id={id}
|
|
50
|
+
inputRef={inputRef}
|
|
42
51
|
{...restProps}
|
|
43
52
|
/>
|
|
44
53
|
{wrapperOpts.label &&
|
|
@@ -74,6 +83,4 @@ class ApiMakerBootstrapCheckbox extends React.PureComponent {
|
|
|
74
83
|
|
|
75
84
|
return classNames.join(" ")
|
|
76
85
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default inputWrapper(ApiMakerBootstrapCheckbox, {type: "checkbox"})
|
|
86
|
+
}))
|
|
@@ -1,34 +1,115 @@
|
|
|
1
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
1
2
|
import {digs} from "diggerize"
|
|
2
|
-
import
|
|
3
|
+
import {useForm} from "../form"
|
|
3
4
|
import * as inflection from "inflection"
|
|
4
5
|
import InvalidFeedback from "./invalid-feedback"
|
|
6
|
+
import memo from "set-state-compare/src/memo"
|
|
5
7
|
import PropTypes from "prop-types"
|
|
6
8
|
import propTypesExact from "prop-types-exact"
|
|
7
|
-
import
|
|
9
|
+
import useInput from "../use-input"
|
|
10
|
+
import {useMemo} from "react"
|
|
8
11
|
|
|
9
|
-
class
|
|
12
|
+
const OptionElement = memo(shapeComponent(class OptionElement extends ShapeComponent {
|
|
13
|
+
render() {
|
|
14
|
+
const {generatedId, inputCheckboxClassName, isDefaultSelected, inputName, option, optionIndex, options, wrapperOpts} = this.p
|
|
15
|
+
const {errors} = digs(wrapperOpts, "errors")
|
|
16
|
+
const id = `${generatedId}-${optionIndex}`
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="checkboxes-option" key={`option-${option[1]}`}>
|
|
20
|
+
<input
|
|
21
|
+
className={inputCheckboxClassName}
|
|
22
|
+
data-option-value={option[1]}
|
|
23
|
+
defaultChecked={isDefaultSelected}
|
|
24
|
+
id={id}
|
|
25
|
+
name={inputName}
|
|
26
|
+
onChange={this.tt.onChange}
|
|
27
|
+
type="checkbox"
|
|
28
|
+
value={option[1]}
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
<label className="ml-1" htmlFor={id}>
|
|
32
|
+
{option[0]}
|
|
33
|
+
</label>
|
|
34
|
+
|
|
35
|
+
{(optionIndex + 1) == options.length && errors.length > 0 &&
|
|
36
|
+
<InvalidFeedback errors={errors} />
|
|
37
|
+
}
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onChange = (event, ...restProps) => {
|
|
43
|
+
this.p.onOptionChecked({event, option: this.p.option})
|
|
44
|
+
|
|
45
|
+
if (this.props.onChange) this.props.onChange(event, ...restProps)
|
|
46
|
+
}
|
|
47
|
+
}))
|
|
48
|
+
|
|
49
|
+
export default memo(shapeComponent(class ApiMakerBootstrapCheckboxes extends ShapeComponent {
|
|
10
50
|
static propTypes = propTypesExact({
|
|
11
51
|
attribute: PropTypes.string,
|
|
12
52
|
defaultValue: PropTypes.array,
|
|
13
|
-
inputProps: PropTypes.object.isRequired,
|
|
14
53
|
label: PropTypes.string,
|
|
15
54
|
labelClassName: PropTypes.string,
|
|
16
55
|
model: PropTypes.object,
|
|
17
56
|
name: PropTypes.string,
|
|
18
57
|
onChange: PropTypes.func,
|
|
19
|
-
options: PropTypes.array.isRequired
|
|
20
|
-
wrapperOpts: PropTypes.object.isRequired
|
|
58
|
+
options: PropTypes.array.isRequired
|
|
21
59
|
})
|
|
22
60
|
|
|
61
|
+
setup() {
|
|
62
|
+
const {inputProps, wrapperOpts} = useInput({props: this.props})
|
|
63
|
+
|
|
64
|
+
this.generatedId = useMemo(
|
|
65
|
+
() => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
|
|
66
|
+
[]
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
this.setInstance({
|
|
70
|
+
form: useForm(),
|
|
71
|
+
inputProps,
|
|
72
|
+
wrapperOpts
|
|
73
|
+
})
|
|
74
|
+
this.useStates({
|
|
75
|
+
checkedOptions: () => {
|
|
76
|
+
if (Array.isArray(this.props.defaultValue)) return this.props.defaultValue
|
|
77
|
+
if (this.props.defaultValue) return [this.props.defaultValue]
|
|
78
|
+
|
|
79
|
+
return []
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
useMemo(() => {
|
|
84
|
+
if (this.form && inputProps.name) {
|
|
85
|
+
this.form.setValue(inputProps.name, this.s.checkedOptions)
|
|
86
|
+
}
|
|
87
|
+
}, [])
|
|
88
|
+
}
|
|
89
|
+
|
|
23
90
|
render () {
|
|
24
91
|
return (
|
|
25
92
|
<div className="component-bootstrap-checkboxes form-group">
|
|
26
93
|
<label className={this.labelClassName()}>
|
|
27
|
-
{this.
|
|
94
|
+
{this.tt.wrapperOpts.label}
|
|
28
95
|
</label>
|
|
29
96
|
|
|
30
|
-
<input name={this.inputName()} ref={this.
|
|
31
|
-
{this.props.options.map((option, index) =>
|
|
97
|
+
<input name={this.inputName()} ref={this.tt.inputProps.ref} type="hidden" value="" />
|
|
98
|
+
{this.props.options.map((option, index) =>
|
|
99
|
+
<OptionElement
|
|
100
|
+
inputCheckboxClassName={this.tt.inputCheckboxClassName()}
|
|
101
|
+
inputName={this.inputName()}
|
|
102
|
+
isDefaultSelected={this.isDefaultSelected(option[1])}
|
|
103
|
+
generatedId={this.tt.generatedId}
|
|
104
|
+
key={option[1]}
|
|
105
|
+
onChange={this.props.onChange}
|
|
106
|
+
onOptionChecked={this.tt.onOptionChecked}
|
|
107
|
+
option={option}
|
|
108
|
+
optionIndex={index}
|
|
109
|
+
options={this.props.options}
|
|
110
|
+
wrapperOpts={this.tt.wrapperOpts}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
32
113
|
</div>
|
|
33
114
|
)
|
|
34
115
|
}
|
|
@@ -39,8 +120,7 @@ class ApiMakerBootstrapCheckboxes extends React.PureComponent {
|
|
|
39
120
|
if (defaultValue) {
|
|
40
121
|
return defaultValue
|
|
41
122
|
} else if (attribute && model) {
|
|
42
|
-
if (!model[attribute])
|
|
43
|
-
throw `No such attribute: ${attribute}`
|
|
123
|
+
if (!model[attribute]) throw `No such attribute: ${attribute}`
|
|
44
124
|
|
|
45
125
|
return this.props.model[attribute]()
|
|
46
126
|
}
|
|
@@ -49,7 +129,7 @@ class ApiMakerBootstrapCheckboxes extends React.PureComponent {
|
|
|
49
129
|
inputCheckboxClassName () {
|
|
50
130
|
const classNames = []
|
|
51
131
|
|
|
52
|
-
if (this.
|
|
132
|
+
if (this.tt.wrapperOpts.errors.length > 0) classNames.push("is-invalid")
|
|
53
133
|
|
|
54
134
|
return classNames.join(" ")
|
|
55
135
|
}
|
|
@@ -82,41 +162,24 @@ class ApiMakerBootstrapCheckboxes extends React.PureComponent {
|
|
|
82
162
|
return classNames.join(" ")
|
|
83
163
|
}
|
|
84
164
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
165
|
+
onOptionChecked = ({event, option}) => {
|
|
166
|
+
const {inputProps, form} = this.tt
|
|
167
|
+
const {name} = inputProps
|
|
168
|
+
const checked = event.target.checked
|
|
169
|
+
let newOptions
|
|
88
170
|
|
|
89
|
-
|
|
90
|
-
|
|
171
|
+
if (checked) {
|
|
172
|
+
newOptions = this.s.checkedOptions.concat([option[1]])
|
|
91
173
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const id = `${this.generatedId()}-${index}`
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<div className="checkboxes-option" key={`option-${option[1]}`}>
|
|
99
|
-
<input
|
|
100
|
-
className={this.inputCheckboxClassName()}
|
|
101
|
-
data-option-value={option[1]}
|
|
102
|
-
defaultChecked={this.isDefaultSelected(option[1])}
|
|
103
|
-
id={id}
|
|
104
|
-
name={this.inputName()}
|
|
105
|
-
onChange={onChange}
|
|
106
|
-
type="checkbox"
|
|
107
|
-
value={option[1]}
|
|
108
|
-
/>
|
|
174
|
+
this.setState({checkedOptions: newOptions})
|
|
175
|
+
} else {
|
|
176
|
+
newOptions = this.s.checkedOptions.filter((value) => value != option[1])
|
|
109
177
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
</label>
|
|
178
|
+
this.setState({checkedOptions: newOptions})
|
|
179
|
+
}
|
|
113
180
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
</div>
|
|
118
|
-
)
|
|
181
|
+
if (form && name) {
|
|
182
|
+
form.setValue(name, newOptions)
|
|
183
|
+
}
|
|
119
184
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export default inputWrapper(ApiMakerBootstrapCheckboxes)
|
|
185
|
+
}))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BaseComponent from "../base-component"
|
|
2
2
|
import {Input as ApiMakerInput} from "@kaspernj/api-maker/src/inputs/input"
|
|
3
|
-
import
|
|
3
|
+
import Checkbox from "./checkbox"
|
|
4
4
|
import memo from "set-state-compare/src/memo"
|
|
5
5
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
6
|
|
|
@@ -13,16 +13,19 @@ export default memo(shapeComponent(class ApiMakerInputsAttachment extends BaseCo
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
setup() {
|
|
16
|
+
const {inputProps} = useInput({props: this.props})
|
|
17
|
+
|
|
18
|
+
this.setInstance({inputProps})
|
|
16
19
|
this.useStates({
|
|
17
20
|
purgeChecked: false
|
|
18
21
|
})
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
render() {
|
|
22
|
-
const {
|
|
25
|
+
const {inputProps} = this.tt
|
|
26
|
+
const {attribute, checkboxComponent, className, label, model, name, onPurgeChanged, purgeName, wrapperOpts, ...restProps} = this.props
|
|
23
27
|
const CheckboxComponent = checkboxComponent || Checkbox
|
|
24
|
-
|
|
25
|
-
inputProps.type = "file"
|
|
28
|
+
const newInputProps = Object.assign({}, inputProps, {type: "file"})
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
31
|
<div className={classNames("api-maker--inputs--attachment", "components--inputs--input", className)} {...restProps}>
|
|
@@ -33,16 +36,16 @@ export default memo(shapeComponent(class ApiMakerInputsAttachment extends BaseCo
|
|
|
33
36
|
}
|
|
34
37
|
{this.getUrl() &&
|
|
35
38
|
<div className="input-checkbox" style={{paddingTop: "15px", paddingBottom: "15px"}}>
|
|
36
|
-
<CheckboxComponent
|
|
39
|
+
<CheckboxComponent id={this.getPurgeInputId()} name={this.getPurgeInputName()} onChange={this.props.onPurgeChanged} />
|
|
37
40
|
<label className="checkbox-label" htmlFor={this.getPurgeInputId()}>
|
|
38
41
|
{I18n.t("js.shared.delete")}
|
|
39
42
|
</label>
|
|
40
43
|
</div>
|
|
41
44
|
}
|
|
42
|
-
{!this.
|
|
45
|
+
{!this.s.purgeChecked &&
|
|
43
46
|
<ApiMakerInput
|
|
44
47
|
defaultValue={null}
|
|
45
|
-
inputProps={
|
|
48
|
+
inputProps={newInputProps}
|
|
46
49
|
model={model}
|
|
47
50
|
/>
|
|
48
51
|
}
|
|
@@ -17,7 +17,7 @@ export default class ApiMakerInputsAutoSubmit {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
value () {
|
|
20
|
-
const inputRef = this.component.props.inputRef || this.component.props.inputProps.ref || this.component.inputRef
|
|
20
|
+
const inputRef = this.component.props.inputRef || this.component.props.inputProps?.ref || this.component.inputProps?.ref || this.component.inputRef
|
|
21
21
|
const input = digg(inputRef, "current")
|
|
22
22
|
|
|
23
23
|
if (input.type == "checkbox") {
|
package/src/inputs/checkbox.jsx
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import AutoSubmit from "./auto-submit.mjs"
|
|
2
2
|
import BaseComponent from "../base-component"
|
|
3
|
-
import {digg
|
|
3
|
+
import {digg} from "diggerize"
|
|
4
4
|
import EventUpdated from "../event-updated"
|
|
5
|
-
import inputWrapper from "./input-wrapper"
|
|
6
5
|
import PropTypes from "prop-types"
|
|
7
6
|
import memo from "set-state-compare/src/memo"
|
|
8
7
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
8
|
+
import useInput from "../use-input"
|
|
9
9
|
import {useForm} from "../form"
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export default memo(shapeComponent(class ApiMakerInputsCheckbox extends BaseComponent {
|
|
12
12
|
static defaultProps = {
|
|
13
13
|
autoRefresh: false,
|
|
14
14
|
autoSubmit: false,
|
|
@@ -32,10 +32,24 @@ const ApiMakerInputsCheckbox = memo(shapeComponent(class ApiMakerInputsCheckbox
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
setup() {
|
|
35
|
-
this.
|
|
35
|
+
const {inputProps, restProps: useInputRestProps} = useInput({props: this.props, wrapperOptions: {type: "checkbox"}})
|
|
36
|
+
const {defaultValue, name} = inputProps
|
|
37
|
+
|
|
38
|
+
this.setInstance({
|
|
39
|
+
form: useForm(),
|
|
40
|
+
inputProps,
|
|
41
|
+
useInputRestProps
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
useMemo(() => {
|
|
45
|
+
if (name) {
|
|
46
|
+
this.tt.form?.setValue(name, defaultValue)
|
|
47
|
+
}
|
|
48
|
+
}, [])
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
render () {
|
|
52
|
+
const {inputProps, useInputRestProps} = this.tt
|
|
39
53
|
const {
|
|
40
54
|
attribute,
|
|
41
55
|
autoRefresh,
|
|
@@ -44,20 +58,18 @@ const ApiMakerInputsCheckbox = memo(shapeComponent(class ApiMakerInputsCheckbox
|
|
|
44
58
|
defaultChecked,
|
|
45
59
|
defaultValue,
|
|
46
60
|
id,
|
|
47
|
-
inputProps,
|
|
48
61
|
inputRef,
|
|
49
62
|
model,
|
|
50
63
|
name,
|
|
51
64
|
onChange,
|
|
52
65
|
zeroInput,
|
|
53
|
-
wrapperOpts,
|
|
54
66
|
...restProps
|
|
55
|
-
} =
|
|
67
|
+
} = useInputRestProps
|
|
56
68
|
|
|
57
69
|
return (
|
|
58
70
|
<>
|
|
59
71
|
{autoRefresh && model &&
|
|
60
|
-
<EventUpdated model={model} onUpdated={
|
|
72
|
+
<EventUpdated model={model} onUpdated={this.tt.onModelUpdated} />
|
|
61
73
|
}
|
|
62
74
|
{zeroInput && inputProps.name &&
|
|
63
75
|
<input defaultValue="0" name={inputProps.name} type="hidden" />
|
|
@@ -67,7 +79,7 @@ const ApiMakerInputsCheckbox = memo(shapeComponent(class ApiMakerInputsCheckbox
|
|
|
67
79
|
data-auto-refresh={autoRefresh}
|
|
68
80
|
data-auto-submit={autoSubmit}
|
|
69
81
|
defaultValue={defaultValue}
|
|
70
|
-
onChange={
|
|
82
|
+
onChange={this.tt.onChanged}
|
|
71
83
|
type="checkbox"
|
|
72
84
|
{...restProps}
|
|
73
85
|
/>
|
|
@@ -85,14 +97,14 @@ const ApiMakerInputsCheckbox = memo(shapeComponent(class ApiMakerInputsCheckbox
|
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
onModelUpdated = (args) => {
|
|
88
|
-
const inputRef = digg(this
|
|
100
|
+
const inputRef = digg(this.tt.inputProps, "ref")
|
|
89
101
|
|
|
90
102
|
if (!inputRef.current) {
|
|
91
103
|
// This can happen if the component is being unmounted
|
|
92
104
|
return
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
const {attribute} =
|
|
107
|
+
const {attribute} = this.p
|
|
96
108
|
const newModel = digg(args, "model")
|
|
97
109
|
const currentChecked = digg(inputRef, "current", "checked")
|
|
98
110
|
const newValue = newModel.readAttribute(attribute)
|
|
@@ -102,6 +114,3 @@ const ApiMakerInputsCheckbox = memo(shapeComponent(class ApiMakerInputsCheckbox
|
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
116
|
}))
|
|
105
|
-
|
|
106
|
-
export {ApiMakerInputsCheckbox as Checkbox}
|
|
107
|
-
export default inputWrapper(ApiMakerInputsCheckbox, {type: "checkbox"})
|
package/src/params.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import qs from "qs"
|
|
|
5
5
|
import urlEncode from "./url-encode.mjs"
|
|
6
6
|
|
|
7
7
|
export default class Params {
|
|
8
|
-
static parse
|
|
8
|
+
static parse() {
|
|
9
9
|
return qs.parse(globalThis.location.search.substr(1))
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
static change
|
|
12
|
+
static change(given) {
|
|
13
13
|
const incorporator = new Incorporator({objects: [Params.parse(), given]})
|
|
14
14
|
|
|
15
15
|
incorporator.replaceArrayIfExists(true)
|
|
@@ -17,14 +17,14 @@ export default class Params {
|
|
|
17
17
|
return incorporator.merge()
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
static withParams
|
|
20
|
+
static withParams(params) {
|
|
21
21
|
const newParams = qs.stringify(params, {encoder: urlEncode})
|
|
22
22
|
const newPath = `${location.pathname}?${newParams}`
|
|
23
23
|
|
|
24
24
|
return newPath
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
static changeParams
|
|
27
|
+
static changeParams(given, opts = {}) {
|
|
28
28
|
const params = Params.change(given)
|
|
29
29
|
const newParams = qs.stringify(params, {encoder: urlEncode})
|
|
30
30
|
const newPath = `${location.pathname}?${newParams}`
|
|
@@ -33,13 +33,13 @@ export default class Params {
|
|
|
33
33
|
appHistory.push(newPath)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
static serializeForm
|
|
36
|
+
static serializeForm(form) {
|
|
37
37
|
const hash = formSerialize(form, {empty: true, hash: true})
|
|
38
38
|
return Params.setUndefined(hash)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// This is used to set all empty values to 'undefined' which makes qs removed those elements from the query string
|
|
42
|
-
static setUndefined
|
|
42
|
+
static setUndefined(given) {
|
|
43
43
|
if (Array.isArray(given)) {
|
|
44
44
|
if (given.length == 0)
|
|
45
45
|
return undefined
|
package/src/table/table.jsx
CHANGED
|
@@ -536,7 +536,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
536
536
|
const {qParams} = digs(this.collection, "qParams")
|
|
537
537
|
|
|
538
538
|
return (
|
|
539
|
-
<Form className="live-table--filter-form" formRef={filterFormRef} onSubmit={this.onFilterFormSubmit} setForm={this.setStates.filterForm}>
|
|
539
|
+
<Form className="live-table--filter-form" formRef={filterFormRef} onSubmit={this.tt.onFilterFormSubmit} setForm={this.setStates.filterForm}>
|
|
540
540
|
{"s" in qParams &&
|
|
541
541
|
<input name="s" type="hidden" value={qParams.s} />
|
|
542
542
|
}
|
|
@@ -853,9 +853,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
853
853
|
onSettingsClicked = (e) => {
|
|
854
854
|
e.preventDefault()
|
|
855
855
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
this.setState({showSettings: !showSettings})
|
|
856
|
+
this.setState({showSettings: !this.s.showSettings})
|
|
859
857
|
}
|
|
860
858
|
|
|
861
859
|
submitFilter = () => {
|
package/src/use-input.mjs
CHANGED
|
@@ -6,7 +6,13 @@ import strftime from "strftime"
|
|
|
6
6
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
7
7
|
import useValidationErrors from "./use-validation-errors.mjs"
|
|
8
8
|
|
|
9
|
-
const useInput = ({props, wrapperOptions}) => {
|
|
9
|
+
const useInput = ({props, wrapperOptions, ...useInputRestProps}) => {
|
|
10
|
+
const useInputRestPropsKeys = Object.keys(useInputRestProps)
|
|
11
|
+
|
|
12
|
+
if (useInputRestPropsKeys.length > 0) {
|
|
13
|
+
throw new Error(`Unknown props given to useInput: ${useInputRestPropsKeys.join(", ")}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
const s = useShape(props)
|
|
11
17
|
|
|
12
18
|
s.useStates({
|
|
@@ -18,6 +24,8 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
18
24
|
}, [s.props.inputRef?.current])
|
|
19
25
|
|
|
20
26
|
s.meta.fakeComponent = {props}
|
|
27
|
+
s.meta.isCheckbox = props.type == "checkbox" || wrapperOptions?.type == "checkbox"
|
|
28
|
+
s.meta.isSelect = wrapperOptions?.type == "select"
|
|
21
29
|
|
|
22
30
|
const formatValue = useCallback((value) => {
|
|
23
31
|
const {formatValue} = s.props
|
|
@@ -36,19 +44,6 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
36
44
|
return value
|
|
37
45
|
}, [])
|
|
38
46
|
|
|
39
|
-
const handleAsCheckbox = useCallback(() => {
|
|
40
|
-
if (s.props.type == "checkbox") return true
|
|
41
|
-
if (!("type" in s.props) && wrapperOptions?.type == "checkbox") return true
|
|
42
|
-
|
|
43
|
-
return false
|
|
44
|
-
}, [])
|
|
45
|
-
|
|
46
|
-
const handleAsSelect = useCallback(() => {
|
|
47
|
-
if (wrapperOptions?.type == "select") return true
|
|
48
|
-
|
|
49
|
-
return false
|
|
50
|
-
}, [])
|
|
51
|
-
|
|
52
47
|
const inputDefaultChecked = useCallback(() => {
|
|
53
48
|
if ("defaultChecked" in s.props) {
|
|
54
49
|
return s.props.defaultChecked
|
|
@@ -83,7 +78,7 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
83
78
|
const inputType = useCallback(() => {
|
|
84
79
|
if ("type" in s.props) {
|
|
85
80
|
return s.props.type
|
|
86
|
-
} else if (
|
|
81
|
+
} else if (s.m.isCheckbox) {
|
|
87
82
|
return "checkbox"
|
|
88
83
|
} else {
|
|
89
84
|
return "text"
|
|
@@ -121,7 +116,7 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
121
116
|
givenInputProps
|
|
122
117
|
)
|
|
123
118
|
|
|
124
|
-
if (
|
|
119
|
+
if (s.m.isCheckbox) {
|
|
125
120
|
if ("checked" in s.props) {
|
|
126
121
|
inputProps.checked = s.props.checked
|
|
127
122
|
}
|
|
@@ -138,14 +133,14 @@ const useInput = ({props, wrapperOptions}) => {
|
|
|
138
133
|
return inputProps
|
|
139
134
|
}, [])
|
|
140
135
|
|
|
141
|
-
const {inputProps: oldInputProps, ...restProps} = props
|
|
136
|
+
const {inputProps: oldInputProps, wrapperOpts: oldWrapperOpts, ...restProps} = props
|
|
142
137
|
const type = inputType()
|
|
143
138
|
|
|
144
139
|
s.meta.inputProps = getInputProps()
|
|
145
140
|
s.meta.inputNameWithoutId = useMemo(() => s.m.inputProps.name?.replace(/\[(.+)_id\]$/, "[$1]"), [s.m.inputProps.name])
|
|
146
141
|
|
|
147
142
|
if (!s.m.inputProps.ref) throw new Error("No input ref?")
|
|
148
|
-
if (!
|
|
143
|
+
if (!s.m.isSelect) s.m.inputProps.type = type
|
|
149
144
|
|
|
150
145
|
const {validationErrors} = useValidationErrors((validationError) =>
|
|
151
146
|
validationError.inputName == s.m.inputProps.name || validationError.inputName == s.m.inputNameWithoutId
|