@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/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/react.js +75 -27
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +75 -27
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -3692,11 +3692,6 @@ function isReactNodeFallback(fallback) {
|
|
|
3692
3692
|
function classNameIsBlock(className) {
|
|
3693
3693
|
return /(?:^|\s)block(?:\s|$)/.test(className || "");
|
|
3694
3694
|
}
|
|
3695
|
-
function htmlHasVisualChrome(html) {
|
|
3696
|
-
return /<(input|button|select|textarea|form|svg|iframe|video|audio|img)\b/i.test(
|
|
3697
|
-
html
|
|
3698
|
-
);
|
|
3699
|
-
}
|
|
3700
3695
|
function canInlineEdit(name, value) {
|
|
3701
3696
|
if (!name || isLikelyNonTextFieldName(name)) return false;
|
|
3702
3697
|
if (value !== void 0 && value !== null && typeof value === "object") {
|
|
@@ -3765,6 +3760,36 @@ function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
|
3765
3760
|
"*"
|
|
3766
3761
|
);
|
|
3767
3762
|
}
|
|
3763
|
+
function looksLikeRichCanvasField(name) {
|
|
3764
|
+
const tokens = String(name || "").replace(/([a-z])([A-Z])/g, "$1 $2").split(/[._\-\s/]+/).map((s) => s.toLowerCase()).filter(Boolean);
|
|
3765
|
+
const last = tokens[tokens.length - 1] || "";
|
|
3766
|
+
return last === "body" || last === "content" || last === "copy" || last === "excerpt" || last === "markdown" || last === "richtext";
|
|
3767
|
+
}
|
|
3768
|
+
var lastRichTextRequestAt = 0;
|
|
3769
|
+
function requestCanvasRichTextEdit(opts) {
|
|
3770
|
+
if (typeof window === "undefined" || window.parent === window) return;
|
|
3771
|
+
if (!opts.name) return;
|
|
3772
|
+
const now = Date.now();
|
|
3773
|
+
if (now - lastRichTextRequestAt < 400) return;
|
|
3774
|
+
lastRichTextRequestAt = now;
|
|
3775
|
+
const rect = opts.el.getBoundingClientRect();
|
|
3776
|
+
window.parent.postMessage(
|
|
3777
|
+
{
|
|
3778
|
+
type: "AMPLIFYUP_RICHTEXT_EDIT",
|
|
3779
|
+
layoutNodeId: opts.layoutNodeId,
|
|
3780
|
+
componentId: opts.componentId,
|
|
3781
|
+
fieldName: opts.name,
|
|
3782
|
+
value: opts.value,
|
|
3783
|
+
bounds: {
|
|
3784
|
+
top: rect.top,
|
|
3785
|
+
left: rect.left,
|
|
3786
|
+
width: Math.max(rect.width, 240),
|
|
3787
|
+
height: Math.max(rect.height, 64)
|
|
3788
|
+
}
|
|
3789
|
+
},
|
|
3790
|
+
"*"
|
|
3791
|
+
);
|
|
3792
|
+
}
|
|
3768
3793
|
function placeCaret(el, atStart = false) {
|
|
3769
3794
|
const range = document.createRange();
|
|
3770
3795
|
range.selectNodeContents(el);
|
|
@@ -3780,7 +3805,8 @@ function ComposerInlineField({
|
|
|
3780
3805
|
className,
|
|
3781
3806
|
render,
|
|
3782
3807
|
layoutNodeId,
|
|
3783
|
-
componentId
|
|
3808
|
+
componentId,
|
|
3809
|
+
rich = false
|
|
3784
3810
|
}) {
|
|
3785
3811
|
const [editing, setEditing] = useState(false);
|
|
3786
3812
|
const [focused, setFocused] = useState(false);
|
|
@@ -3833,6 +3859,19 @@ function ComposerInlineField({
|
|
|
3833
3859
|
if (!text && !storedEmpty && next === fallbackText) return;
|
|
3834
3860
|
commitComposerField(layoutNodeId, componentId, name, next);
|
|
3835
3861
|
};
|
|
3862
|
+
const openRichEditor = (event) => {
|
|
3863
|
+
if (!isComposerEditMode() || !elRef.current) return;
|
|
3864
|
+
event?.preventDefault();
|
|
3865
|
+
event?.stopPropagation();
|
|
3866
|
+
const source = typeof value === "string" && !storedEmpty ? value : text || "";
|
|
3867
|
+
requestCanvasRichTextEdit({
|
|
3868
|
+
el: elRef.current,
|
|
3869
|
+
layoutNodeId,
|
|
3870
|
+
componentId,
|
|
3871
|
+
name,
|
|
3872
|
+
value: source
|
|
3873
|
+
});
|
|
3874
|
+
};
|
|
3836
3875
|
return /* @__PURE__ */ jsx(
|
|
3837
3876
|
"span",
|
|
3838
3877
|
{
|
|
@@ -3841,7 +3880,7 @@ function ComposerInlineField({
|
|
|
3841
3880
|
"data-amplifyup-field": name,
|
|
3842
3881
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3843
3882
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
3844
|
-
contentEditable: !showRendered,
|
|
3883
|
+
contentEditable: !rich && !showRendered,
|
|
3845
3884
|
suppressContentEditableWarning: true,
|
|
3846
3885
|
role: "textbox",
|
|
3847
3886
|
tabIndex: 0,
|
|
@@ -3852,12 +3891,20 @@ function ComposerInlineField({
|
|
|
3852
3891
|
if (!isComposerEditMode()) return;
|
|
3853
3892
|
const link = event.target?.closest?.("a");
|
|
3854
3893
|
if (link) event.preventDefault();
|
|
3894
|
+
if (rich) {
|
|
3895
|
+
openRichEditor(event);
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3855
3898
|
if (render) {
|
|
3856
3899
|
setEditing(true);
|
|
3857
3900
|
}
|
|
3858
3901
|
},
|
|
3859
3902
|
onFocus: () => {
|
|
3860
3903
|
if (!isComposerEditMode()) return;
|
|
3904
|
+
if (rich) {
|
|
3905
|
+
openRichEditor();
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3861
3908
|
setFocused(true);
|
|
3862
3909
|
const el = elRef.current;
|
|
3863
3910
|
if (el && storedEmpty) {
|
|
@@ -3866,7 +3913,7 @@ function ComposerInlineField({
|
|
|
3866
3913
|
}
|
|
3867
3914
|
if (render) setEditing(true);
|
|
3868
3915
|
},
|
|
3869
|
-
onBlur: finishEdit,
|
|
3916
|
+
onBlur: rich ? void 0 : finishEdit,
|
|
3870
3917
|
onKeyDown: (event) => {
|
|
3871
3918
|
event.stopPropagation();
|
|
3872
3919
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
@@ -3898,43 +3945,40 @@ function ComposerInlineField({
|
|
|
3898
3945
|
function ComposerInlineHtml({
|
|
3899
3946
|
name,
|
|
3900
3947
|
html,
|
|
3948
|
+
sourceValue,
|
|
3901
3949
|
className,
|
|
3902
3950
|
Tag = "div",
|
|
3903
3951
|
layoutNodeId,
|
|
3904
3952
|
componentId
|
|
3905
3953
|
}) {
|
|
3906
3954
|
const elRef = useRef(null);
|
|
3907
|
-
const sourceTextRef = useRef("");
|
|
3908
3955
|
useEffect(() => {
|
|
3909
3956
|
const el = elRef.current;
|
|
3910
3957
|
if (!el) return;
|
|
3911
|
-
if (document.activeElement === el || el.contains(document.activeElement)) {
|
|
3912
|
-
return;
|
|
3913
|
-
}
|
|
3914
3958
|
if (el.innerHTML !== html) el.innerHTML = html;
|
|
3915
|
-
sourceTextRef.current = (el.innerText ?? "").replace(/\u00a0/g, " ").trim();
|
|
3916
3959
|
}, [html]);
|
|
3917
|
-
const
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3960
|
+
const openRichEditor = (event) => {
|
|
3961
|
+
if (!elRef.current) return;
|
|
3962
|
+
event.preventDefault();
|
|
3963
|
+
event.stopPropagation();
|
|
3964
|
+
requestCanvasRichTextEdit({
|
|
3965
|
+
el: elRef.current,
|
|
3966
|
+
layoutNodeId,
|
|
3967
|
+
componentId,
|
|
3968
|
+
name,
|
|
3969
|
+
value: sourceValue
|
|
3970
|
+
});
|
|
3925
3971
|
};
|
|
3926
3972
|
return React.createElement(Tag, {
|
|
3927
3973
|
ref: elRef,
|
|
3928
3974
|
className,
|
|
3929
3975
|
"data-amplifyup-field": name,
|
|
3930
3976
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3931
|
-
contentEditable: true,
|
|
3932
|
-
suppressContentEditableWarning: true,
|
|
3933
3977
|
dangerouslySetInnerHTML: { __html: html },
|
|
3934
3978
|
onMouseDown: (event) => {
|
|
3935
3979
|
event.stopPropagation();
|
|
3936
3980
|
},
|
|
3937
|
-
|
|
3981
|
+
onClick: openRichEditor,
|
|
3938
3982
|
style: {
|
|
3939
3983
|
cursor: "text",
|
|
3940
3984
|
outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
|
|
@@ -4030,7 +4074,8 @@ function Field(props) {
|
|
|
4030
4074
|
className,
|
|
4031
4075
|
render,
|
|
4032
4076
|
layoutNodeId: context.layoutNodeId,
|
|
4033
|
-
componentId: context.componentId
|
|
4077
|
+
componentId: context.componentId,
|
|
4078
|
+
rich: looksLikeRichCanvasField(editName)
|
|
4034
4079
|
}
|
|
4035
4080
|
);
|
|
4036
4081
|
}
|
|
@@ -4052,7 +4097,8 @@ function Field(props) {
|
|
|
4052
4097
|
fallback,
|
|
4053
4098
|
className,
|
|
4054
4099
|
layoutNodeId: context.layoutNodeId,
|
|
4055
|
-
componentId: context.componentId
|
|
4100
|
+
componentId: context.componentId,
|
|
4101
|
+
rich: looksLikeRichCanvasField(editName)
|
|
4056
4102
|
}
|
|
4057
4103
|
);
|
|
4058
4104
|
}
|
|
@@ -4111,7 +4157,8 @@ function RichText(props) {
|
|
|
4111
4157
|
fallback: typeof fallback === "string" || typeof fallback === "number" ? fallback : void 0,
|
|
4112
4158
|
className,
|
|
4113
4159
|
layoutNodeId: context?.layoutNodeId,
|
|
4114
|
-
componentId: context?.componentId
|
|
4160
|
+
componentId: context?.componentId,
|
|
4161
|
+
rich: true
|
|
4115
4162
|
}
|
|
4116
4163
|
);
|
|
4117
4164
|
}
|
|
@@ -4138,6 +4185,7 @@ function RichText(props) {
|
|
|
4138
4185
|
{
|
|
4139
4186
|
name: editName,
|
|
4140
4187
|
html,
|
|
4188
|
+
sourceValue: typeof fieldValue === "string" ? fieldValue : html,
|
|
4141
4189
|
className,
|
|
4142
4190
|
Tag,
|
|
4143
4191
|
layoutNodeId: context?.layoutNodeId,
|