@amplifyup/sdk 0.1.26 → 0.1.28

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/dist/react.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
- import { createContext, useState, useEffect, useContext, Fragment as Fragment$1, Component } from 'react';
3
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
+ import { createContext, useState, useEffect, useContext, Fragment as Fragment$1, useRef, Component } from 'react';
4
3
  import { marked } from 'marked';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  /* @amplifyup/sdk - https://amplifyup.ai */
7
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -1781,6 +1781,12 @@ Available Console Commands:
1781
1781
  return;
1782
1782
  }
1783
1783
  try {
1784
+ if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
1785
+ window.dispatchEvent(
1786
+ new CustomEvent("amplifyup:field-patch", { detail: event.data })
1787
+ );
1788
+ return;
1789
+ }
1784
1790
  if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
1785
1791
  const { componentId, deletable, nodeId } = event.data;
1786
1792
  const element = document.querySelector(`[data-component-id="${componentId}"]`);
@@ -1967,6 +1973,10 @@ Available Console Commands:
1967
1973
  setEventSelectionMode(enabled) {
1968
1974
  if (typeof document === "undefined") return;
1969
1975
  this.eventSelectionMode = enabled;
1976
+ if (typeof window !== "undefined") {
1977
+ window.__AMPLIFYUP_EVENT_SELECTION__ = enabled;
1978
+ window.dispatchEvent(new CustomEvent("amplifyup:composer-edit"));
1979
+ }
1970
1980
  if (this.eventSelectionClickHandler) {
1971
1981
  document.removeEventListener("click", this.eventSelectionClickHandler, true);
1972
1982
  this.eventSelectionClickHandler = null;
@@ -2204,6 +2214,14 @@ Available Console Commands:
2204
2214
  el.classList.add("amplifyup-selected");
2205
2215
  }
2206
2216
  });
2217
+ if (typeof window !== "undefined") {
2218
+ window.__AMPLIFYUP_COMPOSER_EDIT__ = highlightComponents;
2219
+ window.dispatchEvent(
2220
+ new CustomEvent("amplifyup:composer-edit", {
2221
+ detail: { enabled: highlightComponents }
2222
+ })
2223
+ );
2224
+ }
2207
2225
  }
