@amplifyup/sdk 0.1.76 → 0.1.78
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/README.md +2 -0
- package/dist/AmplifyRenderer.js +27 -19
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +28 -20
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +3 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.js +108 -62
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +109 -63
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -200,8 +200,10 @@ declare function slotStateFromEl(el: {
|
|
|
200
200
|
getAttribute: (name: string) => string | null;
|
|
201
201
|
} | null | undefined): SlotState | null;
|
|
202
202
|
|
|
203
|
-
declare function ComposerProvider({ children, }: {
|
|
203
|
+
declare function ComposerProvider({ children, enabled, }: {
|
|
204
204
|
children: ReactNode;
|
|
205
|
+
/** When false, pass through any parent store without creating or wiring one. */
|
|
206
|
+
enabled?: boolean;
|
|
205
207
|
}): react_jsx_runtime.JSX.Element;
|
|
206
208
|
declare function MaybeComposerProvider({ enabled, layoutNodeId, children, }: {
|
|
207
209
|
enabled: boolean;
|
package/dist/react.d.ts
CHANGED
|
@@ -200,8 +200,10 @@ declare function slotStateFromEl(el: {
|
|
|
200
200
|
getAttribute: (name: string) => string | null;
|
|
201
201
|
} | null | undefined): SlotState | null;
|
|
202
202
|
|
|
203
|
-
declare function ComposerProvider({ children, }: {
|
|
203
|
+
declare function ComposerProvider({ children, enabled, }: {
|
|
204
204
|
children: ReactNode;
|
|
205
|
+
/** When false, pass through any parent store without creating or wiring one. */
|
|
206
|
+
enabled?: boolean;
|
|
205
207
|
}): react_jsx_runtime.JSX.Element;
|
|
206
208
|
declare function MaybeComposerProvider({ enabled, layoutNodeId, children, }: {
|
|
207
209
|
enabled: boolean;
|
package/dist/react.js
CHANGED
|
@@ -172,6 +172,7 @@ var AWSAdapter = class {
|
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
175
|
+
const debug = this.config?.debug;
|
|
175
176
|
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
176
177
|
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
177
178
|
try {
|
|
@@ -186,15 +187,15 @@ var AWSAdapter = class {
|
|
|
186
187
|
keepalive: true
|
|
187
188
|
});
|
|
188
189
|
if (!response.ok) {
|
|
189
|
-
if (
|
|
190
|
+
if (debug) {
|
|
190
191
|
console.warn(`AmplifyUp SDK: Event tracking failed: ${response.status} ${response.statusText}`);
|
|
191
192
|
}
|
|
192
|
-
} else if (
|
|
193
|
+
} else if (debug) {
|
|
193
194
|
const result = await response.json().catch(() => ({}));
|
|
194
195
|
console.log("AmplifyUp SDK: Event tracked", result);
|
|
195
196
|
}
|
|
196
197
|
} catch (error) {
|
|
197
|
-
if (
|
|
198
|
+
if (debug) {
|
|
198
199
|
console.error("AmplifyUp SDK: Event tracking error:", error);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
@@ -1095,9 +1096,8 @@ function dedupeLayoutProviderFetch(key, fetchFn) {
|
|
|
1095
1096
|
return pending;
|
|
1096
1097
|
}
|
|
1097
1098
|
function previewLayoutReady(opts) {
|
|
1098
|
-
if (opts.hasClientLayout) return true;
|
|
1099
|
-
|
|
1100
|
-
return true;
|
|
1099
|
+
if (opts.hasClientLayout || opts.hasServerLayout) return true;
|
|
1100
|
+
return !opts.clientLoading;
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
1103
|
// src/edge/variantKeys.ts
|
|
@@ -3958,6 +3958,14 @@ function getSDK(adapter) {
|
|
|
3958
3958
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3959
3959
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3960
3960
|
getSDK();
|
|
3961
|
+
var PageContentRegistryContext = React3.createContext(null);
|
|
3962
|
+
function useRegisterPageContent(enabled = true) {
|
|
3963
|
+
const register = React3.useContext(PageContentRegistryContext);
|
|
3964
|
+
React3.useEffect(() => {
|
|
3965
|
+
if (!enabled || !register) return;
|
|
3966
|
+
return register();
|
|
3967
|
+
}, [enabled, register]);
|
|
3968
|
+
}
|
|
3961
3969
|
function useInComposer(force = false) {
|
|
3962
3970
|
const [detected, setDetected] = React3.useState(false);
|
|
3963
3971
|
React3.useEffect(() => {
|
|
@@ -4016,14 +4024,16 @@ function applyComposerPatch(store, name, value, ref, layoutNodeId) {
|
|
|
4016
4024
|
store.set(composerStoreKey(name, ref, layoutNodeId), value);
|
|
4017
4025
|
}
|
|
4018
4026
|
function ComposerProvider({
|
|
4019
|
-
children
|
|
4027
|
+
children,
|
|
4028
|
+
enabled = true
|
|
4020
4029
|
}) {
|
|
4021
4030
|
const existing = React3.useContext(ComposerStoreContext);
|
|
4022
4031
|
const storeRef = React3.useRef(null);
|
|
4023
4032
|
if (!storeRef.current) storeRef.current = new ComposerFieldStore();
|
|
4024
|
-
const
|
|
4033
|
+
const ownsStore = !existing && enabled;
|
|
4034
|
+
const store = existing || (enabled ? storeRef.current : null);
|
|
4025
4035
|
React3.useEffect(() => {
|
|
4026
|
-
if (
|
|
4036
|
+
if (!ownsStore || !store) return;
|
|
4027
4037
|
const applyField = (fieldName, value, nodeId, ref) => {
|
|
4028
4038
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
4029
4039
|
const fieldRef = isFieldRef(ref) ? ref : void 0;
|
|
@@ -4081,8 +4091,7 @@ function ComposerProvider({
|
|
|
4081
4091
|
window.removeEventListener("amplifyup:props-patch", onPropsPatch);
|
|
4082
4092
|
window.removeEventListener("message", onMessage);
|
|
4083
4093
|
};
|
|
4084
|
-
}, [
|
|
4085
|
-
if (existing) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
4094
|
+
}, [ownsStore, store]);
|
|
4086
4095
|
return /* @__PURE__ */ jsxRuntime.jsx(ComposerStoreContext.Provider, { value: store, children });
|
|
4087
4096
|
}
|
|
4088
4097
|
function useComposerFieldValue(name, fallback, ref) {
|
|
@@ -4109,9 +4118,7 @@ function MaybeComposerProvider({
|
|
|
4109
4118
|
layoutNodeId,
|
|
4110
4119
|
children
|
|
4111
4120
|
}) {
|
|
4112
|
-
|
|
4113
|
-
if (!enabled) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: content });
|
|
4114
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: layoutNodeId, children }) });
|
|
4121
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { enabled, children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: enabled ? layoutNodeId : void 0, children }) });
|
|
4115
4122
|
}
|
|
4116
4123
|
function nodeRenderProps(node) {
|
|
4117
4124
|
const settings = node.settings || {};
|
|
@@ -4197,6 +4204,7 @@ function AmplifyRendererInner({
|
|
|
4197
4204
|
composerPreview
|
|
4198
4205
|
}) {
|
|
4199
4206
|
const clientHook = useAmplifyUp();
|
|
4207
|
+
useRegisterPageContent(!serverPageConfig);
|
|
4200
4208
|
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
4201
4209
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
4202
4210
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
@@ -4544,17 +4552,16 @@ function AmplifyRendererInner({
|
|
|
4544
4552
|
if (layoutTree.length === 0) {
|
|
4545
4553
|
return /* @__PURE__ */ jsxRuntime.jsx("main", { children: emptyComponent || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
|
|
4546
4554
|
}
|
|
4547
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4548
|
-
"
|
|
4555
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4556
|
+
"main",
|
|
4549
4557
|
{
|
|
4550
|
-
"data-slot-id": "main",
|
|
4551
|
-
"data-amplifyup-slot": "main",
|
|
4552
|
-
"data-slot-source": "page",
|
|
4553
|
-
"data-slot-state":
|
|
4554
|
-
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4558
|
+
"data-slot-id": composerPreviewFlag ? "main" : void 0,
|
|
4559
|
+
"data-amplifyup-slot": composerPreviewFlag ? "main" : void 0,
|
|
4560
|
+
"data-slot-source": composerPreviewFlag ? "page" : void 0,
|
|
4561
|
+
"data-slot-state": composerPreviewFlag ? "filled" : void 0,
|
|
4555
4562
|
children: layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React3.Fragment, { children: renderNode(node) }, node.id))
|
|
4556
4563
|
}
|
|
4557
|
-
)
|
|
4564
|
+
) });
|
|
4558
4565
|
}
|
|
4559
4566
|
var AmplifyRenderer = React3.memo(AmplifyRendererInner);
|
|
4560
4567
|
function AddComponentIcon({ size = 28 }) {
|
|
@@ -4712,6 +4719,7 @@ function AmplifyPageContent({
|
|
|
4712
4719
|
errorComponent
|
|
4713
4720
|
}) {
|
|
4714
4721
|
const client = useAmplifyUp();
|
|
4722
|
+
useRegisterPageContent();
|
|
4715
4723
|
const preview = useComposerPreviewFlag(forceComposerPreview);
|
|
4716
4724
|
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
4717
4725
|
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
@@ -4730,11 +4738,14 @@ function AmplifyPageContent({
|
|
|
4730
4738
|
if (preview) {
|
|
4731
4739
|
const ready = previewLayoutReady({
|
|
4732
4740
|
clientLoading: client.loading,
|
|
4733
|
-
hasClientLayout: !!clientLayout
|
|
4741
|
+
hasClientLayout: !!clientLayout,
|
|
4742
|
+
hasServerLayout: !!serverLayout
|
|
4743
|
+
});
|
|
4734
4744
|
if (!ready) {
|
|
4735
4745
|
return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: false, children: previewLoading });
|
|
4736
4746
|
}
|
|
4737
|
-
|
|
4747
|
+
const layoutSettled = !client.loading || !!clientLayout;
|
|
4748
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: layoutSettled, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4738
4749
|
AmplifyRenderer,
|
|
4739
4750
|
{
|
|
4740
4751
|
pageConfig: pageConfig ?? void 0,
|
|
@@ -4756,7 +4767,7 @@ function AmplifyPageContent({
|
|
|
4756
4767
|
if (!hasAmplifyLayout(pageConfig)) {
|
|
4757
4768
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
4758
4769
|
}
|
|
4759
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4770
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4760
4771
|
AmplifyRenderer,
|
|
4761
4772
|
{
|
|
4762
4773
|
pageConfig: pageConfig ?? void 0,
|
|
@@ -4765,7 +4776,7 @@ function AmplifyPageContent({
|
|
|
4765
4776
|
emptyComponent,
|
|
4766
4777
|
errorComponent
|
|
4767
4778
|
}
|
|
4768
|
-
);
|
|
4779
|
+
) });
|
|
4769
4780
|
}
|
|
4770
4781
|
|
|
4771
4782
|
// src/slot-state.ts
|
|
@@ -5605,11 +5616,24 @@ function AmplifyUpProvider({
|
|
|
5605
5616
|
if (!initialized || !pageContext) return;
|
|
5606
5617
|
getSDK().setPageContext(pageContext);
|
|
5607
5618
|
}, [initialized, pageContextKey]);
|
|
5619
|
+
const contentMountsRef = React3.useRef(0);
|
|
5620
|
+
const [hasPageContent, setHasPageContent] = React3.useState(false);
|
|
5621
|
+
const registerPageContent = React3.useCallback(() => {
|
|
5622
|
+
contentMountsRef.current += 1;
|
|
5623
|
+
setHasPageContent(true);
|
|
5624
|
+
return () => {
|
|
5625
|
+
contentMountsRef.current -= 1;
|
|
5626
|
+
if (contentMountsRef.current === 0) setHasPageContent(false);
|
|
5627
|
+
};
|
|
5628
|
+
}, []);
|
|
5629
|
+
const [initVersion, setInitVersion] = React3.useState(0);
|
|
5630
|
+
const overlayEnabled = () => isComposerPreview() || config.clientPersonalization !== false;
|
|
5608
5631
|
React3.useEffect(() => {
|
|
5609
5632
|
let cancelled = false;
|
|
5610
5633
|
const sdk = getSDK();
|
|
5611
|
-
|
|
5612
|
-
|
|
5634
|
+
if (contentMountsRef.current > 0 && overlayEnabled()) {
|
|
5635
|
+
sdk.beginPageResolve(getActualRoute());
|
|
5636
|
+
}
|
|
5613
5637
|
const run = async () => {
|
|
5614
5638
|
try {
|
|
5615
5639
|
await sdk.init({
|
|
@@ -5619,20 +5643,59 @@ function AmplifyUpProvider({
|
|
|
5619
5643
|
if (cancelled) return;
|
|
5620
5644
|
if (pageContext) sdk.setPageContext(pageContext);
|
|
5621
5645
|
const actualRoute = getActualRoute();
|
|
5622
|
-
if (
|
|
5646
|
+
if (actualRoute) sdk.routeChange(actualRoute);
|
|
5647
|
+
} catch (err) {
|
|
5648
|
+
if (cancelled) return;
|
|
5649
|
+
console.error("Error initializing AmplifyUp SDK:", err);
|
|
5650
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5651
|
+
} finally {
|
|
5652
|
+
if (!cancelled) {
|
|
5623
5653
|
setInitialized(true);
|
|
5624
|
-
|
|
5625
|
-
return;
|
|
5654
|
+
setInitVersion((v) => v + 1);
|
|
5626
5655
|
}
|
|
5627
|
-
|
|
5656
|
+
}
|
|
5657
|
+
};
|
|
5658
|
+
void run();
|
|
5659
|
+
return () => {
|
|
5660
|
+
cancelled = true;
|
|
5661
|
+
};
|
|
5662
|
+
}, [
|
|
5663
|
+
pathname,
|
|
5664
|
+
config.trackingId,
|
|
5665
|
+
config.target,
|
|
5666
|
+
config.debug,
|
|
5667
|
+
config.dev,
|
|
5668
|
+
config.siteId,
|
|
5669
|
+
config.clientPersonalization,
|
|
5670
|
+
pageContextKey
|
|
5671
|
+
]);
|
|
5672
|
+
const resolveRunRef = React3.useRef(null);
|
|
5673
|
+
React3.useEffect(() => {
|
|
5674
|
+
return () => {
|
|
5675
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5676
|
+
};
|
|
5677
|
+
}, []);
|
|
5678
|
+
React3.useEffect(() => {
|
|
5679
|
+
if (initVersion === 0) return;
|
|
5680
|
+
if (resolveRunRef.current?.version === initVersion) return;
|
|
5681
|
+
const sdk = getSDK();
|
|
5682
|
+
const actualRoute = getActualRoute();
|
|
5683
|
+
if (!actualRoute || contentMountsRef.current === 0 || !overlayEnabled()) {
|
|
5684
|
+
if (actualRoute) sdk.endPageResolve(actualRoute);
|
|
5685
|
+
setPageConfig(null);
|
|
5686
|
+
setLoading(false);
|
|
5687
|
+
return;
|
|
5688
|
+
}
|
|
5689
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5690
|
+
const runState = { version: initVersion, cancelled: false };
|
|
5691
|
+
resolveRunRef.current = runState;
|
|
5692
|
+
const finish = () => {
|
|
5693
|
+
sdk.endPageResolve(actualRoute);
|
|
5694
|
+
if (!runState.cancelled) setLoading(false);
|
|
5695
|
+
};
|
|
5696
|
+
const run = async () => {
|
|
5697
|
+
try {
|
|
5628
5698
|
const preview = isComposerPreview();
|
|
5629
|
-
const overlay = preview || config.clientPersonalization !== false;
|
|
5630
|
-
if (!overlay) {
|
|
5631
|
-
setInitialized(true);
|
|
5632
|
-
setPageConfig(null);
|
|
5633
|
-
setLoading(false);
|
|
5634
|
-
return;
|
|
5635
|
-
}
|
|
5636
5699
|
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
5637
5700
|
setPageConfig(null);
|
|
5638
5701
|
setError(null);
|
|
@@ -5641,9 +5704,7 @@ function AmplifyUpProvider({
|
|
|
5641
5704
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
5642
5705
|
const trackingId = sdk.getTrackingId();
|
|
5643
5706
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
5644
|
-
setInitialized(true);
|
|
5645
5707
|
setError("SDK not initialized");
|
|
5646
|
-
setLoading(false);
|
|
5647
5708
|
return;
|
|
5648
5709
|
}
|
|
5649
5710
|
let variantKeys;
|
|
@@ -5676,7 +5737,7 @@ function AmplifyUpProvider({
|
|
|
5676
5737
|
variantKeys,
|
|
5677
5738
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
5678
5739
|
});
|
|
5679
|
-
if (cancelled) return;
|
|
5740
|
+
if (runState.cancelled) return;
|
|
5680
5741
|
const nextConfig = result.pageConfig || {
|
|
5681
5742
|
id: "default",
|
|
5682
5743
|
route: actualRoute,
|
|
@@ -5693,7 +5754,6 @@ function AmplifyUpProvider({
|
|
|
5693
5754
|
result.pageConfig.pageTaxonomies || null
|
|
5694
5755
|
);
|
|
5695
5756
|
}
|
|
5696
|
-
setInitialized(true);
|
|
5697
5757
|
setSource((prev) => prev === result.source ? prev : result.source);
|
|
5698
5758
|
setMeta(
|
|
5699
5759
|
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
@@ -5707,31 +5767,17 @@ function AmplifyUpProvider({
|
|
|
5707
5767
|
});
|
|
5708
5768
|
loadedRouteRef.current = actualRoute;
|
|
5709
5769
|
} catch (err) {
|
|
5710
|
-
if (cancelled) return;
|
|
5770
|
+
if (runState.cancelled) return;
|
|
5711
5771
|
console.error("Error fetching page config:", err);
|
|
5712
|
-
setInitialized(true);
|
|
5713
5772
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5714
5773
|
setSource(null);
|
|
5715
5774
|
setMeta(null);
|
|
5716
5775
|
} finally {
|
|
5717
|
-
|
|
5718
|
-
if (!cancelled) setLoading(false);
|
|
5776
|
+
finish();
|
|
5719
5777
|
}
|
|
5720
5778
|
};
|
|
5721
5779
|
void run();
|
|
5722
|
-
|
|
5723
|
-
cancelled = true;
|
|
5724
|
-
};
|
|
5725
|
-
}, [
|
|
5726
|
-
pathname,
|
|
5727
|
-
config.trackingId,
|
|
5728
|
-
config.target,
|
|
5729
|
-
config.debug,
|
|
5730
|
-
config.dev,
|
|
5731
|
-
config.siteId,
|
|
5732
|
-
config.clientPersonalization,
|
|
5733
|
-
pageContextKey
|
|
5734
|
-
]);
|
|
5780
|
+
}, [initVersion, hasPageContent]);
|
|
5735
5781
|
React3.useEffect(() => {
|
|
5736
5782
|
const applyLayoutTree = (layoutTree) => {
|
|
5737
5783
|
if (!Array.isArray(layoutTree)) return;
|
|
@@ -5765,13 +5811,13 @@ function AmplifyUpProvider({
|
|
|
5765
5811
|
window.removeEventListener("amplifyup:layout-patch", onCustom);
|
|
5766
5812
|
};
|
|
5767
5813
|
}, []);
|
|
5768
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5814
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PageContentRegistryContext.Provider, { value: registerPageContent, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
5769
5815
|
AmplifyUpContext.Provider,
|
|
5770
5816
|
{
|
|
5771
5817
|
value: { pageConfig, loading, error, source, meta },
|
|
5772
5818
|
children
|
|
5773
5819
|
}
|
|
5774
|
-
);
|
|
5820
|
+
) });
|
|
5775
5821
|
}
|
|
5776
5822
|
function useAmplifyUp() {
|
|
5777
5823
|
const context = React3.useContext(AmplifyUpContext);
|