@amplifyup/sdk 0.1.54 → 0.1.56
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/AmplifyRenderer.d.mts +5 -3
- package/dist/AmplifyRenderer.d.ts +5 -3
- package/dist/AmplifyRenderer.js +58 -27
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +59 -28
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{query-L7zSmLFX.d.ts → query-BqApXxQi.d.ts} +1 -1
- package/dist/{query-CWFb7rSm.d.mts → query-DaJlqU-Z.d.mts} +1 -1
- package/dist/react.d.mts +10 -10
- package/dist/react.d.ts +10 -10
- package/dist/react.js +168 -117
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +170 -119
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/{types-DpTzUg1C.d.mts → types-Db_eLrfU.d.mts} +5 -0
- package/dist/{types-DpTzUg1C.d.ts → types-Db_eLrfU.d.ts} +5 -0
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, { createContext, useState, useEffect, useContext, Fragment as Fragment$1,
|
|
2
|
+
import React, { createContext, memo, useState, useEffect, useContext, Fragment as Fragment$1, Component, useRef, useSyncExternalStore } from 'react';
|
|
3
3
|
import { marked } from 'marked';
|
|
4
|
-
import { jsx,
|
|
4
|
+
import { jsx, Fragment, jsxs } 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, {
|
|
@@ -608,6 +608,49 @@ function getPageResourceFields() {
|
|
|
608
608
|
return pageResourceFields;
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
+
// src/debug.ts
|
|
612
|
+
function envFlag(value) {
|
|
613
|
+
if (!value) return false;
|
|
614
|
+
const v = value.trim().toLowerCase();
|
|
615
|
+
return v === "1" || v === "true" || v === "yes";
|
|
616
|
+
}
|
|
617
|
+
function readAmplifyUpDebugEnv() {
|
|
618
|
+
try {
|
|
619
|
+
if (typeof process === "undefined") return false;
|
|
620
|
+
return envFlag(process.env.NEXT_PUBLIC_AMPLIFYUP_DEBUG) || envFlag(process.env.AMPLIFYUP_DEBUG);
|
|
621
|
+
} catch {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
var configDebug;
|
|
626
|
+
function setAmplifyUpDebug(enabled) {
|
|
627
|
+
configDebug = enabled;
|
|
628
|
+
}
|
|
629
|
+
function isAmplifyUpDebug() {
|
|
630
|
+
if (configDebug === true) return true;
|
|
631
|
+
if (configDebug === false) return false;
|
|
632
|
+
return readAmplifyUpDebugEnv();
|
|
633
|
+
}
|
|
634
|
+
var onceKeys = /* @__PURE__ */ new Set();
|
|
635
|
+
var onceRoute = "";
|
|
636
|
+
function resetOnceIfRouteChanged() {
|
|
637
|
+
const route = typeof window !== "undefined" ? window.location.pathname : "";
|
|
638
|
+
if (route === onceRoute) return;
|
|
639
|
+
onceKeys.clear();
|
|
640
|
+
onceRoute = route;
|
|
641
|
+
}
|
|
642
|
+
function sdkDebug(...args) {
|
|
643
|
+
if (!isAmplifyUpDebug()) return;
|
|
644
|
+
console.log(...args);
|
|
645
|
+
}
|
|
646
|
+
function sdkDebugOnce(key, ...args) {
|
|
647
|
+
if (!isAmplifyUpDebug()) return;
|
|
648
|
+
resetOnceIfRouteChanged();
|
|
649
|
+
if (onceKeys.has(key)) return;
|
|
650
|
+
onceKeys.add(key);
|
|
651
|
+
console.log(...args);
|
|
652
|
+
}
|
|
653
|
+
|
|
611
654
|
// src/edge/normalizeRoute.ts
|
|
612
655
|
function normalizeRoute(route) {
|
|
613
656
|
let path = String(route || "").trim();
|
|
@@ -1181,13 +1224,13 @@ var AmplifyUpSDK = class {
|
|
|
1181
1224
|
}
|
|
1182
1225
|
this.config = {
|
|
1183
1226
|
trackingId: previewOverrides.trackingId || config.trackingId,
|
|
1184
|
-
debug: config.debug ??
|
|
1185
|
-
// Enable debug by default
|
|
1227
|
+
debug: config.debug ?? readAmplifyUpDebugEnv(),
|
|
1186
1228
|
target: this.target,
|
|
1187
1229
|
dev: config.dev,
|
|
1188
1230
|
...config.siteId ? { siteId: config.siteId } : {},
|
|
1189
1231
|
...config.pageContext ? { pageContext: config.pageContext } : {}
|
|
1190
1232
|
};
|
|
1233
|
+
setAmplifyUpDebug(!!this.config.debug);
|
|
1191
1234
|
if (config.pageContext) {
|
|
1192
1235
|
this.pendingPageContext = config.pageContext;
|
|
1193
1236
|
this.recomputeAttachedContext();
|
|
@@ -3519,23 +3562,12 @@ function Slot({
|
|
|
3519
3562
|
className
|
|
3520
3563
|
}) {
|
|
3521
3564
|
const context = useContext(ComponentContext);
|
|
3522
|
-
console.log(`[Slot:${name}] Rendering slot`, {
|
|
3523
|
-
hasContext: !!context,
|
|
3524
|
-
availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
|
|
3525
|
-
slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
|
|
3526
|
-
contextSlots: context?.slots
|
|
3527
|
-
});
|
|
3528
3565
|
if (!context) {
|
|
3529
3566
|
console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
|
|
3530
3567
|
return null;
|
|
3531
3568
|
}
|
|
3532
3569
|
const slotContent = context.slots?.[name];
|
|
3533
3570
|
const isEmpty = !slotContent;
|
|
3534
|
-
console.log(`[Slot:${name}] Slot state`, {
|
|
3535
|
-
isEmpty,
|
|
3536
|
-
hasSlotContent: !!slotContent,
|
|
3537
|
-
slotContentType: slotContent ? typeof slotContent : "null"
|
|
3538
|
-
});
|
|
3539
3571
|
const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
|
|
3540
3572
|
(window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
|
|
3541
3573
|
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)
|
|
@@ -3547,17 +3579,15 @@ function Slot({
|
|
|
3547
3579
|
return false;
|
|
3548
3580
|
}
|
|
3549
3581
|
})());
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
}
|
|
3558
|
-
|
|
3559
|
-
referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
|
|
3560
|
-
});
|
|
3582
|
+
sdkDebugOnce(
|
|
3583
|
+
`slot:${context.layoutNodeId || ""}:${name}`,
|
|
3584
|
+
`[Slot:${name}]`,
|
|
3585
|
+
{
|
|
3586
|
+
isEmpty,
|
|
3587
|
+
isEditorMode,
|
|
3588
|
+
availableSlotKeys: context.slots ? Object.keys(context.slots) : []
|
|
3589
|
+
}
|
|
3590
|
+
);
|
|
3561
3591
|
return /* @__PURE__ */ jsx(
|
|
3562
3592
|
"div",
|
|
3563
3593
|
{
|
|
@@ -3649,13 +3679,31 @@ function htmlHasVisualChrome(html) {
|
|
|
3649
3679
|
);
|
|
3650
3680
|
}
|
|
3651
3681
|
function canInlineEdit(name, value) {
|
|
3652
|
-
if (isLikelyNonTextFieldName(name)) return false;
|
|
3682
|
+
if (!name || isLikelyNonTextFieldName(name)) return false;
|
|
3653
3683
|
if (value !== void 0 && value !== null && typeof value === "object") {
|
|
3654
3684
|
return false;
|
|
3655
3685
|
}
|
|
3656
3686
|
if (typeof value === "boolean") return false;
|
|
3657
3687
|
return true;
|
|
3658
3688
|
}
|
|
3689
|
+
function canInlineEditRichText(name, value) {
|
|
3690
|
+
if (!name || isLikelyNonTextFieldName(name)) return false;
|
|
3691
|
+
if (typeof value === "boolean") return false;
|
|
3692
|
+
if (value !== void 0 && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
3693
|
+
return false;
|
|
3694
|
+
}
|
|
3695
|
+
return true;
|
|
3696
|
+
}
|
|
3697
|
+
function inferEditName(explicitName, contextProps, sourceValue) {
|
|
3698
|
+
if (explicitName) return explicitName;
|
|
3699
|
+
if (!contextProps) return "";
|
|
3700
|
+
const keys = Object.keys(contextProps).filter(
|
|
3701
|
+
(key) => Object.is(contextProps[key], sourceValue)
|
|
3702
|
+
);
|
|
3703
|
+
if (keys.length === 1) return keys[0];
|
|
3704
|
+
if (keys.length === 0 || isComposerEmptyText(sourceValue)) return "";
|
|
3705
|
+
return keys[0];
|
|
3706
|
+
}
|
|
3659
3707
|
function subscribeComposerEdit(onStoreChange) {
|
|
3660
3708
|
if (typeof window === "undefined") return () => {
|
|
3661
3709
|
};
|
|
@@ -3850,9 +3898,11 @@ function ComposerInlineHtml({
|
|
|
3850
3898
|
const finishEdit = () => {
|
|
3851
3899
|
const el = elRef.current;
|
|
3852
3900
|
if (!el) return;
|
|
3853
|
-
const
|
|
3854
|
-
|
|
3855
|
-
|
|
3901
|
+
const nextHtml = el.innerHTML;
|
|
3902
|
+
const nextText = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "").trim();
|
|
3903
|
+
if (nextText === sourceTextRef.current && nextHtml === html) return;
|
|
3904
|
+
const commitValue = htmlHasVisualChrome(html) || /<[a-z][\s\S]*>/i.test(html) ? nextHtml : nextText;
|
|
3905
|
+
commitComposerField(layoutNodeId, componentId, name, commitValue);
|
|
3856
3906
|
};
|
|
3857
3907
|
return React.createElement(Tag, {
|
|
3858
3908
|
ref: elRef,
|
|
@@ -3894,15 +3944,10 @@ function formatFieldValue(value) {
|
|
|
3894
3944
|
}
|
|
3895
3945
|
function warnProjectionProps(component, name, hasExplicitValue) {
|
|
3896
3946
|
if (process.env.NODE_ENV === "production") return;
|
|
3897
|
-
if (hasExplicitValue
|
|
3898
|
-
console.warn(
|
|
3899
|
-
`[AmplifyUp SDK] ${component}: pass either value={\u2026} or deprecated name="\u2026", not both. Prefer value={\u2026} and omit name.`
|
|
3900
|
-
);
|
|
3901
|
-
return;
|
|
3902
|
-
}
|
|
3947
|
+
if (hasExplicitValue) return;
|
|
3903
3948
|
if (name) {
|
|
3904
3949
|
console.warn(
|
|
3905
|
-
`[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props
|
|
3950
|
+
`[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props.`
|
|
3906
3951
|
);
|
|
3907
3952
|
}
|
|
3908
3953
|
}
|
|
@@ -3942,7 +3987,7 @@ function Field(props) {
|
|
|
3942
3987
|
const composerEdit = useComposerEditMode();
|
|
3943
3988
|
const hasExplicitValue = hasOwnProp(props, "value");
|
|
3944
3989
|
const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
|
|
3945
|
-
const editName =
|
|
3990
|
+
const editName = inferEditName(name, context?.props, sourceValue);
|
|
3946
3991
|
const fieldValue = useFieldOverlay(
|
|
3947
3992
|
context?.layoutNodeId,
|
|
3948
3993
|
editName,
|
|
@@ -3956,6 +4001,20 @@ function Field(props) {
|
|
|
3956
4001
|
return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
|
|
3957
4002
|
}
|
|
3958
4003
|
if (render) {
|
|
4004
|
+
if (composerEdit && editName && context && canInlineEdit(editName, fieldValue)) {
|
|
4005
|
+
return /* @__PURE__ */ jsx(
|
|
4006
|
+
ComposerInlineField,
|
|
4007
|
+
{
|
|
4008
|
+
name: editName,
|
|
4009
|
+
value: fieldValue,
|
|
4010
|
+
fallback,
|
|
4011
|
+
className,
|
|
4012
|
+
render,
|
|
4013
|
+
layoutNodeId: context.layoutNodeId,
|
|
4014
|
+
componentId: context.componentId
|
|
4015
|
+
}
|
|
4016
|
+
);
|
|
4017
|
+
}
|
|
3959
4018
|
return /* @__PURE__ */ jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
|
|
3960
4019
|
}
|
|
3961
4020
|
if (Array.isArray(fieldValue)) {
|
|
@@ -4009,7 +4068,7 @@ function RichText(props) {
|
|
|
4009
4068
|
const hasValueProp = hasOwnProp(props, "value");
|
|
4010
4069
|
const hasExplicitValue = hasValueProp || childrenValue !== void 0;
|
|
4011
4070
|
const sourceValue = hasValueProp ? value : childrenValue !== void 0 ? childrenValue : name ? context?.props?.[name] : void 0;
|
|
4012
|
-
const editName =
|
|
4071
|
+
const editName = inferEditName(name, context?.props, sourceValue);
|
|
4013
4072
|
const fieldValue = useFieldOverlay(
|
|
4014
4073
|
context?.layoutNodeId,
|
|
4015
4074
|
editName,
|
|
@@ -4022,7 +4081,7 @@ function RichText(props) {
|
|
|
4022
4081
|
return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
|
|
4023
4082
|
}
|
|
4024
4083
|
warnProjectionProps("RichText", name, hasExplicitValue);
|
|
4025
|
-
const canEdit = !!
|
|
4084
|
+
const canEdit = !!context && canInlineEditRichText(editName, fieldValue);
|
|
4026
4085
|
if (isComposerEmptyText(fieldValue)) {
|
|
4027
4086
|
if (composerEdit && canEdit && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
|
|
4028
4087
|
return /* @__PURE__ */ jsx(
|
|
@@ -4054,17 +4113,6 @@ function RichText(props) {
|
|
|
4054
4113
|
if (!html) {
|
|
4055
4114
|
return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
|
|
4056
4115
|
}
|
|
4057
|
-
if (composerEdit && htmlHasVisualChrome(html)) {
|
|
4058
|
-
return /* @__PURE__ */ jsx(
|
|
4059
|
-
Tag,
|
|
4060
|
-
{
|
|
4061
|
-
className,
|
|
4062
|
-
"data-amplifyup-field": editName || void 0,
|
|
4063
|
-
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
4064
|
-
dangerouslySetInnerHTML: { __html: html }
|
|
4065
|
-
}
|
|
4066
|
-
);
|
|
4067
|
-
}
|
|
4068
4116
|
if (composerEdit && canEdit) {
|
|
4069
4117
|
return /* @__PURE__ */ jsx(
|
|
4070
4118
|
ComposerInlineHtml,
|
|
@@ -4105,7 +4153,7 @@ function Image(props) {
|
|
|
4105
4153
|
const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
|
|
4106
4154
|
const fieldValue = useFieldOverlay(
|
|
4107
4155
|
context?.layoutNodeId,
|
|
4108
|
-
|
|
4156
|
+
inferEditName(name, context?.props, sourceValue),
|
|
4109
4157
|
sourceValue
|
|
4110
4158
|
);
|
|
4111
4159
|
warnProjectionProps("Image", name, hasExplicitValue);
|
|
@@ -4198,7 +4246,7 @@ function LiveNodeRender({
|
|
|
4198
4246
|
layoutNodeId: nodeId
|
|
4199
4247
|
}) });
|
|
4200
4248
|
}
|
|
4201
|
-
function
|
|
4249
|
+
function AmplifyRendererInner({
|
|
4202
4250
|
renderComponent,
|
|
4203
4251
|
pageConfig: serverPageConfig,
|
|
4204
4252
|
loadingComponent,
|
|
@@ -4340,14 +4388,22 @@ function AmplifyRenderer({
|
|
|
4340
4388
|
return `${indent}- ${n.id} (${n.componentId || "?"})${slotsDesc ? "\n" + slotsDesc : ""}`;
|
|
4341
4389
|
}).join("\n");
|
|
4342
4390
|
};
|
|
4343
|
-
|
|
4391
|
+
sdkDebugOnce(
|
|
4392
|
+
`layoutTree:${pageConfig?.id || ""}:${pageConfig?.route || ""}`,
|
|
4393
|
+
"[AmplifyRenderer] layoutTree received:\n%s",
|
|
4394
|
+
describeLayoutTree(layoutTree2)
|
|
4395
|
+
);
|
|
4344
4396
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
4345
4397
|
const message = {
|
|
4346
4398
|
type: "COMPONENT_TREE",
|
|
4347
4399
|
tree: componentTree
|
|
4348
4400
|
};
|
|
4349
4401
|
window.parent.postMessage(message, "*");
|
|
4350
|
-
|
|
4402
|
+
sdkDebug(
|
|
4403
|
+
"[AmplifyRenderer] Sent component tree from layoutTree:",
|
|
4404
|
+
componentTree.length,
|
|
4405
|
+
"root components"
|
|
4406
|
+
);
|
|
4351
4407
|
}
|
|
4352
4408
|
}, [pageConfig]);
|
|
4353
4409
|
useEffect(() => {
|
|
@@ -4498,7 +4554,7 @@ function AmplifyRenderer({
|
|
|
4498
4554
|
);
|
|
4499
4555
|
}
|
|
4500
4556
|
let slotChildren = {};
|
|
4501
|
-
|
|
4557
|
+
sdkDebugOnce(`node:${node.id}`, `[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
|
|
4502
4558
|
hasSlots: !!(node.slots && node.slots.length > 0),
|
|
4503
4559
|
slotCount: node.slots?.length || 0,
|
|
4504
4560
|
slots: node.slots?.map((s) => ({ slotId: s.slotId, zoneId: s.zoneId, childrenCount: s.children?.length || 0 }))
|
|
@@ -4507,30 +4563,13 @@ function AmplifyRenderer({
|
|
|
4507
4563
|
for (const slot of node.slots) {
|
|
4508
4564
|
const slotKey = `${node.id}-${slot.slotId}`;
|
|
4509
4565
|
let childrenToRender = [];
|
|
4510
|
-
console.log(`[AmplifyRenderer] Processing slot ${slot.slotId} for node ${node.id}`, {
|
|
4511
|
-
slotKey,
|
|
4512
|
-
hasZoneId: !!slot.zoneId,
|
|
4513
|
-
hasVariants: !!slot.variants,
|
|
4514
|
-
hasVariantCache: !!variantCache[slotKey],
|
|
4515
|
-
directChildrenCount: slot.children?.length || 0
|
|
4516
|
-
});
|
|
4517
4566
|
if (slot.zoneId && slot.variants && variantCache[slotKey]) {
|
|
4518
4567
|
childrenToRender = variantCache[slotKey].children;
|
|
4519
|
-
console.log(`[AmplifyRenderer] Using cached variant for slot ${slot.slotId}`, {
|
|
4520
|
-
variantId: variantCache[slotKey].variantId,
|
|
4521
|
-
childrenCount: childrenToRender.length
|
|
4522
|
-
});
|
|
4523
4568
|
} else if (slot.zoneId && slot.variants) {
|
|
4524
4569
|
const defaultVariant = slot.variants.find((v) => v.isDefault);
|
|
4525
4570
|
childrenToRender = defaultVariant?.children || [];
|
|
4526
|
-
console.log(`[AmplifyRenderer] Using default variant for slot ${slot.slotId}`, {
|
|
4527
|
-
childrenCount: childrenToRender.length
|
|
4528
|
-
});
|
|
4529
4571
|
} else {
|
|
4530
4572
|
childrenToRender = Array.isArray(slot.children) ? slot.children : [];
|
|
4531
|
-
console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
|
|
4532
|
-
childrenCount: childrenToRender.length
|
|
4533
|
-
});
|
|
4534
4573
|
}
|
|
4535
4574
|
const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
|
|
4536
4575
|
slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
|
|
@@ -4545,10 +4584,6 @@ function AmplifyRenderer({
|
|
|
4545
4584
|
},
|
|
4546
4585
|
slot.slotId
|
|
4547
4586
|
);
|
|
4548
|
-
console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
|
|
4549
|
-
slotId: slot.slotId,
|
|
4550
|
-
renderedChildrenCount: childrenToRender.length
|
|
4551
|
-
});
|
|
4552
4587
|
}
|
|
4553
4588
|
}
|
|
4554
4589
|
const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
|
|
@@ -4586,6 +4621,7 @@ function AmplifyRenderer({
|
|
|
4586
4621
|
}
|
|
4587
4622
|
) : layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
|
|
4588
4623
|
}
|
|
4624
|
+
var AmplifyRenderer = memo(AmplifyRendererInner);
|
|
4589
4625
|
function defaultPreviewCanvas() {
|
|
4590
4626
|
return /* @__PURE__ */ jsx(
|
|
4591
4627
|
"div",
|
|
@@ -4689,6 +4725,12 @@ if (typeof window !== "undefined") {
|
|
|
4689
4725
|
}
|
|
4690
4726
|
}
|
|
4691
4727
|
var AmplifyUpContext = createContext(null);
|
|
4728
|
+
function normalizeRoutePath2(route) {
|
|
4729
|
+
if (!route) return "";
|
|
4730
|
+
const path = route.split("?")[0] || "/";
|
|
4731
|
+
if (path.length > 1 && path.endsWith("/")) return path.replace(/\/+$/, "");
|
|
4732
|
+
return path || "/";
|
|
4733
|
+
}
|
|
4692
4734
|
function AmplifyUpProvider({
|
|
4693
4735
|
children,
|
|
4694
4736
|
config,
|
|
@@ -4716,6 +4758,7 @@ function AmplifyUpProvider({
|
|
|
4716
4758
|
}
|
|
4717
4759
|
return currentPath;
|
|
4718
4760
|
};
|
|
4761
|
+
const loadedRouteRef = useRef(null);
|
|
4719
4762
|
const nextPathname = usePathname ? usePathname() : null;
|
|
4720
4763
|
const [pathname, setPathname] = useState(() => {
|
|
4721
4764
|
if (typeof window !== "undefined") {
|
|
@@ -4749,56 +4792,46 @@ function AmplifyUpProvider({
|
|
|
4749
4792
|
};
|
|
4750
4793
|
}
|
|
4751
4794
|
}, [nextPathname]);
|
|
4752
|
-
|
|
4753
|
-
let cancelled = false;
|
|
4754
|
-
const sdk = getSDK();
|
|
4755
|
-
sdk.init({
|
|
4756
|
-
...config,
|
|
4757
|
-
...pageContext ? { pageContext } : {}
|
|
4758
|
-
}).then(() => {
|
|
4759
|
-
if (!cancelled) {
|
|
4760
|
-
setInitialized(true);
|
|
4761
|
-
}
|
|
4762
|
-
}).catch((err) => {
|
|
4763
|
-
if (cancelled) return;
|
|
4764
|
-
console.error("Failed to initialize AmplifyUp SDK:", err);
|
|
4765
|
-
setError("Failed to initialize tracking");
|
|
4766
|
-
setLoading(false);
|
|
4767
|
-
});
|
|
4768
|
-
return () => {
|
|
4769
|
-
cancelled = true;
|
|
4770
|
-
};
|
|
4771
|
-
}, [config.trackingId, config.target, config.debug, config.dev, config.siteId, pageContext]);
|
|
4795
|
+
const pageContextKey = pageContext ? `${pageContext.resourceType}:${pageContext.key}` : "";
|
|
4772
4796
|
useEffect(() => {
|
|
4773
4797
|
if (!initialized || !pageContext) return;
|
|
4774
4798
|
getSDK().setPageContext(pageContext);
|
|
4775
|
-
}, [initialized,
|
|
4799
|
+
}, [initialized, pageContextKey]);
|
|
4776
4800
|
useEffect(() => {
|
|
4777
|
-
if (!initialized) return;
|
|
4778
4801
|
let cancelled = false;
|
|
4779
|
-
const
|
|
4802
|
+
const sdk = getSDK();
|
|
4803
|
+
const run = async () => {
|
|
4780
4804
|
try {
|
|
4805
|
+
await sdk.init({
|
|
4806
|
+
...config,
|
|
4807
|
+
...pageContext ? { pageContext } : {}
|
|
4808
|
+
});
|
|
4809
|
+
if (cancelled) return;
|
|
4810
|
+
if (pageContext) sdk.setPageContext(pageContext);
|
|
4781
4811
|
const actualRoute = getActualRoute();
|
|
4782
4812
|
if (!actualRoute) {
|
|
4813
|
+
setInitialized(true);
|
|
4783
4814
|
setLoading(false);
|
|
4784
4815
|
return;
|
|
4785
4816
|
}
|
|
4786
|
-
const sdk = getSDK();
|
|
4787
4817
|
sdk.routeChange(actualRoute);
|
|
4788
4818
|
const preview = isComposerPreview();
|
|
4789
4819
|
const overlay = preview || config.clientPersonalization !== false;
|
|
4790
4820
|
if (!overlay) {
|
|
4821
|
+
setInitialized(true);
|
|
4791
4822
|
setPageConfig(null);
|
|
4792
4823
|
setLoading(false);
|
|
4793
4824
|
return;
|
|
4794
4825
|
}
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4826
|
+
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
4827
|
+
setPageConfig(null);
|
|
4828
|
+
setError(null);
|
|
4829
|
+
}
|
|
4798
4830
|
const edgeUrl = sdk.getEdgeUrl();
|
|
4799
4831
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
4800
4832
|
const trackingId = sdk.getTrackingId();
|
|
4801
4833
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
4834
|
+
setInitialized(true);
|
|
4802
4835
|
setError("SDK not initialized");
|
|
4803
4836
|
setLoading(false);
|
|
4804
4837
|
return;
|
|
@@ -4834,28 +4867,37 @@ function AmplifyUpProvider({
|
|
|
4834
4867
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
4835
4868
|
});
|
|
4836
4869
|
if (cancelled) return;
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4870
|
+
const nextConfig = result.pageConfig || {
|
|
4871
|
+
id: "default",
|
|
4872
|
+
route: actualRoute,
|
|
4873
|
+
title: "Page Not Configured",
|
|
4874
|
+
description: "This page has not been published yet.",
|
|
4875
|
+
layoutTree: []
|
|
4876
|
+
};
|
|
4877
|
+
setInitialized(true);
|
|
4878
|
+
setSource((prev) => prev === result.source ? prev : result.source);
|
|
4879
|
+
setMeta(
|
|
4880
|
+
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
4881
|
+
);
|
|
4882
|
+
setError((prev) => prev === result.error ? prev : result.error);
|
|
4883
|
+
setPageConfig((prev) => {
|
|
4884
|
+
if (prev && prev.id === nextConfig.id && normalizeRoutePath2(prev.route) === normalizeRoutePath2(nextConfig.route) && JSON.stringify(prev.layoutTree) === JSON.stringify(nextConfig.layoutTree)) {
|
|
4885
|
+
return prev;
|
|
4886
|
+
}
|
|
4887
|
+
return nextConfig;
|
|
4888
|
+
});
|
|
4889
|
+
if (result.pageConfig) {
|
|
4850
4890
|
sdk.applyResolvedPageData(
|
|
4851
4891
|
result.pageConfig.pageData || null,
|
|
4852
4892
|
result.pageConfig.route,
|
|
4853
4893
|
extractRouteParams(result.pageConfig.route, actualRoute)
|
|
4854
4894
|
);
|
|
4855
4895
|
}
|
|
4896
|
+
loadedRouteRef.current = actualRoute;
|
|
4856
4897
|
} catch (err) {
|
|
4857
4898
|
if (cancelled) return;
|
|
4858
4899
|
console.error("Error fetching page config:", err);
|
|
4900
|
+
setInitialized(true);
|
|
4859
4901
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
4860
4902
|
setSource(null);
|
|
4861
4903
|
setMeta(null);
|
|
@@ -4863,11 +4905,20 @@ function AmplifyUpProvider({
|
|
|
4863
4905
|
if (!cancelled) setLoading(false);
|
|
4864
4906
|
}
|
|
4865
4907
|
};
|
|
4866
|
-
void
|
|
4908
|
+
void run();
|
|
4867
4909
|
return () => {
|
|
4868
4910
|
cancelled = true;
|
|
4869
4911
|
};
|
|
4870
|
-
}, [
|
|
4912
|
+
}, [
|
|
4913
|
+
pathname,
|
|
4914
|
+
config.trackingId,
|
|
4915
|
+
config.target,
|
|
4916
|
+
config.debug,
|
|
4917
|
+
config.dev,
|
|
4918
|
+
config.siteId,
|
|
4919
|
+
config.clientPersonalization,
|
|
4920
|
+
pageContextKey
|
|
4921
|
+
]);
|
|
4871
4922
|
return /* @__PURE__ */ jsx(
|
|
4872
4923
|
AmplifyUpContext.Provider,
|
|
4873
4924
|
{
|