@mgamadeus/ddd-agents 0.1.3 → 0.1.4

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.
@@ -3853,6 +3853,24 @@ const composeFormSubmitSignal = (formName, fieldValues) => {
3853
3853
  );
3854
3854
  };
3855
3855
  const composeFormDeclineSignal = (formName) => `ComposedView form "${formName}" declined.`;
3856
+ const findStoredFormAnswer = (messages, hostMessageId, formName) => {
3857
+ if (!messages || hostMessageId === void 0) return void 0;
3858
+ const hostIndex = messages.findIndex((message) => message.id !== void 0 && message.id !== null && String(message.id) === String(hostMessageId));
3859
+ if (hostIndex < 0) return void 0;
3860
+ const submitHead = `ComposedView form "${formName}" submitted:`;
3861
+ const declineSentence = composeFormDeclineSignal(formName);
3862
+ for (let index = hostIndex + 1; index < messages.length; index += 1) {
3863
+ const message = messages[index];
3864
+ const text2 = typeof message.message === "string" ? message.message : "";
3865
+ if (message.messageType === "SIGNAL") {
3866
+ if (text2.includes(submitHead)) return "sent";
3867
+ if (text2.includes(declineSentence)) return "declined";
3868
+ continue;
3869
+ }
3870
+ if (message.role === "USER") return void 0;
3871
+ }
3872
+ return void 0;
3873
+ };
3856
3874
  const readBoundStateName = (propValue) => {
3857
3875
  if (typeof propValue !== "object" || propValue === null || Array.isArray(propValue)) return void 0;
3858
3876
  if (typeof propValue.$state === "string") return propValue.$state;
@@ -3914,11 +3932,16 @@ const FormNode = (props) => {
3914
3932
  const { node, props: nodeProps, slots, sizeClass, runtime, testId } = props;
3915
3933
  const { state, interactive, isEmailRender, reportNodeStatus } = runtime;
3916
3934
  const isInsideForm = useContext(ComposedViewFormContext);
3917
- const { injectSignal } = useConversationWidgetContext();
3918
- const [submissionStatus, setSubmissionStatus] = useState("idle");
3935
+ const { injectSignal, messages } = useConversationWidgetContext();
3936
+ const [localSubmissionStatus, setSubmissionStatus] = useState("idle");
3919
3937
  const [hasTriedWithMissingFields, setHasTriedWithMissingFields] = useState(false);
3920
3938
  const isSignalInFlightRef = useRef(false);
3921
3939
  const formName = isFormNameAllowed(nodeProps.name) ? nodeProps.name : void 0;
3940
+ const storedAnswer = useMemo(
3941
+ () => formName === void 0 ? void 0 : findStoredFormAnswer(messages, runtime.messageId, formName),
3942
+ [messages, runtime.messageId, formName]
3943
+ );
3944
+ const submissionStatus = localSubmissionStatus === "idle" && storedAnswer !== void 0 ? storedAnswer : localSubmissionStatus;
3922
3945
  const fieldNames = useMemo(
3923
3946
  () => Array.isArray(node.props.fields) ? readStateNameList(node.props.fields, state) : collectBoundStateNames(node).filter((stateName) => Object.prototype.hasOwnProperty.call(state, stateName)),
3924
3947
  [node, state]
@@ -4026,7 +4049,7 @@ const FormNode = (props) => {
4026
4049
  ] }),
4027
4050
  headerItems2.length > 0 ? /* @__PURE__ */ jsx("div", { className: styles$A.headerItems, children: headerItems2 }) : null
4028
4051
  ] }) : null,
