@amplifyup/sdk 0.1.68 → 0.1.70
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.js +12 -46
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +12 -46
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +3 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -25
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +33 -1
- package/dist/react.d.ts +33 -1
- package/dist/react.js +129 -116
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +73 -66
- 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
|
|
2
|
+
import React3, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component, useMemo, useSyncExternalStore, useCallback } from 'react';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import { marked } from 'marked';
|
|
5
5
|
|
|
@@ -1038,7 +1038,7 @@ function dedupeLayoutProviderFetch(key, fetchFn) {
|
|
|
1038
1038
|
function previewLayoutReady(opts) {
|
|
1039
1039
|
if (opts.hasClientLayout) return true;
|
|
1040
1040
|
if (opts.clientLoading) return false;
|
|
1041
|
-
return
|
|
1041
|
+
return true;
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
1044
|
// src/edge/normalizeRoute.ts
|
|
@@ -1509,33 +1509,11 @@ var AmplifyUpSDK = class {
|
|
|
1509
1509
|
}
|
|
1510
1510
|
}
|
|
1511
1511
|
/**
|
|
1512
|
-
* Detect if we're running in visual editor mode
|
|
1513
|
-
*
|
|
1514
|
-
* 1. Preview mode flag is set by proxy
|
|
1515
|
-
* 2. We're in an iframe AND parent is from orchestrator domain
|
|
1516
|
-
* 3. OR visualEditor/preview query parameter is present
|
|
1512
|
+
* Detect if we're running in visual editor mode.
|
|
1513
|
+
* Single source of truth: isComposerPreview() (flag, query, Composer referrer).
|
|
1517
1514
|
*/
|
|
1518
1515
|
detectVisualEditorMode() {
|
|
1519
|
-
|
|
1520
|
-
if (window.__AMPLIFYUP_PREVIEW_MODE__ === true) {
|
|
1521
|
-
return true;
|
|
1522
|
-
}
|
|
1523
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
1524
|
-
if (urlParams.get("visualEditor") === "true" || urlParams.get("preview") === "true") {
|
|
1525
|
-
return true;
|
|
1526
|
-
}
|
|
1527
|
-
const inIframe = window.self !== window.top;
|
|
1528
|
-
if (!inIframe) return false;
|
|
1529
|
-
try {
|
|
1530
|
-
if (document.referrer) {
|
|
1531
|
-
const referrerUrl = new URL(document.referrer);
|
|
1532
|
-
if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/")) {
|
|
1533
|
-
return true;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
} catch (e) {
|
|
1537
|
-
}
|
|
1538
|
-
return false;
|
|
1516
|
+
return isComposerPreview();
|
|
1539
1517
|
}
|
|
1540
1518
|
/**
|
|
1541
1519
|
* Check if we're in preview/composer mode (should disable tracking)
|
|
@@ -3884,13 +3862,16 @@ function getSDK(adapter) {
|
|
|
3884
3862
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3885
3863
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3886
3864
|
getSDK();
|
|
3887
|
-
function
|
|
3865
|
+
function useInComposer(force = false) {
|
|
3888
3866
|
const [detected, setDetected] = useState(false);
|
|
3889
3867
|
useEffect(() => {
|
|
3890
3868
|
if (!force && isComposerPreview()) setDetected(true);
|
|
3891
3869
|
}, [force]);
|
|
3892
3870
|
return force || detected;
|
|
3893
3871
|
}
|
|
3872
|
+
function useComposerPreviewFlag(force = false) {
|
|
3873
|
+
return useInComposer(force);
|
|
3874
|
+
}
|
|
3894
3875
|
|
|
3895
3876
|
// src/composer-store.ts
|
|
3896
3877
|
var ComposerFieldStore = class {
|
|
@@ -4179,26 +4160,7 @@ function AmplifyRendererInner({
|
|
|
4179
4160
|
return () => window.clearTimeout(t);
|
|
4180
4161
|
}, [variantCache, pageConfig?.id]);
|
|
4181
4162
|
useEffect(() => {
|
|
4182
|
-
|
|
4183
|
-
if (typeof window === "undefined") return false;
|
|
4184
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
4185
|
-
if (urlParams.get("visualEditor") === "true" || urlParams.get("preview") === "true") {
|
|
4186
|
-
return true;
|
|
4187
|
-
}
|
|
4188
|
-
const inIframe = window.self !== window.top;
|
|
4189
|
-
if (!inIframe) return false;
|
|
4190
|
-
try {
|
|
4191
|
-
if (document.referrer) {
|
|
4192
|
-
const referrerUrl = new URL(document.referrer);
|
|
4193
|
-
if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001") {
|
|
4194
|
-
return true;
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
} catch (e) {
|
|
4198
|
-
}
|
|
4199
|
-
return false;
|
|
4200
|
-
};
|
|
4201
|
-
if (!isVisualEditorMode()) {
|
|
4163
|
+
if (!isComposerPreview()) {
|
|
4202
4164
|
return;
|
|
4203
4165
|
}
|
|
4204
4166
|
if (!pageConfig) {
|
|
@@ -4492,6 +4454,7 @@ function AmplifyRendererInner({
|
|
|
4492
4454
|
"data-slot-id": "main",
|
|
4493
4455
|
"data-amplifyup-slot": "main",
|
|
4494
4456
|
"data-slot-source": "page",
|
|
4457
|
+
"data-slot-state": layoutTree.length === 0 ? "empty" : "filled",
|
|
4495
4458
|
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4496
4459
|
children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
|
|
4497
4460
|
}
|
|
@@ -4592,16 +4555,34 @@ function EmptySlotHint({
|
|
|
4592
4555
|
}
|
|
4593
4556
|
);
|
|
4594
4557
|
}
|
|
4595
|
-
|
|
4558
|
+
var ComposerLayoutStatusContext = createContext({
|
|
4559
|
+
ready: true
|
|
4560
|
+
});
|
|
4561
|
+
function ComposerLayoutStatusProvider({
|
|
4562
|
+
ready,
|
|
4563
|
+
children
|
|
4564
|
+
}) {
|
|
4565
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusContext.Provider, { value: { ready }, children });
|
|
4566
|
+
}
|
|
4567
|
+
function useComposerLayoutStatus() {
|
|
4568
|
+
return useContext(ComposerLayoutStatusContext);
|
|
4569
|
+
}
|
|
4570
|
+
function previewPageSlot(state) {
|
|
4596
4571
|
return /* @__PURE__ */ jsx(
|
|
4597
4572
|
"div",
|
|
4598
4573
|
{
|
|
4599
4574
|
"data-slot-id": "main",
|
|
4600
4575
|
"data-amplifyup-slot": "main",
|
|
4601
4576
|
"data-slot-source": "page",
|
|
4602
|
-
"data-slot-
|
|
4603
|
-
|
|
4604
|
-
|
|
4577
|
+
"data-slot-state": state,
|
|
4578
|
+
"data-slot-empty": state === "empty" ? "true" : void 0,
|
|
4579
|
+
style: {
|
|
4580
|
+
minHeight: state === "empty" ? "50vh" : void 0,
|
|
4581
|
+
width: "100%",
|
|
4582
|
+
display: "block",
|
|
4583
|
+
position: "relative"
|
|
4584
|
+
},
|
|
4585
|
+
children: state === "empty" ? /* @__PURE__ */ jsx(EmptySlotHint, {}) : null
|
|
4605
4586
|
}
|
|
4606
4587
|
);
|
|
4607
4588
|
}
|
|
@@ -4648,25 +4629,26 @@ function AmplifyPageContent({
|
|
|
4648
4629
|
}
|
|
4649
4630
|
const loading = !hasAmplifyLayout(pageConfig) && client.loading;
|
|
4650
4631
|
const error = hasAmplifyLayout(pageConfig) ? null : pageConfigProp ? null : client.error;
|
|
4651
|
-
const
|
|
4652
|
-
const previewLoading = previewLoadingComponent ??
|
|
4632
|
+
const previewEmpty = previewEmptyComponent ?? previewPageSlot("empty");
|
|
4633
|
+
const previewLoading = previewLoadingComponent ?? previewPageSlot("loading");
|
|
4653
4634
|
if (preview) {
|
|
4654
4635
|
const ready = previewLayoutReady({
|
|
4655
4636
|
clientLoading: client.loading,
|
|
4656
|
-
hasClientLayout: !!clientLayout
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4637
|
+
hasClientLayout: !!clientLayout});
|
|
4638
|
+
if (!ready) {
|
|
4639
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: false, children: previewLoading });
|
|
4640
|
+
}
|
|
4641
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsx(
|
|
4660
4642
|
AmplifyRenderer,
|
|
4661
4643
|
{
|
|
4662
|
-
pageConfig:
|
|
4644
|
+
pageConfig: pageConfig ?? void 0,
|
|
4663
4645
|
renderComponent,
|
|
4664
4646
|
composerPreview: true,
|
|
4665
4647
|
loadingComponent: loadingComponent ?? previewLoading,
|
|
4666
|
-
emptyComponent: emptyComponent ??
|
|
4667
|
-
errorComponent: errorComponent ?? (() =>
|
|
4648
|
+
emptyComponent: emptyComponent ?? previewEmpty,
|
|
4649
|
+
errorComponent: errorComponent ?? (() => previewEmpty)
|
|
4668
4650
|
}
|
|
4669
|
-
);
|
|
4651
|
+
) });
|
|
4670
4652
|
}
|
|
4671
4653
|
if (loading) {
|
|
4672
4654
|
return loadingComponent ? /* @__PURE__ */ jsx(Fragment, { children: loadingComponent }) : null;
|
|
@@ -4690,6 +4672,24 @@ function AmplifyPageContent({
|
|
|
4690
4672
|
);
|
|
4691
4673
|
}
|
|
4692
4674
|
|
|
4675
|
+
// src/slot-state.ts
|
|
4676
|
+
function resolveSlotState(opts) {
|
|
4677
|
+
if (!opts.layoutReady) return "loading";
|
|
4678
|
+
return opts.hasContent ? "filled" : "empty";
|
|
4679
|
+
}
|
|
4680
|
+
function slotShowsAddComponent(state) {
|
|
4681
|
+
return state === "empty";
|
|
4682
|
+
}
|
|
4683
|
+
function slotStateFromEl(el) {
|
|
4684
|
+
if (!el) return null;
|
|
4685
|
+
const explicit = el.getAttribute("data-slot-state");
|
|
4686
|
+
if (explicit === "loading" || explicit === "empty" || explicit === "filled") {
|
|
4687
|
+
return explicit;
|
|
4688
|
+
}
|
|
4689
|
+
if (el.getAttribute("data-slot-empty") === "true") return "empty";
|
|
4690
|
+
return null;
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4693
4693
|
// src/composer-edit-mode.ts
|
|
4694
4694
|
function isComposerEditMode() {
|
|
4695
4695
|
if (typeof window === "undefined") return false;
|
|
@@ -4731,7 +4731,12 @@ function Slot({
|
|
|
4731
4731
|
return null;
|
|
4732
4732
|
}
|
|
4733
4733
|
const slotContent = context.slots?.[name];
|
|
4734
|
-
const
|
|
4734
|
+
const { ready: layoutReady } = useComposerLayoutStatus();
|
|
4735
|
+
const slotState = resolveSlotState({
|
|
4736
|
+
layoutReady,
|
|
4737
|
+
hasContent: !!slotContent
|
|
4738
|
+
});
|
|
4739
|
+
const isEmpty = slotState === "empty";
|
|
4735
4740
|
const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
|
|
4736
4741
|
(window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
|
|
4737
4742
|
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)
|
|
@@ -4747,6 +4752,7 @@ function Slot({
|
|
|
4747
4752
|
`slot:${context.layoutNodeId || ""}:${name}`,
|
|
4748
4753
|
`[Slot:${name}]`,
|
|
4749
4754
|
{
|
|
4755
|
+
slotState,
|
|
4750
4756
|
isEmpty,
|
|
4751
4757
|
isEditorMode,
|
|
4752
4758
|
availableSlotKeys: context.slots ? Object.keys(context.slots) : []
|
|
@@ -4759,6 +4765,7 @@ function Slot({
|
|
|
4759
4765
|
"data-slot-name": name,
|
|
4760
4766
|
"data-slot-id": name,
|
|
4761
4767
|
"data-amplifyup-slot": name,
|
|
4768
|
+
"data-slot-state": slotState,
|
|
4762
4769
|
"data-slot-empty": isEmpty ? "true" : void 0,
|
|
4763
4770
|
"data-parent-node-id": context.layoutNodeId || void 0,
|
|
4764
4771
|
"data-parent-component-id": context.componentId || void 0,
|
|
@@ -4768,7 +4775,7 @@ function Slot({
|
|
|
4768
4775
|
// Only add position relative for overlay positioning in editor mode
|
|
4769
4776
|
position: isEditorMode ? "relative" : void 0
|
|
4770
4777
|
},
|
|
4771
|
-
children: isEmpty ? isEditorMode ? /* @__PURE__ */ jsx(EmptySlotHint, { compact: true }) : /* @__PURE__ */ jsx(
|
|
4778
|
+
children: slotState === "loading" ? null : isEmpty ? isEditorMode ? /* @__PURE__ */ jsx(EmptySlotHint, { compact: true }) : /* @__PURE__ */ jsx(
|
|
4772
4779
|
"div",
|
|
4773
4780
|
{
|
|
4774
4781
|
className: "amplifyup-slot-placeholder",
|
|
@@ -5062,7 +5069,7 @@ function ComposerInlineHtml({
|
|
|
5062
5069
|
fieldRef
|
|
5063
5070
|
});
|
|
5064
5071
|
};
|
|
5065
|
-
return
|
|
5072
|
+
return React3.createElement(Tag, {
|
|
5066
5073
|
ref: elRef,
|
|
5067
5074
|
className,
|
|
5068
5075
|
"data-amplifyup-field": name,
|
|
@@ -5669,6 +5676,6 @@ function useAmplifyUp() {
|
|
|
5669
5676
|
return context;
|
|
5670
5677
|
}
|
|
5671
5678
|
|
|
5672
|
-
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, ComposerProvider, Field, Image, MaybeComposerProvider, QueryContentError, RichText, SelectVariantsError, Slot, attachFieldEnvelopes, composerStoreKey, envelopeListRows, isBrandedFields, isComposerPreview, isFieldEnvelope, isPreviewRequest, isReadOnlyRowField, isWorkingContentRequest, listOwnerFromSpec, nextPageSpec, queryContent, searchSpec, selectVariants, toFieldEnvelopes, useAmplifyUp };
|
|
5679
|
+
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, ComposerLayoutStatusProvider, ComposerProvider, Field, Image, MaybeComposerProvider, QueryContentError, RichText, SelectVariantsError, Slot, attachFieldEnvelopes, composerStoreKey, envelopeListRows, isBrandedFields, isComposerPreview, isFieldEnvelope, isPreviewRequest, isReadOnlyRowField, isWorkingContentRequest, listOwnerFromSpec, nextPageSpec, queryContent, resolveSlotState, searchSpec, selectVariants, slotShowsAddComponent, slotStateFromEl, toFieldEnvelopes, useAmplifyUp, useComposerPreviewFlag, useInComposer };
|
|
5673
5680
|
//# sourceMappingURL=react.mjs.map
|
|
5674
5681
|
//# sourceMappingURL=react.mjs.map
|