2208
2226
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
2209
2227
  setupComposerDragDrop() {
@@ -2512,6 +2530,12 @@ Available Console Commands:
2512
2530
  const clearSelection = opts?.clearSelection !== false;
2513
2531
  this.highlightingEnabled = false;
2514
2532
  this.teardownComposerDragDrop();
2533
+ if (opts?.clearSelection !== false && typeof window !== "undefined") {
2534
+ window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
2535
+ window.dispatchEvent(
2536
+ new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
2537
+ );
2538
+ }
2515
2539
  if (this.mutationObserver) {
2516
2540
  this.mutationObserver.disconnect();
2517
2541
  this.mutationObserver = null;
@@ -2717,6 +2741,417 @@ function getSDK(adapter) {
2717
2741
  var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
2718
2742
  var refreshEventTracking = () => getSDK().refreshEventTracking();
2719
2743
  getSDK();
2744
+ var ComponentContext = createContext(null);
2745
+ function useLiveComposerProps(layoutNodeId, props) {
2746
+ const [live, setLive] = useState(props);
2747
+ useEffect(() => {
2748
+ setLive(props);
2749
+ }, [props]);
2750
+ useEffect(() => {
2751
+ const apply = (fieldName, value, nodeId) => {
2752
+ if (!fieldName || typeof fieldName !== "string") return;
2753
+ if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
2754
+ return;
2755
+ }
2756
+ setLive((prev) => ({ ...prev, [fieldName]: value }));
2757
+ };
2758
+ const onPatch = (event) => {
2759
+ const detail = event.detail || {};
2760
+ apply(detail.fieldName, detail.value, detail.layoutNodeId);
2761
+ };
2762
+ const onMessage = (event) => {
2763
+ if (event.data?.type !== "AMPLIFYUP_FIELD_PATCH") return;
2764
+ apply(event.data.fieldName, event.data.value, event.data.layoutNodeId);
2765
+ };
2766
+ window.addEventListener("amplifyup:field-patch", onPatch);
2767
+ window.addEventListener("message", onMessage);
2768
+ return () => {
2769
+ window.removeEventListener("amplifyup:field-patch", onPatch);
2770
+ window.removeEventListener("message", onMessage);
2771
+ };
2772
+ }, [layoutNodeId]);
2773
+ return live;
2774
+ }
2775
+ function ComponentContextProvider({
2776
+ children,
2777
+ slots,
2778
+ props,
2779
+ layoutNodeId,
2780
+ componentId
2781
+ }) {
2782
+ const liveProps = useLiveComposerProps(layoutNodeId, props || {});
2783
+ return /* @__PURE__ */ jsx(
2784
+ ComponentContext.Provider,
2785
+ {
2786
+ value: { slots, props: liveProps, layoutNodeId, componentId },
2787
+ children
2788
+ }
2789
+ );
2790
+ }
2791
+ function Slot({
2792
+ name,
2793
+ className
2794
+ }) {
2795
+ const context = useContext(ComponentContext);
2796
+ console.log(`[Slot:${name}] Rendering slot`, {
2797
+ hasContext: !!context,
2798
+ availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
2799
+ slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
2800
+ contextSlots: context?.slots
2801
+ });
2802
+ if (!context) {
2803
+ console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
2804
+ return null;
2805
+ }
2806
+ const slotContent = context.slots?.[name];
2807
+ const isEmpty = !slotContent;
2808
+ console.log(`[Slot:${name}] Slot state`, {
2809
+ isEmpty,
2810
+ hasSlotContent: !!slotContent,
2811
+ slotContentType: slotContent ? typeof slotContent : "null"
2812
+ });
2813
+ const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
2814
+ (window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
2815
+ new URLSearchParams(window.location.search).get("preview") === "true" || new URLSearchParams(window.location.search).get("visualEditor") === "true" || // Check if in iframe from orchestrator (check referrer hostname/port)
2816
+ window.self !== window.top && document.referrer && (() => {
2817
+ try {
2818
+ const referrerUrl = new URL(document.referrer);
2819
+ return referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/");
2820
+ } catch {
2821
+ return false;
2822
+ }
2823
+ })());
2824
+ console.log(`[Slot:${name}] Editor mode detection`, {
2825
+ isEditorMode,
2826
+ isWindowDefined: typeof window !== "undefined",
2827
+ previewModeFlag: typeof window !== "undefined" ? window.__AMPLIFYUP_PREVIEW_MODE__ : void 0,
2828
+ urlParams: typeof window !== "undefined" ? {
2829
+ preview: new URLSearchParams(window.location.search).get("preview"),
2830
+ visualEditor: new URLSearchParams(window.location.search).get("visualEditor")
2831
+ } : void 0,
2832
+ inIframe: typeof window !== "undefined" ? window.self !== window.top : false,
2833
+ referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
2834
+ });
2835
+ return /* @__PURE__ */ jsx(
2836
+ "div",
2837
+ {
2838
+ className,
2839
+ "data-slot-name": name,
2840
+ "data-slot-id": name,
2841
+ "data-amplifyup-slot": name,
2842
+ "data-slot-empty": isEmpty ? "true" : void 0,
2843
+ "data-parent-node-id": context.layoutNodeId || void 0,
2844
+ "data-parent-component-id": context.componentId || void 0,
2845
+ style: {
2846
+ // Only add minimum height when empty (for drop target visibility)
2847
+ minHeight: isEmpty ? "60px" : void 0,
2848
+ // Only add position relative for overlay positioning in editor mode
2849
+ position: isEditorMode ? "relative" : void 0
2850
+ },
2851
+ children: isEmpty ? /* @__PURE__ */ jsx(
2852
+ "div",
2853
+ {
2854
+ className: "amplifyup-slot-placeholder",
2855
+ style: {
2856
+ minHeight: "60px",
2857
+ color: "#9ca3af",
2858
+ fontSize: "14px",
2859
+ pointerEvents: "none"
2860
+ },
2861
+ children: isEditorMode ? `Drop components here` : `Empty slot: ${name}`
2862
+ }
2863
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2864
+ isEditorMode && /* @__PURE__ */ jsxs(
2865
+ "div",
2866
+ {
2867
+ className: "amplifyup-slot-placeholder",
2868
+ style: {
2869
+ position: "absolute",
2870
+ top: "4px",
2871
+ left: "4px",
2872
+ fontSize: "10px",
2873
+ color: "#9ca3af",
2874
+ pointerEvents: "none",
2875
+ zIndex: 1,
2876
+ minHeight: "auto"
2877
+ },
2878
+ children: [
2879
+ "Slot: ",
2880
+ name
2881
+ ]
2882
+ }
2883
+ ),
2884
+ slotContent
2885
+ ] })
2886
+ }
2887
+ );
2888
+ }
2889
+ function isComposerEditMode() {
2890
+ if (typeof window === "undefined") return false;
2891
+ return isComposerPreview() && window.__AMPLIFYUP_EVENT_SELECTION__ !== true;
2892
+ }
2893
+ function isLikelyNonTextFieldName(name) {
2894
+ const n = name.toLowerCase();
2895
+ return n.includes("href") || n.includes("url") || n.includes("src") || n.includes("image") || n.includes("icon") || n.includes("overlay") || n.includes("color");
2896
+ }
2897
+ function canInlineEdit(name, value) {
2898
+ if (isLikelyNonTextFieldName(name)) return false;
2899
+ if (value !== void 0 && value !== null && typeof value === "object") {
2900
+ return false;
2901
+ }
2902
+ if (typeof value === "boolean") return false;
2903
+ return true;
2904
+ }
2905
+ function useComposerEditMode() {
2906
+ const [enabled, setEnabled] = useState(false);
2907
+ useEffect(() => {
2908
+ const sync = () => setEnabled(isComposerEditMode());
2909
+ sync();
2910
+ window.addEventListener("amplifyup:composer-edit", sync);
2911
+ return () => window.removeEventListener("amplifyup:composer-edit", sync);
2912
+ }, []);
2913
+ return enabled;
2914
+ }
2915
+ function useFieldOverlay(layoutNodeId, name, source) {
2916
+ const [overlay, setOverlay] = useState(void 0);
2917
+ useEffect(() => {
2918
+ const onPatch = (event) => {
2919
+ const detail = event.detail || {};
2920
+ if (detail.fieldName !== name) return;
2921
+ if (detail.layoutNodeId && layoutNodeId && String(detail.layoutNodeId) !== String(layoutNodeId)) {
2922
+ return;
2923
+ }
2924
+ setOverlay(detail.value);
2925
+ };
2926
+ window.addEventListener("amplifyup:field-patch", onPatch);
2927
+ return () => window.removeEventListener("amplifyup:field-patch", onPatch);
2928
+ }, [layoutNodeId, name]);
2929
+ return overlay !== void 0 ? overlay : source;
2930
+ }
2931
+ function commitComposerField(layoutNodeId, componentId, name, value) {
2932
+ if (typeof window === "undefined" || window.parent === window) return;
2933
+ window.parent.postMessage(
2934
+ {
2935
+ type: "AMPLIFYUP_FIELD_COMMIT",
2936
+ layoutNodeId,
2937
+ componentId,
2938
+ fieldName: name,
2939
+ value
2940
+ },
2941
+ "*"
2942
+ );
2943
+ }
2944
+ function ComposerInlineField({
2945
+ name,
2946
+ value,
2947
+ fallback,
2948
+ className,
2949
+ render,
2950
+ layoutNodeId,
2951
+ componentId
2952
+ }) {
2953
+ const [editing, setEditing] = useState(false);
2954
+ const elRef = useRef(null);
2955
+ const text = formatFieldValue(value);
2956
+ const fallbackText = typeof fallback === "string" || typeof fallback === "number" ? String(fallback) : "";
2957
+ const display = text || fallbackText;
2958
+ const showRendered = !!render && !editing;
2959
+ useEffect(() => {
2960
+ const el = elRef.current;
2961
+ if (!el || showRendered) return;
2962
+ if (document.activeElement === el) return;
2963
+ const next = display || "";
2964
+ if (el.textContent !== next) el.textContent = next;
2965
+ }, [display, showRendered]);
2966
+ useEffect(() => {
2967
+ if (!editing || !elRef.current) return;
2968
+ const el = elRef.current;
2969
+ el.textContent = display || "";
2970
+ el.focus();
2971
+ const range = document.createRange();
2972
+ range.selectNodeContents(el);
2973
+ const sel = window.getSelection();
2974
+ sel?.removeAllRanges();
2975
+ sel?.addRange(range);
2976
+ }, [editing]);
2977
+ const finishEdit = () => {
2978
+ const raw = (elRef.current?.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
2979
+ const next = raw.trim() === "" ? "" : raw;
2980
+ setEditing(false);
2981
+ if (next === text) return;
2982
+ if (!text && next === fallbackText) return;
2983
+ commitComposerField(layoutNodeId, componentId, name, next);
2984
+ };
2985
+ return /* @__PURE__ */ jsx(
2986
+ "span",
2987
+ {
2988
+ ref: elRef,
2989
+ className,
2990
+ "data-amplifyup-field": name,
2991
+ "data-amplifyup-node-id": layoutNodeId || void 0,
2992
+ contentEditable: !showRendered,
2993
+ suppressContentEditableWarning: true,
2994
+ role: "textbox",
2995
+ tabIndex: 0,
2996
+ onMouseDown: (event) => {
2997
+ event.stopPropagation();
2998
+ },
2999
+ onClick: (event) => {
3000
+ const link = event.target?.closest?.("a");
3001
+ if (link) event.preventDefault();
3002
+ if (render && isComposerEditMode()) {
3003
+ setEditing(true);
3004
+ }
3005
+ },
3006
+ onFocus: () => {
3007
+ if (!isComposerEditMode()) return;
3008
+ if (render) setEditing(true);
3009
+ },
3010
+ onBlur: finishEdit,
3011
+ onKeyDown: (event) => {
3012
+ event.stopPropagation();
3013
+ if (event.key === "Enter" && !event.shiftKey) {
3014
+ event.preventDefault();
3015
+ event.currentTarget.blur();
3016
+ }
3017
+ if (event.key === "Escape") {
3018
+ event.preventDefault();
3019
+ if (elRef.current) elRef.current.textContent = display || "";
3020
+ setEditing(false);
3021
+ event.currentTarget.blur();
3022
+ }
3023
+ },
3024
+ style: {
3025
+ cursor: "text",
3026
+ outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
3027
+ outlineOffset: "2px",
3028
+ minWidth: "1ch",
3029
+ display: render ? void 0 : "inline"
3030
+ },
3031
+ children: showRendered ? value != null && value !== "" ? render(value) : fallback ?? display : null
3032
+ }
3033
+ );
3034
+ }
3035
+ function formatFieldValue(value) {
3036
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
3037
+ return String(value);
3038
+ }
3039
+ if (Array.isArray(value)) {
3040
+ const parts = value.map((item) => {
3041
+ if (typeof item === "string") return item;
3042
+ if (item && typeof item === "object" && "children" in item && Array.isArray(item.children)) {
3043
+ return item.children.map((c) => typeof c?.text === "string" ? c.text : "").join("");
3044
+ }
3045
+ return "";
3046
+ }).filter(Boolean);
3047
+ if (parts.length > 0) return parts.join(" ");
3048
+ }
3049
+ if (value && typeof value === "object") {
3050
+ return "";
3051
+ }
3052
+ return "";
3053
+ }
3054
+ function Field({
3055
+ name,
3056
+ fallback,
3057
+ className,
3058
+ render
3059
+ }) {
3060
+ const context = useContext(ComponentContext);
3061
+ const composerEdit = useComposerEditMode();
3062
+ const fieldValue = useFieldOverlay(
3063
+ context?.layoutNodeId,
3064
+ name,
3065
+ context?.props?.[name]
3066
+ );
3067
+ if (!context) {
3068
+ console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
3069
+ return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3070
+ }
3071
+ if (composerEdit && canInlineEdit(name, fieldValue)) {
3072
+ return /* @__PURE__ */ jsx(
3073
+ ComposerInlineField,
3074
+ {
3075
+ name,
3076
+ value: fieldValue,
3077
+ fallback,
3078
+ className,
3079
+ render,
3080
+ layoutNodeId: context.layoutNodeId,
3081
+ componentId: context.componentId
3082
+ }
3083
+ );
3084
+ }
3085
+ if (fieldValue === void 0 || fieldValue === null) {
3086
+ return fallback ? /* @__PURE__ */ jsx("span", { className, children: fallback }) : null;
3087
+ }
3088
+ if (render) {
3089
+ return /* @__PURE__ */ jsx("span", { className, children: render(fieldValue) });
3090
+ }
3091
+ const text = formatFieldValue(fieldValue);
3092
+ if (!text) {
3093
+ return fallback ? /* @__PURE__ */ jsx("span", { className, children: fallback }) : null;
3094
+ }
3095
+ return /* @__PURE__ */ jsx("span", { className, children: text });
3096
+ }
3097
+ function markdownToHtml(markdown) {
3098
+ try {
3099
+ const result = marked.parse(markdown, { async: false });
3100
+ return typeof result === "string" ? result : "";
3101
+ } catch {
3102
+ return markdown;
3103
+ }
3104
+ }
3105
+ function RichText({
3106
+ name,
3107
+ fallback,
3108
+ className,
3109
+ as: Tag = "div"
3110
+ }) {
3111
+ const context = useContext(ComponentContext);
3112
+ const composerEdit = useComposerEditMode();
3113
+ const fieldValue = useFieldOverlay(
3114
+ context?.layoutNodeId,
3115
+ name,
3116
+ context?.props?.[name]
3117
+ );
3118
+ if (!context) {
3119
+ console.warn(`[AmplifyUp SDK] RichText "${name}" used outside ComponentContextProvider`);
3120
+ return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3121
+ }
3122
+ if (composerEdit && canInlineEdit(name, fieldValue)) {
3123
+ return /* @__PURE__ */ jsx(
3124
+ ComposerInlineField,
3125
+ {
3126
+ name,
3127
+ value: fieldValue,
3128
+ fallback,
3129
+ className,
3130
+ layoutNodeId: context.layoutNodeId,
3131
+ componentId: context.componentId
3132
+ }
3133
+ );
3134
+ }
3135
+ if (fieldValue === void 0 || fieldValue === null || fieldValue === "") {
3136
+ return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
3137
+ }
3138
+ let html = "";
3139
+ if (typeof fieldValue === "string") {
3140
+ const trimmed = fieldValue.trim();
3141
+ if (trimmed.startsWith("<") && trimmed.includes(">")) {
3142
+ html = fieldValue;
3143
+ } else {
3144
+ html = markdownToHtml(fieldValue);
3145
+ }
3146
+ } else {
3147
+ const text = formatFieldValue(fieldValue);
3148
+ html = text ? markdownToHtml(text) : "";
3149
+ }
3150
+ if (!html) {
3151
+ return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
3152
+ }
3153
+ return /* @__PURE__ */ jsx(Tag, { className, dangerouslySetInnerHTML: { __html: html } });
3154
+ }
2720
3155
  var ComponentRenderBoundary = class extends Component {
2721
3156
  constructor() {
2722
3157
  super(...arguments);
@@ -2764,6 +3199,18 @@ var ComponentRenderBoundary = class extends Component {
2764
3199
  return this.props.children;
2765
3200
  }
2766
3201
  };
3202
+ function LiveNodeRender({
3203
+ nodeId,
3204
+ componentId,
3205
+ props,
3206
+ slots,
3207
+ renderComponent
3208
+ }) {
3209
+ const liveProps = useLiveComposerProps(nodeId, props);
3210
+ return /* @__PURE__ */ jsx(Fragment, { children: renderComponent(componentId, liveProps, slots, {
3211
+ layoutNodeId: nodeId
3212
+ }) });
3213
+ }
2767
3214
  function AmplifyRenderer({
2768
3215
  renderComponent,
2769
3216
  pageConfig: serverPageConfig,
@@ -3118,20 +3565,21 @@ function AmplifyRenderer({
3118
3565
  }
3119
3566
  }
3120
3567
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
3121
- console.log(`[AmplifyRenderer] Calling renderComponent for ${node.componentId}`, {
3122
- hasSlots: !!slotsToPass,
3123
- slotKeys: slotsToPass ? Object.keys(slotsToPass) : [],
3124
- propKeys: Object.keys(node.props || {}),
3125
- props: node.props || {}
3126
- });
3127
3568
  return /* @__PURE__ */ jsx("div", { "data-node-id": node.id, "data-amplifyup-node": "", children: /* @__PURE__ */ jsx(
3128
3569
  ComponentRenderBoundary,
3129
3570
  {
3130
3571
  componentId: node.componentId,
3131
3572
  nodeId: node.id,
3132
- children: renderComponent(node.componentId, node.props || {}, slotsToPass, {
3133
- layoutNodeId: node.id
3134
- })
3573
+ children: /* @__PURE__ */ jsx(
3574
+ LiveNodeRender,
3575
+ {
3576
+ nodeId: node.id,
3577
+ componentId: node.componentId,
3578
+ props: node.props || {},
3579
+ slots: slotsToPass,
3580
+ renderComponent
3581
+ }
3582
+ )
3135
3583
  }
3136
3584
  ) });
3137
3585
  };
@@ -3258,210 +3706,6 @@ async function fetchPageConfigServer(route, trackingId, preview = false, options
3258
3706
  });
3259
3707
  return result.pageConfig;
3260
3708
  }
