@amplifyup/sdk 0.1.55 → 0.1.56

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
@@ -90,8 +90,8 @@ declare function Field(props: {
90
90
  /** Field value from your component props. Do not also pass `name`. */
91
91
  value?: unknown;
92
92
  /**
93
- * @deprecated Will be removed. Use `value={…}` instead and omit `name`.
94
- * Do not pass `name` together with `value`.
93
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
94
+ * the same value appears on more than one prop.
95
95
  */
96
96
  name?: string;
97
97
  fallback?: ReactNode;
@@ -120,8 +120,8 @@ declare function RichText(props: {
120
120
  /** Markdown (or HTML) string from your component props. Do not also pass `name`. */
121
121
  value?: string | null;
122
122
  /**
123
- * @deprecated Will be removed. Use `value={…}` (or string children) and omit `name`.
124
- * Do not pass `name` together with `value`.
123
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
124
+ * the same value appears on more than one prop.
125
125
  */
126
126
  name?: string;
127
127
  fallback?: ReactNode;
package/dist/react.d.ts CHANGED
@@ -90,8 +90,8 @@ declare function Field(props: {
90
90
  /** Field value from your component props. Do not also pass `name`. */
91
91
  value?: unknown;
92
92
  /**
93
- * @deprecated Will be removed. Use `value={…}` instead and omit `name`.
94
- * Do not pass `name` together with `value`.
93
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
94
+ * the same value appears on more than one prop.
95
95
  */
96
96
  name?: string;
97
97
  fallback?: ReactNode;
@@ -120,8 +120,8 @@ declare function RichText(props: {
120
120
  /** Markdown (or HTML) string from your component props. Do not also pass `name`. */
121
121
  value?: string | null;
122
122
  /**
123
- * @deprecated Will be removed. Use `value={…}` (or string children) and omit `name`.
124
- * Do not pass `name` together with `value`.
123
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
124
+ * the same value appears on more than one prop.
125
125
  */
126
126
  name?: string;
127
127
  fallback?: ReactNode;
package/dist/react.js CHANGED
@@ -3685,13 +3685,31 @@ function htmlHasVisualChrome(html) {
3685
3685
  );
3686
3686
  }
3687
3687
  function canInlineEdit(name, value) {
3688
- if (isLikelyNonTextFieldName(name)) return false;
3688
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3689
3689
  if (value !== void 0 && value !== null && typeof value === "object") {
3690
3690
  return false;
3691
3691
  }
3692
3692
  if (typeof value === "boolean") return false;
3693
3693
  return true;
3694
3694
  }
3695
+ function canInlineEditRichText(name, value) {
3696
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3697
+ if (typeof value === "boolean") return false;
3698
+ if (value !== void 0 && value !== null && typeof value === "object" && !Array.isArray(value)) {
3699
+ return false;
3700
+ }
3701
+ return true;
3702
+ }
3703
+ function inferEditName(explicitName, contextProps, sourceValue) {
3704
+ if (explicitName) return explicitName;
3705
+ if (!contextProps) return "";
3706
+ const keys = Object.keys(contextProps).filter(
3707
+ (key) => Object.is(contextProps[key], sourceValue)
3708
+ );
3709
+ if (keys.length === 1) return keys[0];
3710
+ if (keys.length === 0 || isComposerEmptyText(sourceValue)) return "";
3711
+ return keys[0];
3712
+ }
3695
3713
  function subscribeComposerEdit(onStoreChange) {
3696
3714
  if (typeof window === "undefined") return () => {
3697
3715
  };
@@ -3886,9 +3904,11 @@ function ComposerInlineHtml({
3886
3904
  const finishEdit = () => {
3887
3905
  const el = elRef.current;
3888
3906
  if (!el) return;
3889
- const next = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
3890
- if (next.trim() === sourceTextRef.current) return;
3891
- commitComposerField(layoutNodeId, componentId, name, next.trim());
3907
+ const nextHtml = el.innerHTML;
3908
+ const nextText = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "").trim();
3909
+ if (nextText === sourceTextRef.current && nextHtml === html) return;
3910
+ const commitValue = htmlHasVisualChrome(html) || /<[a-z][\s\S]*>/i.test(html) ? nextHtml : nextText;
3911
+ commitComposerField(layoutNodeId, componentId, name, commitValue);
3892
3912
  };
3893
3913
  return React__default.default.createElement(Tag, {
3894
3914
  ref: elRef,
@@ -3930,15 +3950,10 @@ function formatFieldValue(value) {
3930
3950
  }
3931
3951
  function warnProjectionProps(component, name, hasExplicitValue) {
3932
3952
  if (process.env.NODE_ENV === "production") return;
3933
- if (hasExplicitValue && name) {
3934
- console.warn(
3935
- `[AmplifyUp SDK] ${component}: pass either value={\u2026} or deprecated name="\u2026", not both. Prefer value={\u2026} and omit name.`
3936
- );
3937
- return;
3938
- }
3953
+ if (hasExplicitValue) return;
3939
3954
  if (name) {
3940
3955
  console.warn(
3941
- `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props and omit name.`
3956
+ `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props.`
3942
3957
  );
3943
3958
  }
3944
3959
  }
@@ -3978,7 +3993,7 @@ function Field(props) {
3978
3993
  const composerEdit = useComposerEditMode();
3979
3994
  const hasExplicitValue = hasOwnProp(props, "value");
3980
3995
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
3981
- const editName = hasExplicitValue ? "" : name || "";
3996
+ const editName = inferEditName(name, context?.props, sourceValue);
3982
3997
  const fieldValue = useFieldOverlay(
3983
3998
  context?.layoutNodeId,
3984
3999
  editName,
@@ -3992,6 +4007,20 @@ function Field(props) {
3992
4007
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
3993
4008
  }
3994
4009
  if (render) {
4010
+ if (composerEdit && editName && context && canInlineEdit(editName, fieldValue)) {
4011
+ return /* @__PURE__ */ jsxRuntime.jsx(
4012
+ ComposerInlineField,
4013
+ {
4014
+ name: editName,
4015
+ value: fieldValue,
4016
+ fallback,
4017
+ className,
4018
+ render,
4019
+ layoutNodeId: context.layoutNodeId,
4020
+ componentId: context.componentId
4021
+ }
4022
+ );
4023
+ }
3995
4024
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
3996
4025
  }
3997
4026
  if (Array.isArray(fieldValue)) {
@@ -4045,7 +4074,7 @@ function RichText(props) {
4045
4074
  const hasValueProp = hasOwnProp(props, "value");
4046
4075
  const hasExplicitValue = hasValueProp || childrenValue !== void 0;
4047
4076
  const sourceValue = hasValueProp ? value : childrenValue !== void 0 ? childrenValue : name ? context?.props?.[name] : void 0;
4048
- const editName = hasExplicitValue ? "" : name || "";
4077
+ const editName = inferEditName(name, context?.props, sourceValue);
4049
4078
  const fieldValue = useFieldOverlay(
4050
4079
  context?.layoutNodeId,
4051
4080
  editName,
@@ -4058,7 +4087,7 @@ function RichText(props) {
4058
4087
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
4059
4088
  }
4060
4089
  warnProjectionProps("RichText", name, hasExplicitValue);
4061
- const canEdit = !!editName && !!context && canInlineEdit(editName, fieldValue);
4090
+ const canEdit = !!context && canInlineEditRichText(editName, fieldValue);
4062
4091
  if (isComposerEmptyText(fieldValue)) {
4063
4092
  if (composerEdit && canEdit && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
4064
4093
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -4090,17 +4119,6 @@ function RichText(props) {
4090
4119
  if (!html) {
4091
4120
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(Tag, { className, children: fallback }) : null;
4092
4121
  }
4093
- if (composerEdit && htmlHasVisualChrome(html)) {
4094
- return /* @__PURE__ */ jsxRuntime.jsx(
4095
- Tag,
4096
- {
4097
- className,
4098
- "data-amplifyup-field": editName || void 0,
4099
- "data-amplifyup-node-id": context?.layoutNodeId || void 0,
4100
- dangerouslySetInnerHTML: { __html: html }
4101
- }
4102
- );
4103
- }
4104
4122
  if (composerEdit && canEdit) {
4105
4123
  return /* @__PURE__ */ jsxRuntime.jsx(
4106
4124
  ComposerInlineHtml,
@@ -4141,7 +4159,7 @@ function Image(props) {
4141
4159
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
4142
4160
  const fieldValue = useFieldOverlay(
4143
4161
  context?.layoutNodeId,
4144
- hasExplicitValue ? "" : name || "",
4162
+ inferEditName(name, context?.props, sourceValue),
4145
4163
  sourceValue
4146
4164
  );
4147
4165
  warnProjectionProps("Image", name, hasExplicitValue);