@hanzo/react 0.1.3 → 1.0.0
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/README.md +317 -53
- package/dist/index.d.mts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +548 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +539 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +84 -91
- package/src/components/HanzoProvider.test.tsx +346 -0
- package/src/components/HanzoProvider.tsx +508 -0
- package/src/hooks/index.ts +39 -0
- package/src/hooks/types.ts +162 -0
- package/src/hooks/useAuth.ts +0 -0
- package/src/hooks/useComponent.ts +0 -0
- package/src/hooks/useGenerativeUI.ts +0 -0
- package/src/hooks/useMCP.ts +0 -0
- package/src/hooks/useMessage.ts +105 -0
- package/src/hooks/useModelConfig.ts +0 -0
- package/src/hooks/useStreaming.ts +161 -0
- package/src/hooks/useSuggestions.ts +0 -0
- package/src/hooks/useThread.ts +0 -0
- package/src/hooks/useTool.ts +0 -0
- package/src/index.ts +40 -0
- package/src/types/index.ts +25 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/id.ts +6 -0
- package/src/utils/stream.ts +33 -0
- package/LICENSE +0 -21
- package/dist/index.cjs.js +0 -15736
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.css +0 -789
- package/dist/index.esm.js +0 -15717
- package/dist/index.esm.js.map +0 -1
- package/dist/index.umd.js +0 -15737
- package/dist/index.umd.js.map +0 -1
- package/src/controls/.DS_Store +0 -0
- package/src/controls/MUICheckbox.js +0 -108
- package/src/controls/MUIKeyboardDatePicker.js +0 -90
- package/src/controls/MUIPhone.js +0 -33
- package/src/controls/MUISwitch.js +0 -107
- package/src/controls/MUIText.js +0 -284
- package/src/controls/NumericFormats.js +0 -55
- package/src/controls/control.js +0 -148
- package/src/controls/index.js +0 -7
- package/src/controls/material-ui-phone-number/components/Item.js +0 -66
- package/src/controls/material-ui-phone-number/components/flags.css +0 -789
- package/src/controls/material-ui-phone-number/components/index.js +0 -884
- package/src/controls/material-ui-phone-number/components/polyfills.js +0 -82
- package/src/controls/material-ui-phone-number/country_data.js +0 -1536
- package/src/controls/material-ui-phone-number/index.js +0 -3
- package/src/index.js +0 -1
- /package/src/{core/index.js → hooks/useAttachments.ts} +0 -0
package/src/controls/control.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useRef,
|
|
3
|
-
useState,
|
|
4
|
-
} from 'react'
|
|
5
|
-
|
|
6
|
-
import classnames from 'classnames'
|
|
7
|
-
import {
|
|
8
|
-
isFunction,
|
|
9
|
-
valueOrError,
|
|
10
|
-
valueOrEvent,
|
|
11
|
-
} from '@hanzo/utils'
|
|
12
|
-
|
|
13
|
-
import raf from 'raf'
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
// *** Hanzo Standardized Control Decorator ***
|
|
17
|
-
//
|
|
18
|
-
// A standardized control wrapper for making Hanzo controls all behave the same
|
|
19
|
-
// way and share a common props api.
|
|
20
|
-
//
|
|
21
|
-
// Features
|
|
22
|
-
// - Support react style hooks with getValue/setValue
|
|
23
|
-
// - setValue standarizes behavior use onBlur. This mostly has to do with
|
|
24
|
-
// Material UI using a nonstandard onChange event for controlled inputs
|
|
25
|
-
// - Standardizes the error field for setting the correct error and helperText
|
|
26
|
-
// states
|
|
27
|
-
// - The 'nice' api for controls:
|
|
28
|
-
//
|
|
29
|
-
// const {
|
|
30
|
-
// getValue
|
|
31
|
-
// setValue
|
|
32
|
-
// inputValue
|
|
33
|
-
// error
|
|
34
|
-
// showError
|
|
35
|
-
// } = this.props
|
|
36
|
-
//
|
|
37
|
-
// - Fully optional and compatible with normal Material UI
|
|
38
|
-
//
|
|
39
|
-
// Custom Fields
|
|
40
|
-
// - getValue - a function that is evaluated and is used to set value
|
|
41
|
-
// internally converted into a onBlur function
|
|
42
|
-
// - setValue - a function for taking value instead of an event, executes
|
|
43
|
-
// alongside onBlur. This is designed for creating uncontrolled inputs.
|
|
44
|
-
// - inputValue - a function fo taking value instead of an event, events
|
|
45
|
-
// alongside Material UI onChange (standard onInput). This is designed for
|
|
46
|
-
// creating controleld inputs.
|
|
47
|
-
// - error - setting to true or false replicates
|
|
48
|
-
// - showError - overwrite showing/hiding the error
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
let controlId = 0
|
|
52
|
-
|
|
53
|
-
export default (ControlComponent) => (
|
|
54
|
-
({
|
|
55
|
-
getValue,
|
|
56
|
-
setValue,
|
|
57
|
-
inputValue,
|
|
58
|
-
onBlur,
|
|
59
|
-
onChange,
|
|
60
|
-
defaultValue,
|
|
61
|
-
value,
|
|
62
|
-
error,
|
|
63
|
-
helperText,
|
|
64
|
-
showError,
|
|
65
|
-
...props
|
|
66
|
-
}) => {
|
|
67
|
-
const [id] = useState(() => controlId++)
|
|
68
|
-
const controlEl = useRef()
|
|
69
|
-
|
|
70
|
-
let se = showError
|
|
71
|
-
|
|
72
|
-
// show error defaults to true
|
|
73
|
-
if (se == null) {
|
|
74
|
-
se = true
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let v = value
|
|
78
|
-
let dv = defaultValue
|
|
79
|
-
|
|
80
|
-
// getValue supercedes both defaultValue and value
|
|
81
|
-
if (isFunction(getValue)) {
|
|
82
|
-
v = getValue()
|
|
83
|
-
dv = undefined
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let oc = onChange
|
|
87
|
-
let ob = onBlur
|
|
88
|
-
|
|
89
|
-
// inputValue supercedes setValue
|
|
90
|
-
if (isFunction(inputValue)) {
|
|
91
|
-
const originalOnChange = onChange
|
|
92
|
-
oc = (e) => {
|
|
93
|
-
inputValue(valueOrEvent(e))
|
|
94
|
-
if (isFunction(originalOnChange)) {
|
|
95
|
-
originalOnChange(e)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// setValue supercedes both onBlue and onChange
|
|
99
|
-
} else if (isFunction(setValue)) {
|
|
100
|
-
const originalOnBlur = onBlur
|
|
101
|
-
ob = (e) => {
|
|
102
|
-
setValue(valueOrEvent(e))
|
|
103
|
-
if (isFunction(originalOnBlur)) {
|
|
104
|
-
originalOnBlur(e)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
oc = undefined
|
|
108
|
-
|
|
109
|
-
// // if we are not using the getValue/setValue api, then we must load
|
|
110
|
-
// // a value into the system
|
|
111
|
-
// // some falsy values of value should not cause an initial update
|
|
112
|
-
// if (v != null && v !== '') {
|
|
113
|
-
// raf(() => {
|
|
114
|
-
// ob(v)
|
|
115
|
-
// })
|
|
116
|
-
// } else if (dv !== undefined) {
|
|
117
|
-
// raf(() => {
|
|
118
|
-
// ob(dv)
|
|
119
|
-
// })
|
|
120
|
-
// }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// error must be a string
|
|
124
|
-
const e = valueOrError(error)
|
|
125
|
-
|
|
126
|
-
return (
|
|
127
|
-
<div
|
|
128
|
-
ref={controlEl}
|
|
129
|
-
className={classnames({
|
|
130
|
-
control: true,
|
|
131
|
-
valid: !e,
|
|
132
|
-
invalid: e,
|
|
133
|
-
})}
|
|
134
|
-
>
|
|
135
|
-
<ControlComponent
|
|
136
|
-
id={`control-${id}`}
|
|
137
|
-
onBlur={ob}
|
|
138
|
-
onChange={oc}
|
|
139
|
-
error={!!(se && e)}
|
|
140
|
-
helperText={(se && e !== undefined && e !== false && e !== true) ? e : helperText}
|
|
141
|
-
value={v}
|
|
142
|
-
defaultValue={dv}
|
|
143
|
-
{...props}
|
|
144
|
-
/>
|
|
145
|
-
</div>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
)
|
package/src/controls/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as control } from './control'
|
|
2
|
-
export { default as MUIText, BaseMUIText } from './MUIText'
|
|
3
|
-
export { default as MUIPhone, BaseMUIPhone } from './MUIPhone'
|
|
4
|
-
export { default as MUICheckbox, BaseMUICheckbox } from './MUICheckbox'
|
|
5
|
-
export { default as MUISwitch, BaseMUISwitch } from './MUISwitch'
|
|
6
|
-
export { default as MUIKeyboardDatePicker, BaseMUIKeyboardDatePicker } from './MUIKeyboardDatePicker'
|
|
7
|
-
export * from './NumericFormats.js'
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React, { PureComponent } from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
import MenuItem from '@material-ui/core/MenuItem'
|
|
4
|
-
import RootRef from '@material-ui/core/RootRef'
|
|
5
|
-
|
|
6
|
-
import './flags.css'
|
|
7
|
-
|
|
8
|
-
class Item extends PureComponent {
|
|
9
|
-
render() {
|
|
10
|
-
const {
|
|
11
|
-
name, iso2, dialCode, localization, itemRef, native, ...restProps
|
|
12
|
-
} = this.props
|
|
13
|
-
|
|
14
|
-
if (native) {
|
|
15
|
-
return (
|
|
16
|
-
<option
|
|
17
|
-
className="country"
|
|
18
|
-
data-dial-code="1"
|
|
19
|
-
data-country-code={iso2}
|
|
20
|
-
value={iso2}
|
|
21
|
-
{...restProps}
|
|
22
|
-
>
|
|
23
|
-
{localization || name}
|
|
24
|
-
{' '}
|
|
25
|
-
{`+${dialCode}`}
|
|
26
|
-
</option>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<RootRef rootRef={(node) => itemRef(node)}>
|
|
32
|
-
<MenuItem
|
|
33
|
-
className="country"
|
|
34
|
-
data-dial-code="1"
|
|
35
|
-
data-country-code={iso2}
|
|
36
|
-
{...restProps}
|
|
37
|
-
>
|
|
38
|
-
<span className={`flag-icon flag-icon-${iso2}`}
|
|
39
|
-
style={{ width: 16, marginRight: 8 }}
|
|
40
|
-
/>
|
|
41
|
-
<span className="country-name">
|
|
42
|
-
{localization || name}
|
|
43
|
-
</span>
|
|
44
|
-
|
|
45
|
-
<span className="dial-code">{`+${dialCode}`}</span>
|
|
46
|
-
</MenuItem>
|
|
47
|
-
</RootRef>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Item.propTypes = {
|
|
53
|
-
name: PropTypes.string.isRequired,
|
|
54
|
-
iso2: PropTypes.string.isRequired,
|
|
55
|
-
dialCode: PropTypes.string.isRequired,
|
|
56
|
-
itemRef: PropTypes.func.isRequired,
|
|
57
|
-
localization: PropTypes.string,
|
|
58
|
-
native: PropTypes.bool,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
Item.defaultProps = {
|
|
62
|
-
localization: null,
|
|
63
|
-
native: false,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default Item
|