@amplifyup/sdk 0.1.67 → 0.1.69
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 +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +121 -13
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +121 -13
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +113 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{query-DuRilU_n.d.mts → query-B_DU7yEm.d.mts} +1 -1
- package/dist/{query-BLjZYjHJ.d.ts → query-Hay-oVYp.d.ts} +1 -1
- package/dist/react.d.mts +22 -4
- package/dist/react.d.ts +22 -4
- package/dist/react.js +294 -83
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +243 -36
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +30 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +30 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-C32MgOiv.d.mts → types-CGeBbx84.d.mts} +9 -3
- package/dist/{types-C32MgOiv.d.ts → types-CGeBbx84.d.ts} +9 -3
- 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
|
|
|
@@ -434,6 +434,13 @@ function isFieldEnvelope(value) {
|
|
|
434
434
|
const rec = value;
|
|
435
435
|
return typeof rec.name === "string" && "value" in rec && !("url" in rec);
|
|
436
436
|
}
|
|
437
|
+
var OBJECT_FIELD_KINDS = /* @__PURE__ */ new Set(["object", "array", "list"]);
|
|
438
|
+
function isLeafFieldKind(kind) {
|
|
439
|
+
if (typeof kind !== "string") return false;
|
|
440
|
+
const normalized = kind.trim().toLowerCase();
|
|
441
|
+
if (!normalized) return false;
|
|
442
|
+
return !OBJECT_FIELD_KINDS.has(normalized);
|
|
443
|
+
}
|
|
437
444
|
function isPageResourceSentinel(value) {
|
|
438
445
|
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
|
|
439
446
|
}
|
|
@@ -573,6 +580,10 @@ function toFieldEnvelopes(source, prefix = "", scope) {
|
|
|
573
580
|
out[key] = { value: envelopeListRows(raw, owner), name: path };
|
|
574
581
|
continue;
|
|
575
582
|
}
|
|
583
|
+
if (ctx.leaf?.(path)) {
|
|
584
|
+
out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
576
587
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
577
588
|
out[key] = toFieldEnvelopes(raw, path, ctx);
|
|
578
589
|
continue;
|
|
@@ -601,15 +612,33 @@ function envelopeListRow(item, owner) {
|
|
|
601
612
|
}
|
|
602
613
|
return row;
|
|
603
614
|
}
|
|
615
|
+
var warnedMissingFieldKind = /* @__PURE__ */ new Set();
|
|
616
|
+
function warnMissingFieldKind(fieldName) {
|
|
617
|
+
if (process.env.NODE_ENV === "production") return;
|
|
618
|
+
if (warnedMissingFieldKind.has(fieldName)) return;
|
|
619
|
+
warnedMissingFieldKind.add(fieldName);
|
|
620
|
+
console.warn(
|
|
621
|
+
`[AmplifyUp SDK] Field "${fieldName}" has no schema kind; using value-shape detection. Republish the component definition so its fields carry a type.`
|
|
622
|
+
);
|
|
623
|
+
}
|
|
604
624
|
function attachFieldEnvelopes(props, sources) {
|
|
605
625
|
const raw = props && typeof props === "object" ? { ...props } : {};
|
|
606
626
|
if (isBrandedFields(raw.fields)) return raw;
|
|
607
627
|
const { fields: existing, ...content } = raw;
|
|
608
628
|
const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
|
|
629
|
+
const { reads } = normalizeEnvelopeSources(sources);
|
|
630
|
+
if (reads) {
|
|
631
|
+
for (const [fieldName, read] of Object.entries(reads)) {
|
|
632
|
+
if (!read?.kind) warnMissingFieldKind(fieldName);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
609
635
|
return {
|
|
610
636
|
...raw,
|
|
611
637
|
fields: toFieldEnvelopes(source, "", {
|
|
612
|
-
owners: (fieldName) => listOwnerForField(fieldName, source, sources)
|
|
638
|
+
owners: (fieldName) => listOwnerForField(fieldName, source, sources),
|
|
639
|
+
// Top-level field paths equal field names; nested paths have no schema
|
|
640
|
+
// entry and fall back to shape-based handling.
|
|
641
|
+
leaf: (path) => isLeafFieldKind(reads?.[path]?.kind)
|
|
613
642
|
})
|
|
614
643
|
};
|
|
615
644
|
}
|
|
@@ -884,6 +913,8 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
884
913
|
if (val && typeof val === "object" && !Array.isArray(val) && typeof val.name === "string" && "value" in val && !("url" in val)) {
|
|
885
914
|
const env = val;
|
|
886
915
|
out[key] = {
|
|
916
|
+
// Keep ref / readOnly / source — dropping them severs the write target.
|
|
917
|
+
...val,
|
|
887
918
|
name: env.name,
|
|
888
919
|
value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
|
|
889
920
|
};
|
|
@@ -965,6 +996,51 @@ function sdkDebugOnce(key, ...args) {
|
|
|
965
996
|
console.log(...args);
|
|
966
997
|
}
|
|
967
998
|
|
|
999
|
+
// src/content/layoutProviderCache.ts
|
|
1000
|
+
var SETTLED_TTL_MS = 5e3;
|
|
1001
|
+
var inflight = /* @__PURE__ */ new Map();
|
|
1002
|
+
var settled = /* @__PURE__ */ new Map();
|
|
1003
|
+
function layoutProviderCacheKey(opts) {
|
|
1004
|
+
const route = (opts.route || "/").split("?")[0] || "/";
|
|
1005
|
+
return [
|
|
1006
|
+
route,
|
|
1007
|
+
opts.trackingId || "",
|
|
1008
|
+
opts.instanceId || "",
|
|
1009
|
+
opts.preview ? "1" : "0",
|
|
1010
|
+
opts.working ? "1" : "0",
|
|
1011
|
+
opts.zoneId || "",
|
|
1012
|
+
opts.compositionId || ""
|
|
1013
|
+
].join("|");
|
|
1014
|
+
}
|
|
1015
|
+
function getSettledLayoutProvider(key) {
|
|
1016
|
+
const entry = settled.get(key);
|
|
1017
|
+
if (!entry) return void 0;
|
|
1018
|
+
if (Date.now() - entry.at > SETTLED_TTL_MS) {
|
|
1019
|
+
settled.delete(key);
|
|
1020
|
+
return void 0;
|
|
1021
|
+
}
|
|
1022
|
+
return entry.value;
|
|
1023
|
+
}
|
|
1024
|
+
function dedupeLayoutProviderFetch(key, fetchFn) {
|
|
1025
|
+
const cached = getSettledLayoutProvider(key);
|
|
1026
|
+
if (cached !== void 0) return Promise.resolve(cached);
|
|
1027
|
+
const existing = inflight.get(key);
|
|
1028
|
+
if (existing) return existing;
|
|
1029
|
+
const pending = fetchFn().then((value) => {
|
|
1030
|
+
settled.set(key, { value, at: Date.now() });
|
|
1031
|
+
return value;
|
|
1032
|
+
}).finally(() => {
|
|
1033
|
+
inflight.delete(key);
|
|
1034
|
+
});
|
|
1035
|
+
inflight.set(key, pending);
|
|
1036
|
+
return pending;
|
|
1037
|
+
}
|
|
1038
|
+
function previewLayoutReady(opts) {
|
|
1039
|
+
if (opts.hasClientLayout) return true;
|
|
1040
|
+
if (opts.clientLoading) return false;
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
968
1044
|
// src/edge/normalizeRoute.ts
|
|
969
1045
|
function normalizeRoute(route) {
|
|
970
1046
|
let path = String(route || "").trim();
|
|
@@ -2378,6 +2454,32 @@ Available Console Commands:
|
|
|
2378
2454
|
*/
|
|
2379
2455
|
async fetchPageConfig(route, preview = false) {
|
|
2380
2456
|
const url = this.buildLayoutProviderUrl(route, preview);
|
|
2457
|
+
const pageSearch = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : null;
|
|
2458
|
+
const cacheKey = layoutProviderCacheKey({
|
|
2459
|
+
route,
|
|
2460
|
+
trackingId: this.getTrackingId(),
|
|
2461
|
+
instanceId: getInstanceId(),
|
|
2462
|
+
preview,
|
|
2463
|
+
working: pageSearch ? isWorkingContentRequest(pageSearch) : false,
|
|
2464
|
+
zoneId: pageSearch?.get("zoneId"),
|
|
2465
|
+
compositionId: pageSearch?.get("compositionId")
|
|
2466
|
+
});
|
|
2467
|
+
return dedupeLayoutProviderFetch(cacheKey, async () => {
|
|
2468
|
+
const startedAt = Date.now();
|
|
2469
|
+
sdkDebug("[AmplifyUp SDK] layout/provider request", {
|
|
2470
|
+
route,
|
|
2471
|
+
at: new Date(startedAt).toISOString()
|
|
2472
|
+
});
|
|
2473
|
+
const page = await this.fetchPageConfigUncached(url);
|
|
2474
|
+
sdkDebug("[AmplifyUp SDK] layout/provider response", {
|
|
2475
|
+
route,
|
|
2476
|
+
durationMs: Date.now() - startedAt,
|
|
2477
|
+
hasPage: !!page
|
|
2478
|
+
});
|
|
2479
|
+
return page;
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
async fetchPageConfigUncached(url) {
|
|
2381
2483
|
const response = await fetch(url);
|
|
2382
2484
|
if (!response.ok) {
|
|
2383
2485
|
if (response.status === 404) {
|
|
@@ -2736,6 +2838,12 @@ Available Console Commands:
|
|
|
2736
2838
|
);
|
|
2737
2839
|
return;
|
|
2738
2840
|
}
|
|
2841
|
+
if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
|
|
2842
|
+
window.dispatchEvent(
|
|
2843
|
+
new CustomEvent("amplifyup:layout-patch", { detail: event.data })
|
|
2844
|
+
);
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2739
2847
|
if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
|
|
2740
2848
|
const { componentId, deletable, nodeId } = event.data;
|
|
2741
2849
|
const element = document.querySelector(`[data-component-id="${componentId}"]`);
|
|
@@ -3776,6 +3884,13 @@ function getSDK(adapter) {
|
|
|
3776
3884
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3777
3885
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3778
3886
|
getSDK();
|
|
3887
|
+
function useComposerPreviewFlag(force = false) {
|
|
3888
|
+
const [detected, setDetected] = useState(false);
|
|
3889
|
+
useEffect(() => {
|
|
3890
|
+
if (!force && isComposerPreview()) setDetected(true);
|
|
3891
|
+
}, [force]);
|
|
3892
|
+
return force || detected;
|
|
3893
|
+
}
|
|
3779
3894
|
|
|
3780
3895
|
// src/composer-store.ts
|
|
3781
3896
|
var ComposerFieldStore = class {
|
|
@@ -3992,16 +4107,9 @@ function NodeWithFields({
|
|
|
3992
4107
|
renderComponent,
|
|
3993
4108
|
composerPreview
|
|
3994
4109
|
}) {
|
|
3995
|
-
return /* @__PURE__ */ jsx(
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
enabled: !!(composerPreview || isComposerPreview()),
|
|
3999
|
-
layoutNodeId: nodeId,
|
|
4000
|
-
children: renderComponent(componentId, props, slots, {
|
|
4001
|
-
layoutNodeId: nodeId
|
|
4002
|
-
})
|
|
4003
|
-
}
|
|
4004
|
-
);
|
|
4110
|
+
return /* @__PURE__ */ jsx(MaybeComposerProvider, { enabled: !!composerPreview, layoutNodeId: nodeId, children: renderComponent(componentId, props, slots, {
|
|
4111
|
+
layoutNodeId: nodeId
|
|
4112
|
+
}) });
|
|
4005
4113
|
}
|
|
4006
4114
|
function AmplifyRendererInner({
|
|
4007
4115
|
renderComponent,
|
|
@@ -4012,6 +4120,7 @@ function AmplifyRendererInner({
|
|
|
4012
4120
|
composerPreview
|
|
4013
4121
|
}) {
|
|
4014
4122
|
const clientHook = useAmplifyUp();
|
|
4123
|
+
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
4015
4124
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
4016
4125
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
4017
4126
|
const error = serverPageConfig ? null : clientHook.error;
|
|
@@ -4364,7 +4473,7 @@ function AmplifyRendererInner({
|
|
|
4364
4473
|
props: nodeRenderProps(node),
|
|
4365
4474
|
slots: slotsToPass,
|
|
4366
4475
|
renderComponent,
|
|
4367
|
-
composerPreview
|
|
4476
|
+
composerPreview: composerPreviewFlag
|
|
4368
4477
|
}
|
|
4369
4478
|
)
|
|
4370
4479
|
}
|
|
@@ -4377,12 +4486,13 @@ function AmplifyRendererInner({
|
|
|
4377
4486
|
if (layoutTree.length === 0) {
|
|
4378
4487
|
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." }) }) });
|
|
4379
4488
|
}
|
|
4380
|
-
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx("main", { children:
|
|
4489
|
+
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx("main", { children: composerPreviewFlag ? /* @__PURE__ */ jsx(
|
|
4381
4490
|
"div",
|
|
4382
4491
|
{
|
|
4383
4492
|
"data-slot-id": "main",
|
|
4384
4493
|
"data-amplifyup-slot": "main",
|
|
4385
4494
|
"data-slot-source": "page",
|
|
4495
|
+
"data-slot-state": layoutTree.length === 0 ? "empty" : "filled",
|
|
4386
4496
|
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4387
4497
|
children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
|
|
4388
4498
|
}
|
|
@@ -4483,16 +4593,34 @@ function EmptySlotHint({
|
|
|
4483
4593
|
}
|
|
4484
4594
|
);
|
|
4485
4595
|
}
|
|
4486
|
-
|
|
4596
|
+
var ComposerLayoutStatusContext = createContext({
|
|
4597
|
+
ready: true
|
|
4598
|
+
});
|
|
4599
|
+
function ComposerLayoutStatusProvider({
|
|
4600
|
+
ready,
|
|
4601
|
+
children
|
|
4602
|
+
}) {
|
|
4603
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusContext.Provider, { value: { ready }, children });
|
|
4604
|
+
}
|
|
4605
|
+
function useComposerLayoutStatus() {
|
|
4606
|
+
return useContext(ComposerLayoutStatusContext);
|
|
4607
|
+
}
|
|
4608
|
+
function previewPageSlot(state) {
|
|
4487
4609
|
return /* @__PURE__ */ jsx(
|
|
4488
4610
|
"div",
|
|
4489
4611
|
{
|
|
4490
4612
|
"data-slot-id": "main",
|
|
4491
4613
|
"data-amplifyup-slot": "main",
|
|
4492
4614
|
"data-slot-source": "page",
|
|
4493
|
-
"data-slot-
|
|
4494
|
-
|
|
4495
|
-
|
|
4615
|
+
"data-slot-state": state,
|
|
4616
|
+
"data-slot-empty": state === "empty" ? "true" : void 0,
|
|
4617
|
+
style: {
|
|
4618
|
+
minHeight: state === "empty" ? "50vh" : void 0,
|
|
4619
|
+
width: "100%",
|
|
4620
|
+
display: "block",
|
|
4621
|
+
position: "relative"
|
|
4622
|
+
},
|
|
4623
|
+
children: state === "empty" ? /* @__PURE__ */ jsx(EmptySlotHint, {}) : null
|
|
4496
4624
|
}
|
|
4497
4625
|
);
|
|
4498
4626
|
}
|
|
@@ -4526,7 +4654,7 @@ function AmplifyPageContent({
|
|
|
4526
4654
|
errorComponent
|
|
4527
4655
|
}) {
|
|
4528
4656
|
const client = useAmplifyUp();
|
|
4529
|
-
const preview = forceComposerPreview
|
|
4657
|
+
const preview = useComposerPreviewFlag(forceComposerPreview);
|
|
4530
4658
|
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
4531
4659
|
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
4532
4660
|
let pageConfig = serverLayout ?? clientLayout;
|
|
@@ -4539,20 +4667,26 @@ function AmplifyPageContent({
|
|
|
4539
4667
|
}
|
|
4540
4668
|
const loading = !hasAmplifyLayout(pageConfig) && client.loading;
|
|
4541
4669
|
const error = hasAmplifyLayout(pageConfig) ? null : pageConfigProp ? null : client.error;
|
|
4542
|
-
const
|
|
4543
|
-
const previewLoading = previewLoadingComponent ??
|
|
4670
|
+
const previewEmpty = previewEmptyComponent ?? previewPageSlot("empty");
|
|
4671
|
+
const previewLoading = previewLoadingComponent ?? previewPageSlot("loading");
|
|
4544
4672
|
if (preview) {
|
|
4545
|
-
|
|
4673
|
+
const ready = previewLayoutReady({
|
|
4674
|
+
clientLoading: client.loading,
|
|
4675
|
+
hasClientLayout: !!clientLayout});
|
|
4676
|
+
if (!ready) {
|
|
4677
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: false, children: previewLoading });
|
|
4678
|
+
}
|
|
4679
|
+
return /* @__PURE__ */ jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsx(
|
|
4546
4680
|
AmplifyRenderer,
|
|
4547
4681
|
{
|
|
4548
4682
|
pageConfig: pageConfig ?? void 0,
|
|
4549
4683
|
renderComponent,
|
|
4550
4684
|
composerPreview: true,
|
|
4551
4685
|
loadingComponent: loadingComponent ?? previewLoading,
|
|
4552
|
-
emptyComponent: emptyComponent ??
|
|
4553
|
-
errorComponent: errorComponent ?? (() =>
|
|
4686
|
+
emptyComponent: emptyComponent ?? previewEmpty,
|
|
4687
|
+
errorComponent: errorComponent ?? (() => previewEmpty)
|
|
4554
4688
|
}
|
|
4555
|
-
);
|
|
4689
|
+
) });
|
|
4556
4690
|
}
|
|
4557
4691
|
if (loading) {
|
|
4558
4692
|
return loadingComponent ? /* @__PURE__ */ jsx(Fragment, { children: loadingComponent }) : null;
|
|
@@ -4576,6 +4710,24 @@ function AmplifyPageContent({
|
|
|
4576
4710
|
);
|
|
4577
4711
|
}
|
|
4578
4712
|
|
|
4713
|
+
// src/slot-state.ts
|
|
4714
|
+
function resolveSlotState(opts) {
|
|
4715
|
+
if (!opts.layoutReady) return "loading";
|
|
4716
|
+
return opts.hasContent ? "filled" : "empty";
|
|
4717
|
+
}
|
|
4718
|
+
function slotShowsAddComponent(state) {
|
|
4719
|
+
return state === "empty";
|
|
4720
|
+
}
|
|
4721
|
+
function slotStateFromEl(el) {
|
|
4722
|
+
if (!el) return null;
|
|
4723
|
+
const explicit = el.getAttribute("data-slot-state");
|
|
4724
|
+
if (explicit === "loading" || explicit === "empty" || explicit === "filled") {
|
|
4725
|
+
return explicit;
|
|
4726
|
+
}
|
|
4727
|
+
if (el.getAttribute("data-slot-empty") === "true") return "empty";
|
|
4728
|
+
return null;
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4579
4731
|
// src/composer-edit-mode.ts
|
|
4580
4732
|
function isComposerEditMode() {
|
|
4581
4733
|
if (typeof window === "undefined") return false;
|
|
@@ -4617,7 +4769,12 @@ function Slot({
|
|
|
4617
4769
|
return null;
|
|
4618
4770
|
}
|
|
4619
4771
|
const slotContent = context.slots?.[name];
|
|
4620
|
-
const
|
|
4772
|
+
const { ready: layoutReady } = useComposerLayoutStatus();
|
|
4773
|
+
const slotState = resolveSlotState({
|
|
4774
|
+
layoutReady,
|
|
4775
|
+
hasContent: !!slotContent
|
|
4776
|
+
});
|
|
4777
|
+
const isEmpty = slotState === "empty";
|
|
4621
4778
|
const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
|
|
4622
4779
|
(window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
|
|
4623
4780
|
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)
|
|
@@ -4633,6 +4790,7 @@ function Slot({
|
|
|
4633
4790
|
`slot:${context.layoutNodeId || ""}:${name}`,
|
|
4634
4791
|
`[Slot:${name}]`,
|
|
4635
4792
|
{
|
|
4793
|
+
slotState,
|
|
4636
4794
|
isEmpty,
|
|
4637
4795
|
isEditorMode,
|
|
4638
4796
|
availableSlotKeys: context.slots ? Object.keys(context.slots) : []
|
|
@@ -4645,6 +4803,7 @@ function Slot({
|
|
|
4645
4803
|
"data-slot-name": name,
|
|
4646
4804
|
"data-slot-id": name,
|
|
4647
4805
|
"data-amplifyup-slot": name,
|
|
4806
|
+
"data-slot-state": slotState,
|
|
4648
4807
|
"data-slot-empty": isEmpty ? "true" : void 0,
|
|
4649
4808
|
"data-parent-node-id": context.layoutNodeId || void 0,
|
|
4650
4809
|
"data-parent-component-id": context.componentId || void 0,
|
|
@@ -4654,7 +4813,7 @@ function Slot({
|
|
|
4654
4813
|
// Only add position relative for overlay positioning in editor mode
|
|
4655
4814
|
position: isEditorMode ? "relative" : void 0
|
|
4656
4815
|
},
|
|
4657
|
-
children: isEmpty ? isEditorMode ? /* @__PURE__ */ jsx(EmptySlotHint, { compact: true }) : /* @__PURE__ */ jsx(
|
|
4816
|
+
children: slotState === "loading" ? null : isEmpty ? isEditorMode ? /* @__PURE__ */ jsx(EmptySlotHint, { compact: true }) : /* @__PURE__ */ jsx(
|
|
4658
4817
|
"div",
|
|
4659
4818
|
{
|
|
4660
4819
|
className: "amplifyup-slot-placeholder",
|
|
@@ -4948,7 +5107,7 @@ function ComposerInlineHtml({
|
|
|
4948
5107
|
fieldRef
|
|
4949
5108
|
});
|
|
4950
5109
|
};
|
|
4951
|
-
return
|
|
5110
|
+
return React3.createElement(Tag, {
|
|
4952
5111
|
ref: elRef,
|
|
4953
5112
|
className,
|
|
4954
5113
|
"data-amplifyup-field": name,
|
|
@@ -5005,6 +5164,18 @@ function warnNotScalarField(component, field, fieldValue) {
|
|
|
5005
5164
|
}
|
|
5006
5165
|
return false;
|
|
5007
5166
|
}
|
|
5167
|
+
function assertNamedEnvelope(component, field) {
|
|
5168
|
+
if (process.env.NODE_ENV === "production") return;
|
|
5169
|
+
if (!field || typeof field !== "object" || Array.isArray(field)) return;
|
|
5170
|
+
const rec = field;
|
|
5171
|
+
if (!("value" in rec)) return;
|
|
5172
|
+
if (typeof rec.name === "string" && rec.name) return;
|
|
5173
|
+
throw new Error(
|
|
5174
|
+
`[AmplifyUp SDK] ${component} received an envelope-shaped object with a \`value\` but no \`name\` \u2014 a partial envelope was manufactured upstream (keys: ${Object.keys(
|
|
5175
|
+
rec
|
|
5176
|
+
).join(", ")}). Find the producer; do not strip or rebuild envelopes.`
|
|
5177
|
+
);
|
|
5178
|
+
}
|
|
5008
5179
|
var warnedReadOnlyFields = /* @__PURE__ */ new Set();
|
|
5009
5180
|
function warnReadOnlyRowField(name) {
|
|
5010
5181
|
if (process.env.NODE_ENV === "production") return;
|
|
@@ -5040,6 +5211,7 @@ function Field(props) {
|
|
|
5040
5211
|
const hasField = isFieldEnvelope(field);
|
|
5041
5212
|
const hasValue = hasOwnProp(props, "value");
|
|
5042
5213
|
const { editName, fieldValue, ref } = useBoundField(field, value, name, "Field");
|
|
5214
|
+
assertNamedEnvelope("Field", field);
|
|
5043
5215
|
warnProjectionProps("Field", hasField, hasValue, name);
|
|
5044
5216
|
if (warnNotScalarField("Field", field, fieldValue)) {
|
|
5045
5217
|
return null;
|
|
@@ -5100,6 +5272,7 @@ function RichText(props) {
|
|
|
5100
5272
|
name,
|
|
5101
5273
|
"RichText"
|
|
5102
5274
|
);
|
|
5275
|
+
assertNamedEnvelope("RichText", field);
|
|
5103
5276
|
if (!hasField && !hasValueProp && !name) {
|
|
5104
5277
|
return null;
|
|
5105
5278
|
}
|
|
@@ -5211,6 +5384,7 @@ function Image(props) {
|
|
|
5211
5384
|
...imgProps
|
|
5212
5385
|
} = props;
|
|
5213
5386
|
const context = useContext(ComponentContext);
|
|
5387
|
+
assertNamedEnvelope("Image", field);
|
|
5214
5388
|
const coerced = coerceImageField(field, value, name);
|
|
5215
5389
|
const boundField = coerced.field;
|
|
5216
5390
|
const hasField = isFieldEnvelope(boundField);
|
|
@@ -5446,6 +5620,13 @@ function AmplifyUpProvider({
|
|
|
5446
5620
|
description: "This page has not been published yet.",
|
|
5447
5621
|
layoutTree: []
|
|
5448
5622
|
};
|
|
5623
|
+
if (result.pageConfig) {
|
|
5624
|
+
sdk.applyResolvedPageData(
|
|
5625
|
+
result.pageConfig.pageData || null,
|
|
5626
|
+
result.pageConfig.route,
|
|
5627
|
+
extractRouteParams(result.pageConfig.route, actualRoute)
|
|
5628
|
+
);
|
|
5629
|
+
}
|
|
5449
5630
|
setInitialized(true);
|
|
5450
5631
|
setSource((prev) => prev === result.source ? prev : result.source);
|
|
5451
5632
|
setMeta(
|
|
@@ -5458,13 +5639,6 @@ function AmplifyUpProvider({
|
|
|
5458
5639
|
}
|
|
5459
5640
|
return nextConfig;
|
|
5460
5641
|
});
|
|
5461
|
-
if (result.pageConfig) {
|
|
5462
|
-
sdk.applyResolvedPageData(
|
|
5463
|
-
result.pageConfig.pageData || null,
|
|
5464
|
-
result.pageConfig.route,
|
|
5465
|
-
extractRouteParams(result.pageConfig.route, actualRoute)
|
|
5466
|
-
);
|
|
5467
|
-
}
|
|
5468
5642
|
loadedRouteRef.current = actualRoute;
|
|
5469
5643
|
} catch (err) {
|
|
5470
5644
|
if (cancelled) return;
|
|
@@ -5491,6 +5665,39 @@ function AmplifyUpProvider({
|
|
|
5491
5665
|
config.clientPersonalization,
|
|
5492
5666
|
pageContextKey
|
|
5493
5667
|
]);
|
|
5668
|
+
useEffect(() => {
|
|
5669
|
+
const applyLayoutTree = (layoutTree) => {
|
|
5670
|
+
if (!Array.isArray(layoutTree)) return;
|
|
5671
|
+
setPageConfig((prev) => {
|
|
5672
|
+
const next = envelopePageConfig({
|
|
5673
|
+
...prev || {
|
|
5674
|
+
id: "patched",
|
|
5675
|
+
route: getActualRoute(),
|
|
5676
|
+
title: "",
|
|
5677
|
+
layoutTree: []
|
|
5678
|
+
},
|
|
5679
|
+
layoutTree
|
|
5680
|
+
});
|
|
5681
|
+
return next;
|
|
5682
|
+
});
|
|
5683
|
+
setLoading(false);
|
|
5684
|
+
};
|
|
5685
|
+
const onMessage = (event) => {
|
|
5686
|
+
if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
|
|
5687
|
+
applyLayoutTree(event.data.layoutTree);
|
|
5688
|
+
}
|
|
5689
|
+
};
|
|
5690
|
+
const onCustom = (event) => {
|
|
5691
|
+
const detail = event.detail || {};
|
|
5692
|
+
applyLayoutTree(detail.layoutTree);
|
|
5693
|
+
};
|
|
5694
|
+
window.addEventListener("message", onMessage);
|
|
5695
|
+
window.addEventListener("amplifyup:layout-patch", onCustom);
|
|
5696
|
+
return () => {
|
|
5697
|
+
window.removeEventListener("message", onMessage);
|
|
5698
|
+
window.removeEventListener("amplifyup:layout-patch", onCustom);
|
|
5699
|
+
};
|
|
5700
|
+
}, []);
|
|
5494
5701
|
return /* @__PURE__ */ jsx(
|
|
5495
5702
|
AmplifyUpContext.Provider,
|
|
5496
5703
|
{
|
|
@@ -5507,6 +5714,6 @@ function useAmplifyUp() {
|
|
|
5507
5714
|
return context;
|
|
5508
5715
|
}
|
|
5509
5716
|
|
|
5510
|
-
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 };
|
|
5717
|
+
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 };
|
|
5511
5718
|
//# sourceMappingURL=react.mjs.map
|
|
5512
5719
|
//# sourceMappingURL=react.mjs.map
|