@helpai/elements 0.51.6 → 0.51.8

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/index.mjs CHANGED
@@ -29,7 +29,7 @@ var BRAND = {
29
29
  };
30
30
 
31
31
  // src/core/version.ts
32
- var ELEMENTS_VERSION = true ? "0.51.6" : "0.0.0-dev";
32
+ var ELEMENTS_VERSION = true ? "0.51.8" : "0.0.0-dev";
33
33
  var ELEMENTS_VERSION_PARAM = "_ev";
34
34
 
35
35
  // src/i18n/strings.ts
@@ -5956,13 +5956,16 @@ function MessageList({
5956
5956
  autoPinAtRef.current = performance.now();
5957
5957
  el.scrollTop = el.scrollHeight;
5958
5958
  };
5959
- const firstMessageId = messages.value[0]?.id;
5960
- useLayoutEffect2(() => {
5961
- const el = ref.current;
5962
- if (!el) return;
5963
- if (messages.value.length === 0) return;
5964
- hasHydratedRef.current = true;
5965
- if (!messages.value.some((m) => m.role === "user")) return;
5959
+ const pinBottomSoon = (el, frames) => {
5960
+ pinBottom(el);
5961
+ let left = frames;
5962
+ const tick = () => {
5963
+ pinBottom(el);
5964
+ if (--left > 0) requestAnimationFrame(tick);
5965
+ };
5966
+ if (frames > 0) requestAnimationFrame(tick);
5967
+ };
5968
+ const pinBottomThroughLayout = (el, ms) => {
5966
5969
  const pinNow = () => pinBottom(el);
5967
5970
  pinNow();
5968
5971
  const resizeObs = new ResizeObserver(pinNow);
@@ -5972,12 +5975,21 @@ function MessageList({
5972
5975
  const timerId = setTimeout(() => {
5973
5976
  resizeObs.disconnect();
5974
5977
  mutationObs.disconnect();
5975
- }, 300);
5978
+ }, ms);
5976
5979
  return () => {
5977
5980
  resizeObs.disconnect();
5978
5981
  mutationObs.disconnect();
5979
5982
  clearTimeout(timerId);
5980
5983
  };
5984
+ };
5985
+ const firstMessageId = messages.value[0]?.id;
5986
+ useLayoutEffect2(() => {
5987
+ const el = ref.current;
5988
+ if (!el) return;
5989
+ if (messages.value.length === 0) return;
5990
+ hasHydratedRef.current = true;
5991
+ if (!messages.value.some((m) => m.role === "user")) return;
5992
+ return pinBottomThroughLayout(el, 300);
5981
5993
  }, [firstMessageId]);
5982
5994
  const prevLengthRef = useRef5(0);
5983
5995
  useEffect7(() => {
@@ -5989,7 +6001,7 @@ function MessageList({
5989
6001
  if (!hasHydratedRef.current) return;
5990
6002
  if (list.slice(prevLength).some((m) => m.role === "user")) {
5991
6003
  detachedRef.current = false;
5992
- pinBottom(el);
6004
+ pinBottomSoon(el, 3);
5993
6005
  return;
5994
6006
  }
5995
6007
  if (!list.some((m) => m.role === "user")) return;
@@ -6018,12 +6030,17 @@ function MessageList({
6018
6030
  return () => obs.disconnect();
6019
6031
  }, [messages.value]);
6020
6032
  const activeFormId = form?.form.id;
6033
+ const inlineForm = !!form && (formMarkers ?? []).some((m) => m.formId === form.form.id);
6021
6034
  useLayoutEffect2(() => {
6022
6035
  const el = ref.current;
6023
6036
  if (!el || !activeFormId || detachedRef.current) return;
6024
6037
  if (!messages.value.some((m) => m.role === "user")) return;
6025
- pinBottom(el);
6026
- }, [activeFormId]);
6038
+ if (inlineForm) {
6039
+ el.querySelector(`[data-testid="${TID.formGate}"]`)?.scrollIntoView({ block: "nearest" });
6040
+ } else {
6041
+ pinBottom(el);
6042
+ }
6043
+ }, [activeFormId, inlineForm]);
6027
6044
  useEffect7(() => {
6028
6045
  const el = ref.current;
6029
6046
  if (!el) return;
@@ -6096,15 +6113,29 @@ function MessageList({
6096
6113
  const pendingMarkers = [...formMarkers ?? []].toSorted(
6097
6114
  (a, b) => (a.createdAt ?? Infinity) - (b.createdAt ?? Infinity)
6098
6115
  );
6099
- const markerRow = (marker) => /* @__PURE__ */ jsx19(
6100
- FormDoneMarker,
6101
- {
6102
- marker,
6103
- strings,
6104
- onFill: !form && onFillForm ? () => onFillForm(marker.formId) : void 0
6105
- },
6106
- marker.key
6107
- );
6116
+ const markerRow = (marker) => {
6117
+ if (form && marker.formId === form.form.id) {
6118
+ return /* @__PURE__ */ jsx19(
6119
+ FormGate,
6120
+ {
6121
+ form: form.form,
6122
+ strings,
6123
+ onSubmit: form.onSubmit,
6124
+ onSkip: form.onSkip
6125
+ },
6126
+ `gate:${marker.formId}`
6127
+ );
6128
+ }
6129
+ return /* @__PURE__ */ jsx19(
6130
+ FormDoneMarker,
6131
+ {
6132
+ marker,
6133
+ strings,
6134
+ onFill: !form && onFillForm ? () => onFillForm(marker.formId) : void 0
6135
+ },
6136
+ marker.key
6137
+ );
6138
+ };
6108
6139
  const flushMarkersBefore = (createdAt) => {
6109
6140
  for (let next = pendingMarkers[0]; next?.createdAt !== void 0; next = pendingMarkers[0]) {
6110
6141
  if (createdAt !== void 0 && next.createdAt > createdAt) break;
@@ -6157,7 +6188,7 @@ function MessageList({
6157
6188
  children: [
6158
6189
  loading && messages.value.length === 0 ? /* @__PURE__ */ jsx19("div", { class: `${p18}-list-loading`, role: "status", children: strings.conversationLoading }) : null,
6159
6190
  rows,
6160
- form ? /* @__PURE__ */ jsx19(FormGate, { form: form.form, strings, onSubmit: form.onSubmit, onSkip: form.onSkip }) : null
6191
+ form && !inlineForm ? /* @__PURE__ */ jsx19(FormGate, { form: form.form, strings, onSubmit: form.onSubmit, onSkip: form.onSkip }) : null
6161
6192
  ]
6162
6193
  }
6163
6194
  ),
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  ],
81
81
  "type": "module",
82
82
  "types": "./index.d.ts",
83
- "version": "0.51.6"
83
+ "version": "0.51.8"
84
84
  }
package/web-component.mjs CHANGED
@@ -1794,7 +1794,7 @@ function createAuth(opts) {
1794
1794
  }
1795
1795
 
1796
1796
  // src/core/version.ts
1797
- var ELEMENTS_VERSION = true ? "0.51.6" : "0.0.0-dev";
1797
+ var ELEMENTS_VERSION = true ? "0.51.8" : "0.0.0-dev";
1798
1798
  var ELEMENTS_VERSION_PARAM = "_ev";
1799
1799
 
1800
1800
  // src/stream/types.ts
@@ -5915,13 +5915,16 @@ function MessageList({
5915
5915
  autoPinAtRef.current = performance.now();
5916
5916
  el.scrollTop = el.scrollHeight;
5917
5917
  };
5918
- const firstMessageId = messages.value[0]?.id;
5919
- useLayoutEffect2(() => {
5920
- const el = ref.current;
5921
- if (!el) return;
5922
- if (messages.value.length === 0) return;
5923
- hasHydratedRef.current = true;
5924
- if (!messages.value.some((m) => m.role === "user")) return;
5918
+ const pinBottomSoon = (el, frames) => {
5919
+ pinBottom(el);
5920
+ let left = frames;
5921
+ const tick = () => {
5922
+ pinBottom(el);
5923
+ if (--left > 0) requestAnimationFrame(tick);
5924
+ };
5925
+ if (frames > 0) requestAnimationFrame(tick);
5926
+ };
5927
+ const pinBottomThroughLayout = (el, ms) => {
5925
5928
  const pinNow = () => pinBottom(el);
5926
5929
  pinNow();
5927
5930
  const resizeObs = new ResizeObserver(pinNow);
@@ -5931,12 +5934,21 @@ function MessageList({
5931
5934
  const timerId = setTimeout(() => {
5932
5935
  resizeObs.disconnect();
5933
5936
  mutationObs.disconnect();
5934
- }, 300);
5937
+ }, ms);
5935
5938
  return () => {
5936
5939
  resizeObs.disconnect();
5937
5940
  mutationObs.disconnect();
5938
5941
  clearTimeout(timerId);
5939
5942
  };
5943
+ };
5944
+ const firstMessageId = messages.value[0]?.id;
5945
+ useLayoutEffect2(() => {
5946
+ const el = ref.current;
5947
+ if (!el) return;
5948
+ if (messages.value.length === 0) return;
5949
+ hasHydratedRef.current = true;
5950
+ if (!messages.value.some((m) => m.role === "user")) return;
5951
+ return pinBottomThroughLayout(el, 300);
5940
5952
  }, [firstMessageId]);
5941
5953
  const prevLengthRef = useRef5(0);
5942
5954
  useEffect7(() => {
@@ -5948,7 +5960,7 @@ function MessageList({
5948
5960
  if (!hasHydratedRef.current) return;
5949
5961
  if (list.slice(prevLength).some((m) => m.role === "user")) {
5950
5962
  detachedRef.current = false;
5951
- pinBottom(el);
5963
+ pinBottomSoon(el, 3);
5952
5964
  return;
5953
5965
  }
5954
5966
  if (!list.some((m) => m.role === "user")) return;
@@ -5977,12 +5989,17 @@ function MessageList({
5977
5989
  return () => obs.disconnect();
5978
5990
  }, [messages.value]);
5979
5991
  const activeFormId = form?.form.id;
5992
+ const inlineForm = !!form && (formMarkers ?? []).some((m) => m.formId === form.form.id);
5980
5993
  useLayoutEffect2(() => {
5981
5994
  const el = ref.current;
5982
5995
  if (!el || !activeFormId || detachedRef.current) return;
5983
5996
  if (!messages.value.some((m) => m.role === "user")) return;
5984
- pinBottom(el);
5985
- }, [activeFormId]);
5997
+ if (inlineForm) {
5998
+ el.querySelector(`[data-testid="${TID.formGate}"]`)?.scrollIntoView({ block: "nearest" });
5999
+ } else {
6000
+ pinBottom(el);
6001
+ }
6002
+ }, [activeFormId, inlineForm]);
5986
6003
  useEffect7(() => {
5987
6004
  const el = ref.current;
5988
6005
  if (!el) return;
@@ -6055,15 +6072,29 @@ function MessageList({
6055
6072
  const pendingMarkers = [...formMarkers ?? []].toSorted(
6056
6073
  (a, b) => (a.createdAt ?? Infinity) - (b.createdAt ?? Infinity)
6057
6074
  );
6058
- const markerRow = (marker) => /* @__PURE__ */ jsx19(
6059
- FormDoneMarker,
6060
- {
6061
- marker,
6062
- strings,
6063
- onFill: !form && onFillForm ? () => onFillForm(marker.formId) : void 0
6064
- },
6065
- marker.key
6066
- );
6075
+ const markerRow = (marker) => {
6076
+ if (form && marker.formId === form.form.id) {
6077
+ return /* @__PURE__ */ jsx19(
6078
+ FormGate,
6079
+ {
6080
+ form: form.form,
6081
+ strings,
6082
+ onSubmit: form.onSubmit,
6083
+ onSkip: form.onSkip
6084
+ },
6085
+ `gate:${marker.formId}`
6086
+ );
6087
+ }
6088
+ return /* @__PURE__ */ jsx19(
6089
+ FormDoneMarker,
6090
+ {
6091
+ marker,
6092
+ strings,
6093
+ onFill: !form && onFillForm ? () => onFillForm(marker.formId) : void 0
6094
+ },
6095
+ marker.key
6096
+ );
6097
+ };
6067
6098
  const flushMarkersBefore = (createdAt) => {
6068
6099
  for (let next = pendingMarkers[0]; next?.createdAt !== void 0; next = pendingMarkers[0]) {
6069
6100
  if (createdAt !== void 0 && next.createdAt > createdAt) break;
@@ -6116,7 +6147,7 @@ function MessageList({
6116
6147
  children: [
6117
6148
  loading && messages.value.length === 0 ? /* @__PURE__ */ jsx19("div", { class: `${p18}-list-loading`, role: "status", children: strings.conversationLoading }) : null,
6118
6149
  rows,
6119
- form ? /* @__PURE__ */ jsx19(FormGate, { form: form.form, strings, onSubmit: form.onSubmit, onSkip: form.onSkip }) : null
6150
+ form && !inlineForm ? /* @__PURE__ */ jsx19(FormGate, { form: form.form, strings, onSubmit: form.onSubmit, onSkip: form.onSkip }) : null
6120
6151
  ]
6121
6152
  }
6122
6153
  ),