@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.
Files changed (52) hide show
  1. package/README.md +317 -53
  2. package/dist/index.d.mts +255 -0
  3. package/dist/index.d.ts +255 -0
  4. package/dist/index.js +548 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +539 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +84 -91
  9. package/src/components/HanzoProvider.test.tsx +346 -0
  10. package/src/components/HanzoProvider.tsx +508 -0
  11. package/src/hooks/index.ts +39 -0
  12. package/src/hooks/types.ts +162 -0
  13. package/src/hooks/useAuth.ts +0 -0
  14. package/src/hooks/useComponent.ts +0 -0
  15. package/src/hooks/useGenerativeUI.ts +0 -0
  16. package/src/hooks/useMCP.ts +0 -0
  17. package/src/hooks/useMessage.ts +105 -0
  18. package/src/hooks/useModelConfig.ts +0 -0
  19. package/src/hooks/useStreaming.ts +161 -0
  20. package/src/hooks/useSuggestions.ts +0 -0
  21. package/src/hooks/useThread.ts +0 -0
  22. package/src/hooks/useTool.ts +0 -0
  23. package/src/index.ts +40 -0
  24. package/src/types/index.ts +25 -0
  25. package/src/utils/cn.ts +6 -0
  26. package/src/utils/id.ts +6 -0
  27. package/src/utils/stream.ts +33 -0
  28. package/LICENSE +0 -21
  29. package/dist/index.cjs.js +0 -15736
  30. package/dist/index.cjs.js.map +0 -1
  31. package/dist/index.css +0 -789
  32. package/dist/index.esm.js +0 -15717
  33. package/dist/index.esm.js.map +0 -1
  34. package/dist/index.umd.js +0 -15737
  35. package/dist/index.umd.js.map +0 -1
  36. package/src/controls/.DS_Store +0 -0
  37. package/src/controls/MUICheckbox.js +0 -108
  38. package/src/controls/MUIKeyboardDatePicker.js +0 -90
  39. package/src/controls/MUIPhone.js +0 -33
  40. package/src/controls/MUISwitch.js +0 -107
  41. package/src/controls/MUIText.js +0 -284
  42. package/src/controls/NumericFormats.js +0 -55
  43. package/src/controls/control.js +0 -148
  44. package/src/controls/index.js +0 -7
  45. package/src/controls/material-ui-phone-number/components/Item.js +0 -66
  46. package/src/controls/material-ui-phone-number/components/flags.css +0 -789
  47. package/src/controls/material-ui-phone-number/components/index.js +0 -884
  48. package/src/controls/material-ui-phone-number/components/polyfills.js +0 -82
  49. package/src/controls/material-ui-phone-number/country_data.js +0 -1536
  50. package/src/controls/material-ui-phone-number/index.js +0 -3
  51. package/src/index.js +0 -1
  52. /package/src/{core/index.js → hooks/useAttachments.ts} +0 -0
