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