@amplifyup/sdk 0.1.28 → 0.1.29
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.js.map +1 -1
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/react.d.mts +8 -28
- package/dist/react.d.ts +8 -28
- package/dist/react.js +44 -3
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +44 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
3
|
import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.mjs';
|
|
4
4
|
export { Z as ZoneConfig } from './types-BxpG9Gsy.mjs';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.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,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
3
|
import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.js';
|
|
4
4
|
export { Z as ZoneConfig } from './types-BxpG9Gsy.js';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.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
|
@@ -2774,6 +2774,16 @@ function useLiveComposerProps(layoutNodeId, props) {
|
|
|
2774
2774
|
}, [layoutNodeId]);
|
|
2775
2775
|
return live;
|
|
2776
2776
|
}
|
|
2777
|
+
function useComponentProps() {
|
|
2778
|
+
const context = react.useContext(ComponentContext);
|
|
2779
|
+
if (!context) {
|
|
2780
|
+
console.warn(
|
|
2781
|
+
"[AmplifyUp SDK] useComponentProps used outside ComponentContextProvider"
|
|
2782
|
+
);
|
|
2783
|
+
return {};
|
|
2784
|
+
}
|
|
2785
|
+
return context.props || {};
|
|
2786
|
+
}
|
|
2777
2787
|
function ComponentContextProvider({
|
|
2778
2788
|
children,
|
|
2779
2789
|
slots,
|
|
@@ -3053,6 +3063,33 @@ function formatFieldValue(value) {
|
|
|
3053
3063
|
}
|
|
3054
3064
|
return "";
|
|
3055
3065
|
}
|
|
3066
|
+
function isLinkListItem(value) {
|
|
3067
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
3068
|
+
}
|
|
3069
|
+
function renderLinkList(items, className) {
|
|
3070
|
+
const links = items.filter(isLinkListItem).filter((item) => {
|
|
3071
|
+
const label = typeof item.label === "string" ? item.label.trim() : "";
|
|
3072
|
+
const href = typeof item.href === "string" ? item.href.trim() : "";
|
|
3073
|
+
return !!(label || href);
|
|
3074
|
+
});
|
|
3075
|
+
if (links.length === 0) return null;
|
|
3076
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: links.map((item, index) => {
|
|
3077
|
+
const label = typeof item.label === "string" && item.label.trim() ? item.label : typeof item.href === "string" ? item.href : "Link";
|
|
3078
|
+
const href = typeof item.href === "string" && item.href.trim() ? item.href : "#";
|
|
3079
|
+
const style = typeof item.style === "string" ? item.style.trim() : "";
|
|
3080
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3081
|
+
"a",
|
|
3082
|
+
{
|
|
3083
|
+
href,
|
|
3084
|
+
target: item.openInNewTab ? "_blank" : void 0,
|
|
3085
|
+
rel: item.openInNewTab ? "noreferrer" : void 0,
|
|
3086
|
+
"data-amplifyup-action-style": style || void 0,
|
|
3087
|
+
children: label
|
|
3088
|
+
},
|
|
3089
|
+
typeof item._key === "string" && item._key ? item._key : `${href}-${index}`
|
|
3090
|
+
);
|
|
3091
|
+
}) });
|
|
3092
|
+
}
|
|
3056
3093
|
function Field({
|
|
3057
3094
|
name,
|
|
3058
3095
|
fallback,
|
|
@@ -3070,6 +3107,9 @@ function Field({
|
|
|
3070
3107
|
console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
|
|
3071
3108
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
3072
3109
|
}
|
|
3110
|
+
if (render) {
|
|
3111
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
|
|
3112
|
+
}
|
|
3073
3113
|
if (composerEdit && canInlineEdit(name, fieldValue)) {
|
|
3074
3114
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3075
3115
|
ComposerInlineField,
|
|
@@ -3078,7 +3118,6 @@ function Field({
|
|
|
3078
3118
|
value: fieldValue,
|
|
3079
3119
|
fallback,
|
|
3080
3120
|
className,
|
|
3081
|
-
render,
|
|
3082
3121
|
layoutNodeId: context.layoutNodeId,
|
|
3083
3122
|
componentId: context.componentId
|
|
3084
3123
|
}
|
|
@@ -3087,8 +3126,9 @@ function Field({
|
|
|
3087
3126
|
if (fieldValue === void 0 || fieldValue === null) {
|
|
3088
3127
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: fallback }) : null;
|
|
3089
3128
|
}
|
|
3090
|
-
if (
|
|
3091
|
-
|
|
3129
|
+
if (Array.isArray(fieldValue)) {
|
|
3130
|
+
const list = renderLinkList(fieldValue, className);
|
|
3131
|
+
if (list) return list;
|
|
3092
3132
|
}
|
|
3093
3133
|
const text = formatFieldValue(fieldValue);
|
|
3094
3134
|
if (!text) {
|
|
@@ -3876,6 +3916,7 @@ exports.fetchPageConfigServer = fetchPageConfigServer;
|
|
|
3876
3916
|
exports.isComposerPreview = isComposerPreview;
|
|
3877
3917
|
exports.isPreviewRequest = isPreviewRequest;
|
|
3878
3918
|
exports.useAmplifyUp = useAmplifyUp;
|
|
3919
|
+
exports.useComponentProps = useComponentProps;
|
|
3879
3920
|
exports.useLiveComposerProps = useLiveComposerProps;
|
|
3880
3921
|
//# sourceMappingURL=react.js.map
|
|
3881
3922
|
//# sourceMappingURL=react.js.map
|