@kaspernj/api-maker 1.0.352 → 1.0.354

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.352",
19
+ "version": "1.0.354",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -52,10 +52,11 @@
52
52
  "on-location-changed": ">= 1.0.10",
53
53
  "qs": ">= 6.9.3",
54
54
  "replaceall": ">= 0.1.6",
55
- "set-state-compare": ">= 1.0.30",
55
+ "set-state-compare": ">= 1.0.38",
56
56
  "spark-md5": "^3.0.2",
57
57
  "strftime": ">= 0.10.0",
58
58
  "uniqunize": "^1.0.1",
59
+ "use-did-mount": "^1.0.3",
59
60
  "wake-event": ">= 0.0.1"
60
61
  },
61
62
  "peerDependencies": {
@@ -5,8 +5,9 @@ import InvalidFeedback from "./invalid-feedback"
5
5
  import Money from "../inputs/money"
6
6
  import PropTypes from "prop-types"
7
7
  import React from "react"
8
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
8
9
 
9
- class ApiMakerBootstrapInput extends React.PureComponent {
10
+ const ApiMakerBootstrapInput = shapeComponent(class ApiMakerBootstrapInput extends ShapeComponent {
10
11
  static propTypes = {
11
12
  append: PropTypes.node,
12
13
  appendText: PropTypes.node,
@@ -58,7 +59,7 @@ class ApiMakerBootstrapInput extends React.PureComponent {
58
59
  const {errors} = digs(wrapperOpts, "errors")
59
60
 
60
61
  return (
61
- <div className={this.wrapperClassName()} ref="wrapper">
62
+ <div className={this.wrapperClassName()} ref={this.props.wrapperRef}>
62
63
  {wrapperOpts.label &&
63
64
  <label className={this.labelClassName()} htmlFor={inputProps.id}>
64
65
  {wrapperOpts.label}
@@ -73,7 +74,7 @@ class ApiMakerBootstrapInput extends React.PureComponent {
73
74
  <Money
74
75
  name={inputProps.name}
75
76
  className={this.inputClassName()}
76
- ref="money"
77
+ ref={this.props.moneyRef}
77
78
  {...this.moneyProps()}
78
79
  />
79
80
  }
@@ -166,6 +167,6 @@ class ApiMakerBootstrapInput extends React.PureComponent {
166
167
 
167
168
  return classNames.join(" ")
168
169
  }
169
- }
170
+ })
170
171
 
171
172
  export default inputWrapper(ApiMakerBootstrapInput)
@@ -4,11 +4,12 @@ import EventUpdated from "../event-updated"
4
4
  import inputWrapper from "./input-wrapper"
5
5
  import Money from "./money"
6
6
  import PropTypes from "prop-types"
7
- import React from "react"
7
+ import React, {useRef} from "react"
8
8
  import replaceall from "replaceall"
9
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
9
10
  import strftime from "strftime"
10
11
 
11
- class ApiMakerInputsInput extends React.PureComponent {
12
+ const ApiMakerInputsInput = shapeComponent(class ApiMakerInputsInput extends ShapeComponent {
12
13
  static defaultProps = {
13
14
  autoRefresh: false,
14
15
  autoSubmit: false,
@@ -30,9 +31,12 @@ class ApiMakerInputsInput extends React.PureComponent {
30
31
  type: PropTypes.string
31
32
  }
32
33
 
33
- visibleInputRef = React.createRef()
34
- state = {
35
- blankInputName: digg(this, "props", "inputProps", "type") == "file"
34
+ setup() {
35
+ this.visibleInputRef = useRef()
36
+
37
+ this.useStates({
38
+ blankInputName: digg(this, "props", "inputProps", "type") == "file"
39
+ })
36
40
  }
37
41
 
38
42
  render () {
@@ -132,9 +136,7 @@ class ApiMakerInputsInput extends React.PureComponent {
132
136
  return value
133
137
  }
134
138
 
135
- autoSubmit = () => {
136
- new AutoSubmit({component: this}).autoSubmit()
137
- }
139
+ autoSubmit = () => new AutoSubmit({component: this}).autoSubmit()
138
140
 
139
141
  formatValue (value) {
140
142
  const {formatValue, type} = this.props
@@ -180,9 +182,7 @@ class ApiMakerInputsInput extends React.PureComponent {
180
182
  return this.props.inputProps.name
181
183
  }
182
184
 
183
- inputReference() {
184
- return digg(this, "props", "inputProps", "ref")
185
- }
185
+ inputReference = () => digg(this, "props", "inputProps", "ref")
186
186
 
187
187
  onModelUpdated = (args) => {
188
188
  const inputRef = this.inputReference()
@@ -229,7 +229,7 @@ class ApiMakerInputsInput extends React.PureComponent {
229
229
  if (this.props.inputProps.type == "file" && value == "")
230
230
  return true
231
231
  }
232
- }
232
+ })
233
233
 
234
234
  export {ApiMakerInputsInput as Input}
235
235
  export default inputWrapper(ApiMakerInputsInput)
@@ -6,9 +6,10 @@ import * as inflection from "inflection"
6
6
  import MoneyFormatter from "../money-formatter"
7
7
  import PropTypes from "prop-types"
8
8
  import PropTypesExact from "prop-types-exact"
9
- import React from "react"
9
+ import React, {useRef} from "react"
10
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
10
11
 
11
- export default class ApiMakerInputsMoney extends React.PureComponent {
12
+ export default shapeComponent(class ApiMakerInputsMoney extends ShapeComponent {
12
13
  static defaultProps = {
13
14
  disabled: false,
14
15
  showCurrencyOptions: true
@@ -20,6 +21,7 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
20
21
  className: PropTypes.string,
21
22
  currenciesCollection: PropTypes.array,
22
23
  currencyName: PropTypes.string,
24
+ currencyRef: PropTypes.object,
23
25
  defaultValue: PropTypes.object,
24
26
  disabled: PropTypes.bool.isRequired,
25
27
  id: PropTypes.string,
@@ -31,10 +33,17 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
31
33
  placeholder: PropTypes.node,
32
34
  showCurrencyOptions: PropTypes.bool,
33
35
  small: PropTypes.bool,
34
- type: PropTypes.string
36
+ type: PropTypes.string,
37
+ wholeRef: PropTypes.object
35
38
  })
36
39
 
37
- inputRef = React.createRef()
40
+ setup() {
41
+ this.inputRef = useRef()
42
+ this.currencyRefBackup = useRef()
43
+ this.currencyRef = this.props.currencyRef || this.currencyRefBackup
44
+ this.wholeRefBackup = useRef()
45
+ this.wholeRef = this.props.wholeRef || this.wholeRefBackup
46
+ }
38
47
 
39
48
  getInputRef () {
40
49
  return this.props.inputRef || this.inputRef
@@ -58,7 +67,7 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
58
67
  onChange={digg(this, "setCents")}
59
68
  onKeyUp={digg(this, "setCents")}
60
69
  placeholder={this.props.placeholder}
61
- ref="whole"
70
+ ref={this.wholeRef}
62
71
  type="text"
63
72
  />
64
73
  {showCurrencyOptions &&
@@ -69,7 +78,7 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
69
78
  id={this.inputCurrencyId()}
70
79
  name={this.inputCurrencyName()}
71
80
  onChange={digg(this, "onCurrencyChanged")}
72
- ref="currency"
81
+ ref={this.currencyRef}
73
82
  >
74
83
  <option></option>
75
84
  {currenciesCollection.map((option) => (
@@ -149,19 +158,19 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
149
158
  const inputElement = this.getInputRef().current
150
159
 
151
160
  if (!inputElement.value && inputElement.value == "") {
152
- this.refs.whole.value = ""
161
+ this.wholeRef.current.value = ""
153
162
  } else {
154
163
  const cents = parseFloat(inputElement.value)
155
164
  const formatted = MoneyFormatter.fromMoney({amount: cents, currency: this.inputCurrencyValue()}, {decimals: 2, excludeCurrency: true}).toString()
156
165
 
157
- this.refs.whole.value = formatted
166
+ this.wholeRef.current.value = formatted
158
167
  }
159
168
  }
160
169
 
161
170
  setCents = () => {
162
171
  const inputElement = this.getInputRef().current
163
172
 
164
- let whole = MoneyFormatter.stringToFloat(this.refs.whole.value)
173
+ let whole = MoneyFormatter.stringToFloat(this.wholeRef.current.value)
165
174
  let cents = parseInt(whole * 100, 10)
166
175
  let oldCents = parseInt(inputElement.value, 10)
167
176
 
@@ -174,4 +183,4 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
174
183
  if (this.props.onChange && oldCents != cents)
175
184
  this.props.onChange()
176
185
  }
177
- }
186
+ })
package/src/use-input.mjs CHANGED
@@ -129,7 +129,7 @@ const useInput = ({props, wrapperOptions}) => {
129
129
  if ("defaultChecked" in s.props || (s.props.attribute && s.props.model)) {
130
130
  inputProps.defaultChecked = inputDefaultChecked()
131
131
  }
132
- } else {
132
+ } else if (!("value" in s.props)) {
133
133
  inputProps.defaultValue = inputDefaultValue()
134
134
  }
135
135