@assistant-ui/react 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -907,21 +907,30 @@ var ActionBarPrimitiveRoot = (0, import_react25.forwardRef)(({ hideWhenRunning,
907
907
  ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
908
908
 
909
909
  // src/utils/createActionButton.tsx
910
- var import_primitive = require("@radix-ui/primitive");
911
- var import_react_primitive2 = require("@radix-ui/react-primitive");
912
910
  var import_react26 = require("react");
911
+ var import_react_primitive2 = require("@radix-ui/react-primitive");
912
+ var import_primitive = require("@radix-ui/primitive");
913
913
  var import_jsx_runtime5 = require("react/jsx-runtime");
914
- var createActionButton = (displayName, useActionButton) => {
914
+ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
915
915
  const ActionButton = (0, import_react26.forwardRef)((props, forwardedRef) => {
916
- const callback = useActionButton(props);
916
+ const forwardedProps = {};
917
+ const primitiveProps = {};
918
+ Object.keys(props).forEach((key) => {
919
+ if (forwardProps.includes(key)) {
920
+ forwardedProps[key] = props[key];
921
+ } else {
922
+ primitiveProps[key] = props[key];
923
+ }
924
+ });
925
+ const callback = useActionButton(forwardedProps);
917
926
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
918
927
  import_react_primitive2.Primitive.button,
919
928
  {
920
929
  type: "button",
921
930
  disabled: !callback,
922
- ...props,
931
+ ...primitiveProps,
923
932
  ref: forwardedRef,
924
- onClick: (0, import_primitive.composeEventHandlers)(props.onClick, () => {
933
+ onClick: (0, import_primitive.composeEventHandlers)(primitiveProps.onClick, () => {
925
934
  callback?.();
926
935
  })
927
936
  }
@@ -934,7 +943,8 @@ var createActionButton = (displayName, useActionButton) => {
934
943
  // src/primitives/actionBar/ActionBarCopy.tsx
935
944
  var ActionBarPrimitiveCopy = createActionButton(
936
945
  "ActionBarPrimitive.Copy",
937
- useActionBarCopy
946
+ useActionBarCopy,
947
+ ["copiedDuration"]
938
948
  );
939
949
 
940
950
  // src/primitives/actionBar/ActionBarReload.tsx
@@ -1244,7 +1254,8 @@ var import_react36 = require("react");
1244
1254
  // src/utils/hooks/useSmooth.tsx
1245
1255
  var import_react35 = require("react");
1246
1256
  var TextStreamAnimator = class {
1247
- constructor(setText) {
1257
+ constructor(currentText, setText) {
1258
+ this.currentText = currentText;
1248
1259
  this.setText = setText;
1249
1260
  }
1250
1261
  animationFrameId = null;
@@ -1265,33 +1276,31 @@ var TextStreamAnimator = class {
1265
1276
  const currentTime = Date.now();
1266
1277
  const deltaTime = currentTime - this.lastUpdateTime;
1267
1278
  let timeToConsume = deltaTime;
1268
- this.setText((currentText) => {
1269
- const targetText = this.targetText;
1270
- if (currentText === targetText) {
1271
- this.animationFrameId = null;
1272
- return currentText;
1273
- }
1274
- const remainingChars = targetText.length - currentText.length;
1275
- const baseTimePerChar = Math.min(5, 250 / remainingChars);
1276
- let charsToAdd = 0;
1277
- while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1278
- charsToAdd++;
1279
- timeToConsume -= baseTimePerChar;
1280
- }
1279
+ const remainingChars = this.targetText.length - this.currentText.length;
1280
+ const baseTimePerChar = Math.min(5, 250 / remainingChars);
1281
+ let charsToAdd = 0;
1282
+ while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1283
+ charsToAdd++;
1284
+ timeToConsume -= baseTimePerChar;
1285
+ }
1286
+ if (charsToAdd !== remainingChars) {
1281
1287
  this.animationFrameId = requestAnimationFrame(this.animate);
1282
- if (charsToAdd === 0) {
1283
- return currentText;
1284
- }
1285
- const newText = targetText.slice(0, currentText.length + charsToAdd);
1286
- this.lastUpdateTime = currentTime - timeToConsume;
1287
- return newText;
1288
- });
1288
+ } else {
1289
+ this.animationFrameId = null;
1290
+ }
1291
+ if (charsToAdd === 0) return;
1292
+ this.currentText = this.targetText.slice(
1293
+ 0,
1294
+ this.currentText.length + charsToAdd
1295
+ );
1296
+ this.lastUpdateTime = currentTime - timeToConsume;
1297
+ this.setText(this.currentText);
1289
1298
  };
1290
1299
  };
1291
1300
  var useSmooth = (text, smooth = false) => {
1292
1301
  const [displayedText, setDisplayedText] = (0, import_react35.useState)(text);
1293
1302
  const [animatorRef] = (0, import_react35.useState)(
1294
- new TextStreamAnimator(setDisplayedText)
1303
+ new TextStreamAnimator(text, setDisplayedText)
1295
1304
  );
1296
1305
  (0, import_react35.useEffect)(() => {
1297
1306
  if (!smooth) {
@@ -1300,6 +1309,7 @@ var useSmooth = (text, smooth = false) => {
1300
1309
  }
1301
1310
  if (!text.startsWith(animatorRef.targetText)) {
1302
1311
  setDisplayedText(text);
1312
+ animatorRef.currentText = text;
1303
1313
  animatorRef.targetText = text;
1304
1314
  animatorRef.stop();
1305
1315
  return;
@@ -1951,7 +1961,8 @@ var ThreadPrimitiveScrollToBottom = createActionButton(
1951
1961
  // src/primitives/thread/ThreadSuggestion.tsx
1952
1962
  var ThreadPrimitiveSuggestion = createActionButton(
1953
1963
  "ThreadPrimitive.Suggestion",
1954
- useThreadSuggestion
1964
+ useThreadSuggestion,
1965
+ ["prompt", "autoSend", "method"]
1955
1966
  );
1956
1967
 
1957
1968
  // src/runtimes/local/useLocalRuntime.tsx