@amplifyup/sdk 0.1.28 → 0.1.30

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
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.mjs';
4
- export { Z as ZoneConfig } from './types-BxpG9Gsy.mjs';
2
+ import React, { ReactNode } from 'react';
3
+ import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-6qEnwLda.mjs';
4
+ export { Z as ZoneConfig } from './types-6qEnwLda.mjs';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.mjs';
6
6
  export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
7
7
  export { fetchPageConfigServer } from './server.mjs';
@@ -41,6 +41,11 @@ interface AmplifyPageContentProps {
41
41
  declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, forceComposerPreview, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
43
  declare function useLiveComposerProps(layoutNodeId: string | undefined, props: Record<string, any>): Record<string, any>;
44
+ /**
45
+ * Live props for this layout node (CMS fields + settings).
46
+ * Same values `<Field>` reads — use this when you want to render yourself.
47
+ */
48
+ declare function useComponentProps<T extends Record<string, any> = Record<string, any>>(): T;
44
49
  declare function ComponentContextProvider({ children, slots, props, layoutNodeId, componentId, }: {
45
50
  children: ReactNode;
46
51
  slots?: Record<string, ReactNode>;
@@ -78,37 +83,12 @@ declare function Slot({ name, className, }: {
78
83
  name: string;
79
84
  className?: string;
80
85
  }): react_jsx_runtime.JSX.Element | null;
81
- /**
82
- * Field Component
83
- *
84
- * Renders a field value from component props. Developers use this to define
85
- * where field values should appear in their component, with full control
86
- * over styling and formatting.
87
- *
88
- * For markdown / rich text fields, use {@link RichText} instead.
89
- *
90
- * @example
91
- * ```tsx
92
- * function Hero({ title, description }) {
93
- * return (
94
- * <section className="hero">
95
- * <h1>
96
- * <Field name="title" fallback="Default Title" />
97
- * </h1>
98
- * <p>
99
- * <Field name="description" />
100
- * </p>
101
- * </section>
102
- * );
103
- * }
104
- * ```
105
- */
106
86
  declare function Field({ name, fallback, className, render, }: {
107
87
  name: string;
108
88
  fallback?: ReactNode;
109
89
  className?: string;
110
90
  render?: (value: any) => ReactNode;
111
- }): react_jsx_runtime.JSX.Element | null;
91
+ }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
112
92
  /**
113
93
  * RichText - Renders a markdown (or HTML string) field as formatted HTML.
114
94
  *
@@ -141,4 +121,4 @@ interface AmplifyUpProviderProps {
141
121
  declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
142
122
  declare function useAmplifyUp(): AmplifyUpContextType;
143
123
 
144
- export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, RichText, Slot, useAmplifyUp, useLiveComposerProps };
124
+ export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, RichText, Slot, useAmplifyUp, useComponentProps, useLiveComposerProps };
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.js';
4
- export { Z as ZoneConfig } from './types-BxpG9Gsy.js';
2
+ import React, { ReactNode } from 'react';
3
+ import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-6qEnwLda.js';
4
+ export { Z as ZoneConfig } from './types-6qEnwLda.js';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.js';
6
6
  export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
7
7
  export { fetchPageConfigServer } from './server.js';
@@ -41,6 +41,11 @@ interface AmplifyPageContentProps {
41
41
  declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, forceComposerPreview, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
43
  declare function useLiveComposerProps(layoutNodeId: string | undefined, props: Record<string, any>): Record<string, any>;
44
+ /**
45
+ * Live props for this layout node (CMS fields + settings).
46
+ * Same values `<Field>` reads — use this when you want to render yourself.
47
+ */
48
+ declare function useComponentProps<T extends Record<string, any> = Record<string, any>>(): T;
44
49
  declare function ComponentContextProvider({ children, slots, props, layoutNodeId, componentId, }: {
45
50
  children: ReactNode;
46
51
  slots?: Record<string, ReactNode>;
@@ -78,37 +83,12 @@ declare function Slot({ name, className, }: {
78
83
  name: string;
79
84
  className?: string;
80
85
  }): react_jsx_runtime.JSX.Element | null;
81
- /**
82
- * Field Component
83
- *
84
- * Renders a field value from component props. Developers use this to define
85
- * where field values should appear in their component, with full control
86
- * over styling and formatting.
87
- *
88
- * For markdown / rich text fields, use {@link RichText} instead.
89
- *
90
- * @example
91
- * ```tsx
92
- * function Hero({ title, description }) {
93
- * return (
94
- * <section className="hero">
95
- * <h1>
96
- * <Field name="title" fallback="Default Title" />
97
- * </h1>
98
- * <p>
99
- * <Field name="description" />
100
- * </p>
101
- * </section>
102
- * );
103
- * }
104
- * ```
105
- */
106
86
  declare function Field({ name, fallback, className, render, }: {
107
87
  name: string;
108
88
  fallback?: ReactNode;
109
89
  className?: string;
110
90
  render?: (value: any) => ReactNode;
111
- }): react_jsx_runtime.JSX.Element | null;
91
+ }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
112
92
  /**
113
93
  * RichText - Renders a markdown (or HTML string) field as formatted HTML.
114
94
  *
@@ -141,4 +121,4 @@ interface AmplifyUpProviderProps {
141
121
  declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
142
122
  declare function useAmplifyUp(): AmplifyUpContextType;
143
123
 
144
- export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, RichText, Slot, useAmplifyUp, useLiveComposerProps };
124
+ export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, RichText, Slot, useAmplifyUp, useComponentProps, useLiveComposerProps };
package/dist/react.js CHANGED
@@ -442,7 +442,8 @@ function mapResolvedToPageConfig(payload) {
442
442
  meta: {
443
443
  // Stash edge meta for diagnostics (not visitor-facing)
444
444
  description: payload.meta?.degraded ? "degraded" : void 0
445
- }
445
+ },
446
+ ...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {}
446
447
  };
447
448
  }
448
449
  function collectDegraded(payload) {
@@ -2774,6 +2775,16 @@ function useLiveComposerProps(layoutNodeId, props) {
2774
2775
  }, [layoutNodeId]);
2775
2776
  return live;
2776
2777
  }
2778
+ function useComponentProps() {
2779
+ const context = react.useContext(ComponentContext);
2780
+ if (!context) {
2781
+ console.warn(
2782
+ "[AmplifyUp SDK] useComponentProps used outside ComponentContextProvider"
2783
+ );
2784
+ return {};
2785
+ }
2786
+ return context.props || {};
2787
+ }
2777
2788
  function ComponentContextProvider({
2778
2789
  children,
2779
2790
  slots,
@@ -3053,6 +3064,33 @@ function formatFieldValue(value) {
3053
3064
  }
3054
3065
  return "";
3055
3066
  }
3067
+ function isLinkListItem(value) {
3068
+ return !!value && typeof value === "object" && !Array.isArray(value);
3069
+ }
3070
+ function renderLinkList(items, className) {
3071
+ const links = items.filter(isLinkListItem).filter((item) => {
3072
+ const label = typeof item.label === "string" ? item.label.trim() : "";
3073
+ const href = typeof item.href === "string" ? item.href.trim() : "";
3074
+ return !!(label || href);
3075
+ });
3076
+ if (links.length === 0) return null;
3077
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: links.map((item, index) => {
3078
+ const label = typeof item.label === "string" && item.label.trim() ? item.label : typeof item.href === "string" ? item.href : "Link";
3079
+ const href = typeof item.href === "string" && item.href.trim() ? item.href : "#";
3080
+ const style = typeof item.style === "string" ? item.style.trim() : "";
3081
+ return /* @__PURE__ */ jsxRuntime.jsx(
3082
+ "a",
3083
+ {
3084
+ href,
3085
+ target: item.openInNewTab ? "_blank" : void 0,
3086
+ rel: item.openInNewTab ? "noreferrer" : void 0,
3087
+ "data-amplifyup-action-style": style || void 0,
3088
+ children: label
3089
+ },
3090
+ typeof item._key === "string" && item._key ? item._key : `${href}-${index}`
3091
+ );
3092
+ }) });
3093
+ }
3056
3094
  function Field({
3057
3095
  name,
3058
3096
  fallback,
@@ -3070,6 +3108,9 @@ function Field({
3070
3108
  console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
3071
3109
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
3072
3110
  }
3111
+ if (render) {
3112
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
3113
+ }
3073
3114
  if (composerEdit && canInlineEdit(name, fieldValue)) {
3074
3115
  return /* @__PURE__ */ jsxRuntime.jsx(
3075
3116
  ComposerInlineField,
@@ -3078,7 +3119,6 @@ function Field({
3078
3119
  value: fieldValue,
3079
3120
  fallback,
3080
3121
  className,
3081
- render,
3082
3122
  layoutNodeId: context.layoutNodeId,
3083
3123
  componentId: context.componentId
3084
3124
  }
@@ -3087,8 +3127,9 @@ function Field({
3087
3127
  if (fieldValue === void 0 || fieldValue === null) {
3088
3128
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: fallback }) : null;
3089
3129
  }
3090
- if (render) {
3091
- return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: render(fieldValue) });
3130
+ if (Array.isArray(fieldValue)) {
3131
+ const list = renderLinkList(fieldValue, className);
3132
+ if (list) return list;
3092
3133
  }
3093
3134
  const text = formatFieldValue(fieldValue);
3094
3135
  if (!text) {
@@ -3270,7 +3311,7 @@ function AmplifyRenderer({
3270
3311
  window.clearTimeout(t1);
3271
3312
  window.clearTimeout(t2);
3272
3313
  };
3273
- }, [pageConfig?.id]);
3314
+ }, [pageConfig?.id, pageConfig?.eventTracking]);
3274
3315
  react.useEffect(() => {
3275
3316
  if (!pageConfig) return;
3276
3317
  const t = window.setTimeout(() => {
@@ -3876,6 +3917,7 @@ exports.fetchPageConfigServer = fetchPageConfigServer;
3876
3917
  exports.isComposerPreview = isComposerPreview;
3877
3918
  exports.isPreviewRequest = isPreviewRequest;
3878
3919
  exports.useAmplifyUp = useAmplifyUp;
3920
+ exports.useComponentProps = useComponentProps;
3879
3921
  exports.useLiveComposerProps = useLiveComposerProps;
3880
3922
  //# sourceMappingURL=react.js.map
3881
3923
  //# sourceMappingURL=react.js.map