3261
- var ComponentContext = createContext(null);
3262
- function ComponentContextProvider({
3263
- children,
3264
- slots,
3265
- props,
3266
- layoutNodeId,
3267
- componentId
3268
- }) {
3269
- console.log("[ComponentContextProvider] Providing context", {
3270
- hasSlots: !!slots,
3271
- slotKeys: slots ? Object.keys(slots) : [],
3272
- slotDetails: slots ? Object.keys(slots).map((key) => ({
3273
- key,
3274
- hasContent: !!slots[key],
3275
- contentType: slots[key] ? typeof slots[key] : "null"
3276
- })) : [],
3277
- hasProps: !!props,
3278
- propKeys: props ? Object.keys(props) : [],
3279
- layoutNodeId,
3280
- componentId
3281
- });
3282
- return /* @__PURE__ */ jsx(ComponentContext.Provider, { value: { slots, props, layoutNodeId, componentId }, children });
3283
- }
3284
- function Slot({
3285
- name,
3286
- className
3287
- }) {
3288
- const context = useContext(ComponentContext);
3289
- console.log(`[Slot:${name}] Rendering slot`, {
3290
- hasContext: !!context,
3291
- availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
3292
- slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
3293
- contextSlots: context?.slots
3294
- });
3295
- if (!context) {
3296
- console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
3297
- return null;
3298
- }
3299
- const slotContent = context.slots?.[name];
3300
- const isEmpty = !slotContent;
3301
- console.log(`[Slot:${name}] Slot state`, {
3302
- isEmpty,
3303
- hasSlotContent: !!slotContent,
3304
- slotContentType: slotContent ? typeof slotContent : "null"
3305
- });
3306
- const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
3307
- (window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
3308
- new URLSearchParams(window.location.search).get("preview") === "true" || new URLSearchParams(window.location.search).get("visualEditor") === "true" || // Check if in iframe from orchestrator (check referrer hostname/port)
3309
- window.self !== window.top && document.referrer && (() => {
3310
- try {
3311
- const referrerUrl = new URL(document.referrer);
3312
- return referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/");
3313
- } catch {
3314
- return false;
3315
- }
3316
- })());
3317
- console.log(`[Slot:${name}] Editor mode detection`, {
3318
- isEditorMode,
3319
- isWindowDefined: typeof window !== "undefined",
3320
- previewModeFlag: typeof window !== "undefined" ? window.__AMPLIFYUP_PREVIEW_MODE__ : void 0,
3321
- urlParams: typeof window !== "undefined" ? {
3322
- preview: new URLSearchParams(window.location.search).get("preview"),
3323
- visualEditor: new URLSearchParams(window.location.search).get("visualEditor")
3324
- } : void 0,
3325
- inIframe: typeof window !== "undefined" ? window.self !== window.top : false,
3326
- referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
3327
- });
3328
- return /* @__PURE__ */ jsx(
3329
- "div",
3330
- {
3331
- className,
3332
- "data-slot-name": name,
3333
- "data-slot-id": name,
3334
- "data-amplifyup-slot": name,
3335
- "data-slot-empty": isEmpty ? "true" : void 0,
3336
- "data-parent-node-id": context.layoutNodeId || void 0,
3337
- "data-parent-component-id": context.componentId || void 0,
3338
- style: {
3339
- // Only add minimum height when empty (for drop target visibility)
3340
- minHeight: isEmpty ? "60px" : void 0,
3341
- // Only add position relative for overlay positioning in editor mode
3342
- position: isEditorMode ? "relative" : void 0
3343
- },
3344
- children: isEmpty ? /* @__PURE__ */ jsx(
3345
- "div",
3346
- {
3347
- className: "amplifyup-slot-placeholder",
3348
- style: {
3349
- minHeight: "60px",
3350
- color: "#9ca3af",
3351
- fontSize: "14px",
3352
- pointerEvents: "none"
3353
- },
3354
- children: isEditorMode ? `Drop components here` : `Empty slot: ${name}`
3355
- }
3356
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
3357
- isEditorMode && /* @__PURE__ */ jsxs(
3358
- "div",
3359
- {
3360
- className: "amplifyup-slot-placeholder",
3361
- style: {
3362
- position: "absolute",
3363
- top: "4px",
3364
- left: "4px",
3365
- fontSize: "10px",
3366
- color: "#9ca3af",
3367
- pointerEvents: "none",
3368
- zIndex: 1,
3369
- minHeight: "auto"
3370
- },
3371
- children: [
3372
- "Slot: ",
3373
- name
3374
- ]
3375
- }
3376
- ),
3377
- slotContent
3378
- ] })
3379
- }
3380
- );
3381
- }
3382
- function formatFieldValue(value) {
3383
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
3384
- return String(value);
3385
- }
3386
- if (Array.isArray(value)) {
3387
- const parts = value.map((item) => {
3388
- if (typeof item === "string") return item;
3389
- if (item && typeof item === "object" && "children" in item && Array.isArray(item.children)) {
3390
- return item.children.map((c) => typeof c?.text === "string" ? c.text : "").join("");
3391
- }
3392
- return "";
3393
- }).filter(Boolean);
3394
- if (parts.length > 0) return parts.join(" ");
3395
- }
3396
- if (value && typeof value === "object") {
3397
- return "";
3398
- }
3399
- return "";
3400
- }
3401
- function Field({
3402
- name,
3403
- fallback,
3404
- className,
3405
- render
3406
- }) {
3407
- const context = useContext(ComponentContext);
3408
- if (!context) {
3409
- console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
3410
- return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3411
- }
3412
- const fieldValue = context.props?.[name];
3413
- if (fieldValue === void 0 || fieldValue === null) {
3414
- return fallback ? /* @__PURE__ */ jsx("span", { className, children: fallback }) : null;
3415
- }
3416
- if (render) {
3417
- return /* @__PURE__ */ jsx("span", { className, children: render(fieldValue) });
3418
- }
3419
- const text = formatFieldValue(fieldValue);
3420
- if (!text) {
3421
- return fallback ? /* @__PURE__ */ jsx("span", { className, children: fallback }) : null;
3422
- }
3423
- return /* @__PURE__ */ jsx("span", { className, children: text });
3424
- }
3425
- function markdownToHtml(markdown) {
3426
- try {
3427
- const result = marked.parse(markdown, { async: false });
3428
- return typeof result === "string" ? result : "";
3429
- } catch {
3430
- return markdown;
3431
- }
3432
- }
3433
- function RichText({
3434
- name,
3435
- fallback,
3436
- className,
3437
- as: Tag = "div"
3438
- }) {
3439
- const context = useContext(ComponentContext);
3440
- if (!context) {
3441
- console.warn(`[AmplifyUp SDK] RichText "${name}" used outside ComponentContextProvider`);
3442
- return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3443
- }
3444
- const fieldValue = context.props?.[name];
3445
- if (fieldValue === void 0 || fieldValue === null || fieldValue === "") {
3446
- return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
3447
- }
3448
- let html = "";
3449
- if (typeof fieldValue === "string") {
3450
- const trimmed = fieldValue.trim();
3451
- if (trimmed.startsWith("<") && trimmed.includes(">")) {
3452
- html = fieldValue;
3453
- } else {
3454
- html = markdownToHtml(fieldValue);
3455
- }
3456
- } else {
3457
- const text = formatFieldValue(fieldValue);
3458
- html = text ? markdownToHtml(text) : "";
3459
- }
3460
- if (!html) {
3461
- return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
3462
- }
3463
- return /* @__PURE__ */ jsx(Tag, { className, dangerouslySetInnerHTML: { __html: html } });
3464
- }
3465
3709
  var usePathname = null;
3466
3710
  if (typeof window !== "undefined") {
3467
3711
  try {
@@ -3619,6 +3863,6 @@ function useAmplifyUp() {
3619
3863
  return context;
3620
3864
  }
3621
3865
 
3622
- export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, useAmplifyUp };
3866
+ export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, useAmplifyUp, useLiveComposerProps };
3623
3867
  //# sourceMappingURL=react.mjs.map
3624
3868
  //# sourceMappingURL=react.mjs.map