4029
- /* @__PURE__ */ jsx(ComposedViewFormContext.Provider, { value: true, children: /* @__PURE__ */ jsx("fieldset", { className: styles$A.fields, disabled: isAnswered || isSending, children: slots.children }) }),
4052
+ /* @__PURE__ */ jsx(ComposedViewFormContext.Provider, { value: true, children: /* @__PURE__ */ jsx("fieldset", { className: styles$A.fields, disabled: isAnswered || isSending || !canSend && !isEmailRender, children: slots.children }) }),
4030
4053
  /* @__PURE__ */ jsxs("div", { className: styles$A.footer, "aria-live": "polite", children: [
4031
4054
  showsMissingFields ? /* @__PURE__ */ jsx(Text, { role: "caption", color: ERROR_TEXT_COLOR, testId: `${testId}-error-required`, children: "Please fill in the required fields." }) : null,
4032
4055
  submissionStatus === "failed" ? /* @__PURE__ */ jsx(Text, { role: "caption", color: ERROR_TEXT_COLOR, testId: `${testId}-error`, children: "Something went wrong. Please try again." }) : null,
@@ -5236,11 +5259,13 @@ const pressable = "agents_pressable_07m3Fb";
5236
5259
  const button = "agents_button_bKxiw0";
5237
5260
  const selected = "agents_selected_sDa7Ja";
5238
5261
  const content = "agents_content_FRNdnX";
5262
+ const padded = "agents_padded_huIgOm";
5239
5263
  const styles$r = {
5240
5264
  pressable,
5241
5265
  button,
5242
5266
  selected,
5243
- content
5267
+ content,
5268
+ padded
5244
5269
  };
5245
5270
  const Pressable = (props) => {
5246
5271
  const { node, props: nodeProps, slots, runtime, testId } = props;
@@ -5249,6 +5274,8 @@ const Pressable = (props) => {
5249
5274
  const isSelected = typeof nodeProps.isSelected === "boolean" ? nodeProps.isSelected : void 0;
5250
5275
  const accessibleLabel = readTextProp(nodeProps.label);
5251
5276
  const hasContent = contentNodes.length > 0;
5277
+ const contentDefinitions = node.nodesBySlotName.children ?? [];
5278
+ const padsContent = !(contentDefinitions.length === 1 && contentDefinitions[0].type === "Surface");
5252
5279
  const { reportNodeStatus } = runtime;
5253
5280
  const innerNesting = useMemo(() => ({ ...nesting, isInsidePressable: true }), [nesting]);
5254
5281
  useEffect(() => {
@@ -5257,13 +5284,20 @@ const Pressable = (props) => {
5257
5284
  }, [hasContent, reportNodeStatus]);
5258
5285
  if (!hasContent) return null;
5259
5286
  if (runtime.isEmailRender || nesting.isInsidePressable) {
5260
- return /* @__PURE__ */ jsx("div", { className: classNames(styles$r.pressable, styles$r.content, isSelected && styles$r.selected), "data-testid": testId, children: contentNodes });
5287
+ return /* @__PURE__ */ jsx(
5288
+ "div",
5289
+ {
5290
+ className: classNames(styles$r.pressable, styles$r.content, padsContent && styles$r.padded, isSelected && styles$r.selected),
5291
+ "data-testid": testId,
5292
+ children: contentNodes
5293
+ }
5294
+ );
5261
5295
  }
5262
5296
  return /* @__PURE__ */ jsx(InteractiveSurface, { hoverable: true, className: classNames(styles$r.pressable, isSelected && styles$r.selected), children: /* @__PURE__ */ jsx(
5263
5297
  "button",
5264
5298
  {
5265
5299
  type: "button",
5266
- className: styles$r.button,
5300
+ className: classNames(styles$r.button, padsContent && styles$r.padded),
5267
5301
  "data-testid": testId,
5268
5302
  "aria-pressed": isSelected,
5269
5303
  "aria-label": accessibleLabel,
@@ -6681,6 +6715,7 @@ const ImageNode = (props) => {
6681
6715
  const isCompact = sizeClass === "compact";
6682
6716
  const [hasLoadFailed, setHasLoadFailed] = useState(false);
6683
6717
  const { reportNodeStatus } = runtime;
6718
+ const { isInsidePressable } = useLayoutNesting();
6684
6719
  useEffect(() => {
6685
6720
  setHasLoadFailed(false);
6686
6721
  }, [image2?.src]);
@@ -6708,7 +6743,7 @@ const ImageNode = (props) => {
6708
6743
  );
6709
6744
  }
6710
6745
  if (!image2) return null;
6711
- const openLightbox = runtime.isEmailRender ? void 0 : () => openMediaImagesLightbox([image2], 0);
6746
+ const openLightbox = runtime.isEmailRender || isInsidePressable ? void 0 : () => openMediaImagesLightbox([image2], 0);
6712
6747
  return /* @__PURE__ */ jsxs("figure", { className: classNames(styles$k.image, isCompact && styles$k.imageCompact), "data-testid": testId, children: [
6713
6748
  /* @__PURE__ */ jsx(
6714
6749
  MediaImageTile,
@@ -6767,9 +6802,9 @@ const DEFAULT_MAX_VISIBLE_TILES = 4;
6767
6802
  const COMPACT_MAX_VISIBLE_TILES = 3;
6768
6803
  const PENDING_TILE_COUNT = 4;
6769
6804
  const readImageGroupLayout = (value2) => value2 === "carousel" || value2 === "magazine" ? value2 : "grid";
6770
- const buildOpenImageHandler = (images, imageIndex, isEmailRender) => isEmailRender ? void 0 : () => openMediaImagesLightbox(images, imageIndex);
6805
+ const buildOpenImageHandler = (images, imageIndex, isEmailRender, isInsidePressable) => isEmailRender || isInsidePressable ? void 0 : () => openMediaImagesLightbox(images, imageIndex);
6771
6806
  const ImageGroupGrid = (props) => {
6772
- const { images, aspectRatio, isEmailRender, onImageLoadFailed, maxVisibleTiles, isCompact, testId } = props;
6807
+ const { images, aspectRatio, isEmailRender, isInsidePressable, onImageLoadFailed, maxVisibleTiles, isCompact, testId } = props;
6773
6808
  const visibleImages = images.slice(0, maxVisibleTiles);
6774
6809
  const hiddenImageCount = images.length - visibleImages.length;
6775
6810
  return /* @__PURE__ */ jsx("div", { className: classNames(styles$j.grid, isCompact && styles$j.gridCompact), "data-testid": testId, children: visibleImages.map((image2, imageIndex) => /* @__PURE__ */ jsxs("figure", { className: styles$j.tile, children: [
@@ -6782,7 +6817,7 @@ const ImageGroupGrid = (props) => {
6782
6817
  isEager: isEmailRender,
6783
6818
  isCompact,
6784
6819
  hiddenImageCount: imageIndex === visibleImages.length - 1 ? hiddenImageCount : 0,
6785
- onOpen: buildOpenImageHandler(images, imageIndex, isEmailRender),
6820
+ onOpen: buildOpenImageHandler(images, imageIndex, isEmailRender, isInsidePressable),
6786
6821
  onLoadFailed: () => onImageLoadFailed(imageIndex)
6787
6822
  }
6788
6823
  ),
@@ -6790,7 +6825,7 @@ const ImageGroupGrid = (props) => {
6790
6825
  ] }, `${imageIndex}:${image2.src}`)) });
6791
6826
  };
6792
6827
  const ImageGroupMagazine = (props) => {
6793
- const { images, aspectRatio, heroAspectRatio, isEmailRender, onImageLoadFailed, testId } = props;
6828
+ const { images, aspectRatio, heroAspectRatio, isEmailRender, isInsidePressable, onImageLoadFailed, testId } = props;
6794
6829
  const [heroImage, ...tileImages] = images;
6795
6830
  return /* @__PURE__ */ jsxs("div", { className: styles$j.magazine, "data-testid": testId, children: [
6796
6831
  /* @__PURE__ */ jsxs("figure", { className: styles$j.tile, children: [
@@ -6801,7 +6836,7 @@ const ImageGroupMagazine = (props) => {
6801
6836
  image: heroImage,
6802
6837
  aspectRatio: heroAspectRatio,
6803
6838
  isEager: isEmailRender,
6804
- onOpen: buildOpenImageHandler(images, 0, isEmailRender),
6839
+ onOpen: buildOpenImageHandler(images, 0, isEmailRender, isInsidePressable),
6805
6840
  onLoadFailed: () => onImageLoadFailed(0)
6806
6841
  }
6807
6842
  ),
@@ -6815,7 +6850,7 @@ const ImageGroupMagazine = (props) => {
6815
6850
  image: image2,
6816
6851
  aspectRatio,
6817
6852
  isEager: isEmailRender,
6818
- onOpen: buildOpenImageHandler(images, tileIndex + 1, isEmailRender),
6853
+ onOpen: buildOpenImageHandler(images, tileIndex + 1, isEmailRender, isInsidePressable),
6819
6854
  onLoadFailed: () => onImageLoadFailed(tileIndex + 1)
6820
6855
  }
6821
6856
  ),
@@ -6846,12 +6881,12 @@ const CarouselStepButton = (props) => {
6846
6881
  );
6847
6882
  };
6848
6883
  const ImageGroupCarousel = (props) => {
6849
- const { images, aspectRatio, isEmailRender, onImageLoadFailed, testId } = props;
6884
+ const { images, aspectRatio, isEmailRender, isInsidePressable, onImageLoadFailed, testId } = props;
6850
6885
  const [shownImageIndex, setShownImageIndex] = useState(0);
6851
6886
  const lastImageIndex = images.length - 1;
6852
6887
  const currentImageIndex = Math.min(shownImageIndex, lastImageIndex);
6853
6888
  const currentImage = images[currentImageIndex];
6854
- const hasControls = !isEmailRender && images.length > 1;
6889
+ const hasControls = !isEmailRender && !isInsidePressable && images.length > 1;
6855
6890
  const showImage = (imageIndex) => setShownImageIndex(Math.min(Math.max(imageIndex, 0), lastImageIndex));
6856
6891
  const showImageForKey = (event) => {
6857
6892
  if (event.key === "ArrowLeft") showImage(currentImageIndex - 1);
@@ -6875,7 +6910,7 @@ const ImageGroupCarousel = (props) => {
6875
6910
  image: currentImage,
6876
6911
  aspectRatio,
6877
6912
  isEager: true,
6878
- onOpen: buildOpenImageHandler(images, currentImageIndex, isEmailRender),
6913
+ onOpen: buildOpenImageHandler(images, currentImageIndex, isEmailRender, isInsidePressable),
6879
6914
  onLoadFailed: () => onImageLoadFailed(currentImageIndex)
6880
6915
  },
6881
6916
  `${currentImageIndex}:${currentImage.src}`
@@ -6913,6 +6948,7 @@ const ImageGroupCarousel = (props) => {
6913
6948
  };
6914
6949
  const ImageGroupNode = (props) => {
6915
6950
  const { props: nodeProps, isPending, sizeClass, runtime, testId } = props;
6951
+ const { isInsidePressable } = useLayoutNesting();
6916
6952
  const maxRepeatRows = composedNodeSchema.budgets.maxRepeatRows;
6917
6953
  const { images, droppedCount, cappedCount } = useMemo(
6918
6954
  () => readMediaImageList(nodeProps.images, maxRepeatRows),
@@ -6975,6 +7011,7 @@ const ImageGroupNode = (props) => {
6975
7011
  images,
6976
7012
  aspectRatio: readAspectRatio(nodeProps.aspectRatio, layout === "magazine" ? "1:1" : "4:3"),
6977
7013
  isEmailRender: runtime.isEmailRender,
7014
+ isInsidePressable,
6978
7015
  onImageLoadFailed: markImageLoadFailed,
6979
7016
  testId
6980
7017
  };
@@ -9706,4 +9743,4 @@ export {
9706
9743
  getConversationWidgetRegistryRevision as y,
9707
9744
  readComposedViewTree as z
9708
9745
  };
9709
- //# sourceMappingURL=widget-name-resolver-DboFMAq2.js.map
9746
+ //# sourceMappingURL=widget-name-resolver-7WnzCpdG.js.map