@amplifyup/sdk 0.1.66 → 0.1.68
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 +117 -13
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +117 -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 +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +205 -47
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +205 -47
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { L as LayoutComponentProps, P as PageConfig } from './types-
|
|
4
|
+
import { L as LayoutComponentProps, P as PageConfig } from './types-CGeBbx84.mjs';
|
|
5
5
|
|
|
6
6
|
interface AmplifyRendererProps {
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { L as LayoutComponentProps, P as PageConfig } from './types-
|
|
4
|
+
import { L as LayoutComponentProps, P as PageConfig } from './types-CGeBbx84.js';
|
|
5
5
|
|
|
6
6
|
interface AmplifyRendererProps {
|
|
7
7
|
/**
|
package/dist/AmplifyRenderer.js
CHANGED
|
@@ -436,6 +436,13 @@ function isFieldEnvelope(value) {
|
|
|
436
436
|
const rec = value;
|
|
437
437
|
return typeof rec.name === "string" && "value" in rec && !("url" in rec);
|
|
438
438
|
}
|
|
439
|
+
var OBJECT_FIELD_KINDS = /* @__PURE__ */ new Set(["object", "array", "list"]);
|
|
440
|
+
function isLeafFieldKind(kind) {
|
|
441
|
+
if (typeof kind !== "string") return false;
|
|
442
|
+
const normalized = kind.trim().toLowerCase();
|
|
443
|
+
if (!normalized) return false;
|
|
444
|
+
return !OBJECT_FIELD_KINDS.has(normalized);
|
|
445
|
+
}
|
|
439
446
|
function isPageResourceSentinel(value) {
|
|
440
447
|
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
|
|
441
448
|
}
|
|
@@ -572,6 +579,10 @@ function toFieldEnvelopes(source, prefix = "", scope) {
|
|
|
572
579
|
out[key] = { value: envelopeListRows(raw, owner), name: path };
|
|
573
580
|
continue;
|
|
574
581
|
}
|
|
582
|
+
if (ctx.leaf?.(path)) {
|
|
583
|
+
out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
575
586
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
576
587
|
out[key] = toFieldEnvelopes(raw, path, ctx);
|
|
577
588
|
continue;
|
|
@@ -600,15 +611,33 @@ function envelopeListRow(item, owner) {
|
|
|
600
611
|
}
|
|
601
612
|
return row;
|
|
602
613
|
}
|
|
614
|
+
var warnedMissingFieldKind = /* @__PURE__ */ new Set();
|
|
615
|
+
function warnMissingFieldKind(fieldName) {
|
|
616
|
+
if (process.env.NODE_ENV === "production") return;
|
|
617
|
+
if (warnedMissingFieldKind.has(fieldName)) return;
|
|
618
|
+
warnedMissingFieldKind.add(fieldName);
|
|
619
|
+
console.warn(
|
|
620
|
+
`[AmplifyUp SDK] Field "${fieldName}" has no schema kind; using value-shape detection. Republish the component definition so its fields carry a type.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
603
623
|
function attachFieldEnvelopes(props, sources) {
|
|
604
624
|
const raw = props && typeof props === "object" ? { ...props } : {};
|
|
605
625
|
if (isBrandedFields(raw.fields)) return raw;
|
|
606
626
|
const { fields: existing, ...content } = raw;
|
|
607
627
|
const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
|
|
628
|
+
const { reads } = normalizeEnvelopeSources(sources);
|
|
629
|
+
if (reads) {
|
|
630
|
+
for (const [fieldName, read] of Object.entries(reads)) {
|
|
631
|
+
if (!read?.kind) warnMissingFieldKind(fieldName);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
608
634
|
return {
|
|
609
635
|
...raw,
|
|
610
636
|
fields: toFieldEnvelopes(source, "", {
|
|
611
|
-
owners: (fieldName) => listOwnerForField(fieldName, source, sources)
|
|
637
|
+
owners: (fieldName) => listOwnerForField(fieldName, source, sources),
|
|
638
|
+
// Top-level field paths equal field names; nested paths have no schema
|
|
639
|
+
// entry and fall back to shape-based handling.
|
|
640
|
+
leaf: (path) => isLeafFieldKind(reads?.[path]?.kind)
|
|
612
641
|
})
|
|
613
642
|
};
|
|
614
643
|
}
|
|
@@ -855,6 +884,8 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
855
884
|
if (val && typeof val === "object" && !Array.isArray(val) && typeof val.name === "string" && "value" in val && !("url" in val)) {
|
|
856
885
|
const env = val;
|
|
857
886
|
out[key] = {
|
|
887
|
+
// Keep ref / readOnly / source — dropping them severs the write target.
|
|
888
|
+
...val,
|
|
858
889
|
name: env.name,
|
|
859
890
|
value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
|
|
860
891
|
};
|
|
@@ -936,6 +967,46 @@ function sdkDebugOnce(key, ...args) {
|
|
|
936
967
|
console.log(...args);
|
|
937
968
|
}
|
|
938
969
|
|
|
970
|
+
// src/content/layoutProviderCache.ts
|
|
971
|
+
var SETTLED_TTL_MS = 5e3;
|
|
972
|
+
var inflight = /* @__PURE__ */ new Map();
|
|
973
|
+
var settled = /* @__PURE__ */ new Map();
|
|
974
|
+
function layoutProviderCacheKey(opts) {
|
|
975
|
+
const route = (opts.route || "/").split("?")[0] || "/";
|
|
976
|
+
return [
|
|
977
|
+
route,
|
|
978
|
+
opts.trackingId || "",
|
|
979
|
+
opts.instanceId || "",
|
|
980
|
+
opts.preview ? "1" : "0",
|
|
981
|
+
opts.working ? "1" : "0",
|
|
982
|
+
opts.zoneId || "",
|
|
983
|
+
opts.compositionId || ""
|
|
984
|
+
].join("|");
|
|
985
|
+
}
|
|
986
|
+
function getSettledLayoutProvider(key) {
|
|
987
|
+
const entry = settled.get(key);
|
|
988
|
+
if (!entry) return void 0;
|
|
989
|
+
if (Date.now() - entry.at > SETTLED_TTL_MS) {
|
|
990
|
+
settled.delete(key);
|
|
991
|
+
return void 0;
|
|
992
|
+
}
|
|
993
|
+
return entry.value;
|
|
994
|
+
}
|
|
995
|
+
function dedupeLayoutProviderFetch(key, fetchFn) {
|
|
996
|
+
const cached = getSettledLayoutProvider(key);
|
|
997
|
+
if (cached !== void 0) return Promise.resolve(cached);
|
|
998
|
+
const existing = inflight.get(key);
|
|
999
|
+
if (existing) return existing;
|
|
1000
|
+
const pending = fetchFn().then((value) => {
|
|
1001
|
+
settled.set(key, { value, at: Date.now() });
|
|
1002
|
+
return value;
|
|
1003
|
+
}).finally(() => {
|
|
1004
|
+
inflight.delete(key);
|
|
1005
|
+
});
|
|
1006
|
+
inflight.set(key, pending);
|
|
1007
|
+
return pending;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
939
1010
|
// src/index.ts
|
|
940
1011
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
941
1012
|
var DWELL_POLL_MS = 5e3;
|
|
@@ -1977,6 +2048,32 @@ Available Console Commands:
|
|
|
1977
2048
|
*/
|
|
1978
2049
|
async fetchPageConfig(route, preview = false) {
|
|
1979
2050
|
const url = this.buildLayoutProviderUrl(route, preview);
|
|
2051
|
+
const pageSearch = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : null;
|
|
2052
|
+
const cacheKey = layoutProviderCacheKey({
|
|
2053
|
+
route,
|
|
2054
|
+
trackingId: this.getTrackingId(),
|
|
2055
|
+
instanceId: getInstanceId(),
|
|
2056
|
+
preview,
|
|
2057
|
+
working: pageSearch ? isWorkingContentRequest(pageSearch) : false,
|
|
2058
|
+
zoneId: pageSearch?.get("zoneId"),
|
|
2059
|
+
compositionId: pageSearch?.get("compositionId")
|
|
2060
|
+
});
|
|
2061
|
+
return dedupeLayoutProviderFetch(cacheKey, async () => {
|
|
2062
|
+
const startedAt = Date.now();
|
|
2063
|
+
sdkDebug("[AmplifyUp SDK] layout/provider request", {
|
|
2064
|
+
route,
|
|
2065
|
+
at: new Date(startedAt).toISOString()
|
|
2066
|
+
});
|
|
2067
|
+
const page = await this.fetchPageConfigUncached(url);
|
|
2068
|
+
sdkDebug("[AmplifyUp SDK] layout/provider response", {
|
|
2069
|
+
route,
|
|
2070
|
+
durationMs: Date.now() - startedAt,
|
|
2071
|
+
hasPage: !!page
|
|
2072
|
+
});
|
|
2073
|
+
return page;
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
async fetchPageConfigUncached(url) {
|
|
1980
2077
|
const response = await fetch(url);
|
|
1981
2078
|
if (!response.ok) {
|
|
1982
2079
|
if (response.status === 404) {
|
|
@@ -2335,6 +2432,12 @@ Available Console Commands:
|
|
|
2335
2432
|
);
|
|
2336
2433
|
return;
|
|
2337
2434
|
}
|
|
2435
|
+
if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
|
|
2436
|
+
window.dispatchEvent(
|
|
2437
|
+
new CustomEvent("amplifyup:layout-patch", { detail: event.data })
|
|
2438
|
+
);
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2338
2441
|
if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
|
|
2339
2442
|
const { componentId, deletable, nodeId } = event.data;
|
|
2340
2443
|
const element = document.querySelector(`[data-component-id="${componentId}"]`);
|
|
@@ -3375,6 +3478,13 @@ function getSDK(adapter) {
|
|
|
3375
3478
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3376
3479
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3377
3480
|
getSDK();
|
|
3481
|
+
function useComposerPreviewFlag(force = false) {
|
|
3482
|
+
const [detected, setDetected] = react.useState(false);
|
|
3483
|
+
react.useEffect(() => {
|
|
3484
|
+
if (!force && isComposerPreview()) setDetected(true);
|
|
3485
|
+
}, [force]);
|
|
3486
|
+
return force || detected;
|
|
3487
|
+
}
|
|
3378
3488
|
|
|
3379
3489
|
// src/composer-store.ts
|
|
3380
3490
|
var ComposerFieldStore = class {
|
|
@@ -3591,16 +3701,9 @@ function NodeWithFields({
|
|
|
3591
3701
|
renderComponent,
|
|
3592
3702
|
composerPreview
|
|
3593
3703
|
}) {
|
|
3594
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
enabled: !!(composerPreview || isComposerPreview()),
|
|
3598
|
-
layoutNodeId: nodeId,
|
|
3599
|
-
children: renderComponent(componentId, props, slots, {
|
|
3600
|
-
layoutNodeId: nodeId
|
|
3601
|
-
})
|
|
3602
|
-
}
|
|
3603
|
-
);
|
|
3704
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MaybeComposerProvider, { enabled: !!composerPreview, layoutNodeId: nodeId, children: renderComponent(componentId, props, slots, {
|
|
3705
|
+
layoutNodeId: nodeId
|
|
3706
|
+
}) });
|
|
3604
3707
|
}
|
|
3605
3708
|
function AmplifyRendererInner({
|
|
3606
3709
|
renderComponent,
|
|
@@ -3611,6 +3714,7 @@ function AmplifyRendererInner({
|
|
|
3611
3714
|
composerPreview
|
|
3612
3715
|
}) {
|
|
3613
3716
|
const clientHook = useAmplifyUp();
|
|
3717
|
+
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
3614
3718
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
3615
3719
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
3616
3720
|
const error = serverPageConfig ? null : clientHook.error;
|
|
@@ -3963,7 +4067,7 @@ function AmplifyRendererInner({
|
|
|
3963
4067
|
props: nodeRenderProps(node),
|
|
3964
4068
|
slots: slotsToPass,
|
|
3965
4069
|
renderComponent,
|
|
3966
|
-
composerPreview
|
|
4070
|
+
composerPreview: composerPreviewFlag
|
|
3967
4071
|
}
|
|
3968
4072
|
)
|
|
3969
4073
|
}
|
|
@@ -3976,7 +4080,7 @@ function AmplifyRendererInner({
|
|
|
3976
4080
|
if (layoutTree.length === 0) {
|
|
3977
4081
|
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." }) }) });
|
|
3978
4082
|
}
|
|
3979
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("main", { children:
|
|
4083
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreviewFlag ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3980
4084
|
"div",
|
|
3981
4085
|
{
|
|
3982
4086
|
"data-slot-id": "main",
|