@yoamigo.com/core 0.3.14 → 0.3.17

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 (2) hide show
  1. package/dist/index.js +32 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3552,7 +3552,7 @@ function YaImage({
3552
3552
  fallbackSrc,
3553
3553
  fallbackAlt
3554
3554
  }) {
3555
- const { getValue, mode } = useContentStore();
3555
+ const { getValue, setValue, mode } = useContentStore();
3556
3556
  const containerRef = useRef8(null);
3557
3557
  const imgRef = useRef8(null);
3558
3558
  const [isSelected, setIsSelected] = useState7(false);
@@ -3560,12 +3560,14 @@ function YaImage({
3560
3560
  const [isSmallImage, setIsSmallImage] = useState7(false);
3561
3561
  const [isDropMode, setIsDropMode] = useState7(false);
3562
3562
  const [isDropHover, setIsDropHover] = useState7(false);
3563
+ const [previewOverride, setPreviewOverride] = useState7(null);
3563
3564
  const rawValue = getValue(fieldId);
3564
3565
  const imageData = parseImageValue(rawValue);
3565
- const src = imageData.src || fallbackSrc || PLACEHOLDER_SVG;
3566
- const altText = imageData.alt || alt || fallbackAlt || "";
3567
- const objectFit = imageData.objectFit || propObjectFit || "cover";
3568
- const objectPosition = getObjectPosition(imageData) || propObjectPosition || "50% 50%";
3566
+ const displayData = previewOverride || imageData;
3567
+ const src = displayData.src || fallbackSrc || PLACEHOLDER_SVG;
3568
+ const altText = displayData.alt || alt || fallbackAlt || "";
3569
+ const objectFit = displayData.objectFit || propObjectFit || "cover";
3570
+ const objectPosition = getObjectPosition(displayData) || propObjectPosition || "50% 50%";
3569
3571
  const handleClick = useCallback9(() => {
3570
3572
  if (mode !== "inline-edit") return;
3571
3573
  if (document.body.classList.contains("builder-selector-active")) return;
@@ -3598,17 +3600,23 @@ function YaImage({
3598
3600
  if (mode !== "inline-edit") return;
3599
3601
  const handleMessage2 = (event) => {
3600
3602
  if (event.data?.type === "YA_IMAGE_EDIT_COMPLETE" && event.data.fieldId === fieldId) {
3603
+ const value = event.data.value;
3604
+ setValue(fieldId, serializeImageValue(value), "user");
3605
+ setPreviewOverride(null);
3601
3606
  setIsSelected(false);
3602
3607
  }
3603
3608
  if (event.data?.type === "YA_IMAGE_EDIT_CANCEL" && event.data.fieldId === fieldId) {
3609
+ setPreviewOverride(null);
3604
3610
  setIsSelected(false);
3605
3611
  }
3606
3612
  if (event.data?.type === "YA_IMAGE_UPDATE_PREVIEW" && event.data.fieldId === fieldId) {
3613
+ const value = event.data.value;
3614
+ setPreviewOverride(value);
3607
3615
  }
3608
3616
  };
3609
3617
  window.addEventListener("message", handleMessage2);
3610
3618
  return () => window.removeEventListener("message", handleMessage2);
3611
- }, [mode, fieldId]);
3619
+ }, [mode, fieldId, setValue]);
3612
3620
  useEffect8(() => {
3613
3621
  if (mode !== "inline-edit") return;
3614
3622
  const handleDropModeMessage = (event) => {
@@ -5640,31 +5648,6 @@ function Toolbar({ containerRef, onImageClick, onColorClick, onAIClick, onClearC
5640
5648
  children: "Background Color"
5641
5649
  }
5642
5650
  ) }),
5643
- /* @__PURE__ */ jsx16(
5644
- "button",
5645
- {
5646
- ref: aiRefs.setReference,
5647
- type: "button",
5648
- onClick: onAIClick,
5649
- "aria-label": "Ask AI for help",
5650
- ...getAiRefProps(),
5651
- children: /* @__PURE__ */ jsxs10("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
5652
- /* @__PURE__ */ jsx16("path", { d: "M12 2L2 7l10 5 10-5-10-5z" }),
5653
- /* @__PURE__ */ jsx16("path", { d: "M2 17l10 5 10-5" }),
5654
- /* @__PURE__ */ jsx16("path", { d: "M2 12l10 5 10-5" })
5655
- ] })
5656
- }
5657
- ),
5658
- aiOpen && /* @__PURE__ */ jsx16(FloatingPortal2, { children: /* @__PURE__ */ jsx16(
5659
- "div",
5660
- {
5661
- ref: aiRefs.setFloating,
5662
- className: "ya-container-tooltip",
5663
- style: aiStyles,
5664
- ...getAiFloatProps(),
5665
- children: "AI Assist"
5666
- }
5667
- ) }),
5668
5651
  hasBackground && /* @__PURE__ */ jsxs10(Fragment5, { children: [
5669
5652
  /* @__PURE__ */ jsx16(
5670
5653
  "button",
@@ -5711,6 +5694,7 @@ function YaContainer({
5711
5694
  const [isSelected, setIsSelected] = useState13(false);
5712
5695
  const [isDropMode, setIsDropMode] = useState13(false);
5713
5696
  const [isDropHover, setIsDropHover] = useState13(false);
5697
+ const [previewConfig, setPreviewConfig] = useState13(null);
5714
5698
  useEffect14(() => {
5715
5699
  if (mode !== "inline-edit") return;
5716
5700
  const containerEl = containerRef.current;
@@ -5735,13 +5719,14 @@ function YaContainer({
5735
5719
  }, [mode]);
5736
5720
  const rawValue = getValue(fieldId);
5737
5721
  const backgroundConfig = rawValue ? parseBackgroundConfig(rawValue) : defaultBackground || { type: "none" };
5738
- const hasBackground = backgroundConfig.type !== "none";
5722
+ const displayConfig = previewConfig ?? backgroundConfig;
5723
+ const hasBackground = displayConfig.type !== "none";
5739
5724
  const backgroundStyles = {};
5740
- if (backgroundConfig.type === "color" && backgroundConfig.backgroundColor) {
5741
- backgroundStyles.backgroundColor = backgroundConfig.backgroundColor;
5725
+ if (displayConfig.type === "color" && displayConfig.backgroundColor) {
5726
+ backgroundStyles.backgroundColor = displayConfig.backgroundColor;
5742
5727
  }
5743
- if (backgroundConfig.type === "image" && backgroundConfig.backgroundImage) {
5744
- const img = backgroundConfig.backgroundImage;
5728
+ if (displayConfig.type === "image" && displayConfig.backgroundImage) {
5729
+ const img = displayConfig.backgroundImage;
5745
5730
  const resolvedSrc = resolveAssetUrl(img.src);
5746
5731
  backgroundStyles.backgroundImage = `url(${resolvedSrc})`;
5747
5732
  backgroundStyles.backgroundSize = img.objectFit || "cover";
@@ -5749,9 +5734,9 @@ function YaContainer({
5749
5734
  backgroundStyles.backgroundRepeat = "no-repeat";
5750
5735
  }
5751
5736
  const overlayCustomProps = {};
5752
- if (backgroundConfig.overlay) {
5753
- overlayCustomProps["--ya-overlay-color"] = backgroundConfig.overlay.color;
5754
- overlayCustomProps["--ya-overlay-opacity"] = backgroundConfig.overlay.opacity;
5737
+ if (displayConfig.overlay) {
5738
+ overlayCustomProps["--ya-overlay-color"] = displayConfig.overlay.color;
5739
+ overlayCustomProps["--ya-overlay-opacity"] = displayConfig.overlay.opacity;
5755
5740
  }
5756
5741
  const handleImageClick = useCallback15(() => {
5757
5742
  if (mode !== "inline-edit") return;
@@ -5816,11 +5801,19 @@ function YaContainer({
5816
5801
  useEffect14(() => {
5817
5802
  if (mode !== "inline-edit") return;
5818
5803
  const handleMessage2 = (event) => {
5804
+ if (event.data?.type === "YA_CONTAINER_UPDATE_PREVIEW" && event.data.fieldId === fieldId) {
5805
+ if (event.data.value) {
5806
+ const config = typeof event.data.value === "string" ? parseBackgroundConfig(event.data.value) : event.data.value;
5807
+ setPreviewConfig(config);
5808
+ }
5809
+ }
5819
5810
  if (event.data?.type === "YA_CONTAINER_EDIT_COMPLETE" && event.data.fieldId === fieldId) {
5820
5811
  setIsSelected(false);
5812
+ setPreviewConfig(null);
5821
5813
  }
5822
5814
  if (event.data?.type === "YA_CONTAINER_EDIT_CANCEL" && event.data.fieldId === fieldId) {
5823
5815
  setIsSelected(false);
5816
+ setPreviewConfig(null);
5824
5817
  }
5825
5818
  };
5826
5819
  window.addEventListener("message", handleMessage2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/core",
3
- "version": "0.3.14",
3
+ "version": "0.3.17",
4
4
  "description": "Core components, router, and utilities for YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",