@amplifyup/sdk 0.1.57 → 0.1.58

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
@@ -3698,11 +3698,6 @@ function isReactNodeFallback(fallback) {
3698
3698
  function classNameIsBlock(className) {
3699
3699
  return /(?:^|\s)block(?:\s|$)/.test(className || "");
3700
3700
  }
3701
- function htmlHasVisualChrome(html) {
3702
- return /<(input|button|select|textarea|form|svg|iframe|video|audio|img)\b/i.test(
3703
- html
3704
- );
3705
- }
3706
3701
  function canInlineEdit(name, value) {
3707
3702
  if (!name || isLikelyNonTextFieldName(name)) return false;
3708
3703
  if (value !== void 0 && value !== null && typeof value === "object") {
@@ -3771,6 +3766,36 @@ function commitComposerField(layoutNodeId, componentId, name, value) {
3771
3766
  "*"
3772
3767
  );
3773
3768
  }
3769
+ function looksLikeRichCanvasField(name) {
3770
+ const tokens = String(name || "").replace(/([a-z])([A-Z])/g, "$1 $2").split(/[._\-\s/]+/).map((s) => s.toLowerCase()).filter(Boolean);
3771
+ const last = tokens[tokens.length - 1] || "";
3772
+ return last === "body" || last === "content" || last === "copy" || last === "excerpt" || last === "markdown" || last === "richtext";
3773
+ }
3774
+ var lastRichTextRequestAt = 0;
3775
+ function requestCanvasRichTextEdit(opts) {
3776
+ if (typeof window === "undefined" || window.parent === window) return;
3777
+ if (!opts.name) return;
3778
+ const now = Date.now();
3779
+ if (now - lastRichTextRequestAt < 400) return;
3780
+ lastRichTextRequestAt = now;
3781
+ const rect = opts.el.getBoundingClientRect();
3782
+ window.parent.postMessage(
3783
+ {
3784
+ type: "AMPLIFYUP_RICHTEXT_EDIT",
3785
+ layoutNodeId: opts.layoutNodeId,
3786
+ componentId: opts.componentId,
3787
+ fieldName: opts.name,
3788
+ value: opts.value,
3789
+ bounds: {
3790
+ top: rect.top,
3791
+ left: rect.left,
3792
+ width: Math.max(rect.width, 240),
3793
+ height: Math.max(rect.height, 64)
3794
+ }
3795
+ },
3796
+ "*"
3797
+ );
3798
+ }
3774
3799
  function placeCaret(el, atStart = false) {
3775
3800
  const range = document.createRange();
3776
3801
  range.selectNodeContents(el);
@@ -3786,7 +3811,8 @@ function ComposerInlineField({
3786
3811
  className,
3787
3812
  render,
3788
3813
  layoutNodeId,
3789
- componentId
3814
+ componentId,
3815
+ rich = false
3790
3816
  }) {
3791
3817
  const [editing, setEditing] = React.useState(false);
3792
3818
  const [focused, setFocused] = React.useState(false);
@@ -3839,6 +3865,19 @@ function ComposerInlineField({
3839
3865
  if (!text && !storedEmpty && next === fallbackText) return;
3840
3866
  commitComposerField(layoutNodeId, componentId, name, next);
3841
3867
  };
3868
+ const openRichEditor = (event) => {
3869
+ if (!isComposerEditMode() || !elRef.current) return;
3870
+ event?.preventDefault();
3871
+ event?.stopPropagation();
3872
+ const source = typeof value === "string" && !storedEmpty ? value : text || "";
3873
+ requestCanvasRichTextEdit({
3874
+ el: elRef.current,
3875
+ layoutNodeId,
3876
+ componentId,
3877
+ name,
3878
+ value: source
3879
+ });
3880
+ };
3842
3881
  return /* @__PURE__ */ jsxRuntime.jsx(
3843
3882
  "span",
3844
3883
  {
@@ -3847,7 +3886,7 @@ function ComposerInlineField({
3847
3886
  "data-amplifyup-field": name,
3848
3887
  "data-amplifyup-node-id": layoutNodeId || void 0,
3849
3888
  "data-amplifyup-empty-hint": showHint ? "true" : void 0,
3850
- contentEditable: !showRendered,
3889
+ contentEditable: !rich && !showRendered,
3851
3890
  suppressContentEditableWarning: true,
3852
3891
  role: "textbox",
3853
3892
  tabIndex: 0,
@@ -3858,12 +3897,20 @@ function ComposerInlineField({
3858
3897
  if (!isComposerEditMode()) return;
3859
3898
  const link = event.target?.closest?.("a");
3860
3899
  if (link) event.preventDefault();
3900
+ if (rich) {
3901
+ openRichEditor(event);
3902
+ return;
3903
+ }
3861
3904
  if (render) {
3862
3905
  setEditing(true);
3863
3906
  }
3864
3907
  },
3865
3908
  onFocus: () => {
3866
3909
  if (!isComposerEditMode()) return;
3910
+ if (rich) {
3911
+ openRichEditor();
3912
+ return;
3913
+ }
3867
3914
  setFocused(true);
3868
3915
  const el = elRef.current;
3869
3916
  if (el && storedEmpty) {
@@ -3872,7 +3919,7 @@ function ComposerInlineField({
3872
3919
  }
3873
3920
  if (render) setEditing(true);
3874
3921
  },
3875
- onBlur: finishEdit,
3922
+ onBlur: rich ? void 0 : finishEdit,
3876
3923
  onKeyDown: (event) => {
3877
3924
  event.stopPropagation();
3878
3925
  if (event.key === "Enter" && !event.shiftKey) {
@@ -3904,43 +3951,40 @@ function ComposerInlineField({
3904
3951
  function ComposerInlineHtml({
3905
3952
  name,
3906
3953
  html,
3954
+ sourceValue,
3907
3955
  className,
3908
3956
  Tag = "div",
3909
3957
  layoutNodeId,
3910
3958
  componentId
3911
3959
  }) {
3912
3960
  const elRef = React.useRef(null);
3913
- const sourceTextRef = React.useRef("");
3914
3961
  React.useEffect(() => {
3915
3962
  const el = elRef.current;
3916
3963
  if (!el) return;
3917
- if (document.activeElement === el || el.contains(document.activeElement)) {
3918
- return;
3919
- }
3920
3964
  if (el.innerHTML !== html) el.innerHTML = html;
3921
- sourceTextRef.current = (el.innerText ?? "").replace(/\u00a0/g, " ").trim();
3922
3965
  }, [html]);
3923
- const finishEdit = () => {
3924
- const el = elRef.current;
3925
- if (!el) return;
3926
- const nextHtml = el.innerHTML;
3927
- const nextText = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "").trim();
3928
- if (nextText === sourceTextRef.current && nextHtml === html) return;
3929
- const commitValue = htmlHasVisualChrome(html) || /<[a-z][\s\S]*>/i.test(html) ? nextHtml : nextText;
3930
- commitComposerField(layoutNodeId, componentId, name, commitValue);
3966
+ const openRichEditor = (event) => {
3967
+ if (!elRef.current) return;
3968
+ event.preventDefault();
3969
+ event.stopPropagation();
3970
+ requestCanvasRichTextEdit({
3971
+ el: elRef.current,
3972
+ layoutNodeId,
3973
+ componentId,
3974
+ name,
3975
+ value: sourceValue
3976
+ });
3931
3977
  };
3932
3978
  return React__default.default.createElement(Tag, {
3933
3979
  ref: elRef,
3934
3980
  className,
3935
3981
  "data-amplifyup-field": name,
3936
3982
  "data-amplifyup-node-id": layoutNodeId || void 0,
3937
- contentEditable: true,
3938
- suppressContentEditableWarning: true,
3939
3983
  dangerouslySetInnerHTML: { __html: html },
3940
3984
  onMouseDown: (event) => {
3941
3985
  event.stopPropagation();
3942
3986
  },
3943
- onBlur: finishEdit,
3987
+ onClick: openRichEditor,
3944
3988
  style: {
3945
3989
  cursor: "text",
3946
3990
  outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
@@ -4036,7 +4080,8 @@ function Field(props) {
4036
4080
  className,
4037
4081
  render,
4038
4082
  layoutNodeId: context.layoutNodeId,
4039
- componentId: context.componentId
4083
+ componentId: context.componentId,
4084
+ rich: looksLikeRichCanvasField(editName)
4040
4085
  }
4041
4086
  );
4042
4087
  }
@@ -4058,7 +4103,8 @@ function Field(props) {
4058
4103
  fallback,
4059
4104
  className,
4060
4105
  layoutNodeId: context.layoutNodeId,
4061
- componentId: context.componentId
4106
+ componentId: context.componentId,
4107
+ rich: looksLikeRichCanvasField(editName)
4062
4108
  }
4063
4109
  );
4064
4110
  }
@@ -4117,7 +4163,8 @@ function RichText(props) {
4117
4163
  fallback: typeof fallback === "string" || typeof fallback === "number" ? fallback : void 0,
4118
4164
  className,
4119
4165
  layoutNodeId: context?.layoutNodeId,
4120
- componentId: context?.componentId
4166
+ componentId: context?.componentId,
4167
+ rich: true
4121
4168
  }
4122
4169
  );
4123
4170
  }
@@ -4144,6 +4191,7 @@ function RichText(props) {
4144
4191
  {
4145
4192
  name: editName,
4146
4193
  html,
4194
+ sourceValue: typeof fieldValue === "string" ? fieldValue : html,
4147
4195
  className,
4148
4196
  Tag,
4149
4197
  layoutNodeId: context?.layoutNodeId,