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