@amplifyup/sdk 0.1.26 → 0.1.28

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.
@@ -1612,6 +1612,12 @@ Available Console Commands:
1612
1612
  return;
1613
1613
  }
1614
1614
  try {
1615
+ if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
1616
+ window.dispatchEvent(
1617
+ new CustomEvent("amplifyup:field-patch", { detail: event.data })
1618
+ );
1619
+ return;
1620
+ }
1615
1621
  if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
1616
1622
  const { componentId, deletable, nodeId } = event.data;
1617
1623
  const element = document.querySelector(`[data-component-id="${componentId}"]`);
@@ -1798,6 +1804,10 @@ Available Console Commands:
1798
1804
  setEventSelectionMode(enabled) {
1799
1805
  if (typeof document === "undefined") return;
1800
1806
  this.eventSelectionMode = enabled;
1807
+ if (typeof window !== "undefined") {
1808
+ window.__AMPLIFYUP_EVENT_SELECTION__ = enabled;
1809
+ window.dispatchEvent(new CustomEvent("amplifyup:composer-edit"));
1810
+ }
1801
1811
  if (this.eventSelectionClickHandler) {
1802
1812
  document.removeEventListener("click", this.eventSelectionClickHandler, true);
1803
1813
  this.eventSelectionClickHandler = null;
@@ -2035,6 +2045,14 @@ Available Console Commands:
2035
2045
  el.classList.add("amplifyup-selected");
2036
2046
  }
2037
2047
  });
2048
+ if (typeof window !== "undefined") {
2049
+ window.__AMPLIFYUP_COMPOSER_EDIT__ = highlightComponents;
2050
+ window.dispatchEvent(
2051
+ new CustomEvent("amplifyup:composer-edit", {
2052
+ detail: { enabled: highlightComponents }
2053
+ })
2054
+ );
2055
+ }
2038
2056
  }
2039
2057
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
2040
2058
  setupComposerDragDrop() {
@@ -2343,6 +2361,12 @@ Available Console Commands:
2343
2361
  const clearSelection = opts?.clearSelection !== false;
2344
2362
  this.highlightingEnabled = false;
2345
2363
  this.teardownComposerDragDrop();
2364
+ if (opts?.clearSelection !== false && typeof window !== "undefined") {
2365
+ window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
2366
+ window.dispatchEvent(
2367
+ new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
2368
+ );
2369
+ }
2346
2370
  if (this.mutationObserver) {
2347
2371
  this.mutationObserver.disconnect();
2348
2372
  this.mutationObserver = null;
@@ -2549,6 +2573,36 @@ var trackContentView = (contentId, contentType, properties) => getSDK().trackCon
2549
2573
  var refreshEventTracking = () => getSDK().refreshEventTracking();
2550
2574
  getSDK();
2551
2575
  react.createContext(null);
2576
+ function useLiveComposerProps(layoutNodeId, props) {
2577
+ const [live, setLive] = react.useState(props);
2578
+ react.useEffect(() => {
2579
+ setLive(props);
2580
+ }, [props]);
2581
+ react.useEffect(() => {
2582
+ const apply = (fieldName, value, nodeId) => {
2583
+ if (!fieldName || typeof fieldName !== "string") return;
2584
+ if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
2585
+ return;
2586
+ }
2587
+ setLive((prev) => ({ ...prev, [fieldName]: value }));
2588
+ };
2589
+ const onPatch = (event) => {
2590
+ const detail = event.detail || {};
2591
+ apply(detail.fieldName, detail.value, detail.layoutNodeId);
2592
+ };
2593
+ const onMessage = (event) => {
2594
+ if (event.data?.type !== "AMPLIFYUP_FIELD_PATCH") return;
2595
+ apply(event.data.fieldName, event.data.value, event.data.layoutNodeId);
2596
+ };
2597
+ window.addEventListener("amplifyup:field-patch", onPatch);
2598
+ window.addEventListener("message", onMessage);
2599
+ return () => {
2600
+ window.removeEventListener("amplifyup:field-patch", onPatch);
2601
+ window.removeEventListener("message", onMessage);
2602
+ };
2603
+ }, [layoutNodeId]);
2604
+ return live;
2605
+ }
2552
2606
  var usePathname = null;
2553
2607
  if (typeof window !== "undefined") {
2554
2608
  try {
@@ -2614,6 +2668,18 @@ var ComponentRenderBoundary = class extends react.Component {
2614
2668
  return this.props.children;
2615
2669
  }
2616
2670
  };
2671
+ function LiveNodeRender({
2672
+ nodeId,
2673
+ componentId,
2674
+ props,
2675
+ slots,
2676
+ renderComponent
2677
+ }) {
2678
+ const liveProps = useLiveComposerProps(nodeId, props);
2679
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderComponent(componentId, liveProps, slots, {
2680
+ layoutNodeId: nodeId
2681
+ }) });
2682
+ }
2617
2683
  function AmplifyRenderer({
2618
2684
  renderComponent,
2619
2685
  pageConfig: serverPageConfig,
@@ -2968,20 +3034,21 @@ function AmplifyRenderer({
2968
3034
  }
2969
3035
  }
2970
3036
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
2971
- console.log(`[AmplifyRenderer] Calling renderComponent for ${node.componentId}`, {
2972
- hasSlots: !!slotsToPass,
2973
- slotKeys: slotsToPass ? Object.keys(slotsToPass) : [],
2974
- propKeys: Object.keys(node.props || {}),
2975
- props: node.props || {}
2976
- });
2977
3037
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-node-id": node.id, "data-amplifyup-node": "", children: /* @__PURE__ */ jsxRuntime.jsx(
2978
3038
  ComponentRenderBoundary,
2979
3039
  {
2980
3040
  componentId: node.componentId,
2981
3041
  nodeId: node.id,
2982
- children: renderComponent(node.componentId, node.props || {}, slotsToPass, {
2983
- layoutNodeId: node.id
2984
- })
3042
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3043
+ LiveNodeRender,
3044
+ {
3045
+ nodeId: node.id,
3046
+ componentId: node.componentId,
3047
+ props: node.props || {},
3048
+ slots: slotsToPass,
3049
+ renderComponent
3050
+ }
3051
+ )
2985
3052
  }
2986
3053
  ) });
2987
3054
  };