@amplifyup/sdk 0.1.49 → 0.1.51

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.mjs CHANGED
@@ -3879,6 +3879,23 @@ function formatFieldValue(value) {
3879
3879
  }
3880
3880
  return "";
3881
3881
  }
3882
+ function warnProjectionProps(component, name, hasExplicitValue) {
3883
+ if (process.env.NODE_ENV === "production") return;
3884
+ if (hasExplicitValue && name) {
3885
+ console.warn(
3886
+ `[AmplifyUp SDK] ${component}: pass either value={\u2026} or deprecated name="\u2026", not both. Prefer value={\u2026} and omit name.`
3887
+ );
3888
+ return;
3889
+ }
3890
+ if (name) {
3891
+ console.warn(
3892
+ `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props and omit name.`
3893
+ );
3894
+ }
3895
+ }
3896
+ function hasOwnProp(props, key) {
3897
+ return Object.prototype.hasOwnProperty.call(props, key);
3898
+ }
3882
3899
  function isLinkListItem(value) {
3883
3900
  return !!value && typeof value === "object" && !Array.isArray(value);
3884
3901
  }
@@ -3906,21 +3923,23 @@ function renderLinkList(items, className) {
3906
3923
  );
3907
3924
  }) });
3908
3925
  }
3909
- function Field({
3910
- name,
3911
- fallback,
3912
- className,
3913
- render
3914
- }) {
3926
+ function Field(props) {
3927
+ const { value, name, fallback, className, render } = props;
3915
3928
  const context = useContext(ComponentContext);
3916
3929
  const composerEdit = useComposerEditMode();
3930
+ const hasExplicitValue = hasOwnProp(props, "value");
3931
+ const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
3932
+ const editName = hasExplicitValue ? "" : name || "";
3917
3933
  const fieldValue = useFieldOverlay(
3918
3934
  context?.layoutNodeId,
3919
- name,
3920
- context?.props?.[name]
3935
+ editName,
3936
+ sourceValue
3921
3937
  );
3922
- if (!context) {
3923
- console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
3938
+ warnProjectionProps("Field", name, hasExplicitValue);
3939
+ if (!context && !hasExplicitValue) {
3940
+ console.warn(
3941
+ "[AmplifyUp SDK] Field needs a `value` prop (or deprecated `name` alone)"
3942
+ );
3924
3943
  return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3925
3944
  }
3926
3945
  if (render) {
@@ -3933,11 +3952,11 @@ function Field({
3933
3952
  const text = formatFieldValue(fieldValue);
3934
3953
  const showVisualFallback = !text && isReactNodeFallback(fallback);
3935
3954
  const emptyBlockField = isComposerEmptyText(fieldValue) && classNameIsBlock(className);
3936
- if (composerEdit && canInlineEdit(name, fieldValue) && !showVisualFallback && !emptyBlockField) {
3955
+ if (composerEdit && editName && context && canInlineEdit(editName, fieldValue) && !showVisualFallback && !emptyBlockField) {
3937
3956
  return /* @__PURE__ */ jsx(
3938
3957
  ComposerInlineField,
3939
3958
  {
3940
- name,
3959
+ name: editName,
3941
3960
  value: fieldValue,
3942
3961
  fallback,
3943
3962
  className,
@@ -3962,34 +3981,46 @@ function markdownToHtml(markdown) {
3962
3981
  return markdown;
3963
3982
  }
3964
3983
  }
3965
- function RichText({
3966
- name,
3967
- fallback,
3968
- className,
3969
- as: Tag = "div"
3970
- }) {
3984
+ function RichText(props) {
3985
+ const {
3986
+ value,
3987
+ name,
3988
+ fallback,
3989
+ className,
3990
+ as: Tag = "div",
3991
+ children
3992
+ } = props;
3971
3993
  const context = useContext(ComponentContext);
3972
3994
  const composerEdit = useComposerEditMode();
3995
+ const childrenValue = typeof children === "string" || typeof children === "number" ? String(children) : void 0;
3996
+ const hasValueProp = hasOwnProp(props, "value");
3997
+ const hasExplicitValue = hasValueProp || childrenValue !== void 0;
3998
+ const sourceValue = hasValueProp ? value : childrenValue !== void 0 ? childrenValue : name ? context?.props?.[name] : void 0;
3999
+ const editName = hasExplicitValue ? "" : name || "";
3973
4000
  const fieldValue = useFieldOverlay(
3974
4001
  context?.layoutNodeId,
3975
- name,
3976
- context?.props?.[name]
4002
+ editName,
4003
+ sourceValue
3977
4004
  );
3978
- if (!context) {
3979
- console.warn(`[AmplifyUp SDK] RichText "${name}" used outside ComponentContextProvider`);
4005
+ if (!context && !hasExplicitValue) {
4006
+ console.warn(
4007
+ "[AmplifyUp SDK] RichText needs a `value` prop (or string children), or deprecated `name` alone"
4008
+ );
3980
4009
  return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3981
4010
  }
4011
+ warnProjectionProps("RichText", name, hasExplicitValue);
4012
+ const canEdit = !!editName && !!context && canInlineEdit(editName, fieldValue);
3982
4013
  if (isComposerEmptyText(fieldValue)) {
3983
- if (composerEdit && canInlineEdit(name, fieldValue) && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
4014
+ if (composerEdit && canEdit && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
3984
4015
  return /* @__PURE__ */ jsx(
3985
4016
  ComposerInlineField,
3986
4017
  {
3987
- name,
4018
+ name: editName,
3988
4019
  value: fieldValue,
3989
4020
  fallback: typeof fallback === "string" || typeof fallback === "number" ? fallback : void 0,
3990
4021
  className,
3991
- layoutNodeId: context.layoutNodeId,
3992
- componentId: context.componentId
4022
+ layoutNodeId: context?.layoutNodeId,
4023
+ componentId: context?.componentId
3993
4024
  }
3994
4025
  );
3995
4026
  }
@@ -4015,22 +4046,22 @@ function RichText({
4015
4046
  Tag,
4016
4047
  {
4017
4048
  className,
4018
- "data-amplifyup-field": name,
4019
- "data-amplifyup-node-id": context.layoutNodeId || void 0,
4049
+ "data-amplifyup-field": editName || void 0,
4050
+ "data-amplifyup-node-id": context?.layoutNodeId || void 0,
4020
4051
  dangerouslySetInnerHTML: { __html: html }
4021
4052
  }
4022
4053
  );
4023
4054
  }
4024
- if (composerEdit && canInlineEdit(name, fieldValue)) {
4055
+ if (composerEdit && canEdit) {
4025
4056
  return /* @__PURE__ */ jsx(
4026
4057
  ComposerInlineHtml,
4027
4058
  {
4028
- name,
4059
+ name: editName,
4029
4060
  html,
4030
4061
  className,
4031
4062
  Tag,
4032
- layoutNodeId: context.layoutNodeId,
4033
- componentId: context.componentId
4063
+ layoutNodeId: context?.layoutNodeId,
4064
+ componentId: context?.componentId
4034
4065
  }
4035
4066
  );
4036
4067
  }
@@ -4046,23 +4077,28 @@ function imageSrc(value) {
4046
4077
  if (isPortableImageValue(value)) return value.url.trim();
4047
4078
  return "";
4048
4079
  }
4049
- function Image({
4050
- name,
4051
- alt: altProp,
4052
- className,
4053
- width: widthProp,
4054
- height: heightProp,
4055
- ...imgProps
4056
- }) {
4080
+ function Image(props) {
4081
+ const {
4082
+ value,
4083
+ name,
4084
+ alt: altProp,
4085
+ className,
4086
+ width: widthProp,
4087
+ height: heightProp,
4088
+ ...imgProps
4089
+ } = props;
4057
4090
  const context = useContext(ComponentContext);
4091
+ const hasExplicitValue = hasOwnProp(props, "value");
4092
+ const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
4058
4093
  const fieldValue = useFieldOverlay(
4059
4094
  context?.layoutNodeId,
4060
- name,
4061
- context?.props?.[name]
4095
+ hasExplicitValue ? "" : name || "",
4096
+ sourceValue
4062
4097
  );
4063
- if (!context) {
4098
+ warnProjectionProps("Image", name, hasExplicitValue);
4099
+ if (!context && !hasExplicitValue) {
4064
4100
  console.warn(
4065
- `[AmplifyUp SDK] Image "${name}" used outside ComponentContextProvider`
4101
+ "[AmplifyUp SDK] Image needs a `value` prop (or deprecated `name` alone)"
4066
4102
  );
4067
4103
  return null;
4068
4104
  }