@pingux/astro 2.111.0-alpha.2 → 2.111.0-alpha.3
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/lib/cjs/components/AIComponents/Attachment/Attachment.d.ts +6 -1
- package/lib/cjs/components/AIComponents/Attachment/Attachment.js +4 -2
- package/lib/cjs/components/AIComponents/PromptInput/PromptInput.js +34 -12
- package/lib/cjs/components/AIComponents/PromptInput/PromptInput.stories.js +3 -5
- package/lib/cjs/components/AIComponents/PromptInput/PromptInput.test.js +131 -127
- package/lib/cjs/components/AIComponents/PromptInput/PromptUploadButton.js +17 -6
- package/lib/cjs/hooks/useField/useField.d.ts +8 -2
- package/lib/cjs/hooks/useField/useField.js +4 -3
- package/lib/cjs/hooks/useField/useField.test.js +4 -4
- package/lib/cjs/hooks/useSelectField/useSelectField.d.ts +1 -0
- package/lib/cjs/types/promptInput.d.ts +8 -9
- package/lib/cjs/types/textField.d.ts +1 -1
- package/lib/components/AIComponents/Attachment/Attachment.js +4 -2
- package/lib/components/AIComponents/PromptInput/PromptInput.js +34 -11
- package/lib/components/AIComponents/PromptInput/PromptInput.stories.js +3 -5
- package/lib/components/AIComponents/PromptInput/PromptInput.test.js +134 -126
- package/lib/components/AIComponents/PromptInput/PromptUploadButton.js +18 -6
- package/lib/hooks/useField/useField.js +10 -9
- package/lib/hooks/useField/useField.test.js +4 -4
- package/package.json +1 -1
@@ -30,7 +30,7 @@ export interface FieldControlInputProps extends AriaLabelingProps, DOMProps {
|
|
30
30
|
isIndeterminate?: boolean;
|
31
31
|
maxLength?: ValidPositiveInteger;
|
32
32
|
name?: string;
|
33
|
-
onChange: (event: CustomChangeEventType | React.
|
33
|
+
onChange: (event: CustomChangeEventType | React.FormEvent<Element>) => void | undefined;
|
34
34
|
placeholder?: string;
|
35
35
|
readOnly?: boolean;
|
36
36
|
required?: boolean;
|
@@ -99,10 +99,13 @@ export interface UseFieldProps<T> {
|
|
99
99
|
/** Handler that is called when the element's selection state changes. */
|
100
100
|
onChange?: (e: React.ChangeEvent) => void;
|
101
101
|
onClear?: () => void;
|
102
|
+
/** Handler that is called when a file is added or removed. */
|
103
|
+
onFileChange?: (files: File[]) => void;
|
102
104
|
/** Handler that is called when the element receives focus. */
|
103
105
|
onFocus?: (e: React.FocusEvent) => void;
|
104
106
|
/** Handler that is called when the element's focus status changes. */
|
105
107
|
onFocusChange?: (isFocused: boolean) => void;
|
108
|
+
onKeyUp?: (e: React.KeyboardEvent) => void;
|
106
109
|
onLoadMore?: () => void;
|
107
110
|
onOpenChange?: (isOpen: boolean) => unknown;
|
108
111
|
onSelectionChange?: (key: string) => void;
|
@@ -124,8 +127,11 @@ export interface UseFieldProps<T> {
|
|
124
127
|
wrapperProps?: WrapperProps;
|
125
128
|
}
|
126
129
|
export type CustomChangeEventType = {
|
130
|
+
currentTarget?: {
|
131
|
+
value?: string | number;
|
132
|
+
};
|
127
133
|
target?: {
|
128
|
-
value
|
134
|
+
value?: string | number;
|
129
135
|
};
|
130
136
|
persist?(): void;
|
131
137
|
};
|
@@ -13,6 +13,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
13
13
|
value: true
|
14
14
|
});
|
15
15
|
exports["default"] = void 0;
|
16
|
+
var _isNan = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-nan"));
|
16
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
17
18
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
18
19
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
@@ -94,9 +95,9 @@ var useField = function useField(props) {
|
|
94
95
|
|
95
96
|
// Capture value changes so we can apply the has-value class to the container
|
96
97
|
var fieldOnChange = function fieldOnChange(e) {
|
97
|
-
var
|
98
|
-
var
|
99
|
-
if (!!eventValue ||
|
98
|
+
var eventValue = e.currentTarget.value;
|
99
|
+
var isZero = !(0, _isNan["default"])(Number(eventValue)) && Number(eventValue) === 0;
|
100
|
+
if (!!eventValue || !!placeholder || isZero || !!placeholder || placeholder === 0) {
|
100
101
|
setHasValue(true);
|
101
102
|
} else {
|
102
103
|
setHasValue(false);
|
@@ -173,7 +173,7 @@ test('should return isFloatLabelActive class for container', function () {
|
|
173
173
|
// Does not have the class if the value is invalid
|
174
174
|
(0, _react.act)(function () {
|
175
175
|
return result.current.fieldControlInputProps.onChange({
|
176
|
-
|
176
|
+
currentTarget: {
|
177
177
|
value: undefined
|
178
178
|
}
|
179
179
|
});
|
@@ -240,7 +240,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
240
240
|
// 0 should be a valid value
|
241
241
|
(0, _react.act)(function () {
|
242
242
|
return result.current.fieldControlInputProps.onChange({
|
243
|
-
|
243
|
+
currentTarget: {
|
244
244
|
value: 0
|
245
245
|
}
|
246
246
|
});
|
@@ -251,7 +251,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
251
251
|
// undefined is not a valid value
|
252
252
|
(0, _react.act)(function () {
|
253
253
|
return result.current.fieldControlInputProps.onChange({
|
254
|
-
|
254
|
+
currentTarget: {
|
255
255
|
value: undefined
|
256
256
|
}
|
257
257
|
});
|
@@ -262,7 +262,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
262
262
|
// a non-empty string is a valid value
|
263
263
|
(0, _react.act)(function () {
|
264
264
|
return result.current.fieldControlInputProps.onChange({
|
265
|
-
|
265
|
+
currentTarget: {
|
266
266
|
value: 'a'
|
267
267
|
}
|
268
268
|
});
|
@@ -29,6 +29,7 @@ export interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
|
|
29
29
|
name?: string;
|
30
30
|
placeholder?: string;
|
31
31
|
selectedKey?: string;
|
32
|
+
onKeyUp?: (e: React.KeyboardEvent) => void;
|
32
33
|
onLoadMore?: () => unknown;
|
33
34
|
onOpenChange?: (isOpen: boolean) => unknown;
|
34
35
|
onSelectionChange?: (key: Key) => unknown;
|
@@ -1,18 +1,21 @@
|
|
1
1
|
import type { PressEvent } from '@react-types/shared';
|
2
2
|
import { IconTypeExtended } from './icon';
|
3
|
+
import { IconButtonProps } from './iconButton';
|
3
4
|
import { TextFieldProps } from './textField';
|
4
|
-
export interface
|
5
|
+
export interface PromptProps {
|
5
6
|
attachmentProps?: object;
|
6
|
-
value
|
7
|
+
value?: string;
|
7
8
|
onFileChange?: (files: FileProps[]) => void;
|
8
|
-
onCancel?: (event: PressEvent) => void;
|
9
|
-
onSubmit?: (event: PressEvent) => void;
|
9
|
+
onCancel?: (event: PressEvent | KeyboardEvent) => void;
|
10
|
+
onSubmit?: (event: PressEvent | KeyboardEvent, value?: string) => void;
|
10
11
|
isLoading?: boolean;
|
11
12
|
uploadButtonContainerProps?: object;
|
12
13
|
uploadButtonProps?: object;
|
13
14
|
fileInputButtonProps?: object;
|
14
15
|
isFullScreen?: boolean;
|
15
16
|
}
|
17
|
+
export interface PromptInputProps extends TextFieldProps, PromptProps {
|
18
|
+
}
|
16
19
|
export interface AttachmentProps {
|
17
20
|
title: string;
|
18
21
|
isFullScreen?: boolean;
|
@@ -33,10 +36,6 @@ export interface FileProps {
|
|
33
36
|
status: string;
|
34
37
|
fileObj: object;
|
35
38
|
}
|
36
|
-
export interface PromptUploadButtonProps {
|
39
|
+
export interface PromptUploadButtonProps extends PromptProps, Omit<IconButtonProps, 'onSubmit' | 'value'> {
|
37
40
|
uploadButtonContainerProps?: object;
|
38
|
-
value: string;
|
39
|
-
isLoading?: boolean;
|
40
|
-
onSubmit?: (event: PressEvent) => void;
|
41
|
-
onCancel?: (event: PressEvent) => void;
|
42
41
|
}
|
@@ -24,7 +24,7 @@ export interface TextFieldProps extends StyleProps, SharedFieldProps {
|
|
24
24
|
isReadOnly?: boolean;
|
25
25
|
/** Whether the field is required. */
|
26
26
|
isRequired?: boolean;
|
27
|
-
onChange?: (e: React.ChangeEvent) => void;
|
27
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
28
28
|
/**
|
29
29
|
* Callback fired when focus is lost on the input element.
|
30
30
|
*/
|
@@ -33,8 +33,7 @@ var Attachment = function Attachment(props) {
|
|
33
33
|
id = props.id,
|
34
34
|
containerProps = props.containerProps,
|
35
35
|
iconWrapperProps = props.iconWrapperProps,
|
36
|
-
|
37
|
-
icon = _props$icon === void 0 ? PaperOutlineIcon : _props$icon,
|
36
|
+
icon = props.icon,
|
38
37
|
deleteButtonProps = props.deleteButtonProps;
|
39
38
|
var _useStatusClasses = useStatusClasses(className, {
|
40
39
|
isFullScreen: isFullScreen
|
@@ -95,4 +94,7 @@ var Attachment = function Attachment(props) {
|
|
95
94
|
icon: CloseIcon
|
96
95
|
}))));
|
97
96
|
};
|
97
|
+
Attachment.defaultProps = {
|
98
|
+
icon: PaperOutlineIcon
|
99
|
+
};
|
98
100
|
export default Attachment;
|
@@ -1,15 +1,25 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
2
3
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
3
4
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
4
|
-
var _excluded = ["
|
5
|
+
var _excluded = ["onFileChange"];
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
5
8
|
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
6
9
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
7
10
|
import _URL from "@babel/runtime-corejs3/core-js-stable/url";
|
8
11
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
9
12
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
13
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
14
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
15
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
16
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
17
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
18
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
19
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
10
20
|
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
11
21
|
import { v4 as uuid } from 'uuid';
|
12
|
-
import { useField, useLocalOrForwardRef } from '../../../hooks';
|
22
|
+
import { useField, useLocalOrForwardRef, useProgressiveState } from '../../../hooks';
|
13
23
|
import { Box, FileInputField, Input } from '../../../index';
|
14
24
|
import statuses from '../../../utils/devUtils/constants/statuses';
|
15
25
|
import Attachment, { getFileExtension } from '../Attachment/Attachment';
|
@@ -17,22 +27,27 @@ import PromptUploadButton from './PromptUploadButton';
|
|
17
27
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
18
28
|
var PromptInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
19
29
|
var attachmentProps = props.attachmentProps,
|
20
|
-
onFileChange = props.onFileChange,
|
21
30
|
isFullScreen = props.isFullScreen,
|
22
31
|
isLoading = props.isLoading,
|
23
32
|
fileInputButtonProps = props.fileInputButtonProps,
|
24
|
-
|
33
|
+
valueProp = props.value,
|
34
|
+
defaultValueProp = props.defaultValue,
|
25
35
|
onCancel = props.onCancel,
|
26
36
|
onSubmit = props.onSubmit,
|
27
37
|
uploadButtonContainerProps = props.uploadButtonContainerProps,
|
28
|
-
uploadButtonProps = props.uploadButtonProps
|
29
|
-
|
38
|
+
uploadButtonProps = props.uploadButtonProps;
|
39
|
+
var onFileChange = props.onFileChange,
|
40
|
+
propsWithoutOnFileChange = _objectWithoutProperties(props, _excluded);
|
30
41
|
var firstUpdate = useRef(true);
|
31
42
|
var _useState = useState([]),
|
32
43
|
_useState2 = _slicedToArray(_useState, 2),
|
33
44
|
userFiles = _useState2[0],
|
34
45
|
setUserFiles = _useState2[1];
|
35
|
-
var
|
46
|
+
var _useProgressiveState = useProgressiveState(valueProp, defaultValueProp),
|
47
|
+
_useProgressiveState2 = _slicedToArray(_useProgressiveState, 2),
|
48
|
+
value = _useProgressiveState2[0],
|
49
|
+
setValue = _useProgressiveState2[1];
|
50
|
+
var handleFileSelect = function handleFileSelect(_event, files) {
|
36
51
|
var arrayWithNewFiles = _Array$from(files);
|
37
52
|
var filesWithIdAndLink = _mapInstanceProperty(arrayWithNewFiles).call(arrayWithNewFiles, function (newFile) {
|
38
53
|
return {
|
@@ -63,7 +78,11 @@ var PromptInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
63
78
|
return _file.id !== id;
|
64
79
|
}));
|
65
80
|
};
|
66
|
-
var _useField = useField(
|
81
|
+
var _useField = useField(_objectSpread({
|
82
|
+
onChange: function onChange(e) {
|
83
|
+
setValue(e.target.value);
|
84
|
+
}
|
85
|
+
}, propsWithoutOnFileChange)),
|
67
86
|
fieldContainerProps = _useField.fieldContainerProps,
|
68
87
|
fieldControlInputProps = _useField.fieldControlInputProps,
|
69
88
|
fieldControlWrapperProps = _useField.fieldControlWrapperProps;
|
@@ -117,11 +136,10 @@ var PromptInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
117
136
|
},
|
118
137
|
"aria-label": "add attachment"
|
119
138
|
}, fileInputButtonProps))), ___EmotionJSX(Input, _extends({
|
120
|
-
ref: inputRef
|
121
|
-
}, fieldControlInputProps, {
|
139
|
+
ref: inputRef,
|
122
140
|
variant: "forms.input.promptInput",
|
123
141
|
"data-testid": "prompt-input"
|
124
|
-
})), ___EmotionJSX(PromptUploadButton, _extends({
|
142
|
+
}, fieldControlInputProps)), ___EmotionJSX(PromptUploadButton, _extends({
|
125
143
|
isLoading: isLoading,
|
126
144
|
value: value,
|
127
145
|
onSubmit: onSubmit,
|
@@ -130,4 +148,9 @@ var PromptInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
130
148
|
uploadButtonContainerProps: uploadButtonContainerProps
|
131
149
|
})))));
|
132
150
|
});
|
151
|
+
PromptInput.defaultProps = {
|
152
|
+
controlProps: {
|
153
|
+
'aria-label': 'chat assistant text input'
|
154
|
+
}
|
155
|
+
};
|
133
156
|
export default PromptInput;
|
@@ -30,18 +30,16 @@ export var Default = function Default(args) {
|
|
30
30
|
setValue = _useState2[1];
|
31
31
|
var _useState3 = useState([]),
|
32
32
|
_useState4 = _slicedToArray(_useState3, 2),
|
33
|
-
attachments = _useState4[0],
|
34
33
|
setAttachments = _useState4[1];
|
35
34
|
var onFileChange = function onFileChange(files) {
|
36
|
-
console.log(files);
|
37
35
|
setAttachments(files);
|
38
36
|
};
|
39
37
|
var onCancel = function onCancel(event) {
|
40
38
|
console.log(event);
|
41
39
|
};
|
42
|
-
var onSubmit = function onSubmit(
|
43
|
-
console.log(
|
44
|
-
|
40
|
+
var onSubmit = function onSubmit() {
|
41
|
+
console.log('submit');
|
42
|
+
setValue('');
|
45
43
|
};
|
46
44
|
return ___EmotionJSX(AstroProvider, {
|
47
45
|
themeOverrides: [NextGenTheme]
|