@hanzo/react 0.1.2 → 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 -15755
  30. package/dist/index.cjs.js.map +0 -1
  31. package/dist/index.css +0 -789
  32. package/dist/index.esm.js +0 -15736
  33. package/dist/index.esm.js.map +0 -1
  34. package/dist/index.umd.js +0 -15756
  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 -298
  42. package/src/controls/NumericFormats.js +0 -57
  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,298 +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
- useMemo,
13
- useRef,
14
- useState,
15
- } from 'react'
16
-
17
- import raf from 'raf'
18
- import control from './control'
19
-
20
- const SPECIALNIL = '☭'
21
-
22
- //
23
- // *** Hanzo Standardized Material UI Input ***
24
- //
25
- // A Material UI TextField with the following bug fixes:
26
- // - Selects can now auto set themselves to a placeholder when undefined
27
- // - defaultValue now takes the first non-undefined value so you cna
28
- // asynchronously set default value
29
- // - Forced always into uncontrolled mode so we don't fire a nonstandard onChange
30
- // event compared to a normal input
31
- //
32
- // Custom Fields
33
- // - placeholder - default value for selects
34
- // - options - automatically generate a list of selections/menu items based on
35
- // options map
36
- // - allowEmpty - Make the placeholder in select mode picakble with a
37
- // onBlur/onChange value of undefined
38
- // - shrink - shorthand for InputLabelProps{ shrink }, recommended taht you overwrite
39
- // the whole thing with custom shrink logic if using InputLabelProps
40
- // - sensitive - defaults to a password field unless focused
41
- //
42
-
43
- // Make it so that select can handle a specific nil value based on a rare
44
- // unicode special value because empty string does not work
45
- const wrapSelectSetter = (setter) => (
46
- (e) => {
47
- if (e === SPECIALNIL) {
48
- return setter(undefined)
49
- }
50
-
51
- if (e && e.target && e.target.value === e === SPECIALNIL) {
52
- const newE = Object.create(e, {
53
- target: {
54
- value: undefined,
55
- },
56
- })
57
-
58
- return setter(newE)
59
- }
60
-
61
- return setter(e)
62
- }
63
- )
64
-
65
- export const BaseMUIText = ({
66
- options = [],
67
- value,
68
- defaultValue,
69
- onChange,
70
- onBlur,
71
- onFocus,
72
- InnerComponent,
73
- select,
74
- placeholder,
75
- shrink,
76
- disableAutoChange,
77
- allowEmpty,
78
- sensitive,
79
- type,
80
- InputLabelProps,
81
- InputProps,
82
- ...props
83
- }) => {
84
- const [focused, setFocused] = useState(false)
85
- const inputRef = useRef()
86
-
87
- // Enable sensitive focus detection using Blur and Focus
88
- const wrapSensitiveBlur = (ob) => (
89
- (e) => {
90
- setFocused(false)
91
- console.log('what')
92
-
93
- if (isFunction(ob)) {
94
- ob(e)
95
- }
96
- }
97
- )
98
-
99
- const wrapSensitiveFocus = (of) => (
100
- (e) => {
101
- setFocused(true)
102
-
103
- if (isFunction(of)) {
104
- of(e)
105
- }
106
- }
107
- )
108
-
109
- const isSelect = select != null
110
- const isSensitive = sensitive != null
111
- const doesAllowEmpty = allowEmpty != null
112
-
113
- const selectOptions = []
114
-
115
- let oc = onChange
116
- let ob = onBlur
117
- let of = onFocus
118
- let dv = defaultValue
119
- let v = value
120
-
121
- if (isSelect) {
122
- // set the default value to '' if it doesn't exist
123
- if (!options[dv]) {
124
- dv = SPECIALNIL
125
- }
126
-
127
- // set the value to '' if it doesn't exist
128
- if (!options[v]) {
129
- v = SPECIALNIL
130
- dv = undefined
131
- }
132
-
133
- if (props.SelectProps && props.SelectProps.native) {
134
- if (placeholder) {
135
- if (doesAllowEmpty) {
136
- selectOptions.push(
137
- <option key={SPECIALNIL} value={SPECIALNIL}>
138
- {placeholder}
139
- </option>,
140
- )
141
- } else {
142
- selectOptions.push(
143
- <option disabled key={SPECIALNIL} value={SPECIALNIL}>
144
- {placeholder}
145
- </option>,
146
- )
147
- }
148
- }
149
- for (const k in options) {
150
- ((key) => {
151
- const opt = options[key]
152
-
153
- selectOptions.push(
154
- <option key={key} value={key}>
155
- {opt}
156
- </option>,
157
- )
158
- })(k)
159
- }
160
- } else {
161
- if (placeholder) {
162
- if (doesAllowEmpty) {
163
- selectOptions.push(
164
- <MenuItem key={SPECIALNIL} value={SPECIALNIL}>
165
- {placeholder}
166
- </MenuItem>,
167
- )
168
- } else {
169
- selectOptions.push(
170
- <MenuItem disabled key={SPECIALNIL} value={SPECIALNIL}>
171
- {placeholder}
172
- </MenuItem>,
173
- )
174
- }
175
- }
176
-
177
- for (const k in options) {
178
- ((key) => {
179
- const opt = options[key]
180
- selectOptions.push(
181
- <MenuItem key={key} value={key}>
182
- {opt}
183
- </MenuItem>,
184
- )
185
- })(k)
186
- }
187
- }
188
- }
189
-
190
- const [actualValue, setActualValue] = useState(v || dv)
191
- const [forceFlag, setForceFlag] = useState()
192
-
193
- if (isFunction(oc)) {
194
- const wssoc = wrapSelectSetter(oc)
195
- oc = (e) => {
196
- if (forceFlag && forceFlag === e.target.value) {
197
- setForceFlag(null)
198
- return null
199
- }
200
-
201
- setActualValue(e.target ? e.target.value : e)
202
- return wssoc(e)
203
- }
204
- }
205
-
206
- if (isFunction(ob)) {
207
- const wrappedOb = wrapSelectSetter(ob)
208
- ob = wrappedOb
209
-
210
- if (!isFunction(oc)) {
211
- oc = useMemo(() => {
212
- let onChangeTimeoutId = -1
213
-
214
- return (ev) => {
215
- if (forceFlag && forceFlag === ev.target.value) {
216
- setForceFlag(null)
217
- return
218
- }
219
-
220
- setActualValue(ev.target ? ev.target.value : ev)
221
- if (disableAutoChange) {
222
- return
223
- }
224
-
225
- clearTimeout(onChangeTimeoutId)
226
-
227
- const { target } = ev
228
-
229
- if (isSelect) {
230
- wrappedOb({
231
- target,
232
- })
233
- } else {
234
- onChangeTimeoutId = setTimeout(() => {
235
- wrappedOb({
236
- target,
237
- })
238
- }, 500)
239
- }
240
- }
241
- }, [onBlur])
242
- }
243
- }
244
-
245
- // update component if value is different than actual value
246
- useEffect(() => {
247
- if (v !== actualValue) {
248
- raf(() => {
249
- setForceFlag(v)
250
- setActualValue(v)
251
- })
252
- }
253
- }, [v])
254
-
255
- ob = wrapSensitiveBlur(ob)
256
- of = wrapSensitiveFocus(of)
257
-
258
- const IC = InnerComponent || TextField
259
- const InputPropsCheck = InputProps || {}
260
-
261
- const shrinkInputLabelProps = !!(focused
262
- || (inputRef && inputRef.value)
263
- || !!v
264
- || !!dv
265
- || !!actualValue
266
- || shrink
267
- || isSelect
268
- || placeholder
269
- || InputPropsCheck.startAdornment
270
- || InputPropsCheck.endAdornment)
271
-
272
- return (
273
- <IC
274
- {...props}
275
- inputRef={inputRef}
276
- select={select}
277
- options={options}
278
- placeholder={isSelect ? '' : placeholder}
279
- type={(isSensitive && !focused) ? 'password' : type}
280
- value={actualValue}
281
- defaultValue={actualValue ? undefined : dv}
282
- onChange={isSelect ? (oc || ob) : oc}
283
- onBlur={isSelect ? wrapSensitiveBlur() : ob}
284
- onFocus={of}
285
- InputProps={InputProps}
286
- InputLabelProps={
287
- {
288
- shrink: shrinkInputLabelProps,
289
- ...InputLabelProps,
290
- }
291
- }
292
- >
293
- {selectOptions}
294
- </IC>
295
- )
296
- }
297
-
298
- export default control(BaseMUIText)
@@ -1,57 +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
- console.log(onChange)
44
-
45
- return (
46
- <NF
47
- {...other}
48
- {...opts}
49
- value={value}
50
- getInputRef={inputRef}
51
- onChange={onChange}
52
- onBlur={onBlur}
53
- isNumericString
54
- />
55
- )
56
- }
57
- )