Binary file
@@ -1,108 +0,0 @@
1
- import React, { Component } from 'react'
2
-
3
- import control from './control'
4
- import {
5
- Checkbox,
6
- MenuItem,
7
- FormControl,
8
- FormControlLabel,
9
- FormHelperText
10
- } from '@material-ui/core'
11
-
12
- import { withStyles } from '@material-ui/core/styles'
13
-
14
- //
15
- // *** Hanzo Standardized Checkbox ***
16
- //
17
-
18
- export class BaseMUICheckbox extends Component{
19
- constructor(props) {
20
- super(props)
21
- }
22
-
23
- change(e, checked) {
24
- let { onChange, onBlur } = this.props
25
- onChange = onChange || onBlur
26
-
27
- if (onChange) {
28
- onChange(checked)
29
- }
30
- }
31
-
32
- render() {
33
- let {
34
- id,
35
- value,
36
- defaultValue,
37
- error,
38
- helperText,
39
- disabled,
40
- children,
41
- classes,
42
- label,
43
- onBlur,
44
- onChange,
45
- ...props
46
- } = this.props
47
-
48
- if (!disabled) {
49
- disabled = this.disabled
50
- }
51
-
52
- value = value || defaultValue || false
53
-
54
- let c = pug`Checkbox(
55
- ...props
56
- id=id
57
- disabled=disabled
58
- checked=!!value
59
- onChange=this.change.bind(this)
60
- className=classes.pointer
61
- type='checkbox'
62
- )`
63
-
64
-
65
- return pug`
66
- .switch
67
- FormControl(className=classes.row)
68
- FormControlLabel(
69
- control=c
70
- label=label
71
- )
72
- div(className=classes.break)
73
- if !!helperText
74
- FormHelperText(
75
- disabled=disabled
76
- error=!!error
77
- className=classes.helper
78
- )
79
- =helperText
80
- `
81
- }
82
- }
83
-
84
- const styles = theme => ({
85
- pointer: {
86
- cursor: 'pointer',
87
- },
88
- row: {
89
- flexDirection: 'row',
90
- alignItems: 'center',
91
- flexWrap: 'wrap',
92
- },
93
- break: {
94
- flexBasis: '100%',
95
- height: 0,
96
- },
97
- label: {
98
- textAlign: 'left',
99
- cursor: 'pointer',
100
- },
101
- helper: {
102
- padding: '0 0 15px',
103
- margin: '-3px 0 0',
104
- },
105
- })
106
-
107
- @control
108
- export default withStyles(styles)(class MUICheckbox extends BaseMUICheckbox {})
@@ -1,90 +0,0 @@
1
- import React, { Component } from 'react'
2
- import moment from 'moment-timezone'
3
- import MomentUtils from '@date-io/moment'
4
- import { MuiPickersUtilsProvider } from '@material-ui/pickers'
5
-
6
- import control from './control'
7
- import { KeyboardDatePicker } from '@material-ui/pickers'
8
-
9
- import {
10
- defaultFormat,
11
- renderJSONDate,
12
- isFunction,
13
- } from '@hanzo/utils'
14
-
15
- //
16
- // *** Hanzo Standardized Keyboard Date Picker ***
17
- //
18
- // A Material UI Date Picker with Keyboard Support. It returns hanzo
19
- // compatible dates (rfc3339) and converts from hanzo compatible dates.
20
- //
21
- // Custom Fields
22
- // - unix - instead of converting to and from rfc3339, target unix time integers
23
- // instead
24
- //
25
-
26
- export class BaseMUIKeyboardDatePicker extends Component {
27
- options = undefined
28
-
29
- constructor(props) {
30
- super(props)
31
- }
32
-
33
- // Make it so that setters convert to unix dates if set to do so
34
- wrapUnixSetter(setter) {
35
- return (e) => {
36
- return setter(this.props.unix != null ? e.unix() : renderJSONDate(e))
37
- }
38
- }
39
-
40
- render() {
41
- let {
42
- value,
43
- defaultValue,
44
- format,
45
- shrink,
46
- onChange,
47
- onBlur,
48
- unix,
49
- inputVariant,
50
- variant,
51
- ...props
52
- } = this.props
53
-
54
- let isUnix = unix != null
55
-
56
- if (isFunction(onChange)) {
57
- onChange = this.wrapUnixSetter(onChange)
58
- }
59
-
60
- if (isFunction(onBlur)) {
61
- onBlur = this.wrapUnixSetter(onBlur)
62
- }
63
-
64
- // handle dates in unix mode
65
- if (isUnix) {
66
- if (value) {
67
- value = moment(value).unix()
68
- }
69
-
70
- if (defaultValue) {
71
- defaultValue = moment(defaultValue).unix()
72
- }
73
- }
74
-
75
- return pug`
76
- MuiPickersUtilsProvider(utils=MomentUtils)
77
- KeyboardDatePicker(
78
- ...props
79
- inputVariant=variant || inputVariant
80
- format=format || defaultFormat()
81
- onChange=onBlur || onChange
82
- value=value || defaultValue
83
- InputLabelProps={ shrink: !!value || !!defaultValue || shrink }
84
- )
85
- `
86
- }
87
- }
88
-
89
- @control
90
- export default class MUIKeyboardDatePicker extends BaseMUIKeyboardDatePicker {}
@@ -1,33 +0,0 @@
1
- import React, { useRef } from 'react'
2
-
3
- import control from './control'
4
-
5
- import MUIPhoneNumber from './material-ui-phone-number'
6
-
7
- //
8
- // *** Hanzo Standardized Material UI Phone Input ***
9
- //
10
- // This control requires onChange
11
- //
12
-
13
- export const BaseMUIPhone = ({
14
- defaultCountry,
15
- onChange,
16
- onBlur,
17
- ...props
18
- }) => {
19
- const ref = useRef()
20
- const oc = onChange || onBlur
21
-
22
- return (
23
- <div ref={ref}>
24
- <MUIPhoneNumber
25
- defaultCountry={defaultCountry === undefined ? 'us' : ''}
26
- onChange={oc}
27
- {...props}
28
- />
29
- </div>
30
- )
31
- }
32
-
33
- export default control(BaseMUIPhone)
@@ -1,107 +0,0 @@
1
- import React, { Component } from 'react'
2
-
3
- import control from './control'
4
- import {
5
- Switch,
6
- MenuItem,
7
- FormControl,
8
- FormControlLabel,
9
- FormHelperText
10
- } from '@material-ui/core'
11
-
12
- import { withStyles } from '@material-ui/core/styles'
13
-
14
- //
15
- // *** Hanzo Standardized Switch ***
16
- //
17
-
18
- export class BaseMUISwitch extends Component{
19
- constructor(props) {
20
- super(props)
21
- }
22
-
23
- change(e, checked) {
24
- let { onChange, onBlur } = this.props
25
- onChange = onChange || onBlur
26
-
27
- if (onChange) {
28
- onChange(checked)
29
- }
30
- }
31
-
32
- render() {
33
- let {
34
- id,
35
- value,
36
- defaultValue,
37
- error,
38
- helperText,
39
- disabled,
40
- children,
41
- classes,
42
- label,
43
- onBlur,
44
- onChange,
45
- ...props
46
- } = this.props
47
-
48
- if (!disabled) {
49
- disabled = this.disabled
50
- }
51
-
52
- value = value || defaultValue || false
53
-
54
- let c = pug`Switch(
55
- ...props
56
- id=id
57
- disabled=disabled
58
- checked=!!value
59
- onChange=this.change.bind(this)
60
- className=classes.pointer
61
- type='checkbox'
62
- )`
63
-
64
- return pug`
65
- .switch
66
- FormControl(className=classes.row)
67
- FormControlLabel(
68
- control=c
69
- label=label
70
- )
71
- div(className=classes.break)
72
- if !!helperText
73
- FormHelperText(
74
- disabled=disabled
75
- error=!!error
76
- className=classes.helper
77
- )
78
- =helperText
79
- `
80
- }
81
- }
82
-
83
- const styles = theme => ({
84
- pointer: {
85
- cursor: 'pointer',
86
- },
87
- row: {
88
- flexDirection: 'row',
89
- alignItems: 'center',
90
- flexWrap: 'wrap',
91
- },
92
- break: {
93
- flexBasis: '100%',
94
- height: 0,
95
- },
96
- label: {
97
- textAlign: 'left',
98
- cursor: 'pointer',
99
- },
100
- helper: {
101
- padding: '0 0 15px',
102
- margin: '-3px 0 0',
103
- },
104
- })
105
-
106
- @control
107
- export default withStyles(styles)(class MUISwitch extends BaseMUISwitch {})
@@ -1,284 +0,0 @@
1
- import {
2
- isFunction,
3
- } from '@hanzo/utils'
4
-
5
- import {
6
- MenuItem,
7
- TextField,
8
- } from '@material-ui/core'
9
-
10
- import React, {
11
- useEffect,
12
- useRef,
13
- useState,
14
- } from 'react'
15
-
16
- import raf from 'raf'
17
- import control from './control'
18
-
19
- const SPECIALNIL = '☭'
20
-
21
- const onChangeTimeoutIds = {}
22
-
23
- //
24
- // *** Hanzo Standardized Material UI Input ***
25
- //
26
- // A Material UI TextField with the following bug fixes:
27
- // - Selects can now auto set themselves to a placeholder when undefined
28
- // - defaultValue now takes the first non-undefined value so you cna
29
- // asynchronously set default value
30
- // - Forced always into uncontrolled mode so we don't fire a nonstandard onChange
31
- // event compared to a normal input
32
- //
33
- // Custom Fields
34
- // - placeholder - default value for selects
35
- // - options - automatically generate a list of selections/menu items based on
36
- // options map
37
- // - allowEmpty - Make the placeholder in select mode picakble with a
38
- // onBlur/onChange value of undefined
39
- // - shrink - shorthand for InputLabelProps{ shrink }, recommended taht you overwrite
40
- // the whole thing with custom shrink logic if using InputLabelProps
41
- // - sensitive - defaults to a password field unless focused
42
- //
43
-
44
- // Make it so that select can handle a specific nil value based on a rare
45
- // unicode special value because empty string does not work
46
- const wrapSelectSetter = (setter) => (
47
- (e) => {
48
- if (e === SPECIALNIL) {
49
- return setter(undefined)
50
- }
51
-
52
- if (e && e.target && e.target.value === e === SPECIALNIL) {
53
- const newE = Object.create(e, {
54
- target: {
55
- value: undefined,
56
- },
57
- })
58
-
59
- return setter(newE)
60
- }
61
-
62
- return setter(e)
63
- }
64
- )
65
-
66
- export const BaseMUIText = ({
67
- id,
68
- options = [],
69
- value,
70
- defaultValue,
71
- onChange,
72
- onBlur,
73
- onFocus,
74
- InnerComponent,
75
- select,
76
- placeholder,
77
- shrink,
78
- disableAutoChange,
79
- allowEmpty,
80
- sensitive,
81
- type,
82
- InputLabelProps,
83
- InputProps,
84
- ...props
85
- }) => {
86
- const [focused, setFocused] = useState(false)
87
- const inputRef = useRef()
88
-
89
- // Enable sensitive focus detection using Blur and Focus
90
- const wrapSensitiveBlur = (ob) => (
91
- (e) => {
92
- setFocused(false)
93
-
94
- if (isFunction(ob)) {
95
- ob(e)
96
- }
97
- }
98
- )
99
-
100
- const wrapSensitiveFocus = (of) => (
101
- (e) => {
102
- setFocused(true)
103
-
104
- if (isFunction(of)) {
105
- of(e)
106
- }
107
- }
108
- )
109
-
110
- const isSelect = select != null
111
- const isSensitive = sensitive != null
112
- const doesAllowEmpty = allowEmpty != null
113
-
114
- const selectOptions = []
115
-
116
- let oc = onChange
117
- let ob = onBlur
118
- let of = onFocus
119
- let dv = defaultValue
120
- let v = value
121
-
122
- if (isSelect) {
123
- // set the default value to '' if it doesn't exist
124
- if (!options[dv]) {
125
- dv = SPECIALNIL
126
- }
127
-
128
- // set the value to '' if it doesn't exist
129
- if (!options[v]) {
130
- v = SPECIALNIL
131
- dv = undefined
132
- }
133
-
134
- if (props.SelectProps && props.SelectProps.native) {
135
- if (placeholder) {
136
- if (doesAllowEmpty) {
137
- selectOptions.push(
138
- <option key={SPECIALNIL} value={SPECIALNIL}>
139
- {placeholder}
140
- </option>,
141
- )
142
- } else {
143
- selectOptions.push(
144
- <option disabled key={SPECIALNIL} value={SPECIALNIL}>
145
- {placeholder}
146
- </option>,
147
- )
148
- }
149
- }
150
- for (const k in options) {
151
- ((key) => {
152
- const opt = options[key]
153
-
154
- selectOptions.push(
155
- <option key={key} value={key}>
156
- {opt}
157
- </option>,
158
- )
159
- })(k)
160
- }
161
- } else {
162
- if (placeholder) {
163
- if (doesAllowEmpty) {
164
- selectOptions.push(
165
- <MenuItem key={SPECIALNIL} value={SPECIALNIL}>
166
- {placeholder}
167
- </MenuItem>,
168
- )
169
- } else {
170
- selectOptions.push(
171
- <MenuItem disabled key={SPECIALNIL} value={SPECIALNIL}>
172
- {placeholder}
173
- </MenuItem>,
174
- )
175
- }
176
- }
177
-
178
- for (const k in options) {
179
- ((key) => {
180
- const opt = options[key]
181
- selectOptions.push(
182
- <MenuItem key={key} value={key}>
183
- {opt}
184
- </MenuItem>,
185
- )
186
- })(k)
187
- }
188
- }
189
- }
190
-
191
- const [actualValue, setActualValue] = useState(v || dv)
192
-
193
- if (isFunction(oc)) {
194
- const wssoc = wrapSelectSetter(oc)
195
- oc = (e) => {
196
- setActualValue(e.target ? e.target.value : e)
197
- return wssoc(e)
198
- }
199
- }
200
-
201
- if (isFunction(ob)) {
202
- const wrappedOb = wrapSelectSetter(ob)
203
- ob = wrappedOb
204
-
205
- if (!isFunction(oc)) {
206
- oc = (ev) => {
207
- setActualValue(ev.target ? ev.target.value : ev)
208
- if (disableAutoChange) {
209
- return
210
- }
211
-
212
- clearTimeout(onChangeTimeoutIds[id])
213
-
214
- const { target } = ev
215
-
216
- if (isSelect) {
217
- wrappedOb({
218
- target,
219
- })
220
- } else {
221
- onChangeTimeoutIds[id] = setTimeout(() => {
222
- wrappedOb({
223
- target,
224
- })
225
- }, 500)
226
- }
227
- }
228
- }
229
- }
230
-
231
- // update component if value is different than actual value
232
- useEffect(() => {
233
- if (v !== actualValue) {
234
- raf(() => {
235
- clearTimeout(onChangeTimeoutIds[id])
236
- setActualValue(v)
237
- })
238
- }
239
- }, [v])
240
-
241
- ob = wrapSensitiveBlur(ob)
242
- of = wrapSensitiveFocus(of)
243
-
244
- const IC = InnerComponent || TextField
245
- const InputPropsCheck = InputProps || {}
246
-
247
- const shrinkInputLabelProps = !!(focused
248
- || (inputRef && inputRef.value)
249
- || !!v
250
- || !!dv
251
- || !!actualValue
252
- || shrink
253
- || isSelect
254
- || placeholder
255
- || InputPropsCheck.startAdornment
256
- || InputPropsCheck.endAdornment)
257
-
258
- return (
259
- <IC
260
- {...props}
261
- inputRef={inputRef}
262
- select={select}
263
- options={options}
264
- placeholder={isSelect ? '' : placeholder}
265
- type={(isSensitive && !focused) ? 'password' : type}
266
- value={actualValue}
267
- defaultValue={actualValue ? undefined : dv}
268
- onChange={isSelect ? (oc || ob) : oc}
269
- onBlur={isSelect ? wrapSensitiveBlur() : ob}
270
- onFocus={of}
271
- InputProps={InputProps}
272
- InputLabelProps={
273
- {
274
- shrink: shrinkInputLabelProps,
275
- ...InputLabelProps,
276
- }
277
- }
278
- >
279
- {selectOptions}
280
- </IC>
281
- )
282
- }
283
-
284
- export default control(BaseMUIText)
@@ -1,55 +0,0 @@
1
- import { signs } from '@hanzo/utils'
2
-
3
- import React from 'react'
4
- import NF from 'react-number-format'
5
-
6
- export const CreateCurrencyFormat = (currency, opts) => (
7
- (props) => {
8
- const {
9
- inputRef,
10
- onBlur,
11
- onChange,
12
- onFocus,
13
- value,
14
- ...other
15
- } = props
16
-
17
- return (
18
- <NF
19
- {...other}
20
- {...opts}
21
- value={value}
22
- getInputRef={inputRef}
23
- onChange={onChange}
24
- onBlur={onBlur}
25
- isNumericString
26
- prefix={signs[currency || '']}
27
- />
28
- )
29
- }
30
- )
31
-
32
- export const CreateNumberFormat = (opts) => (
33
- (props) => {
34
- const {
35
- inputRef,
36
- onBlur,
37
- onChange,
38
- onFocus,
39
- value,
40
- ...other
41
- } = props
42
-
43
- return (
44
- <NF
45
- {...other}
46
- {...opts}
47
- value={value}
48
- getInputRef={inputRef}
49
- onChange={onChange}
50
- onBlur={onBlur}
51
- isNumericString
52
- />
53
- )
54
- }
55
- )