@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React3, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component,
|
|
2
|
+
import React3, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component, useCallback, useSyncExternalStore } from 'react';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import { marked } from 'marked';
|
|
5
5
|
|
|
@@ -166,6 +166,7 @@ var AWSAdapter = class {
|
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
169
|
+
const debug = this.config?.debug;
|
|
169
170
|
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
170
171
|
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
171
172
|
try {
|
|
@@ -180,15 +181,15 @@ var AWSAdapter = class {
|
|
|
180
181
|
keepalive: true
|
|
181
182
|
});
|
|
182
183
|
if (!response.ok) {
|
|
183
|
-
if (
|
|
184
|
+
if (debug) {
|
|
184
185
|
console.warn(`AmplifyUp SDK: Event tracking failed: ${response.status} ${response.statusText}`);
|
|
185
186
|
}
|
|
186
|
-
} else if (
|
|
187
|
+
} else if (debug) {
|
|
187
188
|
const result = await response.json().catch(() => ({}));
|
|
188
189
|
console.log("AmplifyUp SDK: Event tracked", result);
|
|
189
190
|
}
|
|
190
191
|
} catch (error) {
|
|
191
|
-
if (
|
|
192
|
+
if (debug) {
|
|
192
193
|
console.error("AmplifyUp SDK: Event tracking error:", error);
|
|
193
194
|
}
|
|
194
195
|
}
|
|
@@ -1089,9 +1090,8 @@ function dedupeLayoutProviderFetch(key, fetchFn) {
|
|
|
1089
1090
|
return pending;
|
|
1090
1091
|
}
|
|
1091
1092
|
function previewLayoutReady(opts) {
|
|
1092
|
-
if (opts.hasClientLayout) return true;
|
|
1093
|
-
|
|
1094
|
-
return true;
|
|
1093
|
+
if (opts.hasClientLayout || opts.hasServerLayout) return true;
|
|
1094
|
+
return !opts.clientLoading;
|
|
1095
1095
|
}
|
|
1096
1096
|
|
|
1097
1097
|
// src/edge/variantKeys.ts
|
|
@@ -3952,6 +3952,14 @@ function getSDK(adapter) {
|
|
|
3952
3952
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3953
3953
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3954
3954
|
getSDK();
|
|
3955
|
+
var PageContentRegistryContext = createContext(null);
|
|
3956
|
+
function useRegisterPageContent(enabled = true) {
|
|
3957
|
+
const register = useContext(PageContentRegistryContext);
|
|
3958
|
+
useEffect(() => {
|
|
3959
|
+
if (!enabled || !register) return;
|
|
3960
|
+
return register();
|
|
3961
|
+
}, [enabled, register]);
|
|
3962
|
+
}
|
|
3955
3963
|
function useInComposer(force = false) {
|
|
3956
3964
|
const [detected, setDetected] = useState(false);
|
|
3957
3965
|
useEffect(() => {
|
|
@@ -4010,14 +4018,16 @@ function applyComposerPatch(store, name, value, ref, layoutNodeId) {
|
|
|
4010
4018
|
store.set(composerStoreKey(name, ref, layoutNodeId), value);
|
|
4011
4019
|
}
|
|
4012
4020
|
function ComposerProvider({
|
|
4013
|
-
children
|
|
4021
|
+
children,
|
|
4022
|
+
enabled = true
|
|
4014
4023
|
}) {
|
|
4015
4024
|
const existing = useContext(ComposerStoreContext);
|
|
4016
4025
|
const storeRef = useRef(null);
|
|
4017
4026
|
if (!storeRef.current) storeRef.current = new ComposerFieldStore();
|
|
4018
|
-
const
|
|
4027
|
+
const ownsStore = !existing && enabled;
|
|
4028
|
+
const store = existing || (enabled ? storeRef.current : null);
|
|
4019
4029
|
useEffect(() => {
|
|
4020
|
-
if (
|
|
4030
|
+
if (!ownsStore || !store) return;
|
|
4021
4031
|
const applyField = (fieldName, value, nodeId, ref) => {
|
|
4022
4032
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
4023
4033
|
const fieldRef = isFieldRef(ref) ? ref : void 0;
|
|
@@ -4075,8 +4085,7 @@ function ComposerProvider({
|
|
|
4075
4085
|
window.removeEventListener("amplifyup:props-patch", onPropsPatch);
|
|
4076
4086
|
window.removeEventListener("message", onMessage);
|
|
4077
4087
|
};
|
|
4078
|
-
}, [
|
|
4079
|
-
if (existing) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
4088
|
+
}, [ownsStore, store]);
|
|
4080
4089
|
return /* @__PURE__ */ jsx(ComposerStoreContext.Provider, { value: store, children });
|
|
4081
4090
|
}
|
|
4082
4091
|
function useComposerFieldValue(name, fallback, ref) {
|
|
@@ -4103,9 +4112,7 @@ function MaybeComposerProvider({
|
|
|
4103
4112
|
layoutNodeId,
|
|
4104
4113
|
children
|
|
4105
4114
|
}) {
|
|
4106
|
-
|
|
4107
|
-
if (!enabled) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
4108
|
-
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx(ComposerNodeContext.Provider, { value: layoutNodeId, children }) });
|
|
4115
|
+
return /* @__PURE__ */ jsx(ComposerProvider, { enabled, children: /* @__PURE__ */ jsx(ComposerNodeContext.Provider, { value: enabled ? layoutNodeId : void 0, children }) });
|
|
4109
4116
|
}
|
|
4110
4117
|
function nodeRenderProps(node) {
|
|
4111
4118
|
const settings = node.settings || {};
|
|
@@ -4191,6 +4198,7 @@ function AmplifyRendererInner({
|
|
|
4191
4198
|
composerPreview
|
|
4192
4199
|
}) {
|
|
4193
4200
|
const clientHook = useAmplifyUp();
|
|
4201
|
+
useRegisterPageContent(!serverPageConfig);
|
|
4194
4202
|
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
4195
4203
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
4196
4204
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
@@ -4538,17 +4546,16 @@ function AmplifyRendererInner({
|
|
|
4538
4546
|
if (layoutTree.length === 0) {
|
|
4539
4547
|
return /* @__PURE__ */ jsx("main", { children: emptyComponent || /* @__PURE__ */ jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
|
|
4540
4548
|
}
|
|
4541
|
-
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx(
|
|
4542
|
-
"
|
|
4549
|
+
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx(
|
|
4550
|
+
"main",
|
|
4543
4551
|
{
|
|
4544
|
-
"data-slot-id": "main",
|
|
4545
|
-
"data-amplifyup-slot": "main",
|
|
4546
|
-
"data-slot-source": "page",
|
|
4547
|
-
"data-slot-state":
|
|
4548
|
-
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4552
|
+
"data-slot-id": composerPreviewFlag ? "main" : void 0,
|
|
4553
|
+
"data-amplifyup-slot": composerPreviewFlag ? "main" : void 0,
|
|
4554
|
+
"data-slot-source": composerPreviewFlag ? "page" : void 0,
|
|
4555
|
+
"data-slot-state": composerPreviewFlag ? "filled" : void 0,
|
|
4549
4556
|
children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
|
|
4550
4557
|
}
|
|
4551
|
-
)
|
|
4558
|
+
) });
|
|
4552
4559
|
}
|
|
4553
4560
|
var AmplifyRenderer = memo(AmplifyRendererInner);
|
|
4554
4561
|
function AddComponentIcon({ size = 28 }) {
|
|
@@ -4706,6 +4713,7 @@ function AmplifyPageContent({
|
|
|
4706
4713
|
errorComponent
|
|
4707
4714
|
}) {
|
|
4708
4715
|
const client = useAmplifyUp();
|
|
4716
|
+
useRegisterPageContent();
|
|
4709
4717
|
const preview = useComposerPreviewFlag(forceComposerPreview);
|
|
4710
4718
|
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
4711
4719
|
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
@@ -4724,11 +4732,14 @@ function AmplifyPageContent({
|
|
|
4724
4732
|
if (preview) {
|
|
4725
4733
|
const ready = previewLayoutReady({
|
|
4726
4734
|
clientLoading: client.loading,
|
|
4727
|
-
hasClientLayout: !!clientLayout
|
|
4735
|
+
hasClientLayout: !!clientLayout,
|
|
4736
|
+
hasServerLayout: !!serverLayout
|
|
4737
|
+
});
|
|
4728
4738
|
if (!ready) {
|
|
4729
4739
|
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: false, children: previewLoading });
|
|
4730
4740
|
}
|
|
4731
|
-
|
|
4741
|
+
const layoutSettled = !client.loading || !!clientLayout;
|
|
4742
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: layoutSettled, children: /* @__PURE__ */ jsx(
|
|
4732
4743
|
AmplifyRenderer,
|
|
4733
4744
|
{
|
|
4734
4745
|
pageConfig: pageConfig ?? void 0,
|
|
@@ -4750,7 +4761,7 @@ function AmplifyPageContent({
|
|
|
4750
4761
|
if (!hasAmplifyLayout(pageConfig)) {
|
|
4751
4762
|
return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
|
|
4752
4763
|
}
|
|
4753
|
-
return /* @__PURE__ */ jsx(
|
|
4764
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsx(
|
|
4754
4765
|
AmplifyRenderer,
|
|
4755
4766
|
{
|
|
4756
4767
|
pageConfig: pageConfig ?? void 0,
|
|
@@ -4759,7 +4770,7 @@ function AmplifyPageContent({
|
|
|
4759
4770
|
emptyComponent,
|
|
4760
4771
|
errorComponent
|
|
4761
4772
|
}
|
|
4762
|
-
);
|
|
4773
|
+
) });
|
|
4763
4774
|
}
|
|
4764
4775
|
|
|
4765
4776
|
// src/slot-state.ts
|
|
@@ -5599,11 +5610,24 @@ function AmplifyUpProvider({
|
|
|
5599
5610
|
if (!initialized || !pageContext) return;
|
|
5600
5611
|
getSDK().setPageContext(pageContext);
|
|
5601
5612
|
}, [initialized, pageContextKey]);
|
|
5613
|
+
const contentMountsRef = useRef(0);
|
|
5614
|
+
const [hasPageContent, setHasPageContent] = useState(false);
|
|
5615
|
+
const registerPageContent = useCallback(() => {
|
|
5616
|
+
contentMountsRef.current += 1;
|
|
5617
|
+
setHasPageContent(true);
|
|
5618
|
+
return () => {
|
|
5619
|
+
contentMountsRef.current -= 1;
|
|
5620
|
+
if (contentMountsRef.current === 0) setHasPageContent(false);
|
|
5621
|
+
};
|
|
5622
|
+
}, []);
|
|
5623
|
+
const [initVersion, setInitVersion] = useState(0);
|
|
5624
|
+
const overlayEnabled = () => isComposerPreview() || config.clientPersonalization !== false;
|
|
5602
5625
|
useEffect(() => {
|
|
5603
5626
|
let cancelled = false;
|
|
5604
5627
|
const sdk = getSDK();
|
|
5605
|
-
|
|
5606
|
-
|
|
5628
|
+
if (contentMountsRef.current > 0 && overlayEnabled()) {
|
|
5629
|
+
sdk.beginPageResolve(getActualRoute());
|
|
5630
|
+
}
|
|
5607
5631
|
const run = async () => {
|
|
5608
5632
|
try {
|
|
5609
5633
|
await sdk.init({
|
|
@@ -5613,20 +5637,59 @@ function AmplifyUpProvider({
|
|
|
5613
5637
|
if (cancelled) return;
|
|
5614
5638
|
if (pageContext) sdk.setPageContext(pageContext);
|
|
5615
5639
|
const actualRoute = getActualRoute();
|
|
5616
|
-
if (
|
|
5640
|
+
if (actualRoute) sdk.routeChange(actualRoute);
|
|
5641
|
+
} catch (err) {
|
|
5642
|
+
if (cancelled) return;
|
|
5643
|
+
console.error("Error initializing AmplifyUp SDK:", err);
|
|
5644
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5645
|
+
} finally {
|
|
5646
|
+
if (!cancelled) {
|
|
5617
5647
|
setInitialized(true);
|
|
5618
|
-
|
|
5619
|
-
return;
|
|
5648
|
+
setInitVersion((v) => v + 1);
|
|
5620
5649
|
}
|
|
5621
|
-
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
void run();
|
|
5653
|
+
return () => {
|
|
5654
|
+
cancelled = true;
|
|
5655
|
+
};
|
|
5656
|
+
}, [
|
|
5657
|
+
pathname,
|
|
5658
|
+
config.trackingId,
|
|
5659
|
+
config.target,
|
|
5660
|
+
config.debug,
|
|
5661
|
+
config.dev,
|
|
5662
|
+
config.siteId,
|
|
5663
|
+
config.clientPersonalization,
|
|
5664
|
+
pageContextKey
|
|
5665
|
+
]);
|
|
5666
|
+
const resolveRunRef = useRef(null);
|
|
5667
|
+
useEffect(() => {
|
|
5668
|
+
return () => {
|
|
5669
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5670
|
+
};
|
|
5671
|
+
}, []);
|
|
5672
|
+
useEffect(() => {
|
|
5673
|
+
if (initVersion === 0) return;
|
|
5674
|
+
if (resolveRunRef.current?.version === initVersion) return;
|
|
5675
|
+
const sdk = getSDK();
|
|
5676
|
+
const actualRoute = getActualRoute();
|
|
5677
|
+
if (!actualRoute || contentMountsRef.current === 0 || !overlayEnabled()) {
|
|
5678
|
+
if (actualRoute) sdk.endPageResolve(actualRoute);
|
|
5679
|
+
setPageConfig(null);
|
|
5680
|
+
setLoading(false);
|
|
5681
|
+
return;
|
|
5682
|
+
}
|
|
5683
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5684
|
+
const runState = { version: initVersion, cancelled: false };
|
|
5685
|
+
resolveRunRef.current = runState;
|
|
5686
|
+
const finish = () => {
|
|
5687
|
+
sdk.endPageResolve(actualRoute);
|
|
5688
|
+
if (!runState.cancelled) setLoading(false);
|
|
5689
|
+
};
|
|
5690
|
+
const run = async () => {
|
|
5691
|
+
try {
|
|
5622
5692
|
const preview = isComposerPreview();
|
|
5623
|
-
const overlay = preview || config.clientPersonalization !== false;
|
|
5624
|
-
if (!overlay) {
|
|
5625
|
-
setInitialized(true);
|
|
5626
|
-
setPageConfig(null);
|
|
5627
|
-
setLoading(false);
|
|
5628
|
-
return;
|
|
5629
|
-
}
|
|
5630
5693
|
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
5631
5694
|
setPageConfig(null);
|
|
5632
5695
|
setError(null);
|
|
@@ -5635,9 +5698,7 @@ function AmplifyUpProvider({
|
|
|
5635
5698
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
5636
5699
|
const trackingId = sdk.getTrackingId();
|
|
5637
5700
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
5638
|
-
setInitialized(true);
|
|
5639
5701
|
setError("SDK not initialized");
|
|
5640
|
-
setLoading(false);
|
|
5641
5702
|
return;
|
|
5642
5703
|
}
|
|
5643
5704
|
let variantKeys;
|
|
@@ -5670,7 +5731,7 @@ function AmplifyUpProvider({
|
|
|
5670
5731
|
variantKeys,
|
|
5671
5732
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
5672
5733
|
});
|
|
5673
|
-
if (cancelled) return;
|
|
5734
|
+
if (runState.cancelled) return;
|
|
5674
5735
|
const nextConfig = result.pageConfig || {
|
|
5675
5736
|
id: "default",
|
|
5676
5737
|
route: actualRoute,
|
|
@@ -5687,7 +5748,6 @@ function AmplifyUpProvider({
|
|
|
5687
5748
|
result.pageConfig.pageTaxonomies || null
|
|
5688
5749
|
);
|
|
5689
5750
|
}
|
|
5690
|
-
setInitialized(true);
|
|
5691
5751
|
setSource((prev) => prev === result.source ? prev : result.source);
|
|
5692
5752
|
setMeta(
|
|
5693
5753
|
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
@@ -5701,31 +5761,17 @@ function AmplifyUpProvider({
|
|
|
5701
5761
|
});
|
|
5702
5762
|
loadedRouteRef.current = actualRoute;
|
|
5703
5763
|
} catch (err) {
|
|
5704
|
-
if (cancelled) return;
|
|
5764
|
+
if (runState.cancelled) return;
|
|
5705
5765
|
console.error("Error fetching page config:", err);
|
|
5706
|
-
setInitialized(true);
|
|
5707
5766
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5708
5767
|
setSource(null);
|
|
5709
5768
|
setMeta(null);
|
|
5710
5769
|
} finally {
|
|
5711
|
-
|
|
5712
|
-
if (!cancelled) setLoading(false);
|
|
5770
|
+
finish();
|
|
5713
5771
|
}
|
|
5714
5772
|
};
|
|
5715
5773
|
void run();
|
|
5716
|
-
|
|
5717
|
-
cancelled = true;
|
|
5718
|
-
};
|
|
5719
|
-
}, [
|
|
5720
|
-
pathname,
|
|
5721
|
-
config.trackingId,
|
|
5722
|
-
config.target,
|
|
5723
|
-
config.debug,
|
|
5724
|
-
config.dev,
|
|
5725
|
-
config.siteId,
|
|
5726
|
-
config.clientPersonalization,
|
|
5727
|
-
pageContextKey
|
|
5728
|
-
]);
|
|
5774
|
+
}, [initVersion, hasPageContent]);
|
|
5729
5775
|
useEffect(() => {
|
|
5730
5776
|
const applyLayoutTree = (layoutTree) => {
|
|
5731
5777
|
if (!Array.isArray(layoutTree)) return;
|
|
@@ -5759,13 +5805,13 @@ function AmplifyUpProvider({
|
|
|
5759
5805
|
window.removeEventListener("amplifyup:layout-patch", onCustom);
|
|
5760
5806
|
};
|
|
5761
5807
|
}, []);
|
|
5762
|
-
return /* @__PURE__ */ jsx(
|
|
5808
|
+
return /* @__PURE__ */ jsx(PageContentRegistryContext.Provider, { value: registerPageContent, children: /* @__PURE__ */ jsx(
|
|
5763
5809
|
AmplifyUpContext.Provider,
|
|
5764
5810
|
{
|
|
5765
5811
|
value: { pageConfig, loading, error, source, meta },
|
|
5766
5812
|
children
|
|
5767
5813
|
}
|
|
5768
|
-
);
|
|
5814
|
+
) });
|
|
5769
5815
|
}
|
|
5770
5816
|
function useAmplifyUp() {
|
|
5771
5817
|
const context = useContext(AmplifyUpContext);
|