@amplifyup/sdk 0.1.53 → 0.1.55

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.
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { createContext, useState, useEffect, Fragment as Fragment$1, useContext, Component } from 'react';
2
+ import { createContext, memo, useState, useEffect, useContext, Fragment as Fragment$1, Component } from 'react';
3
3
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
4
  import 'marked';
5
5
 
@@ -556,6 +556,49 @@ function mergeEventContext(properties, attached) {
556
556
  function setPageResourceFields(fields) {
557
557
  }
558
558
 
559
+ // src/debug.ts
560
+ function envFlag(value) {
561
+ if (!value) return false;
562
+ const v = value.trim().toLowerCase();
563
+ return v === "1" || v === "true" || v === "yes";
564
+ }
565
+ function readAmplifyUpDebugEnv() {
566
+ try {
567
+ if (typeof process === "undefined") return false;
568
+ return envFlag(process.env.NEXT_PUBLIC_AMPLIFYUP_DEBUG) || envFlag(process.env.AMPLIFYUP_DEBUG);
569
+ } catch {
570
+ return false;
571
+ }
572
+ }
573
+ var configDebug;
574
+ function setAmplifyUpDebug(enabled) {
575
+ configDebug = enabled;
576
+ }
577
+ function isAmplifyUpDebug() {
578
+ if (configDebug === true) return true;
579
+ if (configDebug === false) return false;
580
+ return readAmplifyUpDebugEnv();
581
+ }
582
+ var onceKeys = /* @__PURE__ */ new Set();
583
+ var onceRoute = "";
584
+ function resetOnceIfRouteChanged() {
585
+ const route = typeof window !== "undefined" ? window.location.pathname : "";
586
+ if (route === onceRoute) return;
587
+ onceKeys.clear();
588
+ onceRoute = route;
589
+ }
590
+ function sdkDebug(...args) {
591
+ if (!isAmplifyUpDebug()) return;
592
+ console.log(...args);
593
+ }
594
+ function sdkDebugOnce(key, ...args) {
595
+ if (!isAmplifyUpDebug()) return;
596
+ resetOnceIfRouteChanged();
597
+ if (onceKeys.has(key)) return;
598
+ onceKeys.add(key);
599
+ console.log(...args);
600
+ }
601
+
559
602
  // src/index.ts
560
603
  var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
561
604
  var DWELL_POLL_MS = 5e3;
@@ -787,13 +830,13 @@ var AmplifyUpSDK = class {
787
830
  }
788
831
  this.config = {
789
832
  trackingId: previewOverrides.trackingId || config.trackingId,
790
- debug: config.debug ?? true,
791
- // Enable debug by default
833
+ debug: config.debug ?? readAmplifyUpDebugEnv(),
792
834
  target: this.target,
793
835
  dev: config.dev,
794
836
  ...config.siteId ? { siteId: config.siteId } : {},
795
837
  ...config.pageContext ? { pageContext: config.pageContext } : {}
796
838
  };
839
+ setAmplifyUpDebug(!!this.config.debug);
797
840
  if (config.pageContext) {
798
841
  this.pendingPageContext = config.pageContext;
799
842
  this.recomputeAttachedContext();
@@ -2945,11 +2988,9 @@ var refreshEventTracking = () => getSDK().refreshEventTracking();
2945
2988
  getSDK();
2946
2989
  createContext(null);
2947
2990
  function useLiveComposerProps(layoutNodeId, props) {
2948
- const [live, setLive] = useState(props);
2949
- useEffect(() => {
2950
- setLive(props);
2951
- }, [props]);
2991
+ const [patch, setPatch] = useState(null);
2952
2992
  useEffect(() => {
2993
+ setPatch(null);
2953
2994
  const matchesNode = (nodeId) => {
2954
2995
  if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
2955
2996
  return false;
@@ -2959,15 +3000,15 @@ function useLiveComposerProps(layoutNodeId, props) {
2959
3000
  const applyField = (fieldName, value, nodeId) => {
2960
3001
  if (!fieldName || typeof fieldName !== "string") return;
2961
3002
  if (!matchesNode(nodeId)) return;
2962
- setLive((prev) => ({ ...prev, [fieldName]: value }));
3003
+ setPatch((prev) => ({ ...prev || {}, [fieldName]: value }));
2963
3004
  };
2964
3005
  const applyProps = (nextProps, nodeId) => {
2965
3006
  if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
2966
3007
  return;
2967
3008
  }
2968
3009
  if (!matchesNode(nodeId)) return;
2969
- setLive((prev) => ({
2970
- ...prev,
3010
+ setPatch((prev) => ({
3011
+ ...prev || {},
2971
3012
  ...nextProps
2972
3013
  }));
2973
3014
  };
@@ -2996,7 +3037,7 @@ function useLiveComposerProps(layoutNodeId, props) {
2996
3037
  window.removeEventListener("message", onMessage);
2997
3038
  };
2998
3039
  }, [layoutNodeId]);
2999
- return live;
3040
+ return patch ? { ...props, ...patch } : props;
3000
3041
  }
3001
3042
  var usePathname = null;
3002
3043
  if (typeof window !== "undefined") {
@@ -3081,7 +3122,7 @@ function LiveNodeRender({
3081
3122
  layoutNodeId: nodeId
3082
3123
  }) });
3083
3124
  }
3084
- function AmplifyRenderer({
3125
+ function AmplifyRendererInner({
3085
3126
  renderComponent,
3086
3127
  pageConfig: serverPageConfig,
3087
3128
  loadingComponent,
@@ -3223,14 +3264,22 @@ function AmplifyRenderer({
3223
3264
  return `${indent}- ${n.id} (${n.componentId || "?"})${slotsDesc ? "\n" + slotsDesc : ""}`;
3224
3265
  }).join("\n");
3225
3266
  };
3226
- console.log("[AmplifyRenderer] layoutTree received:\n%s", describeLayoutTree(layoutTree2));
3267
+ sdkDebugOnce(
3268
+ `layoutTree:${pageConfig?.id || ""}:${pageConfig?.route || ""}`,
3269
+ "[AmplifyRenderer] layoutTree received:\n%s",
3270
+ describeLayoutTree(layoutTree2)
3271
+ );
3227
3272
  if (typeof window !== "undefined" && window.parent && window.parent !== window) {
3228
3273
  const message = {
3229
3274
  type: "COMPONENT_TREE",
3230
3275
  tree: componentTree
3231
3276
  };
3232
3277
  window.parent.postMessage(message, "*");
3233
- console.log("[AmplifyRenderer] Sent component tree from layoutTree:", componentTree.length, "root components");
3278
+ sdkDebug(
3279
+ "[AmplifyRenderer] Sent component tree from layoutTree:",
3280
+ componentTree.length,
3281
+ "root components"
3282
+ );
3234
3283
  }
3235
3284
  }, [pageConfig]);
3236
3285
  useEffect(() => {
@@ -3381,7 +3430,7 @@ function AmplifyRenderer({
3381
3430
  );
3382
3431
  }
3383
3432
  let slotChildren = {};
3384
- console.log(`[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
3433
+ sdkDebugOnce(`node:${node.id}`, `[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
3385
3434
  hasSlots: !!(node.slots && node.slots.length > 0),
3386
3435
  slotCount: node.slots?.length || 0,
3387
3436
  slots: node.slots?.map((s) => ({ slotId: s.slotId, zoneId: s.zoneId, childrenCount: s.children?.length || 0 }))
@@ -3390,30 +3439,13 @@ function AmplifyRenderer({
3390
3439
  for (const slot of node.slots) {
3391
3440
  const slotKey = `${node.id}-${slot.slotId}`;
3392
3441
  let childrenToRender = [];
3393
- console.log(`[AmplifyRenderer] Processing slot ${slot.slotId} for node ${node.id}`, {
3394
- slotKey,
3395
- hasZoneId: !!slot.zoneId,
3396
- hasVariants: !!slot.variants,
3397
- hasVariantCache: !!variantCache[slotKey],
3398
- directChildrenCount: slot.children?.length || 0
3399
- });
3400
3442
  if (slot.zoneId && slot.variants && variantCache[slotKey]) {
3401
3443
  childrenToRender = variantCache[slotKey].children;
3402
- console.log(`[AmplifyRenderer] Using cached variant for slot ${slot.slotId}`, {
3403
- variantId: variantCache[slotKey].variantId,
3404
- childrenCount: childrenToRender.length
3405
- });
3406
3444
  } else if (slot.zoneId && slot.variants) {
3407
3445
  const defaultVariant = slot.variants.find((v) => v.isDefault);
3408
3446
  childrenToRender = defaultVariant?.children || [];
3409
- console.log(`[AmplifyRenderer] Using default variant for slot ${slot.slotId}`, {
3410
- childrenCount: childrenToRender.length
3411
- });
3412
3447
  } else {
3413
3448
  childrenToRender = Array.isArray(slot.children) ? slot.children : [];
3414
- console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
3415
- childrenCount: childrenToRender.length
3416
- });
3417
3449
  }
3418
3450
  const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
3419
3451
  slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
@@ -3428,10 +3460,6 @@ function AmplifyRenderer({
3428
3460
  },
3429
3461
  slot.slotId
3430
3462
  );
3431
- console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
3432
- slotId: slot.slotId,
3433
- renderedChildrenCount: childrenToRender.length
3434
- });
3435
3463
  }
3436
3464
  }
3437
3465
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
@@ -3469,6 +3497,7 @@ function AmplifyRenderer({
3469
3497
  }
3470
3498
  ) : layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
3471
3499
  }
3500
+ var AmplifyRenderer = memo(AmplifyRendererInner);
3472
3501
 
3473
3502
  export { AmplifyRenderer };
3474
3503
  //# sourceMappingURL=AmplifyRenderer.mjs.map