@amplifyup/sdk 0.1.76 → 0.1.77

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/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
@@ -1095,9 +1095,8 @@ function dedupeLayoutProviderFetch(key, fetchFn) {
1095
1095
  return pending;
1096
1096
  }
1097
1097
  function previewLayoutReady(opts) {
1098
- if (opts.hasClientLayout) return true;
1099
- if (opts.clientLoading) return false;
1100
- return true;
1098
+ if (opts.hasClientLayout || opts.hasServerLayout) return true;
1099
+ return !opts.clientLoading;
1101
1100
  }
1102
1101
 
1103
1102
  // src/edge/variantKeys.ts
@@ -4016,14 +4015,16 @@ function applyComposerPatch(store, name, value, ref, layoutNodeId) {
4016
4015
  store.set(composerStoreKey(name, ref, layoutNodeId), value);
4017
4016
  }
4018
4017
  function ComposerProvider({
4019
- children
4018
+ children,
4019
+ enabled = true
4020
4020
  }) {
4021
4021
  const existing = React3.useContext(ComposerStoreContext);
4022
4022
  const storeRef = React3.useRef(null);
4023
4023
  if (!storeRef.current) storeRef.current = new ComposerFieldStore();
4024
- const store = existing || storeRef.current;
4024
+ const ownsStore = !existing && enabled;
4025
+ const store = existing || (enabled ? storeRef.current : null);
4025
4026
  React3.useEffect(() => {
4026
- if (existing) return;
4027
+ if (!ownsStore || !store) return;
4027
4028
  const applyField = (fieldName, value, nodeId, ref) => {
4028
4029
  if (!fieldName || typeof fieldName !== "string") return;
4029
4030
  const fieldRef = isFieldRef(ref) ? ref : void 0;
@@ -4081,8 +4082,7 @@ function ComposerProvider({
4081
4082
  window.removeEventListener("amplifyup:props-patch", onPropsPatch);
4082
4083
  window.removeEventListener("message", onMessage);
4083
4084
  };
4084
- }, [existing, store]);
4085
- if (existing) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
4085
+ }, [ownsStore, store]);
4086
4086
  return /* @__PURE__ */ jsxRuntime.jsx(ComposerStoreContext.Provider, { value: store, children });
4087
4087
  }
4088
4088
  function useComposerFieldValue(name, fallback, ref) {
@@ -4109,9 +4109,7 @@ function MaybeComposerProvider({
4109
4109
  layoutNodeId,
4110
4110
  children
4111
4111
  }) {
4112
- const content = React3.useMemo(() => children, [children]);
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 }) });
4112
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { enabled, children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: enabled ? layoutNodeId : void 0, children }) });
4115
4113
  }
4116
4114
  function nodeRenderProps(node) {
4117
4115
  const settings = node.settings || {};
@@ -4544,17 +4542,16 @@ function AmplifyRendererInner({
4544
4542
  if (layoutTree.length === 0) {
4545
4543
  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
4544
  }
4547
- return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreviewFlag ? /* @__PURE__ */ jsxRuntime.jsx(
4548
- "div",
4545
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
4546
+ "main",
4549
4547
  {
4550
- "data-slot-id": "main",
4551
- "data-amplifyup-slot": "main",
4552
- "data-slot-source": "page",
4553
- "data-slot-state": layoutTree.length === 0 ? "empty" : "filled",
4554
- "data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
4548
+ "data-slot-id": composerPreviewFlag ? "main" : void 0,
4549
+ "data-amplifyup-slot": composerPreviewFlag ? "main" : void 0,
4550
+ "data-slot-source": composerPreviewFlag ? "page" : void 0,
4551
+ "data-slot-state": composerPreviewFlag ? "filled" : void 0,
4555
4552
  children: layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React3.Fragment, { children: renderNode(node) }, node.id))
4556
4553
  }
4557
- ) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React3.Fragment, { children: renderNode(node) }, node.id)) }) });
4554
+ ) });
4558
4555
  }
4559
4556
  var AmplifyRenderer = React3.memo(AmplifyRendererInner);
4560
4557
  function AddComponentIcon({ size = 28 }) {
@@ -4730,11 +4727,14 @@ function AmplifyPageContent({
4730
4727
  if (preview) {
4731
4728
  const ready = previewLayoutReady({
4732
4729
  clientLoading: client.loading,
4733
- hasClientLayout: !!clientLayout});
4730
+ hasClientLayout: !!clientLayout,
4731
+ hasServerLayout: !!serverLayout
4732
+ });
4734
4733
  if (!ready) {
4735
4734
  return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: false, children: previewLoading });
4736
4735
  }
4737
- return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsxRuntime.jsx(
4736
+ const layoutSettled = !client.loading || !!clientLayout;
4737
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: layoutSettled, children: /* @__PURE__ */ jsxRuntime.jsx(
4738
4738
  AmplifyRenderer,
4739
4739
  {
4740
4740
  pageConfig: pageConfig ?? void 0,
@@ -4756,7 +4756,7 @@ function AmplifyPageContent({
4756
4756
  if (!hasAmplifyLayout(pageConfig)) {
4757
4757
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
4758
4758
  }
4759
- return /* @__PURE__ */ jsxRuntime.jsx(
4759
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerLayoutStatusProvider, { ready: true, children: /* @__PURE__ */ jsxRuntime.jsx(
4760
4760
  AmplifyRenderer,
4761
4761
  {
4762
4762
  pageConfig: pageConfig ?? void 0,
@@ -4765,7 +4765,7 @@ function AmplifyPageContent({
4765
4765
  emptyComponent,
4766
4766
  errorComponent
4767
4767
  }
4768
- );
4768
+ ) });
4769
4769
  }
4770
4770
 
4771
4771
  // src/slot-state.ts